w32: Always use standard instead of native format strings
PATCH 1/1 w32: Always use standard instead of native format strings
GLib 2.0 include files use __printf__ for the format attribute which resolves to native format strings on w32 hosts.
QEMU wants standard format strings instead of native format strings, so we simply change any declaration with __printf__ to use __gnu_printf__.
This works because all basic printf functions support both kinds of format strings.
This fixes a compiler warning:
qapi/string-output-visitor.c: In function ‘print_type_int’:qapi/string-output-visitor.c:34:5: warning: unknown conversion type character ‘l’ in format [-Wformat] qapi/string-output-visitor.c:34:5: warning: too many arguments for format [-Wformat-extra-args]
--- compiler.h | 5 +++++ 1 file changed, 5 insertions(+)
compiler.h +5 -0
@@ -44,6 +44,11 @@/* 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))) +# if defined(_WIN32) +/* Map __printf__ to __gnu_printf__ because we want standard format strings +* even when MinGW or GLib include files use __printf__. */ +# define __printf__ __gnu_printf__ +# endif # endif #if defined(_WIN32)#define GCC_WEAK __attribute__((weak))
Signature · 1 line
1.7.10
Stefan Hajnoczi
AppliedQuoted 12 lines · Stefan Weil
GLib 2.0 include files use
__printf__for the format attribute which resolves to native format strings on w32 hosts.QEMU wants standard format strings instead of native format strings, so we simply change any declaration with
__printf__to use__gnu_printf__.This works because all basic printf functions support both kinds of format strings.
This fixes a compiler warning:
Quoted 8 lines
qapi/string-output-visitor.c: In function ‘print_type_int’:qapi/string-output-visitor.c:34:5: warning: unknown conversion type character ‘l’ in format [-Wformat]qapi/string-output-visitor.c:34:5: warning: too many arguments for format [-Wformat-extra-args]Signed-off-by Stefan Weil <[email protected]>--- compiler.h | 5 +++++ 1 file changed, 5 insertions(+)
Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches
Stefan
Quoted 26 lines · Stefan Weil
GLib 2.0 include files use
__printf__for the format attribute which resolves to native format strings on w32 hosts.QEMU wants standard format strings instead of native format strings, so we simply change any declaration with
__printf__to use__gnu_printf__.This works because all basic printf functions support both kinds of format strings.
This fixes a compiler warning:
qapi/string-output-visitor.c: In function ‘print_type_int’:qapi/string-output-visitor.c:34:5: warning: unknown conversion type character ‘l’ in format [-Wformat]qapi/string-output-visitor.c:34:5: warning: too many arguments for format [-Wformat-extra-args]Signed-off-by Stefan Weil <[email protected]>--- compiler.h | 5 +++++ 1 file changed, 5 insertions(+)compiler.h +0
-0
compiler.h line 51
Quoted 8 lines
compiler.h +5
-0@@ -44,6 +44,11 @@/* 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))) +# if defined(_WIN32) +/* Map __printf__ to __gnu_printf__ because we want standard format strings +* even when MinGW or GLib include files use __printf__. */ +# define __printf__ __gnu_printf__ +# endif
Don't you need to make this conditional on the gcc version? That is, gcc 4.4 added __gnu_printf__, but gcc 4.3 understands only __printf__ and attempts to pass __gnu_printf__ will cause compilation failure.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Am 24.09.2012 21:28, schrieb Eric Blake:
Quoted 31 lines · Stefan Weil
Quoted 30 lines
GLib 2.0 include files use
__printf__for the format attribute which resolves to native format strings on w32 hosts.QEMU wants standard format strings instead of native format strings, so we simply change any declaration with
__printf__to use__gnu_printf__.This works because all basic printf functions support both kinds of format strings.
This fixes a compiler warning:
qapi/string-output-visitor.c: In function ‘print_type_int’:qapi/string-output-visitor.c:34:5: warning: unknown conversion type character ‘l’ in format [-Wformat]qapi/string-output-visitor.c:34:5: warning: too many arguments for format [-Wformat-extra-args]Signed-off-by Stefan Weil<[email protected]>--- compiler.h | 5 +++++ 1 file changed, 5 insertions(+)compiler.h +1
-0@@ -44,6 +44,11 @@/* 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))) +# if defined(_WIN32)
Quoted 9 lines
compiler.h line 51
Quoted 4 lines
compiler.h +4
-0+/* Map __printf__ to __gnu_printf__ because we want standard format strings +* even when MinGW or GLib include files use __printf__. */ +# define __printf__ __gnu_printf__ +# endif Don't you need to make this conditional on the gcc version? That is, gcc 4.4 added
__gnu_printf__, but gcc 4.3 understands only__printf__and attempts to pass__gnu_printf__will cause compilation failure.
It is conditional. The complete code is here:
# if !QEMU_GNUC_PREREQ(4, 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)))
# if defined(_WIN32)
/* Map __printf__ to __gnu_printf__ because we want standard format
strings
* even when MinGW or GLib include files use __printf__. */
# define __printf__ __gnu_printf__
# endif
# endifgcc 4.3 and older will still produce compiler warnings.