[PATCH 4/7] Move libc_freeres_ptrs and libc_subfreeres to weak functions

Florian Weimer fweimer@redhat.com
Mon Dec 12 14:05:41 GMT 2022


* Adhemerval Zanella Netto:

>> I think you should consider introducing a call_free_static_weak that
>> does something like
>> 
>>   if (&ptr != NULL)
>>     free (ptr);
>> 
>> in the static case, and calls
>> 
>>   free (ptr);
>> 
>> unconditionally for the dynamic case.  And then add attribute_hidden
>> variable declarations to a suitable wrapper header under include/.
>> 
>> This avoids writing all these little helper functions.
>
> We already have call_free_static_weak function that does exactly that,

I don't see call_free_static_weak?

> maybe you are proposing a something like:
>
> # ifdef SHARED
> #  define declare_libc_freeres (name, ptr) \
> static void name (void) { free (ptr); }
> # else 
> #  define declare_libc_freeres (name, ptr) \
> static void name (void) { if (ptr != NULL) free (ptr); }
> # endif

It has to be &ptr != NULL for the weak case, and you also need to create
a weak alias.

Thanks,
Florian



More information about the Libc-alpha mailing list