Version française
Home     About     Download     Resources     Contact us    
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: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions
 Andy Yang [Mon, 12 Jul 2004]:
 > The two functions are defines as follows in ocaml:
 >  
 > type zchaff_solver
 > external zchaff_InitManager : unit -> zchaff_solver = "zchaff_InitManager"
 > external zchaff_ReadCnf : zchaff_solver -> string -> unit = "zchaff_ReadCnf"
 >  
 > and my usage of these two functions are :
 >  
 > # let mysolver = zchaff_InitManager () ;;
 > # let _ = zchaff_ReadCnf (mysolver) ("testcaser/1.cnf");;  
 >
 > > value zchaff_InitManager(void)
 > > {
 > > CAMLparam0();
 > > CAMLlocal1(val);
 > > void* solver = SAT_InitManager();
 > > val = copy_int32((int)solver);
 > > cout<<"solver = "<> CAMLreturn ( val );
 > > }
 > >
 > > void zchaff_ReadCnf(value mng, value filename)
should be:
     value zchaff_ReadCnf(value mng, value filename)

 > > {
 > > CAMLparam2(mng, filename);
 > > SAT_Manager solver = (void*)Int32_val(mng);
 > > cout<<"solver = "<> assert(solver != NULL);
 > > char * fn = String_val(filename);
 > > cout<<"file = "<> read_cnf(solver, fn);
 > > CAMLreturn0;
should be:
     CAMLreturn(Val_unit);
 > > }

Also, you should use an abstract block for storing the pointer:

in _InitManager :
 val = alloc_small(1, Abstract_tag);
 Field(val, 0) = Val_bp(solver);

in _ReadCnf:
 solver = (SAT_Manager) Bp_val(mng);

-- 
   Olivier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners