mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
committed by
rwmjones
parent
ed40333a23
commit
fd4db60cff
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user