building stubs and modules from ANSI C include files

jeff (jsparkes@bnr.ca)
Tue, 19 Sep 1995 11:03:00 -0400

Date:  Tue, 19 Sep 1995 11:03:00 -0400 
From: "jeff (j.d.) sparkes" <jsparkes@bnr.ca>
To: caml-list@margaux.inria.fr
Subject: building stubs and modules from ANSI C include files

I've been thinking about the problem of interfacing to external C
libraries.

The tkcompiler program in camltk4 is very good start, but it's not
that general.

It seems that the "external" keyword in CSL gives most of the
information about how to call a C function. It should be possible to
build the stub routines from a module description.

And it should be possible to build a module description from an ANSI C
include file which gives the types of all of the arguments.

What's missing? Off the top of my head... please feel free to
contribute more...
- no way to say that returned memory needs to be freed
- how to raise exceptions, and which ones...
- descriptions of C structures that are returned or passed in
- currently no interface to dlopen if it exists. Easy to add on
Solaris, at least.

A useful experiment would be to try and generate the current libunix
and libstr just from include files. I'll try to take a look at what
would be needed.

I got started thinking about this because I wanted DLL support on
windows. Since I know nothing about windows, I thought about how I'd
do this on unix. Once its done there, maybe we can transfer the interface.

--
Jeff Sparkes
jsparkes@bnr.ca    Bell-Northern Research, Ottawa, Ontario, Canada