This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]