From: Richard Jones <rich@annexia.org>
To: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
Cc: OCaml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml?
Date: Sun, 14 Feb 2010 18:06:50 +0000 [thread overview]
Message-ID: <20100214180650.GA22433@annexia.org> (raw)
In-Reply-To: <4B781ACC.4040603@citycable.ch>
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 ...)
(2) A simple list, eg. for a C function that takes a NULL-terminated
list of strings.
(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)
(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).
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.
Rich.
--
Richard Jones
Red Hat
next prev parent reply other threads:[~2010-02-14 18:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-14 15:46 Guillaume Yziquel
2010-02-14 18:06 ` Richard Jones [this message]
2010-02-14 20:26 ` [Caml-list] " Richard Jones
2010-02-14 22:46 ` Guillaume Yziquel
2010-02-14 22:59 ` Richard Jones
2010-02-14 23:13 ` Guillaume Yziquel
2010-02-14 23:19 ` Richard Jones
2010-02-15 1:34 ` Guillaume Yziquel
2010-02-15 2:37 ` Thomas Fischbacher
2010-02-14 23:31 ` Richard Jones
2010-02-15 10:16 ` Florent Monnier
[not found] ` <201002151106.23642.fmonnier@linux-nantes.fr.eu.org>
[not found] ` <4B7F3FED.4010100@citycable.ch>
2010-02-20 2:41 ` Guillaume Yziquel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100214180650.GA22433@annexia.org \
--to=rich@annexia.org \
--cc=caml-list@inria.fr \
--cc=guillaume.yziquel@citycable.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).