This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] tdestroy() should allow passing 'NULL' for 'freefct' callback
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Ivo Raisr <ivosh at ivosh dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 11 Jun 2013 10:16:15 +0200
- Subject: Re: [PATCH] tdestroy() should allow passing 'NULL' for 'freefct' callback
- References: <CANXv6=sw64PRodqTgArqUHQLTcQd8eEE_==6QHVHgLn52jh=1Q at mail dot gmail dot com>
On Fri, May 24, 2013 at 12:29:56AM +0200, Ivo Raisr wrote:
> 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
>From functional part this patch is mostly OK.
I realized that there is simpler way to do this. You could test in tdestroy
if freefct is null and set it to freenop.
There are several style issues, see:
http://sourceware.org/glibc/wiki/Style_and_Conventions
and post v2.
Ondra