Page MenuHomeFreeBSD

Improve typing of POSIX search tree functions.
ClosedPublic

Authored by ed on Oct 9 2016, 4:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Apr 24 2024, 9:01 AM
Unknown Object (File)
Apr 20 2024, 3:58 AM
Unknown Object (File)
Apr 20 2024, 3:55 AM
Unknown Object (File)
Mar 10 2024, 9:57 PM
Unknown Object (File)
Mar 10 2024, 9:57 PM
Unknown Object (File)
Mar 10 2024, 9:52 PM
Unknown Object (File)
Mar 7 2024, 10:10 PM
Unknown Object (File)
Jan 28 2024, 12:04 AM
Subscribers

Details

Summary

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 through the notes
of the last two meetings, they are actually making some good progress in
this area now. A new type 'posix_tnode' is being added to correspond to
tree nodes. It will still be 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.

Even though the next version of POSIX will only be released years from
now, go ahead and implement it now. It improves the readability of the
code and the documentation.

Austin Group bug report: http://austingroupbugs.net/view.php?id=1011

Note to reviewers: I will only commit this change when the bug in the
Austin group bug tracker is marked as fixed.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ed retitled this revision from to Improve typing of POSIX search tree functions..
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added reviewers: emaste, wblock.

Looks like Austin Groups bug 1011 has been resolved, proposing the same changes as described in the meeting notes. This means that we can go ahead with this change.

Any feedback?

This revision was automatically updated to reflect the committed changes.

For the record: I like the change, but did not have time to review in detail.

head/lib/libc/stdlib/tsearch.3
145

The "it" is not needed here:

but is expected to be standardized by future versions of the standard.
151

The "it" here is unclear, suggested rearrangement:

makes distinguishing between nodes and keys easier.