From: "Christopher L Conway" <cconway@cs.nyu.edu>
To: "David Teller" <David.Teller@ens-lyon.org>
Cc: "Nathan Mishra Linger" <nathan.mishralinger@gmail.com>,
caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml/C interface
Date: Sun, 28 Oct 2007 09:48:50 -0400 [thread overview]
Message-ID: <4a051d930710280648t72075b40r13d7a0fa225caece@mail.gmail.com> (raw)
In-Reply-To: <1193575003.6383.19.camel@Blefuscu>
This is very similar to what you would get from SWIG
(http://www.swig.org/, OCaml support is in SVN): it generates a
binding where each C function has type c_obj -> c_obj, where c_obj is
more or less your c_type. Basically, this just hoists the problem up
one level of abstraction, so that instead of writing C code using
mltypes.h, you write OCaml code that massages effectively untyped
values coming out of the library.
Regards,
Chris
On 10/28/07, David Teller <David.Teller@ens-lyon.org> wrote:
> I'm wondering how hard it would be to write a generic module for calling
> C functions without having to write a specific wrapper. Something along
> the lines of (with revised syntax)
>
>
> type c_type =
> [ TVoid
> | TChar
> | TInt32
> | TInt64
> | ...
> | TStruct of list c_type
> | TUnion of list c_type
> | TPointer of c_type
> | TArray of array c_type
> | TString
> | TWString
> | ...
> | TReclaimable of c_type
> | TNotReclaimable of c_type
> ];
>
> type c_value =
> [ Void
> | TChar of char
> | TInt32 of int32
> | ...
> ];
>
> type t; (*The type of a C function*)
>
> (**
> Perform a dynamic link with a C function.
> Evalutes to None in case of dynamic linking error.
> *)
> value acquire_function : ~name:string -> ~args:list c_type -> option t;
>
> (**
> Actually perform the call.
> *)
> value call : t -> ~args:list c_type -> c_type;
>
> value release_value : c_value -> unit;
> value release_function : t -> unit;
>
> Etc.
>
> Come to think about it, we could draw some inspiration from Python's
> CTypes [1]. While it wouldn't be as safe as the current manner of
> calling C from OCaml, it would be much more convenient at least for
> prototyping. Plus, with a little Camlp4, it would make it possible to
> write something like
>
> external "C" my_native_function = "char* stuff(char* a, char* b)"
>
> That was just a random thought, I have no particular interest in
> implementing this, but what do you think about it ?
>
> Cheers,
> David
>
> [1] http://docs.python.org/lib/module-ctypes.html
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
next prev parent reply other threads:[~2007-10-28 13:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-25 22:17 Nathan Mishra Linger
2007-10-26 9:18 ` [Caml-list] " Julien Moutinho
2007-10-26 18:13 ` Nathan Mishra Linger
2007-10-28 12:36 ` David Teller
2007-10-28 13:34 ` skaller
2007-10-28 13:48 ` Christopher L Conway [this message]
2007-10-28 15:39 ` David Teller
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=4a051d930710280648t72075b40r13d7a0fa225caece@mail.gmail.com \
--to=cconway@cs.nyu.edu \
--cc=David.Teller@ens-lyon.org \
--cc=caml-list@yquem.inria.fr \
--cc=nathan.mishralinger@gmail.com \
/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