8007770: fix name clash of assert macro in debug.hpp with libc's assert macro [Was: Re: Bug 100297 - [patch] fix name clash of assert macro in debug.hpp with libc's assert macro]

David Holmes david.holmes at oracle.com
Tue Feb 19 23:50:07 PST 2013


On 20/02/2013 4:33 PM, Dean Long wrote:
> On 2/19/2013 6:44 PM, David Holmes wrote:
>> If this is potentially a problem then I think we need to avoid it by
>> other means - most likely by bracketing standard includes with "#undef
>> assert" so that they are not affected by hotspot's definition, and our
>> source is not affected by the definition from assert.h
>>
>
> Can't we just do something like the following in debug.hpp?
>
> #include <assert.h>
> #undef assert
> #define assert(p, msg) \
> ...
>
> Any #include <assert.h> that happens after this should be a no-op
> because it was already included once.

Not true for assert.h. Every individual include of assert.h can be 
modified by setting NDEBUG, so assert.h does not use the "#ifndef 
_ASSERT_H" trick to only process the file once.

Plus if a standard header includes assert.h and uses assert, we probably 
don't want it to use the VM's assert. That said if we use the C 
libraries assert it probably won't work nicely with the VM. So we would 
probably need

#undef assert
#define NDEBUG
#include <otherstuff>
#undef NDEBUG
#undef assert

David

> dl
>
>> David
>> -----
>


More information about the hotspot-dev mailing list