From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA08299; Mon, 12 Jul 2004 15:33:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA08714 for ; Mon, 12 Jul 2004 15:33:18 +0200 (MET DST) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6CDXHEV021043 for ; Mon, 12 Jul 2004 15:33:17 +0200 Received: from localhost (akasha.ijm.jussieu.fr [134.157.173.57]) by shiva.jussieu.fr (8.12.11/jtpda-5.4) with ESMTP id i6CDX5TO072922 ; Mon, 12 Jul 2004 15:33:05 +0200 (CEST) X-Ids: 164 Date: Mon, 12 Jul 2004 15:33:15 +0200 (CEST) Message-Id: <20040712.153315.120542265.andrieu@ijm.jussieu.fr> To: yyu08@yahoo.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions From: Olivier Andrieu In-Reply-To: <20040712131641.85775.qmail@web53203.mail.yahoo.com> References: <86A9CD32-D3F7-11D8-B633-00039310CAE8@inria.fr> <20040712131641.85775.qmail@web53203.mail.yahoo.com> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40F2931D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at shiva.jussieu.fr with ID 40F29311.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Antivirus: scanned by sophie at shiva.jussieu.fr X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 crashes:01 andrieu:01 andrieu:01 2004:99 solver:01 solver:01 camlparam:01 camllocal:01 val:01 val:01 camlreturn:01 mng:99 mng:99 camlparam:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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