From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7GAdbwN012670 for ; Tue, 16 Aug 2011 12:39:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIDALFHSk7VBIoTkWdsb2JhbABBmSOPHgEBAQEJCwsHFAQhgUABAQUyAVYLGC4UKDSHcrsEhWhfBJMSkHc X-IronPort-AV: E=Sophos;i="4.67,379,1309730400"; d="scan'208";a="105576435" Received: from impaqm3.telefonica.net (HELO telefonica.net) ([213.4.138.19]) by mail4-smtp-sop.national.inria.fr with ESMTP; 16 Aug 2011 12:39:32 +0200 Received: from IMPmailhost4.adm.correo ([10.20.102.125]) by IMPaqm3.telefonica.net with bizsmtp id Lv6E1h00j2iL0W23PyfX5N; Tue, 16 Aug 2011 12:39:31 +0200 Received: from NANA.localdomain ([81.32.70.106]) by IMPmailhost4.adm.correo with BIZ IMP id LyfW1h00d2HaYQp1kyfXkM; Tue, 16 Aug 2011 12:39:31 +0200 X-Brightmail-Tracker: AAAAAA== X-original-sender: ferferse@telefonica.net Received: from mfp by NANA.localdomain with local (Exim 4.72) (envelope-from ) id 1QtH3S-0007rV-Ci for caml-list@inria.fr; Tue, 16 Aug 2011 12:39:30 +0200 Date: Tue, 16 Aug 2011 12:39:29 +0200 From: Mauricio Fernandez To: caml-list@inria.fr Message-ID: <20110816103929.GB3772@NANA.localdomain> Mail-Followup-To: caml-list@inria.fr References: <20110816.105738.246515733851238101.Christophe.Troestler@umons.ac.be> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) Subject: Re: [Caml-list] Interfacing with C: bad practice On Tue, Aug 16, 2011 at 01:21:02PM +0400, Dmitry Bely wrote: > On Tue, Aug 16, 2011 at 12:57 PM, Christophe TROESTLER > wrote: > > On Tue, 16 Aug 2011 11:37:03 +0400, Dmitry Bely wrote: > >> In the line > >> > >>         list = wrp_ml_cons(caml_copy_string(*s), list); /* bug! */ > >> > > Let me explain again. Before wrp_ml_cons() is called, C compiler > > 1. Pushes a _copy_ of list value onto the stack. > 2. Calls caml_copy_string(*s) and pushes its result onto the stack also. > 3. Calls wrp_ml_cons(). > > After (2) the second parameter of wrp_ml_cons() becomes invalid: it is > a _copy_ of list, not registered as a local root. This has been in my mind for a while: why don't CAMLparamX declare the local variables as volatile? -- Mauricio Fernandez - http://eigenclass.org