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] Toplevel crashes when trying to call external functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Anne Pacalet <anne.pacalet@t...>
Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions
Andy Yang a écrit :
> I am relatively new to Ocaml. 

I am VERY new to Ocaml...

> When I call these functions in a .ml file. It is okay.
> .However, when I tried to call these functions
> interactively, segmentation fault happens.

and I have to same problem with even the simplest functions.
For instance :

extern "C" void Caml_load_project(value v_0){
   String x_0 = String_val (v_0);
   C_load_project (x_0);
extern "C" value Caml_show_refs(value v_0, value v_1){
   CAMLparam2(v_0, v_1);
   CAMLlocal1 (v_res);
   int x_0 = Int_val (v_0);
   int x_1 = Int_val (v_1);
   std::list<int> res = C_show_refs (x_0, x_1);
   v_res = Val_listInt (res);
   CAMLreturn (v_res);

And I noticed that if I add "flush" or "print" calls, it works.
So, I did :

external c_load_project : string -> unit = "Caml_load_project"
external c_show_refs : int -> int -> int list = "Caml_show_refs"

let load_project a_0 =
   c_load_project a_0 ; flush_all()
let show_refs a_0 a_1 =
   let r = c_show_refs a_0 a_1 in flush_all() ; r

and the functions 'load_project' and 'show_refs' work fine even 
interactively. I don't know why (I would be happy to know)... but maybe 
this workaround can help !


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: