[Libguestfs] [PATCH libnbd v2 5/5] lib: Use unsigned for pread_structured status parameter.

Richard W.M. Jones rjones at redhat.com
Wed Jul 24 16:54:43 UTC 2019


This is a bitmask so using an unsigned type is slightly safer.  This
is not an ABI change since the types are compatible.

Thanks: Eric Blake.
---
 examples/strict-structured-reads.c |  2 +-
 generator/generator                | 67 ++++++++++++++++--------------
 interop/structured-read.c          |  2 +-
 lib/internal.h                     |  2 +-
 tests/oldstyle.c                   |  2 +-
 5 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/examples/strict-structured-reads.c b/examples/strict-structured-reads.c
index a996a67..2279301 100644
--- a/examples/strict-structured-reads.c
+++ b/examples/strict-structured-reads.c
@@ -53,7 +53,7 @@ static int total_success;
 static int
 read_chunk (unsigned valid_flag, void *opaque,
             const void *bufv, size_t count, uint64_t offset,
-            int status, int *error)
+            unsigned status, int *error)
 {
   struct data *data = opaque;
   struct range *r, **prev;
diff --git a/generator/generator b/generator/generator
index 34ca3f1..d46e8d6 100755
--- a/generator/generator
+++ b/generator/generator
@@ -1348,7 +1348,7 @@ protocol extensions).";
     args = [ BytesOut ("buf", "count"); UInt64 "offset";
              Closure { cbname="chunk";
                        cbargs=[BytesIn ("subbuf", "count");
-                               UInt64 "offset"; Int "status";
+                               UInt64 "offset"; UInt "status";
                                Mutable (Int "error")] };
              Flags "flags" ];
     ret = RErr;
@@ -1751,7 +1751,7 @@ cause a deadlock.";
              Closure { cbname="chunk";
                        cbargs=[BytesIn ("subbuf", "count");
                                UInt64 "offset";
-                               Int "status";
+                               UInt "status";
                                Mutable (Int "error");]};
              Flags "flags" ];
     ret = RInt64;
@@ -1772,7 +1772,7 @@ documented in C<nbd_pread_structured>.";
              Closure { cbname="chunk";
                        cbargs=[BytesIn ("subbuf", "count");
                                UInt64 "offset";
-                               Int "status";
+                               UInt "status";
                                Mutable (Int "error"); ]};
              Closure { cbname="callback";
                        cbargs=[Int64 "cookie";
@@ -3789,8 +3789,8 @@ let print_python_binding name { args; ret } =
             pr "    for (size_t i = 0; i < %s; ++i)\n" len;
             pr "      PyList_SET_ITEM (py_%s, i, PyLong_FromUnsignedLong (%s[i]));\n" n n
          | BytesIn _
-           | Int _
-           | Int64 _ -> ()
+         | Int _
+         | Int64 _ -> ()
          | Mutable (Int n) ->
             pr "    PyObject *py_%s_modname = PyUnicode_FromString (\"ctypes\");\n" n;
             pr "    if (!py_%s_modname) { PyErr_PrintEx (0); return -1; }\n" n;
@@ -3799,15 +3799,16 @@ let print_python_binding name { args; ret } =
             pr "    if (!py_%s_mod) { PyErr_PrintEx (0); return -1; }\n" n;
             pr "    PyObject *py_%s = PyObject_CallMethod (py_%s_mod, \"c_int\", \"i\", *%s);\n" n n n;
             pr "    if (!py_%s) { PyErr_PrintEx (0); return -1; }\n" n;
-         | String n
-           | UInt64 n -> ()
+         | String _
+         | UInt _
+         | UInt64 _ -> ()
          (* The following not yet implemented for callbacks XXX *)
          | ArrayAndLen _ | Bool _ | BytesOut _
            | BytesPersistIn _ | BytesPersistOut _
            | Closure _
            | Flags _ | Mutable _
            | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+           | UInt32 _ -> assert false
          ) cbargs;
        pr "\n";
 
@@ -3820,6 +3821,7 @@ let print_python_binding name { args; ret } =
          | Int64 n -> pr " \"L\""
          | Mutable (Int n) -> pr " \"O\""
          | String n -> pr " \"s\""
+         | UInt n -> pr " \"I\""
          | UInt64 n -> pr " \"K\""
          (* The following not yet implemented for callbacks XXX *)
          | ArrayAndLen _ | Bool _ | BytesOut _
@@ -3827,7 +3829,7 @@ let print_python_binding name { args; ret } =
            | Closure _
            | Flags _ | Mutable _
            | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+           | UInt32 _ -> assert false
          ) cbargs;
        pr " \")\"";
        List.iter (
@@ -3836,15 +3838,15 @@ let print_python_binding name { args; ret } =
          | BytesIn (n, len) -> pr ", %s, (int) %s" n len
          | Mutable (Int n) -> pr ", py_%s" n
          | Int n | Int64 n
-           | String n
-           | UInt64 n -> pr ", %s" n
+         | String n
+         | UInt n | UInt64 n -> pr ", %s" n
          (* The following not yet implemented for callbacks XXX *)
          | ArrayAndLen _ | Bool _ | BytesOut _
            | BytesPersistIn _ | BytesPersistOut _
            | Closure _
            | Flags _ | Mutable _
            | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+           | UInt32 _ -> assert false
          ) cbargs;
        pr ");\n";
        pr "    Py_INCREF (py_args);\n";
