From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 5BA3ABBAF for ; Sun, 14 Feb 2010 23:45:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjcBAH8LeEtV2gB4mWdsb2JhbACDBZgtAQEBAQEICwoHEyOsE448gTCCUFsEiWE X-IronPort-AV: E=Sophos;i="4.49,472,1262559600"; d="scan'208";a="44803898" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail3-smtp-sop.national.inria.fr with SMTP; 14 Feb 2010 23:45:44 +0100 Received: from [192.168.0.12] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id 8AB7512C302; Sun, 14 Feb 2010 23:45:42 +0100 (CET) Message-ID: <4B787D32.10505@citycable.ch> Date: Sun, 14 Feb 2010 23:46:10 +0100 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: Richard Jones Cc: OCaml List Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml? References: <4B781ACC.4040603@citycable.ch> <20100214180650.GA22433@annexia.org> In-Reply-To: <20100214180650.GA22433@annexia.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 ocaml:01 0100,:01 c-api:01 varargs:01 ocaml:01 variants:01 ncurses:01 printf:01 bindings:01 avoided:01 varargs:01 wrote:01 unix:01 Richard Jones a =C3=A9crit : > 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 wi= th=20 >> an ellipsis. Is this documented somewhere, or has someone already done= =20 >> something like this? >=20 > It really depends on the function and how it will be used. It > might translate to any of: >=20 > (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.h= tml) 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=20 trickery in the concept. It looks that it is C that is not mapping the=20 concept to its fullest potential. I mean, it seems that varargs means on the receiving end "the number of=20 arguments you'r giving me, as a function, is not limited", whereas on=20 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 limitati= on? --=20 Guillaume Yziquel http://yziquel.homelinux.org/