From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 64D5DBBAF for ; Wed, 3 Sep 2008 18:08:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtoEAHpTvkhYvxGE/2dsb2JhbACBZbUsgWc X-IronPort-AV: E=Sophos;i="4.32,320,1217800800"; d="ml'?c'?scan'208";a="28775385" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Sep 2008 18:08:59 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m83G8wnI006776 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 3 Sep 2008 18:08:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtoEAHpTvkhYvxGE/2dsb2JhbACBZbUsgWc X-IronPort-AV: E=Sophos;i="4.32,320,1217800800"; d="ml'?c'?scan'208";a="28775383" Received: from www.rastageeks.org (HELO mail.rastageeks.org) ([88.191.17.132]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Sep 2008 18:08:58 +0200 Received: from leonard.local (AMontsouris-156-1-119-212.w83-202.abo.wanadoo.fr [83.202.150.212]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.rastageeks.org (Postfix) with ESMTP id 1358DA77EB; Wed, 3 Sep 2008 18:08:57 +0200 (CEST) From: Romain Beauxis To: caml-list@inria.fr Subject: toplevel not executed: Bug ? Date: Wed, 3 Sep 2008 18:08:55 +0200 User-Agent: KMail/1.9.9 Cc: smimram@debian.org MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_XarvIC1A/8kdAYC" Message-Id: <200809031808.55821.toots@rastageeks.org> X-Miltered: at concorde with ID 48BEB69A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; toplevel:01 bug:01 bug:01 toplevel:01 segfault:01 camlprim:01 camlparam:01 printf:01 val:01 camlreturn:01 val:01 printf:01 struct:01 gcc:01 stubs:01 X-Attachments: type="application/octet-stream" name="bla.ml" name="bla.ml" cset="iso 8859-15" name="test.ml" name="test.ml" type="text/x-csrc" cset="iso 8859-15" name="test_stubs.c" name="test_stubs.c" --Boundary-00=_XarvIC1A/8kdAYC Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 #include #include 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 --Boundary-00=_XarvIC1A/8kdAYC Content-Type: application/octet-stream; name="bla.ml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="bla.ml" (* This needs to be executed *) let () = Test.Test.f2 () let () = Test.Test.f () --Boundary-00=_XarvIC1A/8kdAYC Content-Type: text/plain; charset="iso 8859-15"; name="test.ml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test.ml" 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 --Boundary-00=_XarvIC1A/8kdAYC Content-Type: text/x-csrc; charset="iso 8859-15"; name="test_stubs.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="test_stubs.c" #include #include #include CAMLprim value f(unit) { CAMLparam0(); caml_callback(*caml_named_value("test_printf"),Val_unit); CAMLreturn(Val_unit); } --Boundary-00=_XarvIC1A/8kdAYC--