From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA22519; Thu, 8 Mar 2001 10:34:54 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA23164 for ; Thu, 8 Mar 2001 10:34:53 +0100 (MET) Received: from mta5.snfc21.pbi.net (mta5.snfc21.pbi.net [206.13.28.241]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f289YlD13262; Thu, 8 Mar 2001 10:34:48 +0100 (MET) Received: from checkerlap.d6.com ([64.160.54.42]) by mta5.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with ESMTP id <0G9V00E3VH9H90@mta5.snfc21.pbi.net>; Thu, 8 Mar 2001 01:34:30 -0800 (PST) Date: Thu, 08 Mar 2001 01:34:34 -0800 From: Chris Hecker Subject: Re: [Caml-list] dynamically loading C functions In-reply-to: <15015.16731.108064.51473@cremant.inria.fr> X-Sender: def6@shell16.ba.best.com To: fabrice.le_fessant@inria.fr Cc: caml-list@inria.fr Message-id: <4.3.2.7.2.20010308010305.00cd4140@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" References: <4.3.2.7.2.20010304235205.00dea6a0@shell16.ba.best.com> <4.3.2.7.2.20010305164831.00e2cd60@shell16.ba.best.com> <4.3.2.7.2.20010306094319.00e2b8e0@shell16.ba.best.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >I've written a Dlopen module for x86 and alpha available at >http://pauillac.inria.fr/~lefessan/src/dlopen.tar.gz Neat! This is a very nice type hack to get the return value parameterizable with format: val dlsym : dll -> string -> ('c -> 'a,unit, 'c) format -> 'a When I was thinking of using the printf format strings, I couldn't figure out how to get the implicit 'c return value out of there on the result, but putting it in the first type argument as well is ingenious! Does this library ever build closures around C functions and pass them back to caml (like you mentioned in a previous mail)? I don't see the code that does that anywhere. From looking at the cmmgen.ml source, it looks like closures are a pretty simple layout (there's a header before these): if physical arity 1: word: pointer to function word: 3 (arity (as caml int 1 lsl 1 + 1)) if physical arity > 1: word: pointer to a curry function generated at link time word: arity word: pointer to function But I've only looked at x86 so far. The compiler actually is pretty smart (as if we didn't know that already :). From what I can tell, if a module has been compiled, the cmx file (and maybe the cmi file) has extra information in it about the physical arity of its functions, so when they're called from another module, the compiler can just directly call the function rather than grovel around in its closure datastructure to find its physical arity (or call a subroutine to do this, which is what happens if you haven't compiled a module and you call a function in it, or just have an mli file but no ml file backing it). I guess this is one of the currying optimizations people have been talking about. I wonder how compilation-unit-order-dependent this is... Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr