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 CB383BC6B for ; Sun, 28 Oct 2007 13:36:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFoeJEdA6ba7kmdsb2JhbACOYwIBAQcCBimBKQ X-IronPort-AV: E=Sophos;i="4.21,338,1188770400"; d="scan'208";a="18697864" Received: from nf-out-0910.google.com ([64.233.182.187]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Oct 2007 13:36:39 +0100 Received: by nf-out-0910.google.com with SMTP id e27so953182nfd for ; Sun, 28 Oct 2007 05:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:subject:from:to:cc:in-reply-to:references:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding:sender; bh=SBb6uyKzbuvnwBVIGZuVsRrUHBecYHMRiwmtLkAG7jg=; b=YrepJePgv80PCa2UcMZ1Dkz5X1HO5iXiy1IRlugJyokymLNVmv0r+3pGKLk5cEGqfFR6hjOkT2Ch1gS/FC8zlZ5zj5D/rwJAcacJB5nt5hAreLTvcMxMxpeIWhsrxv+4xiyvcxwQ8DiI3E6HHIUdUJ3z4xLrA2TPKvYnmS7aaG0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:subject:from:to:cc:in-reply-to:references:content-type:date:message-id:mime-version:x-mailer:content-transfer-encoding:sender; b=Hf8FEE/bqCjMk7RZJcAUciCo9y0GYK1S2v7LsJNL6JRn/1lTpsiqzALkj5bM46GRGaNCLU0JZ+A7kqTe0dNya8gvQxuD/aYr3IEBu3Bn6nKvjOiiPAA/5IFnPKK9WrDqjDE0sBPI+TN718QalyVqyibwmIpWb6BANsXv+9HUbrQ= Received: by 10.86.50.8 with SMTP id x8mr3924004fgx.1193574998661; Sun, 28 Oct 2007 05:36:38 -0700 (PDT) Received: from ?192.168.0.12? ( [82.235.58.110]) by mx.google.com with ESMTPS id 13sm10154515fks.2007.10.28.05.36.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 28 Oct 2007 05:36:37 -0700 (PDT) Subject: Re: [Caml-list] OCaml/C interface From: David Teller To: Nathan Mishra Linger Cc: Julien Moutinho , caml-list@yquem.inria.fr In-Reply-To: References: <20071026091806.GA10054@localhost> Content-Type: text/plain Date: Sun, 28 Oct 2007 13:36:43 +0100 Message-Id: <1193575003.6383.19.camel@Blefuscu> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit Sender: David Teller X-Spam: no; 0.00; ocaml:01 ens-lyon:01 syntax:01 python's:01 ocaml:01 prototyping:01 camlp:01 cheers:01 lib:01 char:01 char:01 caml-list:01 functions:01 int:01 revised:02 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