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 QAA21900; Fri, 16 Jul 2004 16:22:55 +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 QAA21799 for ; Fri, 16 Jul 2004 16:22:54 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6GEMrSH011781 for ; Fri, 16 Jul 2004 16:22:53 +0200 Received: from bourg.inria.fr (bourg.inria.fr [128.93.11.100]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA21729 for ; Fri, 16 Jul 2004 16:22:53 +0200 (MET DST) Received: from basile by bourg.inria.fr with local (Exim 4.34) id 1BlTbT-0004SN-7D for caml-list@inria.fr; Fri, 16 Jul 2004 16:22:23 +0200 Date: Fri, 16 Jul 2004 16:22:23 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] segfault in caml_copy_string Message-ID: <20040716142223.GA17108@bourg.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6+20040523i From: "Basile Starynkevitch [local]" X-Miltered: at concorde with ID 40F7E4BD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 segfault:01 basile:01 basile:01 2004:99 bauer:01 camlprim:01 camlparam:01 const:01 char:01 camlreturn:01 camlreturn:01 allocates:01 camlprim:01 camlparam:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Jul 16, 2004 at 04:10:47PM +0200, Bauer, Christoph wrote: > Hi, > > here is a simple C-function: > > CAMLprim value getparam(value request, value key) > { > CAMLparam2(request, key); > const char * result; > CAMLreturn(key); /* 1 */ > CAMLreturn(caml_copy_string("test")); /* 2 */ > } > > Version 1 returns the key and everything works (except that > key is not what I need.) > > Version 2 calls caml_copy_string and this fails. Has anybody a idea why? caml_copy_string actually allocates a *garbage-collected* string, so you need to tell about its result to the GC. Try instead CAMLprim value getparam(value request, value key){ CAMLparam2(request, key); CAMLlocal1(result); result = caml_copy_string("test"); CAML_return(result); } (to understand why, read any material on precise moving garbage collectors) -- Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359 http://cristal.inria.fr/~starynke --- all opinions are only mine ------------------- 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