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

Re: [Xen-devel] [PATCH v6 03/11] libxl: ocaml: event management



On Tue, 2013-12-10 at 15:48 +0000, Rob Hoes wrote:

> > > +value stub_libxl_osevent_register_hooks(value ctx, value user) {
> > > + CAMLparam2(ctx, user);
> > > + CAMLlocal1(result);
> > > + libxl_osevent_hooks *hooks;
> > > + value *p;
> > > +
> > > + hooks = malloc(sizeof(*hooks));
> > > + if (!hooks)
> > > +         failwith_xl(ERROR_NOMEM, "cannot allocate osevent hooks");
> > > + hooks->fd_register = fd_register;
> > > + hooks->fd_modify = fd_modify;
> > > + hooks->fd_deregister = fd_deregister;
> > > + hooks->timeout_register = timeout_register;
> > > + hooks->timeout_modify = timeout_modify;
> > > + hooks->timeout_deregister = timeout_deregister;
> > > +
> > > + p = malloc(sizeof(value));
> > > + if (!p)
> > > +         failwith_xl(ERROR_NOMEM, "cannot allocate value");
> > > + *p = user;
> > > + caml_register_global_root(p);
> > > +
> > > + libxl_osevent_register_hooks(CTX, hooks, (void *) p);
> > > +
> > > + result = caml_alloc(1, Abstract_tag);
> > > + *((libxl_osevent_hooks **) result) = hooks;
> > > +
> > > + CAMLreturn(result);
> > 
> > Why do we need to return this results thing which is a pointer to the
> > hooks pointer? Something to do with keeping it live in the gc? Doesn't
> > that rely on the caller assigning it to a long lived variable so that it
> > isn't gc'd?
> 
> I think I made it return a pointer to the hooks, to be able to use it
> as a handle that we can give to a cleanup function. However, no such
> cleanup function currently exists (yet), and we don't actually use the
> return value.

Is this because changing the ocaml API in the future is a bit tricky? In
which case I suppose it is fine.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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