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 BAA23503; Fri, 12 Apr 2002 01:26:16 +0200 (MET DST) 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 BAA15410 for ; Fri, 12 Apr 2002 01:26:16 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mel-rto6.wanadoo.fr (smtp-out-6.wanadoo.fr [193.252.19.25]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3BNQFT11073 for ; Fri, 12 Apr 2002 01:26:15 +0200 (MET DST) Received: from mel-rta2.wanadoo.fr (193.252.19.152) by mel-rto6.wanadoo.fr; 12 Apr 2002 01:26:15 +0200 Received: from debian (80.8.74.147) by mel-rta2.wanadoo.fr; 12 Apr 2002 01:25:44 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 16vnwo-0000li-00 for ; Fri, 12 Apr 2002 01:25:46 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Hybrid ML/C programs and exceptions References: <200204112133.OAA05135@gnp.com> From: Remi VANICAT Date: 12 Apr 2002 01:25:46 +0200 In-Reply-To: <200204112133.OAA05135@gnp.com> Message-ID: <87wuvd4y2t.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Tom Buscher writes: > Hi, > > We have a hybrid O'Caml/C application in which ML calls C, > which calls ML, like this: > > ML -> C -> ML > 1 2 3 > > The "lower" ML(3) raises an exception, which is dealt with > by C(2) using one of the callback_exn functions. When the C > function returns, the "upper" ML function generates a bus > error on Solaris 8, on writing to a mutable global variable. > We are using O'Caml 3.04 with the bytecode compiler. > > Attached is a sample program of the same structure that > reproduces this problem. The problem appears to be caused by > the handling of the RAISE opcode in interprete(), executing > the "lower" ML bytecode. It sets extern_sp to a value which > reflects the program state before the C layer was called. > > Is this program structure allowed? > > Regards, > > Tom, Trevor and Jeff > > ------------------------------------------------------------ > FILE: top.ml > ------------------------------------------------------------ > exception Bot;; > let bot() = raise Bot > let _ = Callback.register "bot" bot > > external foo : unit -> unit = "foo" > > let r = ref 1;; > r := 2; > foo(); > r := 3 > > ------------------------------------------------------------ > FILE: foo.c > ------------------------------------------------------------ > #include > #include > #include > > CAMLprim void > foo(value unit) > { > CAMLparam1(unit); > callback_exn(*caml_named_value("bot"), Val_int(0)); > CAMLreturn0; > } this seem suspicious, CAMLprim should have type CAMLprim value foo(value) CAMLreturn0 is only usefull in the case of something like ML call C witch call C witch call ML (for example it useful for Gtk binding, where there are C callback which then call ML). by the way, changing foo.c with : #include #include #include CAMLprim value foo(value unit) { CAMLparam1(unit); callback_exn(*caml_named_value("bot"), Val_int(0)); CAMLreturn(Val_unit); } doesn't change the problem... -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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