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

Jose Fonseca jfonseca at vmware.com
Mon Sep 7 06:54:08 PDT 2015


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:


   class AtExit
   {
   public:
      ~AtExit() {
          // do what must be done
       }
   };

   AtExit atExit();


After all, it seems wrong to use non-standard C to replicate what 
standard C++ can do.


Jose



More information about the mesa-stable mailing list