List Info

Thread: "ocaml_beginners"::[] camlidl




"ocaml_beginners"::[] camlidl
country flaguser name
United Kingdom
2008-03-06 13:12:51


Can someone point me to any significant projects using camlidl as
their main method for binding interfaces? And/or if you have written
a complex *.idl file can you share it with me? I'm hitting brick
walls trying to do some fairly common things and I'm wondering if my
whole approach is wrong.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] camlidl
country flaguser name
United Kingdom
2008-03-06 13:44:09

On Thursday 06 March 2008 19:12:51 Richard Jones wrote:
> Can someone point me to any significant projects using camlidl as
> their main method for binding interfaces? And/or if you have written
> a complex *.idl file can you share it with me? I'm hitting brick
> walls trying to do some fairly common things and I'm wondering if my
> whole approach is wrong.
>
> Rich.

Isaac Trotts tried to use camlidl to write (the attached) idlgl bindings to
OpenGL from OCaml. He was never happy enough with it to release it though:
Elliott Oti got further with GLCaml by writing a custom FFI generator rather
than using camlidl. Also, I believe Isaac had to tweak camlidl to get it to
do what he wanted.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] camlidl
country flaguser name
United States
2008-03-06 13:55:13

On Thu, Mar 6, 2008 at 2:12 PM, Richard Jones < rich%40annexia.org">richannexia.org> wrote:
&gt; Can someone point me to any significant projects using camlidl as
> their main method for binding interfaces? And/or if you have written
> a complex *.idl file can you share it with me? I'm hitting brick
&gt; walls trying to do some fairly common things and I'm wondering if my
> whole approach is wrong.
&gt;
> Rich.

I use camlidl to generate most of the bindings for a PLplot [1]
wrapper - http://ocaml-plplot.googlecode.com/ as well as for an HDF4
[2] wrapper. The HDF wrapper is not released yet as it still needs
more cleaning up, but the method is the same as for PLplot. The
ocaml-plplot code can be browsed at [3].

I start from an edited C header file (mainly commenting out functions
which can not be wrapped easily with camlidl) (plplot_h in [3]) then
process this header file with a Perl or OCaml program/script which
adds the proper annotations for camlidl (touchup.ml in [3]). The
output from that script/program can be seen in plplot_h.inc, and the
idl file is plplot.idl (both in [3]). Any functions which I want to
use from OCaml but which camlidl can not support easily I wrap by hand
in a separate C file (plplot_impl.c in [3]). plplot.idl also contains
a few lines for the functions I wrote in plplot_impl.c. Finally, I
wrote a short myocamlbuild.ml and libocaml_plplot.clib to build
everything using ocamlbuild. OCamlMakefile also has nice support for
projects using camlidl - I was using OCamlMakefile to build
ocaml-plplot until very recently.

There are a lot of steps here, but they have made writing bindings for
tens if not hundreds of functions reasonable. I only have to write a
few bindings by hand in each case, generally for handling callbacks or
void* which need to be cast appropriately (only in the HDF bindings).

I have also done these camlidl annotations by hand, but for each of
these libraries it was easier to write write a somewhat ugly script to
do most of the dirty work for me.

I hope this helps. Please feel free to ask if you have any questions
regarding details of how I implemented the PLplot bindings.

Hez

[1] - http://plplot.sf.net/
[2] - http://hdfgroup.org/
[3] - http://code.google.com/p/ocaml-plplot/source/browse/trunk/
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] camlidl
country flaguser name
United Kingdom
2008-03-06 17:18:02

Thanks to everyone who replied.

I'll be a bit more specific about what I'm trying to do and where I'm
having problems. The bindings are for newt, a text widget library.
This is the sparsely documented header file:

http://www.annexia.org/tmp/newt.h.txt

Specifics:

(1) Newt has a 'newtComponent' object. Components can be general
widgets like entry boxes, buttons and so on. Or they can be grids or
forms, both of which contain (recursively) other components.

The internals of the C library have absolutely zero type checking --
if you pass a button component to a function like newtFormSetSize
which expects a form, then it will probably segfault.

A high quality binding would use phantom types to enforce the types,
so:

val newtForm : ... -> [`Form|`Component]
val newtFormSetSize : [>`Form] -> unit

It's very hard to annotate this in camlidl (actually impossible - I
didn't find any way to do it satisfactorily).

(2) Newt uses callbacks, but it seems that function pointers aren't
implemented by camlidl.

(3) Newt lets you attach data to some components:

void newtListboxSetData (newtComponent co, int num, void *data);
void *newtListboxGetCurrent (newtComponent co);

High quality bindings like lablgtk make complex use of polymorphic
types to allow you to store and retrieve data safely, but for the
simpler listbox case above we might just want (ignoring my phantom
types above):

type 'a listbox
val newtListboxSetData : 'a listbox -> int -> 'a -> unit
val newtListboxGetCurrent : 'a listbox -> 'a

(4) NULL pointers & exceptions: If you bind pointers using [ref] then
you get a segfault when a function returns NULL (eg. indicating an
error). But if you don't do that you have to deal with Some/None
everywhere.

(5) Flags:

#define NEWT_FLAG_RETURNEXIT (1 << 0)
#define NEWT_FLAG_HIDDEN (1 << 1)
#define NEWT_FLAG_SCROLL (1 << 2)

Obviously these are meant to be or-ed together.

(6) A bunch of minor things:

- const correctness, camlidl doesn't have it
- unions -- are they supported at all?
- varargs?

OK so enough complaining. What I was thinking of doing was using
camlidl straight (as far as it goes) to make an unsafe NewtInt
internal binding, then wrapping a hand-written OCaml binding on top
which gives all the good stuff like type safety, finalization and
exceptions.

At this point I'm not sure how much work I'm saving ...

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )