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 TAA16918; Tue, 6 Mar 2001 19:57:44 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA16974 for ; Tue, 6 Mar 2001 19:57:43 +0100 (MET) Received: from mail.mimuw.edu.pl (po20.warszawa.cvx.ppp.tpnet.pl [213.76.110.20]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f26IvWb04126 for ; Tue, 6 Mar 2001 19:57:37 +0100 (MET) Received: (from news@localhost) by mail.mimuw.edu.pl (PLD/8.9.3) id TAA31190 for caml-list@inria.fr; Tue, 6 Mar 2001 19:58:59 +0100 X-Authentication-Warning: qrnik.zagroda: news set sender to qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk) using -f From: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk) Subject: Re: [Caml-list] create a closure in external C function? Date: 6 Mar 2001 18:58:56 GMT Organization: Klub Nieszkodliwych =?iso-8859-2?Q?Manjak=F3w?= Message-ID: References: <4.3.2.7.2.20010306011427.03669de0@shell16.ba.best.com> <20010306180128.B12522@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 8bit X-Trace: qrnik.zagroda 983905136 31188 192.168.0.1 (6 Mar 2001 18:58:56 GMT) X-Complaints-To: news@qrnik.zagroda NNTP-Posting-Date: 6 Mar 2001 18:58:56 GMT User-Agent: slrn/0.9.6.3 (Linux) To: caml-list@inria.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Tue, 6 Mar 2001 18:01:28 +0100, Xavier Leroy pisze: > 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. What about another issue: converting a function closure to a C function pointer? This too cannot be done portably, can be done unportably, is needed in the functional programming context, and I don't know any C library or compiler extension which provides it (besides gcc's downward closures, but they are not sufficient). A generic C interface would probably express it as partial application. Semi-standard Haskell's foreign function interface provides this (converting a Haskell's function closure to a C function pointer). There is a function which frees the data assiociated with a function pointer produced that way. Last time I looked at this, I hadn't found this functionality in OCaml. You can at most register OCaml's functions under textual names. This interface is too limited. You can't even unregister them. Should OCaml provide this? I haven't really used OCaml much, but imagine that currently you have to rely on whatever poor man's closure mechanism was provided by the C library you are interfacing to. E.g. gtk+ uses the standard C trick of bundling a callback function pointer with a void * value which is passed to the function as an additional argument. Designers of some other libraries were not aware of the fact that there exist languages which treat functions as data, e.g. readline wants just function pointers, and it even doesn't let the programmer know when the function pointer is no longer needed. The implementation of this conversion must of course build heap-allocated machine code at runtime, hiding the data pointer inside it. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTĘPCZA QRCZAK ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr