Best explained with the diff that results in the generated "ocaml/nbd-c.c"
source file:
--- old 2023-04-21 10:44:30.192602608 +0200
+++ new 2023-04-21 10:51:46.582658399 +0200
@@ -205,7 +205,10 @@ extent_wrapper_locked (void *user_data,
metacontextv = caml_copy_string (metacontext);
offsetv = caml_copy_int64 (offset);
- entriesv = nbd_internal_ocaml_alloc_int64_from_uint32_array (entries, nr_entries);
+ entriesv = nbd_internal_ocaml_alloc_i64_from_u32_array (
+ entries,
+ nr_entries
+ );
errorv = caml_alloc_tuple (1);
Store_field (errorv, 0, Val_int (*error));
args[0] = metacontextv;
(1) "entries" is an API parameter name (of CBArrayAndLen type), so it can
be arbitrarily long; pre-patch, it is embedded three times in the same
line. Place each occurrence on a separate line.
(2) nbd_internal_ocaml_alloc_int64_from_uint32_array() is a humongous
function name even for libnbd standards, and even after change (1), it
will share a generated line with one instance of the API parameter
name. Rename "int64" to "i64" and "uint32" to
"u32" in the function's
name, to save some characters.
While at it, drop a superfluous (harmless) semicolon, dating back to
commit 9564dc52abac ("generator: Add OCaml bindings.", 2019-05-30).
Bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=2172516
Signed-off-by: Laszlo Ersek <lersek(a)redhat.com>
---
generator/OCaml.ml | 9 +++++++--
ocaml/helpers.c | 2 +-
ocaml/nbd-c.h | 3 +--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/generator/OCaml.ml b/generator/OCaml.ml
index fc29a6a43281..94ab1d589738 100644
--- a/generator/OCaml.ml
+++ b/generator/OCaml.ml
@@ -524,8 +524,13 @@ let
List.iter (
function
| CBArrayAndLen (UInt32 n, count) ->
- pr " %sv = nbd_internal_ocaml_alloc_int64_from_uint32_array (%s,
%s);\n"
- n n count;
+ pr " %sv = " n;
+ let fncol = output_column () in
+ let indent = spaces fncol in
+ pr "nbd_internal_ocaml_alloc_i64_from_u32_array (\n";
+ pr "%s %s,\n" indent n;
+ pr "%s %s\n" indent count;
+ pr "%s);\n" indent
| CBBytesIn (n, len) ->
pr " %sv = caml_alloc_initialized_string (%s, %s);\n" n len n
| CBInt n | CBUInt n ->
diff --git a/ocaml/helpers.c b/ocaml/helpers.c
index 8b4b6693a8f1..3361a6968a23 100644
--- a/ocaml/helpers.c
+++ b/ocaml/helpers.c
@@ -118,7 +118,7 @@ nbd_internal_ocaml_string_list (value ssv)
}
value
-nbd_internal_ocaml_alloc_int64_from_uint32_array (uint32_t *a, size_t len)
+nbd_internal_ocaml_alloc_i64_from_u32_array (uint32_t *a, size_t len)
{
CAMLparam0 ();
CAMLlocal2 (v, rv);
diff --git a/ocaml/nbd-c.h b/ocaml/nbd-c.h
index 8f46415ab16f..f853c84a7756 100644
--- a/ocaml/nbd-c.h
+++ b/ocaml/nbd-c.h
@@ -61,8 +61,7 @@ extern void nbd_internal_ocaml_raise_error (void) Noreturn;
extern void nbd_internal_ocaml_raise_closed (const char *func) Noreturn;
extern const char **nbd_internal_ocaml_string_list (value);
-extern value nbd_internal_ocaml_alloc_int64_from_uint32_array (uint32_t *,
- size_t);
+extern value nbd_internal_ocaml_alloc_i64_from_u32_array (uint32_t *, size_t);
extern void nbd_internal_unix_sockaddr_to_sa (value, struct sockaddr_storage *,
socklen_t *);
extern void nbd_internal_ocaml_exception_in_wrapper (const char *, value);