@@ -3877,16 +3879,16 @@ let print_python_binding name { args; ret } =
             pr "    Py_DECREF (py_%s_ret);\n" n;
             pr "    Py_DECREF (py_%s);\n" n
          | BytesIn _
-           | Int _ | Int64 _
-           | String _
-           | UInt64 _ -> ()
+         | Int _ | Int64 _
+         | String _
+         | UInt _ | UInt64 _ -> ()
          (* The following not yet implemented for callbacks XXX *)
          | ArrayAndLen _ | Bool _ | BytesOut _
            | BytesPersistIn _ | BytesPersistOut _
            | Closure _
            | Flags _ | Mutable _
            | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+           | UInt32 _ -> assert false
          ) cbargs;
        pr "  }\n";
        pr "\n";
@@ -4600,8 +4602,8 @@ let print_ocaml_binding (name, { args; ret }) =
          List.map (
            function
            | ArrayAndLen (UInt32 n, _) | BytesIn (n, _)
-             | Int n | Int64 n
-             | Mutable (Int n) | String n | UInt64 n ->
+           | Int n | Int64 n
+           | Mutable (Int n) | String n | UInt n | UInt64 n ->
               n ^ "v"
            (* The following not yet implemented for callbacks XXX *)
            | ArrayAndLen _ | Bool _ | BytesOut _
@@ -4609,7 +4611,7 @@ let print_ocaml_binding (name, { args; ret }) =
              | Closure _
              | Flags _ | Path _ | Mutable _
              | SockAddrAndLen _ | StringList _
-             | UInt _ | UInt32 _ -> assert false
+             | UInt32 _ -> assert false
            ) cbargs in
 
        pr "/* Wrapper for %s callback of %s. */\n" cbname name;
@@ -4634,7 +4636,7 @@ let print_ocaml_binding (name, { args; ret }) =
          | BytesIn (n, len) ->
             pr "  %sv = caml_alloc_string (%s);\n" n len;
             pr "  memcpy (String_val (%sv), %s, %s);\n" n n len
-         | Int n ->
+         | Int n | UInt n ->
             pr "  %sv = Val_int (%s);\n" n n
          | Int64 n ->
             pr "  %sv = caml_copy_int64 (%s);\n" n n
@@ -4651,7 +4653,7 @@ let print_ocaml_binding (name, { args; ret }) =
            | Closure _
            | Flags _ | Mutable _
            | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+           | UInt32 _ -> assert false
          ) cbargs;
 
        List.iteri (fun i n -> pr "  args[%d] = %s;\n" i n) argnames;
@@ -4663,21 +4665,22 @@ let print_ocaml_binding (name, { args; ret }) =
 
        List.iter (
          function
-         | ArrayAndLen (UInt32 n, count) -> ()
-         | BytesIn (n, len) -> ()
-         | Int n -> ()
-         | Int64 n -> ()
-         | String n -> ()
-         | UInt64 n -> ()
+         | ArrayAndLen (UInt32 _, _)
+         | BytesIn _
+         | Int _
+         | Int64 _
+         | String _
+         | UInt _
+         | UInt64 _ -> ()
          | Mutable (Int n) ->
             pr "  *%s = Int_val (Field (%sv, 0));\n" n n
          (* The following not yet implemented for callbacks XXX *)
          | ArrayAndLen _ | Bool _ | BytesOut _
-           | BytesPersistIn _ | BytesPersistOut _
-           | Closure _
-           | Flags _ | Mutable _
-           | Path _ | SockAddrAndLen _ | StringList _
-           | UInt _ | UInt32 _ -> assert false
+         | BytesPersistIn _ | BytesPersistOut _
+         | Closure _
+         | Flags _ | Mutable _
+         | Path _ | SockAddrAndLen _ | StringList _
+         | UInt32 _ -> assert false
          ) cbargs;
 
        pr "  if (Is_exception_result (rv)) {\n";
diff --git a/interop/structured-read.c b/interop/structured-read.c
index e0e511b..4c6e619 100644
--- a/interop/structured-read.c
+++ b/interop/structured-read.c
@@ -50,7 +50,7 @@ struct data {
 static int
 read_cb (unsigned valid_flag, void *opaque,
          const void *bufv, size_t count, uint64_t offset,
-         int status, int *error)
+         unsigned status, int *error)
 {
   struct data *data = opaque;
   const char *buf = bufv;
diff --git a/lib/internal.h b/lib/internal.h
index 9d88f08..dd417ea 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -253,7 +253,7 @@ typedef int (*extent_fn) (unsigned valid_flag, void *user_data,
                           uint32_t *entries, size_t nr_entries, int *error);
 typedef int (*read_fn) (unsigned valid_flag, void *user_data,
                         const void *buf, size_t count,
-                        uint64_t offset, int status, int *error);
+                        uint64_t offset, unsigned status, int *error);
 typedef int (*callback_fn) (unsigned valid_flag, void *user_data,
                             int64_t cookie, int *error);
 
diff --git a/tests/oldstyle.c b/tests/oldstyle.c
index cb0d435..95e1c97 100644
--- a/tests/oldstyle.c
+++ b/tests/oldstyle.c
@@ -39,7 +39,7 @@ static const char *progname;
 static int
 pread_cb (unsigned valid_flag, void *data,
           const void *buf, size_t count, uint64_t offset,
-          int status, int *error)
+          unsigned status, int *error)
 {
   int *calls;
 
-- 
2.22.0




More information about the Libguestfs mailing list