[Mesa-stable] [Mesa-dev] [PATCH] ralloc: Use __attribute__((destructor)) instead of atexit(3)

Jose Fonseca jfonseca at vmware.com
Thu Sep 10 05:29:58 PDT 2015


On 10/09/15 02:54, Ian Romanick wrote:
> On 09/07/2015 06:54 AM, Jose Fonseca wrote:
>> On 07/09/15 10:17, Jean-Sébastien Pédron wrote:
>>> On 04.09.2015 01:37, Matt Turner wrote:
>>>> You need to test for this support in configure.ac. It's as simple as
>>>> adding a call to AX_GCC_FUNC_ATTRIBUTE in the existing alphabetized
>>>> list and then a little bit of preprocessor in src/util/macros.h.
>>>
>>> Should the code fallbacks on atexit(3) if the attribute is not
>>> supported?
>>
>> At least on Windows, with MSVC,  atexit should be the right thing to do,
>> since we statically link MSVC RunTime,
>>
>>
>>> Can I use the HAVE_FUNC_ATTRIBUTE_DESTRUCTOR macro in
>>> ralloc.c for this purpose?
>>
>> For the record, another alternative (way more portable), is you have a
>> simple .cpp file with a static destructior:
>
> Arg. :(  We used to have code that used this in several places, but that
> idiom has gradually been removed.  See c61bc6ed (although that was using
> a constructor to initialize instead of a destructor to free).  I don't
> care too much what idiom we pick, but I think we should pick one and
> stick with it.

It's not necessary to do it in several places, at least for the 
destructor -- we could have a single C++ module inside src/util, which 
provided a "dl_atexit".

I don't feel too strongly either way, but my impression is that the 
hassle of doing this with non-standard vendor-specific C extensions is 
greater than having a small C++ file somewhere.

For the constructor problem, we could just rely on the standard C11 
once_flag/call_once.

Jose


More information about the mesa-stable mailing list