100 lines
3.5 KiB
Diff
100 lines
3.5 KiB
Diff
From fd4db60cffd9d0ece25a436932aca5411e13b94e Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Tue, 12 Aug 2025 14:05:44 +0100
|
|
Subject: [PATCH] generator: Implement StringList for OCaml functions
|
|
|
|
No existing OCaml functions have a StringList parameter, but we would
|
|
like to add one.
|
|
|
|
The original plan seems to have been to map these to 'string array'
|
|
types, but 'string list' is more natural, albeit marginally less
|
|
efficient. The implementation here just has to convert the 'char **'
|
|
into the OCaml linked list of values.
|
|
---
|
|
daemon/daemon-c.c | 24 ++++++++++++++++++++++++
|
|
daemon/daemon-c.h | 1 +
|
|
generator/daemon.ml | 6 ++++--
|
|
3 files changed, 29 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/daemon/daemon-c.c b/daemon/daemon-c.c
|
|
index 1754cf0d2..371c2a9e4 100644
|
|
--- a/daemon/daemon-c.c
|
|
+++ b/daemon/daemon-c.c
|
|
@@ -114,6 +114,30 @@ guestfs_int_daemon_copy_mountable (const mountable_t *mountable)
|
|
CAMLreturn (r);
|
|
}
|
|
|
|
+/* Implement StringList(...) parameter. */
|
|
+value
|
|
+guestfs_int_daemon_copy_string_list (char * const *strs)
|
|
+{
|
|
+ CAMLparam0 ();
|
|
+ CAMLlocal3 (v, tlv, rv);
|
|
+ size_t i;
|
|
+
|
|
+ /* We need to build the list backwards so start at the end. */
|
|
+ for (i = 0; strs[i] != NULL; ++i)
|
|
+ ;
|
|
+
|
|
+ while (i > 0) {
|
|
+ --i;
|
|
+ v = caml_copy_string (strs[i]);
|
|
+ rv = caml_alloc (2, 0);
|
|
+ Store_field (rv, 0, v);
|
|
+ Store_field (rv, 1, tlv);
|
|
+ tlv = rv;
|
|
+ }
|
|
+
|
|
+ CAMLreturn (rv);
|
|
+}
|
|
+
|
|
/* Implement RStringList. */
|
|
char **
|
|
guestfs_int_daemon_return_string_list (value retv)
|
|
diff --git a/daemon/daemon-c.h b/daemon/daemon-c.h
|
|
index 9b7085bce..b06efc0cf 100644
|
|
--- a/daemon/daemon-c.h
|
|
+++ b/daemon/daemon-c.h
|
|
@@ -29,6 +29,7 @@
|
|
|
|
extern void guestfs_int_daemon_exn_to_reply_with_error (const char *func, value exn);
|
|
extern value guestfs_int_daemon_copy_mountable (const mountable_t *mountable);
|
|
+extern value guestfs_int_daemon_copy_string_list (char * const *strs);
|
|
extern char **guestfs_int_daemon_return_string_list (value retv);
|
|
extern char *guestfs_int_daemon_return_string_mountable (value retv);
|
|
extern char **guestfs_int_daemon_return_string_mountable_list (value retv);
|
|
diff --git a/generator/daemon.ml b/generator/daemon.ml
|
|
index 6221531d2..2b74f3059 100644
|
|
--- a/generator/daemon.ml
|
|
+++ b/generator/daemon.ml
|
|
@@ -558,7 +558,7 @@ and generate_ocaml_daemon_prototype name (ret, args, optargs) =
|
|
| OInt n -> pr "?%s:int -> " n
|
|
| OInt64 n -> pr "?%s:int64 -> " n
|
|
| OString n -> pr "?%s:string -> " n
|
|
- | OStringList n -> pr "?%s:string array -> " n
|
|
+ | OStringList n -> pr "?%s:string list -> " n
|
|
) optargs;
|
|
if args <> [] then
|
|
List.iter (
|
|
@@ -566,7 +566,7 @@ and generate_ocaml_daemon_prototype name (ret, args, optargs) =
|
|
| String (typ, _) -> pr "%s -> " (type_for_stringt typ)
|
|
| BufferIn _ -> pr "string -> "
|
|
| OptString _ -> pr "string option -> "
|
|
- | StringList (typ, _) -> pr "%s array -> " (type_for_stringt typ)
|
|
+ | StringList (typ, _) -> pr "%s list -> " (type_for_stringt typ)
|
|
| Bool _ -> pr "bool -> "
|
|
| Int _ -> pr "int -> "
|
|
| Int64 _ | Pointer _ -> pr "int64 -> "
|
|
@@ -820,6 +820,8 @@ let generate_daemon_caml_stubs () =
|
|
pr "guestfs_int_daemon_copy_mountable (%s)" n
|
|
| String _ -> assert false
|
|
| OptString _ -> assert false
|
|
+ | StringList ((PlainString|Filename|Pathname), n) ->
|
|
+ pr "guestfs_int_daemon_copy_string_list (%s)" n
|
|
| StringList _ -> assert false
|
|
| BufferIn _ -> assert false
|
|
| Pointer _ -> assert false
|
|
--
|
|
2.47.1
|
|
|