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 UAA00209; Sun, 11 Jul 2004 20:11:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA00364 for ; Sun, 11 Jul 2004 20:11:12 +0200 (MET DST) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6BIBASH029657 for ; Sun, 11 Jul 2004 20:11:11 +0200 Received: (qmail 26768 invoked from network); 11 Jul 2004 18:11:09 -0000 Received: from dsl081-145-152.chi1.dsl.speakeasy.net (HELO firebird) ([64.81.145.152]) (envelope-sender ) by mail1.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 11 Jul 2004 18:11:09 -0000 Date: Sun, 11 Jul 2004 13:14:42 -0500 From: art yerkes To: Andy Yang Cc: caml-list@inria.fr Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions Message-Id: <20040711131442.4557bb6e.ayerkes@speakeasy.net> In-Reply-To: <20040711012047.86808.qmail@web53203.mail.yahoo.com> References: <20040711012047.86808.qmail@web53203.mail.yahoo.com> X-Mailer: Sylpheed version 0.9.10 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40F182BE.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; yerkes:01 ayerkes:01 caml-list:01 crashes:01 2004:99 camlparam:01 solver:01 val:01 alloc:01 val:01 solver:01 camlreturn:01 mng:99 camlparam:01 mng:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 10 Jul 2004 18:20:47 -0700 (PDT) Andy Yang wrote: > 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) > { > CAMLparam0(); > 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); > CAMLreturn0; > } > These may not solve this specific problem but I think they are good advice: First: 17.9.2. Custom blocks must be allocated via the alloc_custom function. (And remember that the custom block size argument is in bytes). Second: Passing 1 as the block size to alloc allocates a block with one word as a tail (at offset 0), but Data_custom_val accesses a value in the tail at offset 1. This is probably the error you're looking for. Third: I don't understand why you're going through Int32_val and Val_int32 to get and set your pointer. You probably want to write a new macro that will access the custom area as a pointer-sized chunk on every architecture. Assuming pointers to be 32-bits really is a bad idea. -- Hey, Adam Smith, keep your invisible hands to yourself! ------------------- 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