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 9BBA8BC69 for ; Fri, 26 Oct 2007 22:36:30 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANrrIUdC+Vyokmdsb2JhbACOYQIBAQcEBBMW X-IronPort-AV: E=Sophos;i="4.21,335,1188770400"; d="scan'208";a="18666372" Received: from ug-out-1314.google.com ([66.249.92.168]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Oct 2007 22:36:30 +0200 Received: by ug-out-1314.google.com with SMTP id m3so704568ugc for ; Fri, 26 Oct 2007 13:36:29 -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:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; bh=WfRXleMFc9Ek8IGD4LSEa1TP52c4+TPIO3ctbLYBhLk=; b=gEkLrY495JmOcUqR3AOqjALZBhYKSzUKnpYq7sYWpy0jBQlaActdK2/3O+mWlnMMaxllvh8yJOqlsbPXBudQ+KxYalC/3W1R6teSRDHZMLXTI3LORy+z/Z/39NV8+sbUZ7KnXtcZ4CSVbDY6e2rRz+3NWC+itksZPry+qI/b7jw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=DpbWp+uIrlz0jIDereHFpSwjHDygUjTeMnsvAQnu1NmjW5372s3h1eQD0kj/rCML+hQWvHOYeii3e3QAsbauzy23IfvFSQ+Kvb5iOYA/BFXD7pCDsB3rEAoLsuPPgDWB1NnbUbNJDa5UBVNy8xDmVwIO6PenA2kHfCuwBqVhpTQ= Received: by 10.78.147.6 with SMTP id u6mr2639297hud.1193430986433; Fri, 26 Oct 2007 13:36:26 -0700 (PDT) Received: by 10.78.156.10 with HTTP; Fri, 26 Oct 2007 13:36:26 -0700 (PDT) Message-ID: <4a051d930710261336r33a4d3aycda32880c1663953@mail.gmail.com> Date: Fri, 26 Oct 2007 16:36:26 -0400 From: "Christopher L Conway" Sender: christopherleeconway@gmail.com To: caml-list Subject: Camlidl questions MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 9a08e39127912272 X-Spam: no; 0.00; camlidl:01 camlidl:01 foo:01 ocaml:01 foo:01 bool:01 stub:01 pointer:01 stub:01 allocates:01 ocaml:01 hand-written:01 inputs:01 allocating:01 functions:01 I'm trying to write an interface to an existing C library using Camlidl and I'm having trouble in just a few cases... The documentation and examples only go so far... The library has a function which returns a boolean and, if the result is true, populates an array with a set of "witnesses." The original function looks like: int foo(T x, U** y, int* n) where x is the input, *y will be the array of witnesses, and *n will be the length of *y. The desired type of the OCaml binding is foo : t -> bool * u array for which I've tried the Camlidl declaration boolean foo([in] T x, [out, size_is(*n), ref*] U** y, [ignore] int* n) This does indeed generate the desired type, but the stub is wrong. It tries to use *n to allocate the array _before_ calling foo in the C library. Camlidl seemingly can't distinguish between size_is as a pre-condition vs. a post-condition in this case. In contrast, if a C function returns a pointer to an array and has the size as an output parameter, Camlidl does the right thing. I.e., [size_is(*n)] U *bar([in] T x, [ignore] int* n) generates a binding bar : t -> u array and the stub code allocates the array after calling bar in the C library using *n, as expected. Is it possible to accomplish this without writing my own C stub? Note 1: It would be even better if the OCaml return type where something like: type foo_ret = No | Yes of u array Can Camlidl do this (again, without resorting to a hand-written stub)? Note 2: It's always nice to have lists at the OCaml level... It would be even better still (and this would apply to the inputs and outputs of many functions in the library, even without the behavior of foo) if the array could be transformed into a list... It wouldn't even be inefficient, since the stub is already allocating and copying over the entire array as it is. Can Camlidl do this? Any insight is appreciated. Thanks, Chris