caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Christopher L Conway" <cconway@cs.nyu.edu>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Camlidl questions
Date: Fri, 26 Oct 2007 16:36:26 -0400	[thread overview]
Message-ID: <4a051d930710261336r33a4d3aycda32880c1663953@mail.gmail.com> (raw)

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


             reply	other threads:[~2007-10-26 20:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 20:36 Christopher L Conway [this message]
2007-10-27  8:43 ` [Caml-list] " Daniel Bünzli
2007-10-27 16:45   ` Richard Jones
2007-10-27 23:27     ` Chris Conway
2007-10-28 21:48       ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a051d930710261336r33a4d3aycda32880c1663953@mail.gmail.com \
    --to=cconway@cs.nyu.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).