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 DF723BBAF for ; Sun, 14 Feb 2010 19:06:52 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAN/Jd0tQRFuw/2dsb2JhbACbHXS7HIRbBA X-IronPort-AV: E=Sophos;i="4.49,472,1262559600"; d="scan'208";a="44798675" Received: from furbychan.cocan.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 14 Feb 2010 19:06:52 +0100 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1Ngirq-0005va-1O; Sun, 14 Feb 2010 18:06:50 +0000 Date: Sun, 14 Feb 2010 18:06:50 +0000 To: Guillaume Yziquel Cc: OCaml List Subject: Re: [Caml-list] Wrapping var_args, or C ... in ocaml? Message-ID: <20100214180650.GA22433@annexia.org> References: <4B781ACC.4040603@citycable.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B781ACC.4040603@citycable.ch> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 0100,:01 guillaume:01 c-api:01 varargs:01 ocaml:01 variants:01 ncurses:01 printf:01 bindings:01 avoided:01 varargs:01 wrote:01 unix:01 unix:01 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