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 SAA21440; Mon, 5 Nov 2001 18:57:17 +0100 (MET) 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 SAA21316 for ; Mon, 5 Nov 2001 18:57:16 +0100 (MET) Received: from kiste.thiemo.net (kiste.thiemo.net [193.159.181.84]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fA5HvAH22039 for ; Mon, 5 Nov 2001 18:57:12 +0100 (MET) Received: (from jc@localhost) by kiste.thiemo.net (8.9.3/8.9.3) id SAA24522; Mon, 5 Nov 2001 18:56:56 +0100 (CET) (envelope-from jc@joerch.org) Date: Mon, 5 Nov 2001 18:56:56 +0100 (CET) Message-Id: <200111051756.SAA24522@kiste.thiemo.net> From: Joerg Czeranski MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: malc@pulsesoft.com Subject: Re: [Caml-list] Troubles with C->Caml Cc: caml-list@inria.fr In-Reply-To: Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 21 Oct 2001 16:27:08 +0400 (MSD) malc wrote: > > value func (value param) > { > CAMLparam1 (param); > CAMLlocal2 (result, err); > char *p = String_val (param); > void *h = af (p); > err = yaf (); > if (some_condition) { > /* raise exception */ > ... > } else { > if (Is_exception_result (err)) { > result = alloc_small (2, 1); > Field (result, 0) = (value)h; > Field (result, 1) = Extract_exception (err); > CAMLreturn (result); > } > result = alloc_small (1, 0); > Field (result, 0) = (value)h; > CAMLreturn (result); > } > } > > The decorations are there ditto coredump. Hi, I don't remember whether somebody has answered this, but I think you should never copy an O'Caml pointer into a variable that's not in CAMLlocal...(), e.g. "char *p = String_val (param);" copies the pointer param into the local variable p. When the GC moves param, p points to garbage. (Same for h.) On the other hand you can't declare p with CAMLparam..., so you probably have to write "String_val (param)" wherever you'd use p. I'm not sure whether the documentation mentions this, and I think it's not completely obvious. regards, jörch ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr