From: Adrien <camaradetux@gmail.com>
To: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Binding C libraries which use variable arguments (stdarg.h)
Date: Sun, 1 Nov 2009 10:31:21 +0100 [thread overview]
Message-ID: <666572260911010131x1b3c778bgc1c87879ca96a62d@mail.gmail.com> (raw)
In-Reply-To: <4AEAB347.3060008@inria.fr>
On 30/10/2009, Xavier Leroy <Xavier.Leroy@inria.fr> wrote:
> [Invoking a variadic C argument from OCaml]
>
>>> Assuming a Linux system, you could lazily generate the glue code and
>>> invoke dynamic linker on it. So the general case would be to call the
>>> code generator.
>>
>> On linux and x86, I could probably use an array where I would move by
>> sizeof(some_type). I really want portability however (I want to use
>> these bindings at least on windows too).
>
> It might be worth investigating the "libffi" library. If I guess
> correctly, it lets you synthesize calls to native C functions when the
> number and type of arguments are statically unknown.
I had checked libffi but its readme (from gcc-4.3) stated variable
arguments weren't supported. After some time I had doubts about the
relevance of the documentation (the last change mentionned was from
98) and tried anyway.
It turned out it worked on linux x86_32, linux x86_64, netbsd sparc64
with 32-bit userland, debian's kfreebsd amd64 and ppc32. There's
windows which I haven't checked yet though.
I posted my test code on vpaste.net[1]. I think it's good enough to
actually check libffi works with variable arguments but it could
probably be made better. Any comment welcome.
I also asked on the libffi mailing-list and was told by someone it
should work almost everywhere except on really exotic architectures.
That means I'll probably go the libffi way. :-)
[1] http://vpaste.net/6vPst?
---
Adrien Nader
next prev parent reply other threads:[~2009-11-01 9:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 22:07 Adrien
2009-10-28 22:45 ` Basile STARYNKEVITCH
2009-10-29 8:55 ` Goswin von Brederlow
2009-10-29 21:37 ` Adrien
2009-10-29 23:31 ` Goswin von Brederlow
2009-10-29 21:18 ` Adrien
2009-10-30 9:35 ` Xavier Leroy
2009-11-01 9:31 ` Adrien [this message]
2009-11-01 11:07 ` Florian Weimer
2009-11-01 12:12 ` Adrien
2009-11-01 12:16 ` Florian Weimer
2009-11-01 14:58 ` Adrien
2009-11-01 20:06 ` Richard Jones
2009-11-03 19:33 ` Florian Weimer
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=666572260911010131x1b3c778bgc1c87879ca96a62d@mail.gmail.com \
--to=camaradetux@gmail.com \
--cc=caml-list@yquem.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).