List:Internals« Previous MessageNext Message »
From:Mark Callaghan Date:July 20 2006 8:54pm
Subject:Re: Question about macro for __attribute__ in include/my_global.h
View as plain text  
I agree that my suggested change might not be correct with respect to 
which versions of gcc support what features for attribute. But it was 
good enough to let me check for format errors in the various print 
functions. I am also concerned that enabling use of the other 
attribute-based macros in my_global.h might be risky, but they don't 
appear to be used (yet).

And there is a missing format arg in join_read_last() in sql_select.cc 
in MySql 4.0.26. So all of this effort has not been wasted.

>       sql_print_error("read_last_with_key: Got error %d when reading table",
>                     error, table->path);


Marc Alff wrote:
> Hi Mark
> 
> Mark Callaghan wrote:
>> There is a macro in my_global.h that defines __attribute__ to be a no-op
>> when gcc is used. '__cplusplus' is defined when gcc3.2 and gcc3.4 are
>> used
>> to compile MySQL on Linux. The result of this is that the many uses of
>> __attribute__ are not available, including type-checking the format
>> args to
>> printf (and printf-like) statements.
>>
>> This is the macro in 4.0.26 and 5.1.11. Is this definition correct?
>>
>> #if !defined(__attribute__) && (defined(__cplusplus) ||
>> !defined(__GNUC__)
>> || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
>> #define __attribute__(A)
>> #endif
>>
>> If the macro were defined as this, then it would not be a no-op for gcc
>> versions >= 3.4
>>
>> #if !defined(__attribute__) && \
>>       (!defined(__GNUC__)  || \
>>             (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || \
>>             (defined(__cplusplus) && (__GNUC__ < 3 || __GNUC__ == 3
> &&
>> __GNUC_MINOR__ < 4)))
>> #define __attribute__(A)
>> #endif
>>
> 
> Good catch, verified by this quick test with 5.1-BK & GCC 3.4.6 :
> 
> #include "mysql_priv.h"
> 
> #ifdef __attribute__
> #error why, since I use GCC 3.4.6 which should be told about __attribute__
> #endif
> 
> 
> To add to the discussion and regarding version numbers, there are
> probably two things to consider :
> - which version of GCC supports the __attribute__ keyword
> - which version of GCC supports each attribute used (weak, unused,
> noreturn, etc)
> 
> For the first part, /usr/include/ansidecl.h on linux does it the
> following way
> (much simpler) :
> 
> #if (GCC_VERSION < 2007)
> # define __attribute__(x)
> #endif
> 
> For the second part, there is an example in MySQL :
> 
> /*
>   The following macros are used to control inlining a bit more than
>   usual. These macros are used to ensure that inlining always or
>   never occurs (independent of compilation mode).
>   For more input see GCC manual (available in GCC 3.1.1 and later)
> */
> 
> #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
> #define ALWAYS_INLINE __attribute__ ((always_inline))
> #define NEVER_INLINE __attribute__ ((noinline))
> #else
> #define ALWAYS_INLINE
> #define NEVER_INLINE
> #endif
> 
> 
> /usr/include/ansidecl.h on Linux uses GCC_VERSION instead :
> 
> /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
> #ifndef ATTRIBUTE_MALLOC
> # if (GCC_VERSION >= 2096)
> #  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
> # else
> #  define ATTRIBUTE_MALLOC
> # endif /* GNUC >= 2.96 */
> #endif /* ATTRIBUTE_MALLOC */
> 
> So, I don't think a test on 3.4 should be part of the __attribute__ macro.
> If a specific attribute only introduced in 3.4
> is used, I would define helpers similar to ATTRIBUTE_MALLOC.
> 
> Regards,
> Marc Alff
> 
> 


-- 
Mark Callaghan
mcallaghan@stripped
650-253-2780
Thread
Question about macro for __attribute__ in include/my_global.hMark Callaghan20 Jul
  • Re: Question about macro for __attribute__ in include/my_global.hMarc Alff20 Jul
    • Re: Question about macro for __attribute__ in include/my_global.hMark Callaghan20 Jul