Pino Toscano
2017-Jul-20 11:44 UTC
Re: [Libguestfs] [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
On Wednesday, 19 July 2017 22:25:41 CEST Richard W.M. Jones wrote:> On Wed, Jul 19, 2017 at 03:13:47PM +0200, Pino Toscano wrote: > > On Friday, 14 July 2017 15:39:10 CEST Richard W.M. Jones wrote: > > > .gitignore | 6 +- > > > Makefile.am | 2 +- > > > common/mlutils/Makefile.am | 4 - > > > daemon/Makefile.am | 103 +++++++++++++++++++++++-- > > > daemon/chroot.ml | 85 +++++++++++++++++++++ > > > daemon/chroot.mli | 35 +++++++++ > > > daemon/daemon-c.c | 35 +++++++++ > > > daemon/daemon.ml | 39 ++++++++++ > > > daemon/guestfsd.c | 50 ++++++++++++ > > > daemon/sysroot-c.c | 37 +++++++++ > > > daemon/sysroot.ml | 19 +++++ > > > daemon/sysroot.mli | 22 ++++++ > > > daemon/utils.ml | 156 +++++++++++++++++++++++++++++++++++++ > > > daemon/utils.mli | 65 ++++++++++++++++ > > > > TBH I'd just have a single "Daemon" module for the OCaml helpers for > > the daemon, instead of different modules, wirh a single -c.c file for > > all the C implementations. The Sysroot submodule could be implemented > > like the various submodules in Unix_utils. > > Do you mean Daemon.Chroot, Daemon.Sysroot etc?Yes, exactly.> > > +val f : t -> ('a -> 'b) -> 'a -> 'b > > > +(** Run a function in the chroot, returning the result or re-raising > > > + any exception thrown. *) > > > > After reading patch #11, IMHO there should be a variant that takes a > > generic (unit -> unit) function (called 'fn', maybe?), and have 'f' > > use it: > > > > let f t fun arg > > f (fun () -> fun arg) > > I'm a bit confused, do you have a compilable example?Not really without rewriting all of it, but I can improve the snippets. An interface like: val f : t -> ('a -> 'b) -> 'a -> 'b val fn : t -> (unit -> unit) -> 'a With the implementation like: let f t func arg fn (fun () -> func arg) let fn func ... let ret try Either (func ()) with exn -> Or exn in This way, when calling more more than a single-parameter function, it is slightly easier to read (IMHO, of course): let res = Chroot.f chroot (fun () -> ...) in than let res = Chroot.f chroot (fun () -> ...) () in This is mostly syntactic sugar.> > > +/* Convert an OCaml exception to a reply_with_error_errno call > > > + * as best we can. > > > + */ > > > +extern void ocaml_exn_to_reply_with_error (const char *func, value exn); > > > + > > > +void > > > +ocaml_exn_to_reply_with_error (const char *func, value exn) > > > +{ > > > > Shouldn't this use CAMLparam1 + CAMLreturn? > > It doesn't allocate on the OCaml heap so it should be safe. > > > > +let udev_settle ?filename () > > > > Ditto. > > ‘Ditto’ means bind the C udev_settle_* functions?Yes, that's correct. -- Pino Toscano
Richard W.M. Jones
2017-Jul-21 12:35 UTC
Re: [Libguestfs] [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
On Thu, Jul 20, 2017 at 01:44:14PM +0200, Pino Toscano wrote:> An interface like: > val f : t -> ('a -> 'b) -> 'a -> 'b > val fn : t -> (unit -> unit) -> 'aI'm still not very clear. In any case you can't [without using unsafe OCaml features] have an interface that returns 'a without some parameter also being polymorphic. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Pino Toscano
2017-Jul-24 11:04 UTC
Re: [Libguestfs] [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
On Friday, 21 July 2017 14:35:10 CEST Richard W.M. Jones wrote:> On Thu, Jul 20, 2017 at 01:44:14PM +0200, Pino Toscano wrote: > > An interface like: > > val f : t -> ('a -> 'b) -> 'a -> 'b > > val fn : t -> (unit -> unit) -> 'a > > I'm still not very clear. > > In any case you can't [without using unsafe OCaml features] have an > interface that returns 'a without some parameter also being > polymorphic.Ah ok, I see -- a pity IMHO. Thanks, -- Pino Toscano
Maybe Matching Threads
- Re: [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
- Re: [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
- Re: [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
- [PATCH 02/27] daemon: Allow parts of the daemon and APIs to be written in OCaml.
- Re: [PATCH 03/27] daemon: Reimplement ‘file’ API in OCaml.