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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 8002CBBCA for ; Fri, 15 Feb 2008 21:46:56 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE+JtUfRVciujGdsb2JhbACQTgEBAQcFBgcKGJ1a X-IronPort-AV: E=Sophos;i="4.25,360,1199660400"; d="scan'208";a="7367428" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Feb 2008 21:46:56 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1FKku9r007491 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 15 Feb 2008 21:46:56 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE+JtUfRVciujGdsb2JhbACQTgEBAQcFBgcKGJ1a X-IronPort-AV: E=Sophos;i="4.25,360,1199660400"; d="scan'208";a="7367427" Received: from wf-out-1314.google.com ([209.85.200.174]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Feb 2008 21:46:55 +0100 Received: by wf-out-1314.google.com with SMTP id 26so175638wfd.0 for ; Fri, 15 Feb 2008 12:46:54 -0800 (PST) Received: by 10.142.203.13 with SMTP id a13mr2663885wfg.148.1203108414046; Fri, 15 Feb 2008 12:46:54 -0800 (PST) Received: by 10.142.173.18 with HTTP; Fri, 15 Feb 2008 12:46:54 -0800 (PST) Message-ID: <3a360f590802151246m7200b276q266c734ec8f5b84d@mail.gmail.com> Date: Fri, 15 Feb 2008 15:46:54 -0500 From: "Hezekiah M. Carty" Sender: hcarty@mulethief.com To: "Brian Hurt" Subject: Re: [Caml-list] camlidl and 2D arrays with the [out] attribute Cc: caml-list In-Reply-To: <47B5F2CA.6070809@janestcapital.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <3a360f590802151102s27f9a2f6i7d9877daa7c67249@mail.gmail.com> <47B5F2CA.6070809@janestcapital.com> X-Google-Sender-Auth: 87a626343f7811bd X-Miltered: at discorde with ID 47B5FA40.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlidl:01 arrays:01 camlidl:01 allocating:01 malloc:01 sizeof:01 pointer:01 pointer:01 bug:01 arrays:01 malloc:01 sizeof:01 pointers:01 allocating:01 ocaml:01 On Fri, Feb 15, 2008 at 3:15 PM, Brian Hurt wrote: > Hezekiah M. Carty wrote: > > >I am attempting to use camlidl to wrap a function with the following C > >prototype portion (see [1] for the full prototype): > > > >... void c_plriddata( ... int nptsx, ... int nptsy, [out, > >size_is(nptsx,nptsy)] double ** zg ...); > > > >There is a lot more in the full prototype [1], but these are the > >important bits for this question. In this form, the 2D zg array is > >not allocated as I would have expected. Rather than allocating a > >rectangular nptsx by nptsy array, the generated C is: > > > >zg = camlidl_malloc(nptsx * sizeof(double *), _ctx); > > > > > > > I think the problem is with your C code. zg is defined as a pointer to > a pointer- not a pointer to an array! And yes, Virginia, there is a > difference. If c_plriddata is accessing this pointer as a pointer to an > array, you probably have a bug in your C code. > > Brian > > The C code in question is from the PLplot library[1]. From what I understand, zg is treated as a two dimensional array in the c_plgriddata code - zg[i][j] to access an element. There are a set of functions plAlloc2dGrid(zg, xdim, ydim) and plFree2dGrid(zg, xdim, ydim) use in the C API which respectively allocate and free a 2D array using a (double** zg). I have written the interface for this c_plgriddata function by hand using these plAlloc2dGrid and plFree2dGrid functions, but I would like to be able to use camlidl to do the work instead. As I mentioned, camlidl works as I expected for other functions which take a (double**) argument with an [in] attribute and treat them as 2D double arrays. While it may not be possible, I would ideally like camlidl to do the same memory allocation for an [out] double** as it does for an [in] double **. As I mentioned in my post, camlidl currently generates this line to allocate zg when it has just an [out] attribute: zg = camlidl_malloc(nptsx * sizeof(double *), _ctx); Something along the lines of a set of camlidl_malloc(nptsy * sizeof(double), _ctx) calls for each of the nptsx double* pointers allocated in the above line should do the trick of allocating the appropriate memory. This is what camlidl does for parameters with an [in] attribute, since it needs to copy the OCaml float array array to a C 2D array. I do not know how to tell camlidl to do this for parameters with an [out] attribute, or if there is a way to tell it to do this. The c_plgriddata function does work properly in C applications and with my hand-written wrapper [2], so I don't think that the problem is in the PLplot library. Hez [1] - http://plplot.sf.net/ [2] - The working hand-written wrapper code: http://ocaml.pastewith.us/33 -- Hezekiah M. Carty Graduate Research Assistant University of Maryland Department of Atmospheric and Oceanic Science