Version française
Home     About     Download     Resources     Contact us    
Browse thread
Camlidl questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christopher L Conway <cconway@c...>
Subject: Camlidl questions
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