caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Automatic wrapper generator
Date: Tue, 18 May 2004 13:11:47 +0100	[thread overview]
Message-ID: <20040518121147.GA20094@redhat.com> (raw)
In-Reply-To: <1084875941.19838.446.camel@pelican.wigram>

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!

Rich.

[1] The low-level interface:
http://www.merjis.com/developers/perl4caml/html/Perl.html

[2] Example of a high-level wrapper:
http://www.merjis.com/developers/perl4caml/html/Pl_HTML_Element.html
http://www.merjis.com/developers/perl4caml/html/Pl_HTML_Element.html_element.html

-- 
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


  reply	other threads:[~2004-05-18 12:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-18  8:38 skaller
2004-05-18  8:58 ` Richard Jones
2004-05-18 10:07   ` skaller
2004-05-18  9:06 ` Basile Starynkevitch local
2004-05-18 10:25   ` skaller
2004-05-18 12:11     ` Richard Jones [this message]
2004-05-18 17:21       ` Michael Hamburg
2004-05-18 18:34         ` skaller
2004-05-18 19:27           ` Richard Jones
2004-05-18 20:52             ` skaller
2004-05-18 20:02       ` Gerd Stolpmann
2004-05-18 20:10         ` [Caml-list] Functional critical section SWAMPY
2004-05-18 20:31           ` Kenneth Knowles
2004-05-18 20:39           ` Evan Martin
2004-05-19  7:35             ` thornber
2004-05-19  7:33           ` thornber
2004-05-18  9:25 ` [Caml-list] Automatic wrapper generator Olivier Andrieu
2004-05-18 10:36   ` skaller
2004-05-18  9:38 ` Fermin Reig
2004-05-18 10:42   ` skaller
2004-05-18 10:57     ` Felix Winkelmann
2004-05-18 10:58     ` John Chu
2004-05-18 11:33       ` skaller
2004-05-22 10:09 ` Marcin 'Qrczak' Kowalczyk
2004-05-22 13:13   ` skaller
2004-05-22 14:19     ` Marcin 'Qrczak' Kowalczyk
2004-05-22 16:14       ` skaller
2004-05-23 10:58         ` Marcin 'Qrczak' Kowalczyk
2004-05-23 19:59           ` skaller

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=20040518121147.GA20094@redhat.com \
    --to=rich@annexia.org \
    --cc=caml-list@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).