From: Dmitry V. Levin Date: Sun, 29 Mar 2015 22:42:55 +0000 (+0000) Subject: Introduce macros for gcc attributes X-Git-Tag: v4.11~533 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c84d0b8363aeec9f89641c180d97902836fb0b6f;p=strace Introduce macros for gcc attributes Define macros for gcc attributes that are already in use or going to be used soon. * defs.h (GNUC_PREREQ, ATTRIBUTE_NORETURN, ATTRIBUTE_FORMAT, ATTRIBUTE_ALIGNED, ATTRIBUTE_PACKED, ATTRIBUTE_MALLOC, ATTRIBUTE_NOINLINE, ATTRIBUTE_ALLOC_SIZE): New macros. --- diff --git a/defs.h b/defs.h index 1d3d41d9..e1bf7a4d 100644 --- a/defs.h +++ b/defs.h @@ -67,8 +67,46 @@ const char *strerror(int); extern char *stpcpy(char *dst, const char *src); #endif -#if !defined __GNUC__ -# define __attribute__(x) /*nothing*/ +#if defined __GNUC__ && defined __GNUC_MINOR__ +# define GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +# define __attribute__(x) /* empty */ +# define GNUC_PREREQ(maj, min) 0 +#endif + +#if GNUC_PREREQ(2, 5) +# define ATTRIBUTE_NORETURN __attribute__((__noreturn__)) +#else +# define ATTRIBUTE_NORETURN /* empty */ +#endif + +#if GNUC_PREREQ(2, 7) +# define ATTRIBUTE_FORMAT(args) __attribute__((__format__ args)) +# define ATTRIBUTE_ALIGNED(arg) __attribute__((__aligned__(arg))) +# define ATTRIBUTE_PACKED __attribute__((__packed__)) +#else +# define ATTRIBUTE_FORMAT(args) /* empty */ +# define ATTRIBUTE_ALIGNED(arg) /* empty */ +# define ATTRIBUTE_PACKED /* empty */ +#endif + +#if GNUC_PREREQ(3, 0) +# define ATTRIBUTE_MALLOC __attribute__((__malloc__)) +#else +# define ATTRIBUTE_MALLOC /* empty */ +#endif + +#if GNUC_PREREQ(3, 1) +# define ATTRIBUTE_NOINLINE __attribute__((__noinline__)) +#else +# define ATTRIBUTE_NOINLINE /* empty */ +#endif + +#if GNUC_PREREQ(4, 3) +# define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args)) +#else +# define ATTRIBUTE_ALLOC_SIZE(args) /* empty */ #endif #ifndef offsetof