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: Andy Yang <yyu08@y...>
Subject: [Caml-list] Toplevel crashes when trying to call external functions
Hi, all

I am relatively new to Ocaml. Sorry about the spam if
this is a trivial problem. I am trying to give call
some external functions. 

Some codes are as follows:

value zchaff_InitManager(void)
  void * solver = SAT_InitManager();
  value val = alloc(1, Custom_tag);
  Int32_val(val) = (int) solver;
  CAMLreturn ( val );

void zchaff_ReadCnf(value mng, value filename)
  CAMLparam2(mng, filename);
  void* solver = (void*)Int32_val(mng);
  char * fn = String_val(filename);
  read_cnf(solver, fn);  

When I call these functions in a .ml file. It is okay.
.However, when I tried to call these functions
interactively, segmentation fault happens. The
interactive way is as follows:

# let solver = zchaff_InitManager () ;;
solver = 0x8092328
val solver : zchaff_solver = <abstr>
# Gc.full_major();;
- : unit = ()
# solver ;;
- : zchaff_solver = <abstr>
# let _ = zchaff_ReadCnf solver "testcase/4.cnf";;
solver = 0x400
file = testcase/4.cnf
Segmentation fault

It seems that the variable "solver" is not registered
in Gc's root tree. So solver's value changes after
Gc.full_major(). Where are wrong in my codes? Tracing
with gdb, the stack is as follows when segmentation
fault happens.

#0  0x0807120f in obj_tag ()
#1  0x08074c8f in interprete ()
#2  0x08075dbe in caml_main ()
#3  0x08067a9c in main ()

Thanks a lot!


Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish. 

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