From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 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 D8D66BC6B for ; Fri, 21 Dec 2007 12:20:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAGowa0dQRFuw/2dsb2JhbACRVZdE X-IronPort-AV: E=Sophos;i="4.24,194,1196636400"; d="scan'208";a="7144104" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 21 Dec 2007 12:20:09 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lBLBK96w023850 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 21 Dec 2007 12:20:09 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAGowa0dQRFuw/2dsb2JhbACRVZdE X-IronPort-AV: E=Sophos;i="4.24,194,1196636400"; d="scan'208";a="7144103" Received: from furbychan.cocan.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP; 21 Dec 2007 12:20:08 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1J5fvC-0004nt-00 for ; Fri, 21 Dec 2007 11:20:06 +0000 Date: Fri, 21 Dec 2007 11:20:06 +0000 To: caml-list@inria.fr Subject: Re: [Caml-list] Easier FFI Message-ID: <20071221112006.GA10879@furbychan.cocan.org> References: <200712201639.15513.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200712201639.15513.jon@ffconsultancy.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at discorde with ID 476BA169.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ffi:01 unfocused:01 ocaml:01 ocaml:01 segfault:01 enum:01 runtime:01 type-safe:01 bindings:01 ocaml':01 bindings:01 camlp:01 type-safe:01 gcc:01 compile-time:01 I've got flu at the moment so apologies about this slightly unfocused laundry-list ... Lessons from ocaml-libvirt: [Line numbers refer to this file: http://hg.et.redhat.com/virt/applications/virt-top--devel?f=c29881e5aa70;file=libvirt/libvirt_c.c ] (1) You need to be able to link to multiple versions of a dynamic library. Programs written in OCaml, using ocaml-libvirt, can link to any libvirt.so >= 0.2.1, even to *future* versions of libvirt.so. At the very least you need to be able to find out if a function exists in the dynamic library, and turn non-existance into an OCaml exception (instead of a dynamic linker segfault). [lines 65-143, example on lines 560-578] (2) In this library and in ODE, C objects contain implicit relationships with each other, and use reference counting to free themselves. This had to be modelled by making the implicit references explicit in OCaml (so the GC knows about them). [lines 168-208] (3) Some libvirt API calls are long-running and need enter_blocking_section / leave_blocking_section around them. Others are short-running and so don't. [lines 47-57] (4) You can't assume that a library won't add more values to the end of an enum, particularly if you allow yourself to link to a later version of the library than you compile against. [lines 1826-1889] On the subject of 'ctypes': perl4caml offers two 'levels' of access to Perl code. At the low level you can directly load / instantiate Perl packages and objects. This low level is unsafe -- it can throw runtime type exceptions -- but requires no explicit binding code at all. If you see a Perl library which you like, as long as it is installed on your system an OCaml program can use it. There's also a higher level where you can write OCaml code which uses Perl objects in a type-safe way, but that requires someone to write bindings for the Perl library. However does a 'ctypes for OCaml' need to be type unsafe. PG'OCaml (my PostgreSQL bindings for OCaml) does this with a camlp4 preprocessor which processes the SQL statements embedded in the OCaml code, checks the types of the arguments / return values with the database, and generates inline type-safe code. If there was a way to take a block of C code, work out what types it requires (using something like gcc? CIL?), then you could generate compile-time type-safe bindings for inline C code. That would be a marvellous thing to have ... Rich. -- Richard Jones Red Hat