Browse thread
Wrapping var_args, or C ... in ocaml?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2010-02-14 (22:45) |
From: | Guillaume Yziquel <guillaume.yziquel@c...> |
Subject: | Re: [Caml-list] Wrapping var_args, or C ... in ocaml? |
Richard Jones a écrit : > On Sun, Feb 14, 2010 at 04:46:20PM +0100, Guillaume Yziquel wrote: >> Hello. >> >> I'm currently looking at: >> >> http://docs.python.org/c-api/arg.html >> >> and I would like to know how to wrap up C functions with va_list of with >> an ellipsis. Is this documented somewhere, or has someone already done >> something like this? > > It really depends on the function and how it will be used. It > might translate to any of: > > (1) A collection of functions implementing different aspects of the C > function. eg. The open(2) function in Unix is really a varargs > function, and depending on whether you want to open a file for input, > output, create, etc. you'd probably be better off with different > functions in OCaml. (Unix.openfile does _not_ do this ...) Not the case. > (2) A simple list, eg. for a C function that takes a NULL-terminated > list of strings. Could be. > (3) A variant list of variants, or option labels, eg. for a C function > that takes 'type, value'(s), such TIFFSetField in > libtiff. (http://www.remotesensing.org/libtiff/man/TIFFSetField.3tiff.html) No. > (4) Something very specialized, eg. the 'printw' function in ncurses > is like printf and so would need quite a tricky implementation in > OCaml. (Probably best to use ksprintf to convert to a string in OCaml > and then pass printw ("%s", str) in C). I do not think so. > In libguestfs where we autogenerate bindings we avoided varargs > altogether, because it's hard to map such a concept to all the > different languages we support. True. But, I mean, from the point of view of the ABI, there's not much trickery in the concept. It looks that it is C that is not mapping the concept to its fullest potential. I mean, it seems that varargs means on the receiving end "the number of arguments you'r giving me, as a function, is not limited", whereas on the sending end, you hard-code the number of arguments in your C code. Is there a way to map an OCaml list to an ellipsis? Or is it a C limitation? -- Guillaume Yziquel http://yziquel.homelinux.org/