Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Hybrid ML/C programs and exceptions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-04-11 (22:22)
From: Tom Buscher <tbuscher@g...>
Subject: [Caml-list] Hybrid ML/C programs and exceptions

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?


Tom, Trevor and Jeff

exception Bot;;
let bot() = raise Bot 
let _ = Callback.register "bot" bot

external foo : unit -> unit = "foo"

let r = ref 1;;
r := 2;
r := 3

FILE: foo.c
#include <caml/mlvalues.h>
#include <caml/callback.h>
#include <caml/memory.h>

CAMLprim void
foo(value unit)
        callback_exn(*caml_named_value("bot"), Val_int(0));

Build command (with gcc-2.95.3):

  ocamlc -custom -o top foo.c
Tom Buscher                       "For every complex problem,
GNP Computers, Inc.                there is a simple solution.                   And it is wrong."
fon: +1 626.305.8484
fax: +1 626.599.3115                         -- H. L. Mencken
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: