blob: 5f51c4515885b3cd6f39c6205902c932b415bf55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
(* TEST
include unix;
modules = "test4_.c";
libunix;
{
bytecode;
}{
native;
}
*)
(* Tests nested calls from C (main C) to OCaml (main OCaml) to C (caml_to_c) to
* OCaml (c_to_caml) to C (printf functions). Exception is raised in a
* Callback, which unwinds the C stack and gets caught in OCaml. *)
exception E
let printf = Printf.printf
let c_to_caml () =
printf "[Caml] Enter c_to_caml\n%!";
printf "[Caml] c_to_caml: raise exception\n%!";
raise E
let _ = Callback.register "c_to_caml" c_to_caml
external caml_to_c : unit -> unit = "caml_to_c"
let _ =
try
printf "[Caml] Call caml_to_c\n%!";
caml_to_c ();
printf "[Caml] Return from caml_to_c\n%!"
with E -> printf "[Caml] Caught exception\n%!"
|