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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id B4D07BC6B for ; Sun, 28 Oct 2007 14:48:54 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACowJEdA6ba+nmdsb2JhbACOYwIBAQcEBimBJw X-IronPort-AV: E=Sophos;i="4.21,338,1188770400"; d="scan'208";a="18699215" Received: from nf-out-0910.google.com ([64.233.182.190]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Oct 2007 14:48:54 +0100 Received: by nf-out-0910.google.com with SMTP id e27so959736nfd for ; Sun, 28 Oct 2007 06:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=i1TcXaexd3vLuowEQZTsgzptP/cw8BfF8byaNHLFjXg=; b=Fl6+0vDTrgSfja04MTTUxU7TQ58x7K40gRDhZvUAS6jEuyDJbizAIQdaS05RqtIwlc2rhk8Vtyhyx1t87n2wDIHFSTJEZuvll2uHms4Hz1j2n1e1sIE9Td22obh+OpUDVn6VObelXVnmTm4jwi/1He7xY1+UDRM605Tyeftv1cY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=L/U+jP6cSWWISNGe9CX9FVbDPc0d6IeDX96hoPE/id6LP05jxxJ6b2mRV293+KYszzwLSXjUTPUomTQAp2/3xImFlCE8VLi5XV6wWshkVCIudxBBB89puiH6NTeRSELv8ouzevAhcF7mP84ndpaLIL7K1HBjfnLYykKtLCQwxjs= Received: by 10.78.170.6 with SMTP id s6mr3574690hue.1193579330331; Sun, 28 Oct 2007 06:48:50 -0700 (PDT) Received: by 10.78.157.16 with HTTP; Sun, 28 Oct 2007 06:48:50 -0700 (PDT) Message-ID: <4a051d930710280648t72075b40r13d7a0fa225caece@mail.gmail.com> Date: Sun, 28 Oct 2007 09:48:50 -0400 From: "Christopher L Conway" Sender: christopherleeconway@gmail.com To: "David Teller" Subject: Re: [Caml-list] OCaml/C interface Cc: "Nathan Mishra Linger" , caml-list@yquem.inria.fr In-Reply-To: <1193575003.6383.19.camel@Blefuscu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20071026091806.GA10054@localhost> <1193575003.6383.19.camel@Blefuscu> X-Google-Sender-Auth: aab26589e54af332 X-Spam: no; 0.00; ocaml:01 swig:01 swig:01 ocaml:01 abstraction:01 untyped:01 ens-lyon:01 syntax:01 python's:01 prototyping:01 camlp:01 cheers:01 lib:01 beginner's:01 bug:01 This is very similar to what you would get from SWIG (http://www.swig.org/, OCaml support is in SVN): it generates a binding where each C function has type c_obj -> c_obj, where c_obj is more or less your c_type. Basically, this just hoists the problem up one level of abstraction, so that instead of writing C code using mltypes.h, you write OCaml code that massages effectively untyped values coming out of the library. Regards, Chris On 10/28/07, David Teller wrote: > I'm wondering how hard it would be to write a generic module for calling > C functions without having to write a specific wrapper. Something along > the lines of (with revised syntax) > > > type c_type = > [ TVoid > | TChar > | TInt32 > | TInt64 > | ... > | TStruct of list c_type > | TUnion of list c_type > | TPointer of c_type > | TArray of array c_type > | TString > | TWString > | ... > | TReclaimable of c_type > | TNotReclaimable of c_type > ]; > > type c_value = > [ Void > | TChar of char > | TInt32 of int32 > | ... > ]; > > type t; (*The type of a C function*) > > (** > Perform a dynamic link with a C function. > Evalutes to None in case of dynamic linking error. > *) > value acquire_function : ~name:string -> ~args:list c_type -> option t; > > (** > Actually perform the call. > *) > value call : t -> ~args:list c_type -> c_type; > > value release_value : c_value -> unit; > value release_function : t -> unit; > > Etc. > > Come to think about it, we could draw some inspiration from Python's > CTypes [1]. While it wouldn't be as safe as the current manner of > calling C from OCaml, it would be much more convenient at least for > prototyping. Plus, with a little Camlp4, it would make it possible to > write something like > > external "C" my_native_function = "char* stuff(char* a, char* b)" > > That was just a random thought, I have no particular interest in > implementing this, but what do you think about it ? > > Cheers, > David > > [1] http://docs.python.org/lib/module-ctypes.html > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >