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 AAA21445; Fri, 12 Apr 2002 00:22:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA18754 for caml-list@pauillac.inria.fr; Fri, 12 Apr 2002 00:22:38 +0200 (MET DST) 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 XAA19849 for ; Thu, 11 Apr 2002 23:34:12 +0200 (MET DST) Received: from northwall.gnp.com (lsanca1-ar8-066-060.biz.dsl.gtei.net [4.35.66.60]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3BLYAT08838 for ; Thu, 11 Apr 2002 23:34:11 +0200 (MET DST) Received: (from smap@localhost) by northwall.gnp.com (8.8.7/8.8.7) id OAA17747 for ; Thu, 11 Apr 2002 14:34:08 -0700 Received: from borealis.gnp.com(64.242.32.241) by northwall.gnp.com via smap (V2.1) id xma017743; Thu, 11 Apr 02 14:33:39 -0700 Received: by gnp.com (SMI-8.6/SMI-SVR4) id OAA05135; Thu, 11 Apr 2002 14:33:04 -0700 Message-Id: <200204112133.OAA05135@gnp.com> Received: from aardvark(192.168.20.32) by polaris via smap (V2.1) id xma005066; Thu, 11 Apr 02 14:32:42 -0700 X-Sender: tbuscher@mailhost.555.gnp.com X-Mailer: QUALCOMM Windows Eudora Pro Version 4.0 Date: Thu, 11 Apr 2002 14:34:38 -0700 To: caml-list@inria.fr From: Tom Buscher Subject: [Caml-list] Hybrid ML/C programs and exceptions Cc: jpolakow@gnp.com, tfoucher@gnp.com Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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; } ------------------------------------------------------------ Build command (with gcc-2.95.3): ocamlc -custom -o top top.ml foo.c ------------------------------------------------------------ Tom Buscher "For every complex problem, GNP Computers, Inc. there is a simple solution. tbuscher@gnp.com And it is wrong." fon: +1 626.305.8484 fax: +1 626.599.3115 -- H. L. Mencken ------------------- 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