Hi all !

I've encountered a strange bug while preparing a caml module with C function. 
Depending on the execution of a caml-defined function, the toplevel is 
evaluated or not, leading to a segfault when calling a caml callback from C.

The code of the C part is:
<---
#include <caml/callback.h>
#include <caml/custom.h>
#include <caml/memory.h>

CAMLprim value f(unit)
{
  CAMLparam0();
  caml_callback(*caml_named_value("test_printf"),Val_unit);
  CAMLreturn(Val_unit);
}
<---

The code of the caml part is:
<---
let f () = Printf.printf "blalba\n"; flush_all ()

let () = Callback.register "test_printf" f

module Test=
struct

  external f : unit -> unit = "f"

  let f2 () = Printf.printf "f2\n"; flush_all ()

end
<---

The code that uses the module is:
<---
(* This needs to be executed *)
let () = Test.Test.f2 ()

let () = Test.Test.f ()
<---

Step to reproduce:
Compile all using the following sequence:
gcc -c -o test_stubs.o ./test_stubs.c -fPIC
ocamlmklib -o test_stubs ./test_stubs.o
ocamlopt -c test.ml
ocamlopt -a -cclib -ltest_stubs -o test.cmxa test.cmx
ocamlopt -c bla.ml
ocamlopt -I . test.cmxa bla.cmx -o bla

Then, if you comment the first call to f2 in bla.ml, then the toplevel is not 
evaluated before executing the C function, leading to a segfault..

Is this a bug or am I missing something ?

Romain

PS: files attached

Attachment: bla.ml
Description: Binary data

let f () = Printf.printf "blalba\n"; flush_all ()

let () = Callback.register "test_printf" f

module Test=
struct

  external f : unit -> unit = "f"

  let f2 () = Printf.printf "f2\n"; flush_all () 

end


#include <caml/callback.h>
#include <caml/custom.h>
#include <caml/memory.h>

CAMLprim value f(unit)
{
  CAMLparam0();
  caml_callback(*caml_named_value("test_printf"),Val_unit);
  CAMLreturn(Val_unit);
}

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to