[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 4 of 9] ocaml: add helper's for Some/None option types



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1327512173 0
# Node ID 32e51774992b4d22b07f1ce3ab16880e33aa3794
# Parent  a7776e38447d4e633a45b926295f7923c046fbc9
ocaml: add helper's for Some/None option types.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c 
b/tools/ocaml/libs/xl/xenlight_stubs.c
--- a/tools/ocaml/libs/xl/xenlight_stubs.c
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c
@@ -130,6 +130,19 @@ static int string_string_tuple_array_val
 
 #endif
 
+/* Option type support as per 
http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php */
+#define Val_none Val_int(0)
+#define Some_val(v) Field(v,0)
+
+static value Val_some(value v)
+{
+       CAMLparam1(v);
+       CAMLlocal1(some);
+       some = caml_alloc(1, 0);
+       Store_field(some, 0, v);
+       CAMLreturn(some);
+}
+
 static value Val_mac (libxl_mac *c_val)
 {
        CAMLparam0();
@@ -205,14 +218,13 @@ static value Val_topologyinfo(libxl_topo
 
        topologyinfo = caml_alloc_tuple(c_val->coremap.entries);
        for (i = 0; i < c_val->coremap.entries; i++) {
-               v = Val_int(0); /* None */
+               v = Val_none;
                if (c_val->coremap.array[i] != LIBXL_CPUARRAY_INVALID_ENTRY) {
                        topology = caml_alloc_tuple(3);
                        Store_field(topology, 0, 
Val_int(c_val->coremap.array[i]));
                        Store_field(topology, 1, 
Val_int(c_val->socketmap.array[i]));
                        Store_field(topology, 2, 
Val_int(c_val->nodemap.array[i]));
-                       v = caml_alloc(1, 0); /* Some */
-                       Store_field(v, 0, topology);
+                       v = Val_some(topology);
                }
                Store_field(topologyinfo, i, v);
        }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.