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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E44CCBC0B for ; Fri, 8 Dec 2006 07:36:45 +0100 (CET) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.236]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kB86ajHG009041 for ; Fri, 8 Dec 2006 07:36:45 +0100 Received: by wx-out-0506.google.com with SMTP id i31so722004wxd for ; Thu, 07 Dec 2006 22:36:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rCvDYYoqgRUD7NAGaCVsVq8w2j4zL+jKpqbqR7yWwWlAre/rQy7njIqG7lozxDmqRUu285OrgNMMWRDYiD6w1BOg6HA/ph2G+ebklAAVyYNHr5LuwcLM7gQF9S+wrqe5HpvXtu3IC5zSfnka8gSjhgWxmnZC9zcm5m2cTg1P+T0= Received: by 10.90.75.10 with SMTP id x10mr1220725aga.1165559804744; Thu, 07 Dec 2006 22:36:44 -0800 (PST) Received: by 10.90.55.3 with HTTP; Thu, 7 Dec 2006 22:36:44 -0800 (PST) Message-ID: <875c7e070612072236s4b5e42c9qed9002c14959c409@mail.gmail.com> Date: Fri, 8 Dec 2006 01:36:44 -0500 From: "Chris King" To: "Erik de Castro Lopo" Subject: Re: [Caml-list] Creating wrappers for C libraries Cc: caml-list@inria.fr In-Reply-To: <20061208155437.7ed85c4f.mle+ocaml@mega-nerd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20061208155437.7ed85c4f.mle+ocaml@mega-nerd.com> X-j-chkmail-Score: MSGID : 457907FD.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 457907FD.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; wrappers:01 ocaml:01 ocaml:01 bindings:01 swig:01 swig:01 o'caml:01 o'caml:01 o'caml's:01 bigarrays:01 wrappers:01 1.3:98 wrote:01 integer:01 caml-list:01 On 12/7/06, Erik de Castro Lopo wrote: > I was wondering if there was any semi-automated too for creating > Ocaml bindings for C libraries. I recently discovered that SWIG (http://www.swig.org/) supports O'Caml (though I haven't yet used it myself). If you're looking for speed though it may not be the best choice since all C types are mapped to one variant type in O'Caml. You can find O'Caml-specific docs here: http://www.swig.org/Doc1.3/Ocaml.html I presume you're looking to wrap libsndfile... I've wrapped a few similar libraries manually with very few problems. The libsndfile API looks to me like it should be fairly straightforward to wrap thanks to O'Caml's Bigarrays (plus you'll have lots of cut & paste). Start by writing a few simple integer, string, or array functions for O'Caml in C to get a feel for the API without having to worry about custom blocks and such. The curses wrapper in chapter 18 of the O'Caml manual is also a very good starting point. The custom block from that example can be used nearly verbatim for many C structures (such as SNDFILE *). I can provide you with the source of a couple other small wrappers if you like. Hope this helps, Chris