Patchwork Move macros GCC_ATTR and GCC_FMT_ATTR to common header file

login
register
mail settings
Submitter Stefan Weil
Date Sept. 20, 2010, 9:05 p.m.
Message ID <1285016702-31558-1-git-send-email-weil@mail.berlios.de>
Download mbox | patch
Permalink /patch/65254/
State New
Headers show

Comments

Stefan Weil - Sept. 20, 2010, 9:05 p.m.
By moving the definition of GCC_ATTR and GCC_FMT_ATTR
from audio_int.h to qemu-common.h these macros are
now generally available for further patches which add
the gcc format attribute.

Newer gcc versions support format gnu_printf which is
better suited for use in QEMU than format printf
(QEMU always uses standard format strings (even with mingw32)).

Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 audio/audio_int.h |    8 --------
 qemu-common.h     |   16 ++++++++++++++++
 2 files changed, 16 insertions(+), 8 deletions(-)
Stefan Weil - Sept. 21, 2010, 5:46 p.m.
Please ignore this patch. It's wrong (= instead of ==).
I'll send a fixed version.

Sorry,
Stefan

Am 20.09.2010 23:05, schrieb Stefan Weil:
> By moving the definition of GCC_ATTR and GCC_FMT_ATTR
> from audio_int.h to qemu-common.h these macros are
> now generally available for further patches which add
> the gcc format attribute.
>
> Newer gcc versions support format gnu_printf which is
> better suited for use in QEMU than format printf
> (QEMU always uses standard format strings (even with mingw32)).
>
> Cc: Blue Swirl<blauwirbel@gmail.com>
> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
> ---
>   audio/audio_int.h |    8 --------
>   qemu-common.h     |   16 ++++++++++++++++
>   2 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/audio/audio_int.h b/audio/audio_int.h
> index f6a77ad..d8560b6 100644
> --- a/audio/audio_int.h
> +++ b/audio/audio_int.h
> @@ -236,14 +236,6 @@ static inline int audio_ring_dist (int dst, int src, int len)
>       return (dst>= src) ? (dst - src) : (len - src + dst);
>   }
>
> -#if defined __GNUC__
> -#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2)))
> -#define GCC_FMT_ATTR(n, m) __attribute__ ((format (gnu_printf, n, m)))
> -#else
> -#define GCC_ATTR /**/
> -#define GCC_FMT_ATTR(n, m)
> -#endif
> -
>   static void GCC_ATTR dolog (const char *fmt, ...)
>   {
>       va_list ap;
> diff --git a/qemu-common.h b/qemu-common.h
> index 956b545..8a2872a 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -70,6 +70,22 @@ struct iovec {
>   #include<sys/uio.h>
>   #endif
>
> +#if defined __GNUC__
> +# if (__GNUC__<  4) || \
> +     defined(__GNUC_MINOR__)&&  (__GNUC__ = 4)&&  (__GNUC_MINOR__<  4)
> +   /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
> +#  define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
> +#  define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
> +# else
> +   /* Use gnu_printf when supported (qemu uses standard format strings). */
> +#  define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
> +#  define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
> +# endif
> +#else
> +#define GCC_ATTR /**/
> +#define GCC_FMT_ATTR(n, m)
> +#endif
> +
>   #ifdef _WIN32
>   #define fsync _commit
>   #define lseek _lseeki64
>

Patch

diff --git a/audio/audio_int.h b/audio/audio_int.h
index f6a77ad..d8560b6 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -236,14 +236,6 @@  static inline int audio_ring_dist (int dst, int src, int len)
     return (dst >= src) ? (dst - src) : (len - src + dst);
 }
 
-#if defined __GNUC__
-#define GCC_ATTR __attribute__ ((__unused__, format (gnu_printf, 1, 2)))
-#define GCC_FMT_ATTR(n, m) __attribute__ ((format (gnu_printf, n, m)))
-#else
-#define GCC_ATTR /**/
-#define GCC_FMT_ATTR(n, m)
-#endif
-
 static void GCC_ATTR dolog (const char *fmt, ...)
 {
     va_list ap;
diff --git a/qemu-common.h b/qemu-common.h
index 956b545..8a2872a 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -70,6 +70,22 @@  struct iovec {
 #include <sys/uio.h>
 #endif
 
+#if defined __GNUC__
+# if (__GNUC__ < 4) || \
+     defined(__GNUC_MINOR__) && (__GNUC__ = 4) && (__GNUC_MINOR__ < 4)
+   /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
+#  define GCC_ATTR __attribute__((__unused__, format(printf, 1, 2)))
+#  define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
+# else
+   /* Use gnu_printf when supported (qemu uses standard format strings). */
+#  define GCC_ATTR __attribute__((__unused__, format(gnu_printf, 1, 2)))
+#  define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
+# endif
+#else
+#define GCC_ATTR /**/
+#define GCC_FMT_ATTR(n, m)
+#endif
+
 #ifdef _WIN32
 #define fsync _commit
 #define lseek _lseeki64