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 VAA19362; Wed, 28 Apr 2004 21:38:41 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA19349 for ; Wed, 28 Apr 2004 21:38:40 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3SJccYM019726 for ; Wed, 28 Apr 2004 21:38:39 +0200 Received: from fichte.ai.univie.ac.at (markus@localhost [127.0.0.1]) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) with ESMTP id i3SJcKDu016410; Wed, 28 Apr 2004 21:38:20 +0200 Received: (from markus@localhost) by fichte.ai.univie.ac.at (8.12.3/8.12.3/Debian-6.6) id i3SJcJ1G016409; Wed, 28 Apr 2004 21:38:19 +0200 Date: Wed, 28 Apr 2004 21:38:19 +0200 From: Markus Mottl To: Yaron Minsky Cc: caml-list@inria.fr Subject: Re: [Caml-list] Byte code and dynamic linking of C libraries Message-ID: <20040428193819.GD11866@fichte.ai.univie.ac.at> Mail-Followup-To: Yaron Minsky , caml-list@inria.fr References: <40551.141.155.88.179.1083177798.squirrel@minsky-primus.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <40551.141.155.88.179.1083177798.squirrel@minsky-primus.homeip.net> User-Agent: Mutt/1.4.1i X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 yaron:01 minsky:01 dynamically:01 vectors:01 camlprim:01 pcre:01 stub:01 argv:01 argn:01 pcre:01 stub:01 argv:01 statically:01 dlopen:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 28 Apr 2004, Yaron Minsky wrote: > I've got some code that dynamically links in a C library. The code > works just fine when I compile to native code, but blows up when I > compile to bytecode. Hm, this may indicate that one of your C-functions accessed from OCaml takes more than five arguments. In this case you'll have to write a wrapper that uses argument vectors. E.g.: CAMLprim value pcre_exec_stub_bc(value *argv, int argn) { return pcre_exec_stub(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); } The external declaration in OCaml then looks as follows (note the two entry points for byte- and native code): external unsafe_pcre_exec : irflag -> regexp -> int -> string -> int -> int array -> callout option -> unit = "pcre_exec_stub_bc" "pcre_exec_stub" ------------------- ---------------- Earlier OCaml-releases didn't check the number of arguments, but I'm not sure whether you'll have to grab a CVS-version to be warned about this (if this is the cause of the problem)? > Just to be clear, the dynamic linking I'm doing happens > entirely on the C side: I've got a c library that is linked in > statically, and the dlopen and dlclose calls all happen within that C > library. When I try this trick in bytecode, I get a segfault. > > So, any ideas as to what I need to do to make dynamic linking and byte > code to play nicely together? I can't imagine any good reason why dynamic linking performed at runtime by C-code should have an effect on the byte code interpreter. But maybe there are bad ones? Markus -- Markus Mottl http://www.oefai.at/~markus markus@oefai.at ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners