caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: Xavier Leroy <Xavier.Leroy@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] create a closure in external C function?
Date: Tue, 06 Mar 2001 10:19:23 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20010306100442.00e18a60@shell16.ba.best.com> (raw)
In-Reply-To: <20010306180128.B12522@pauillac.inria.fr>


At 06:01 PM 3/6/01 +0100, Xavier Leroy wrote:
>Not directly, at least.  Building closures from C isn't impossible,
>just very delicate and highly processor-dependent (in the case of the
>native-code compiler).
>Right. caml_c_call does part of the job, but is indeed very
>platform-specific.

It seems like most of the platform specific parts are already there in pieces in the native compiler itself.  I'm not familiar enough with calling conventions on the other platforms, but is it true that one could stitch together a bunch of the asmrun functions to give us a simple c-callable function that can be passed as a closure?  Or, are the caml calling conventions such that you need to do special stuff depending on how many arguments there are?

> As Fabrice noted, the hard part is
>to deal with arbitrary many C function types, determined dynamically.
>There, you'd need some kind of dynamic invocation interface for C
>functions, and I don't know of any C library that provides this in a
>portable or semi-portable fashion.
> ...
At 11:50 AM 3/6/01 +0100, Fabrice Le Fessant wrote:
>My problem is: how to call the function f_v, using the types in
>types_v (either integer, char, string or double) to build the call,
>and using arg1_v (translated using its type) as argument.
>Of course, I can implement this easily on my PC, but I don't know any
>way to implement such a function in an architecture-independant way...

I think I can do this part with the ffcall library.  It has functions for building c-callable functions, both in the stdargs way but with return values as well, and the opposite (where you incrementally tell it what paramters the function takes, and then it gives you back a pointer you can call as a full c function call).  It's highly portable (I think it supports more platforms than ocaml, even, so it's overkill).

I was hoping to avoid the "list of parms" solution and just get both ends hooked up directly, which would be really cool.

>PS: I can give you the code I have already written for building the
>closure, and so on if you are interested... but I'm stuck on this
>function !

Yes, that'd be great.  Please email me the code.

Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-03-06 18:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-06  9:29 Chris Hecker
2001-03-06 10:50 ` Fabrice Le Fessant
2001-03-06 17:01 ` Xavier Leroy
2001-03-06 18:19   ` Chris Hecker [this message]
2001-03-07  3:23     ` Fergus Henderson
2001-03-06 18:58   ` Marcin 'Qrczak' Kowalczyk
2001-03-06 19:13     ` Chris Hecker
2001-03-06 21:16       ` Marcin 'Qrczak' Kowalczyk
2001-03-06 22:56         ` Chris Hecker
2001-03-07  0:22           ` Marcin 'Qrczak' Kowalczyk
2001-03-07  0:44             ` Chris Hecker
2001-03-07  8:49               ` Marcin 'Qrczak' Kowalczyk

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=4.3.2.7.2.20010306100442.00e18a60@shell16.ba.best.com \
    --to=checker@d6.com \
    --cc=Xavier.Leroy@inria.fr \
    --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).