qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings
@ 2012-08-22 19:42 Stefan Weil
  2012-09-23  6:39 ` Stefan Hajnoczi
  2012-09-24 19:28 ` Eric Blake
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Weil @ 2012-08-22 19:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, 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 <sw@weilnetz.de>
---
 compiler.h |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/compiler.h b/compiler.h
index 07ba1f8..c734a71 100644
--- a/compiler.h
+++ b/compiler.h
@@ -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))
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings
  2012-08-22 19:42 [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings Stefan Weil
@ 2012-09-23  6:39 ` Stefan Hajnoczi
  2012-09-24 19:28 ` Eric Blake
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2012-09-23  6:39 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, qemu-devel

On Wed, Aug 22, 2012 at 09:42:32PM +0200, Stefan Weil wrote:
> 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 <sw@weilnetz.de>
> ---
>  compiler.h |    5 +++++
>  1 file changed, 5 insertions(+)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings
  2012-08-22 19:42 [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings Stefan Weil
  2012-09-23  6:39 ` Stefan Hajnoczi
@ 2012-09-24 19:28 ` Eric Blake
  2012-09-24 19:45   ` Stefan Weil
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Blake @ 2012-09-24 19:28 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Blue Swirl, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]

On 08/22/2012 01:42 PM, Stefan Weil wrote:
> 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 <sw@weilnetz.de>
> ---
>  compiler.h |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/compiler.h b/compiler.h
> index 07ba1f8..c734a71 100644
> --- a/compiler.h
> +++ b/compiler.h
> @@ -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.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 617 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings
  2012-09-24 19:28 ` Eric Blake
@ 2012-09-24 19:45   ` Stefan Weil
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Weil @ 2012-09-24 19:45 UTC (permalink / raw)
  To: Eric Blake; +Cc: Blue Swirl, qemu-devel

Am 24.09.2012 21:28, schrieb Eric Blake:
> On 08/22/2012 01:42 PM, Stefan Weil wrote:
>> 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<sw@weilnetz.de>
>> ---
>>   compiler.h |    5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/compiler.h b/compiler.h
>> index 07ba1f8..c734a71 100644
>> --- a/compiler.h
>> +++ b/compiler.h
>> @@ -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.
>

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
# endif

gcc 4.3 and older will still produce compiler warnings.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-24 19:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-22 19:42 [Qemu-devel] [PATCH] w32: Always use standard instead of native format strings Stefan Weil
2012-09-23  6:39 ` Stefan Hajnoczi
2012-09-24 19:28 ` Eric Blake
2012-09-24 19:45   ` Stefan Weil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).