]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: ocaml: use the "string option" type for IDL strings
authorRob Hoes <rob.hoes@citrix.com>
Wed, 6 Nov 2013 17:49:53 +0000 (17:49 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 11 Nov 2013 15:39:39 +0000 (15:39 +0000)
The libxl IDL is based on C type "char *", and therefore "strings" can
by NULL, or be an actual string. In ocaml, it is common to encode such
things as option types.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Acked-by: David Scott <dave.scott@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/ocaml/libs/xl/genwrap.py
tools/ocaml/libs/xl/xenlight_stubs.c

index 5a3fd8d1eb2c44e027651ccce5abf82486e9da07..3d939d618cd4f3ed1ab0b7f1aa69de9586db3249 100644 (file)
@@ -8,7 +8,7 @@ import idl
 builtins = {
     "bool":                 ("bool",                   "%(c)s = Bool_val(%(o)s)",           "Val_bool(%(c)s)" ),
     "int":                  ("int",                    "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
-    "char *":               ("string",                 "%(c)s = dup_String_val(%(o)s)", "caml_copy_string(%(c)s)"),
+    "char *":               ("string option",          "%(c)s = String_option_val(%(o)s)",  "Val_string_option(%(c)s)"),
     "libxl_domid":          ("domid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_devid":          ("devid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_defbool":        ("bool option",            "%(c)s = Defbool_val(%(o)s)",        "Val_defbool(%(c)s)" ),
index 94601c47993623d90d3b8ebcfe5d3b87cd3cee54..372ce8f18236b96e9227bcaa92d80957e61fecbc 100644 (file)
@@ -347,6 +347,27 @@ static value Val_hwcap(libxl_hwcap *c_val)
        CAMLreturn(hwcap);
 }
 
+static value Val_string_option(const char *c_val)
+{
+       CAMLparam0();
+       CAMLlocal2(tmp1, tmp2);
+       if (c_val) {
+               tmp1 = caml_copy_string(c_val);
+               tmp2 = Val_some(tmp1);
+               CAMLreturn(tmp2);
+       }
+       else
+               CAMLreturn(Val_none);
+}
+
+static char *String_option_val(value v)
+{
+       char *s = NULL;
+       if (v != Val_none)
+               s = dup_String_val(Some_val(v));
+       return s;
+}
+
 #include "_libxl_types.inc"
 
 #define _STRINGIFY(x) #x