]> granicus.if.org Git - strace/commitdiff
Introduce macros for gcc attributes
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 29 Mar 2015 22:42:55 +0000 (22:42 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 30 Mar 2015 00:32:56 +0000 (00:32 +0000)
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.

defs.h

diff --git a/defs.h b/defs.h
index 1d3d41d9b70e755c70cb6ba7e2f0b4aa2a49d880..e1bf7a4dc7be3a6bba23369e445d9a6217d61f13 100644 (file)
--- 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