[Libguestfs] [PATCHES] avoid more warnings

Jim Meyering jim at meyering.net
Fri Aug 28 13:17:32 UTC 2009


>From 23740528cd2d75a236aae1fb5d073e8be2e5a295 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 28 Aug 2009 13:43:16 +0200
Subject: [PATCH libguestfs 1/3] generator.ml: avoid warnings in generated ocaml/guestfs_c_actions.c

* src/generator.ml: Emit prototypes for ocaml_guestfs_* functions,
to avoid warnings from gcc -Wmissing-prototypes.  Normally we'd put
these somewhere else, but in this unusual case, they're not needed
anywhere else.  Handle the >5-argument case, too, for these:
ocaml_guestfs_test0_byte, ocaml_guestfs_sfdisk_byte,
ocaml_guestfs_sfdisk_N_byte.
---
 src/generator.ml |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/generator.ml b/src/generator.ml
index 46fcf2c..fa7d240 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6770,6 +6770,10 @@ copy_table (char * const * argv)
       let needs_extra_vs =
         match fst style with RConstOptString _ -> true | _ -> false in

+      pr "/* Emit prototype to appease gcc's -Wmissing-prototypes. */\n";
+      pr "CAMLprim value ocaml_guestfs_%s (value %s" name (List.hd params);
+      List.iter (pr ", value %s") (List.tl params); pr ");\n";
+
       pr "CAMLprim value\n";
       pr "ocaml_guestfs_%s (value %s" name (List.hd params);
       List.iter (pr ", value %s") (List.tl params);
@@ -6903,6 +6907,9 @@ copy_table (char * const * argv)
       pr "\n";

       if List.length params > 5 then (
+        pr "/* Emit prototype to appease gcc's -Wmissing-prototypes. */\n";
+        pr "CAMLprim value ";
+        pr "ocaml_guestfs_%s_byte (value *argv, int argn);\n" name;
         pr "CAMLprim value\n";
         pr "ocaml_guestfs_%s_byte (value *argv, int argn)\n" name;
         pr "{\n";
--
1.6.4.1.373.g81fb2


>From ba5842c1147f4463fce7f613618938fd5b9a1c1a Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 28 Aug 2009 13:53:36 +0200
Subject: [PATCH libguestfs 2/3] generator.ml: avoid defined-but-not-used warnings in guestfs_c_actions.c

* src/generator.ml (emit_ocaml_copy_list_function): New function.
Emit a function definition only if it will be used.
---
 src/generator.ml |   53 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/generator.ml b/src/generator.ml
index fa7d240..569e1a1 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6692,6 +6692,29 @@ copy_table (char * const * argv)
 ";

   (* Struct copy functions. *)
+
+  let emit_ocaml_copy_list_function typ =
+    pr "static CAMLprim value\n";
+    pr "copy_%s_list (const struct guestfs_%s_list *%ss)\n" typ typ typ;
+    pr "{\n";
+    pr "  CAMLparam0 ();\n";
+    pr "  CAMLlocal2 (rv, v);\n";
+    pr "  unsigned int i;\n";
+    pr "\n";
+    pr "  if (%ss->len == 0)\n" typ;
+    pr "    CAMLreturn (Atom (0));\n";
+    pr "  else {\n";
+    pr "    rv = caml_alloc (%ss->len, 0);\n" typ;
+    pr "    for (i = 0; i < %ss->len; ++i) {\n" typ;
+    pr "      v = copy_%s (&%ss->val[i]);\n" typ typ;
+    pr "      caml_modify (&Field (rv, i), v);\n";
+    pr "    }\n";
+    pr "    CAMLreturn (rv);\n";
+    pr "  }\n";
+    pr "}\n";
+    pr "\n";
+  in
+
   List.iter (
     fun (typ, cols) ->
       let has_optpercent_col =
@@ -6738,29 +6761,17 @@ copy_table (char * const * argv)
       pr "  CAMLreturn (rv);\n";
       pr "}\n";
       pr "\n";
-
-      pr "static CAMLprim value\n";
-      pr "copy_%s_list (const struct guestfs_%s_list *%ss)\n"
-        typ typ typ;
-      pr "{\n";
-      pr "  CAMLparam0 ();\n";
-      pr "  CAMLlocal2 (rv, v);\n";
-      pr "  int i;\n";
-      pr "\n";
-      pr "  if (%ss->len == 0)\n" typ;
-      pr "    CAMLreturn (Atom (0));\n";
-      pr "  else {\n";
-      pr "    rv = caml_alloc (%ss->len, 0);\n" typ;
-      pr "    for (i = 0; i < %ss->len; ++i) {\n" typ;
-      pr "      v = copy_%s (&%ss->val[i]);\n" typ typ;
-      pr "      caml_modify (&Field (rv, i), v);\n";
-      pr "    }\n";
-      pr "    CAMLreturn (rv);\n";
-      pr "  }\n";
-      pr "}\n";
-      pr "\n";
   ) structs;

+  (* Emit a copy_TYPE_list function definition only if that function is used. *)
+  List.iter (
+    function
+    | typ, (RStructListOnly | RStructAndList) ->
+        (* generate the function for typ *)
+        emit_ocaml_copy_list_function typ
+    | typ, _ -> () (* empty *)
+  ) rstructs_used;
+
   (* The wrappers. *)
   List.iter (
     fun (name, style, _, _, _, _, _) ->
--
1.6.4.1.373.g81fb2


>From de81a7d930a6a2ad558eff9396da20237e06ccc1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 28 Aug 2009 14:07:35 +0200
Subject: [PATCH libguestfs 3/3] generator.ml: avoid a warning about signed overflow in tests.c

* src/generator.ml: Emit "unsigned long int n_failed;" rather than
"int failed;", to avoid warning from gcc about "assuming signed
overflow does not occur when simplifying conditional to constant".
---
 src/generator.ml |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/generator.ml b/src/generator.ml
index 569e1a1..2e2b70e 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -5379,7 +5379,7 @@ static void print_table (char const *const *argv)
 int main (int argc, char *argv[])
 {
   char c = 0;
-  int failed = 0;
+  unsigned long int n_failed = 0;
   const char *filename;
   int fd;
   int nr_tests, test_num = 0;
@@ -5513,7 +5513,7 @@ int main (int argc, char *argv[])
       pr "  printf (\"%%3d/%%3d %s\\n\", test_num, nr_tests);\n" test_name;
       pr "  if (%s () == -1) {\n" test_name;
       pr "    printf (\"%s FAILED\\n\");\n" test_name;
-      pr "    failed++;\n";
+      pr "    n_failed++;\n";
       pr "  }\n";
   ) test_names;
   pr "\n";
@@ -5524,8 +5524,8 @@ int main (int argc, char *argv[])
   pr "  unlink (\"test3.img\");\n";
   pr "\n";

-  pr "  if (failed > 0) {\n";
-  pr "    printf (\"***** %%d / %%d tests FAILED *****\\n\", failed, nr_tests);\n";
+  pr "  if (n_failed > 0) {\n";
+  pr "    printf (\"***** %%lu / %%d tests FAILED *****\\n\", n_failed, nr_tests);\n";
   pr "    exit (1);\n";
   pr "  }\n";
   pr "\n";
--
1.6.4.1.373.g81fb2




More information about the Libguestfs mailing list