Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
camlidl and 2D arrays with the [out] attribute
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-15 (19:02)
From: Hezekiah M. Carty <hcarty@a...>
Subject: camlidl and 2D arrays with the [out] attribute
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);

This is then passed in to the c_plgriddata function as-is, which in
turn causes a segmentation fault as c_plgriddata expects that zg has
already been fully allocated as a two dimensional double array.

If I add the "in" attribute to the zg argument in the annotated C
prototype, then camlidl fully allocates the required space.  I do not
want to have to do this, as the zg array is only needed as an output
from this function, not an input.

If there is no fix/solution to my problem with camlidl then I can
write the binding for this particular function by hand.  I would
prefer to keep the amount of hand-written C bindings I need to
maintain to a minimum.  camlidl has made wrapping almost all of the
rest of this library (PLplot) very straightforward.


[1] - Full function prototype:
[mlname(plgriddata)] void
c_plgriddata (
[in, size_is(npts)] double * x, [in, size_is(npts)] double * y,
[in, size_is(npts)] double * z, int npts,
[in, size_is(nptsx)] double * xg, int nptsx,
[in, size_is(nptsy)] double * yg, int nptsy,
[out, size_is(nptsx,nptsy)] double ** zg,
int type, double data);

Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science