[PATCH] tdestroy() should allow passing 'NULL' for 'freefct' callback

Ivo Raisr ivosh@ivosh.net
Thu May 23 22:29:00 GMT 2013


This is a modest enhancement which would make lives of many developers
a bit more cheerful.

Glibc contains function tdestroy() which is not specified by any standard.
This function is very handy because it allows destroying whole binary
search tree at once.

However the 'freefct' callback cannot be NULL even if no work
is necessary (keys are integers, for example).
I can only speculate why it is so. The only valid reason might be performance:
  (*freefct) ((void *) root->key);
could be called directly in tdestroy_recurse() without checking for
non-NULL first.

However that puts unnecessary burden on the application developers,
although the manpage says that 'freefct' in that case must point to
an empty function. Even glibc itself has such empty function (freenoop).

Glibc should be more friendly in this case and allow passing NULL
for 'freefct".

Please kindly review the attached patch and let me know.
Ivo Raisr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-tdestroy-freefct-NULL.patch
Type: application/octet-stream
Size: 1881 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20130523/4e9c3d7c/attachment.obj>


More information about the Libc-alpha mailing list