diff options
author | ed <ed@FreeBSD.org> | 2016-10-29 14:41:22 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2016-10-29 14:41:22 +0000 |
commit | adae91bf0400dead60dcfa3476fdbb234db14e18 (patch) | |
tree | 96359a06310ef1f91c3a76c17d1cd738278f0e30 /lib/libc/tests/stdlib/tsearch_test.c | |
parent | 9e5cbc784b00f68c9ca71fdabd4b7deacfc6b34e (diff) | |
download | FreeBSD-src-adae91bf0400dead60dcfa3476fdbb234db14e18.zip FreeBSD-src-adae91bf0400dead60dcfa3476fdbb234db14e18.tar.gz |
MFC r307227 and r307343:
Improve typing of POSIX search tree functions.
Back in 2015 when I reimplemented these functions to use an AVL tree, I
was annoyed by the weakness of the typing of these functions. Both tree
nodes and keys are represented by 'void *', meaning that things like the
documentation for these functions are an absolute train wreck.
To make things worse, users of these functions need to cast the return
value of tfind()/tsearch() from 'void *' to 'type_of_key **' in order to
access the key. Technically speaking such casts violate aliasing rules.
I've observed actual breakages as a result of this by enabling features
like LTO.
I've filed a bug report at the Austin Group. Looking at the way the bug
got resolved, they made a pretty good step in the right direction. A new
type 'posix_tnode' has been added to correspond to tree nodes. It is
still defined as 'void' for source-level compatibility, but in the very
far future it could be replaced by a proper structure type containing a
key pointer.
Diffstat (limited to 'lib/libc/tests/stdlib/tsearch_test.c')
-rw-r--r-- | lib/libc/tests/stdlib/tsearch_test.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/tests/stdlib/tsearch_test.c b/lib/libc/tests/stdlib/tsearch_test.c index b08fd94..88c62f5 100644 --- a/lib/libc/tests/stdlib/tsearch_test.c +++ b/lib/libc/tests/stdlib/tsearch_test.c @@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$"); /* Validates the integrity of an AVL tree. */ static inline unsigned int -tnode_assert(const node_t *n) +tnode_assert(const posix_tnode *n) { unsigned int height_left, height_right; int balance; @@ -79,7 +79,7 @@ ATF_TC_BODY(tsearch_test, tc) keys[i] = i; /* Apply random operations on a binary tree and check the results. */ - void *root = NULL; + posix_tnode *root = NULL; bool present[NKEYS] = {}; for (int i = 0; i < NKEYS * 10; ++i) { int key = nrand48(random_state) % NKEYS; |