From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7GAHaSI012113 for ; Tue, 16 Aug 2011 12:17:36 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkEAIFCSk7RVdY2imdsb2JhbABBmSKPAggUAQEBCgkNBxIGIYFAAQEBAQMMBgIeAQ0BGxwCAwwGBQsNCRYPCQMCAQIBEREBBQEcEwYCAh6HUJ0ACow3glWFOjuIbQIDBoZBBIdZizmFDIEohiU8g2M X-IronPort-AV: E=Sophos;i="4.67,379,1309730400"; d="scan'208";a="115971698" Received: from mail-bw0-f54.google.com ([209.85.214.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Aug 2011 12:17:31 +0200 Received: by bkat8 with SMTP id t8so7125492bka.27 for ; Tue, 16 Aug 2011 03:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=sXasn+eJId8BJMSIjPO80AX1YC4Tx0Ve/peqPI3KJMI=; b=G6pwFRiW/hijj6rCf1rVAqJtAocE8dVIb8djNOmgC+sQKCvofmhEflJeBPt/vvdSQe A20VbFa0LSlYpgEgXk4eo+4Rme4nusNoJN3pV9v1Sku3GfxHA3ZDsaE1rpCBN16GFSsd 9Y0NCJbctg5FhN2mWpQnrpopMyz3mmQNasjsM= Received: by 10.204.171.66 with SMTP id g2mr1378997bkz.8.1313489851069; Tue, 16 Aug 2011 03:17:31 -0700 (PDT) Received: from [192.168.1.101] ([79.114.94.185]) by mx.google.com with ESMTPS id x19sm1840858bkt.9.2011.08.16.03.17.29 (version=SSLv3 cipher=OTHER); Tue, 16 Aug 2011 03:17:29 -0700 (PDT) Message-ID: <4E4A43B8.8030306@gmail.com> Date: Tue, 16 Aug 2011 13:17:28 +0300 From: =?ISO-8859-1?Q?T=F6r=F6k_Edwin?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110626 Icedove/3.1.11 MIME-Version: 1.0 To: caml-list@inria.fr References: <4E4A2488.4050706@gmail.com> <4E4A2DAC.5010207@gmail.com> <20110816094636.GA6227@ccellier.rd.securactive.lan> In-Reply-To: X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Interfacing with C: bad practice On 08/16/2011 12:53 PM, Dmitry Bely wrote: > On Tue, Aug 16, 2011 at 1:46 PM, wrote: >> -[ Tue, Aug 16, 2011 at 11:43:24AM +0300, Török Edwin ]---- >>> 'list' should be reachable via caml_local_roots, so if it really gets an invalid value >>> it sounds like a bug to me. >> >> list may not be garbage collected (since it is indeed registered as the >> root), but it may be moved arround (ie promoted to major heap). >> The address of list would be fixed in the local variable (the root) but >> not the transiant copy on the stack. >> Maybe that's the actual problem ? > > Exactly. List is moved but its stack copy (wrp_ml_cons 2nd parameter) > is not updated and holds an old address. Ah yes. So a best practice would be to always use a temporary variable registered with CAMLlocal* when you call a function that can potentially invoke the GC? (in your example to store the result of caml_copy_string). Best regards, --Edwin