qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Avoid issue with pp-directive in macro
@ 2009-08-07 22:15 Bruce Rogers
  2009-08-08  1:44 ` Anthony Liguori
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Rogers @ 2009-08-07 22:15 UTC (permalink / raw)
  To: qemu-devel

When building for SLES10, I ran into a build failure which results from printf being a macro, and two files which have an #include preprocessing directive within the macro arguments.  There are other pp-directives,but the #include was the only one causing problems.  (This was with gcc 4.x btw.)

It is undefined behavior to include pp-directives within macro arguments, and pretty much any of the std-c defined functions can be implemented as macros, so this patch avoids the issue by ensuring we are not using the macro version in the problematic cases.

Signed-off-by: Bruce Rogers <brogers@novell.com>

 qemu-img.c |    2 +-
 vl.c       |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 070fe2e..581a908 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -58,7 +58,7 @@ static void format_print(void *opaque, const char *name)
 /* Please keep in synch with qemu-img.texi */
 static void help(void)
 {
-    printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+    (printf)("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
            "usage: qemu-img command [command options]\n"
            "QEMU disk image utility\n"
            "\n"
diff --git a/vl.c b/vl.c
index fdd4f03..0bea27f 100644
--- a/vl.c
+++ b/vl.c
@@ -4337,7 +4337,7 @@ static void version(void)
 static void help(int exitcode)
 {
     version();
-    printf("usage: %s [options] [disk_image]\n"
+    (printf)("usage: %s [options] [disk_image]\n"
            "\n"
            "'disk_image' is a raw hard image image for IDE hard disk 0\n"
            "\n"

^ permalink raw reply related	[flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Avoid issue with pp-directive in macro
@ 2009-08-10 17:30 Bruce Rogers
  0 siblings, 0 replies; 3+ messages in thread
From: Bruce Rogers @ 2009-08-10 17:30 UTC (permalink / raw)
  To: anthony; +Cc: qemu-devel

Is this any more palatable then?

Signed-off-by: Bruce Rogers <brogers@novell.com>
---
 qemu-img.c |   70 +++++++++++++++++++++++++++++++------------------------------
 vl.c       |   30 +++++++++++++-------------
 2 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 070fe2e..313b136 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -58,44 +58,46 @@ static void format_print(void *opaque, const char *name)
 /* Please keep in synch with qemu-img.texi */
 static void help(void)
 {
-    printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
-           "usage: qemu-img command [command options]\n"
-           "QEMU disk image utility\n"
-           "\n"
-           "Command syntax:\n"
+    static const char *msg =
+        "qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+        "usage: qemu-img command [command options]\n"
+        "QEMU disk image utility\n"
+        "\n"
+        "Command syntax:\n"
 #define DEF(option, callback, arg_string)        \
-           "  " arg_string "\n"
+        "  " arg_string "\n"
 #include "qemu-img-cmds.h"
 #undef DEF
 #undef GEN_DOCS
-           "\n"
-           "Command parameters:\n"
-           "  'filename' is a disk image filename\n"
-           "  'base_image' is the read-only disk image which is used as base for a copy on\n"
-           "    write image; the copy on write image only stores the modified data\n"
-           "  'output_base_image' forces the output image to be created as a copy on write\n"
-           "    image of the specified base image; 'output_base_image' should have the same\n"
-           "    content as the input's base image, however the path, image format, etc may\n"
-           "    differ\n"
-           "  'fmt' is the disk image format. It is guessed automatically in most cases\n"
-           "  'size' is the disk image size in kilobytes. Optional suffixes\n"
-           "    'M' (megabyte, 1024 * 1024) and 'G' (gigabyte, 1024 * 1024 * 1024) are\n"
-           "    supported any 'k' or 'K' is ignored\n"
-           "  'output_filename' is the destination disk image filename\n"
-           "  'output_fmt' is the destination format\n"
-           "  'options' is a comma separated list of format specific options in a\n"
-           "    name=value format. Use -o ? for an overview of the options supported by the\n"
-           "    used format\n"
-           "  '-c' indicates that target image must be compressed (qcow format only)\n"
-           "  '-h' with or without a command shows this help and lists the supported formats\n"
-           "\n"
-           "Parameters to snapshot subcommand:\n"
-           "  'snapshot' is the name of the snapshot to create, apply or delete\n"
-           "  '-a' applies a snapshot (revert disk to saved state)\n"
-           "  '-c' creates a snapshot\n"
-           "  '-d' deletes a snapshot\n"
-           "  '-l' lists all snapshots in the given image\n"
-           );
+        "\n"
+        "Command parameters:\n"
+        "  'filename' is a disk image filename\n"
+        "  'base_image' is the read-only disk image which is used as base for a copy on\n"
+        "    write image; the copy on write image only stores the modified data\n"
+        "  'output_base_image' forces the output image to be created as a copy on write\n"
+        "    image of the specified base image; 'output_base_image' should have the same\n"
+        "    content as the input's base image, however the path, image format, etc may\n"
+        "    differ\n"
+        "  'fmt' is the disk image format. It is guessed automatically in most cases\n"
+        "  'size' is the disk image size in kilobytes. Optional suffixes\n"
+        "    'M' (megabyte, 1024 * 1024) and 'G' (gigabyte, 1024 * 1024 * 1024) are\n"
+        "    supported any 'k' or 'K' is ignored\n"
+        "  'output_filename' is the destination disk image filename\n"
+        "  'output_fmt' is the destination format\n"
+        "  'options' is a comma separated list of format specific options in a\n"
+        "    name=value format. Use -o ? for an overview of the options supported by the\n"
+        "    used format\n"
+        "  '-c' indicates that target image must be compressed (qcow format only)\n"
+        "  '-h' with or without a command shows this help and lists the supported formats\n"
+        "\n"
+        "Parameters to snapshot subcommand:\n"
+        "  'snapshot' is the name of the snapshot to create, apply or delete\n"
+        "  '-a' applies a snapshot (revert disk to saved state)\n"
+        "  '-c' creates a snapshot\n"
+        "  '-d' deletes a snapshot\n"
+        "  '-l' lists all snapshots in the given image\n";
+
+    printf(msg);
     printf("\nSupported formats:");
     bdrv_iterate_format(format_print, NULL);
     printf("\n");
diff --git a/vl.c b/vl.c
index a526cb0..b173274 100644
--- a/vl.c
+++ b/vl.c
@@ -4339,26 +4339,28 @@ static void version(void)
 
 static void help(int exitcode)
 {
-    version();
-    printf("usage: %s [options] [disk_image]\n"
-           "\n"
-           "'disk_image' is a raw hard image image for IDE hard disk 0\n"
-           "\n"
+    static const char *msg = 
+        "usage: %s [options] [disk_image]\n"
+        "\n"
+        "'disk_image' is a raw hard image image for IDE hard disk 0\n"
+        "\n"
 #define DEF(option, opt_arg, opt_enum, opt_help)        \
-           opt_help
+        opt_help
 #define DEFHEADING(text) stringify(text) "\n"
 #include "qemu-options.h"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
-           "\n"
-           "During emulation, the following keys are useful:\n"
-           "ctrl-alt-f      toggle full screen\n"
-           "ctrl-alt-n      switch to virtual console 'n'\n"
-           "ctrl-alt        toggle mouse and keyboard grab\n"
-           "\n"
-           "When using -nographic, press 'ctrl-a h' to get some help.\n"
-           ,
+        "\n"
+        "During emulation, the following keys are useful:\n"
+        "ctrl-alt-f      toggle full screen\n"
+        "ctrl-alt-n      switch to virtual console 'n'\n"
+        "ctrl-alt        toggle mouse and keyboard grab\n"
+        "\n"
+        "When using -nographic, press 'ctrl-a h' to get some help.\n";
+
+    version();
+    printf(msg,
            "qemu",
            DEFAULT_RAM_SIZE,
 #ifndef _WIN32

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

end of thread, other threads:[~2009-08-10 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 22:15 [Qemu-devel] [PATCH] Avoid issue with pp-directive in macro Bruce Rogers
2009-08-08  1:44 ` Anthony Liguori
  -- strict thread matches above, loose matches on Subject: below --
2009-08-10 17:30 Bruce Rogers

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).