English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Automatic wrapper generator
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-05-18 (12:11)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Automatic wrapper generator
On Tue, May 18, 2004 at 08:25:41PM +1000, skaller wrote:
> Yes, it parses the whole of GTK2 and unistd.h and Xlib.h,
> 433 files total. I am not responsible for this though:
> the parsing is done by frontc, and the parse tree is then
> massaged by Cil. All I did here was repackage
> other peoples work.
> Some files don't parse correctly, and some
> have clashes, a couple are serious.
> Whether the resultant 'glue code' is correct 
> I do not know yet. The techniques are the same
> as the SWIG based generator I was using previously,
> and I managed to correctly call some gdk functions
> returning screen dimensions.

The actual problem with Gtk revolves (yet again) around memory
management.  Gtk uses a rather half-baked reference counting scheme.
The problems with this are similar to the problems with interfacing
Perl (see below).

> However at some stage, the only way to make a genuinely
> Ocaml centric version of a library such as Gtk is to write
> the wrapper code by hand.
> A low level generator is still useful though.
> It can help by importing the C interface into Ocaml,
> so at least you can try to do most of the remodelling
> to a higher level interface in Ocaml.

It sounds very similar to Perl4caml, which offers two levels of
interface.  At the lowest level you get to manipulate SVs, HVs and AVs
directly from OCaml [1].  You have to convert strings/ints to SVs when
calling Perl code (using sv_of_string, etc.), and when returning
values you have to convert them from SVs to OCaml native types (using
string_of_sv, etc.).  For some libraries I've written high-level
wrappers which do all this conversion for you, allowing you to use
objects and modules which look just like OCaml native objects [2].

Perl uses reference counting.  I still haven't worked out a scheme to
make reference counting behave well with the OCaml garbage collector,
so the current version of Perl4caml will never deallocate Perl objects
(there is an experimental makefile flag to turn deallocation on, but
this sometimes causes programs to crash).  I've tried wrapping the
Perl objects in custom blocks, but it doesn't work, and I'd appreciate
some help sorting it out!


[1] The low-level interface:

[2] Example of a high-level wrapper:

Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
http://www.winwinsales.co.uk/ - CRM improvement consultancy

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners