aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ocaml
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2012-01-31 16:34:39 +0000
committerIan Campbell <ian.campbell@citrix.com>2012-01-31 16:34:39 +0000
commit427a35b7f1403c216ce73c68438f0081db1fd0d4 (patch)
tree4eb511ca6820e5e5655ff37abf1e3ab758dacfb7 /tools/ocaml
parentf80309d43143c81de1261d669e8b995e171ea73a (diff)
downloadxen-427a35b7f1403c216ce73c68438f0081db1fd0d4.tar.gz
xen-427a35b7f1403c216ce73c68438f0081db1fd0d4.tar.bz2
xen-427a35b7f1403c216ce73c68438f0081db1fd0d4.zip
ocaml: add helpers for Some/None option types.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/ocaml')
-rw-r--r--tools/ocaml/libs/xl/xenlight_stubs.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c
index 4b19e9a858..d3e4751a36 100644
--- 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 (caml_gc *gc, char ***c_val, value v)
#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_topologyinfo *c_val)
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);
}