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

Re: [Xen-devel] [PATCH 08/28] libxc: ocaml: add simple binding for xentoollog (output only).

> I think we should avoid returning "bare pointers" to the OCaml heap for two
> reasons:

I see, thanks for pointing that out.

> Instead of returning a "bare pointer" I think we should use a "Custom"
> value. This involves declaring a "struct custom_operations" like this:
>    static struct custom_operations foo_custom_operations = {
>       "foo_custom_operations",
>       custom_finalize_default,
>       custom_compare_default,
>       custom_hash_default,
>       custom_serialize_default,
>       custom_deserialize_default
>    };
> And then wrapping and unwrapping "Custom" blocks using something like:
>    #define Foo_val(x) (*((struct foo *)Data_custom_val(x)))
>    static value
>    Val_foo (struct foo *x)
>    {
>      CAMLparam0 ();
>      CAMLlocal1 (result);
>      result = caml_alloc_custom (&foo_custom_operations,
>                                 sizeof (struct foo*), 0, 1);
>      Foo_val (result) = x;
>      CAMLreturn (result);
>   }

I'll update all occurrences of this pattern. The same think happens for the 
libxl context as well.


> It's also worth considering whether to use the finalizer support to
> automatically free the underlying C resource when the last reference to it
> from OCaml has been GCed. This would be safer than exposing a direct
> "free" function in the OCaml interface, since it would prevent use-after-
> free.

Agreed. I'll try this.


Xen-devel mailing list



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