Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Romain Beauxis <toots@rastageeks.org>
To: caml-list@inria.fr
Cc: smimram@debian.org
Subject: toplevel not executed: Bug ?
Date: Wed, 3 Sep 2008 18:08:55 +0200	[thread overview]
Message-ID: <200809031808.55821.toots@rastageeks.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

	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 #2: bla.ml --]
[-- Type: application/octet-stream, Size: 84 bytes --]


(* This needs to be executed *)
let () = Test.Test.f2 ()

let () = Test.Test.f ()


[-- Attachment #3: test.ml --]
[-- Type: text/plain, Size: 208 bytes --]


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


[-- Attachment #4: test_stubs.c --]
[-- Type: text/x-csrc, Size: 208 bytes --]



#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);
}


             reply	other threads:[~2008-09-03 16:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-03 16:08 Romain Beauxis [this message]
2008-09-03 21:56 ` [Caml-list] " Stéphane Glondu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200809031808.55821.toots@rastageeks.org \
    --to=toots@rastageeks.org \
    --cc=caml-list@inria.fr \
    --cc=smimram@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox