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 VAA20909; Sun, 1 Jun 2003 21:51:02 +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 VAA20897 for ; Sun, 1 Jun 2003 21:51:01 +0200 (MET DST) Received: from mallaury.noc.nerim.net (smtp-100-sunday.noc.nerim.net [62.4.17.100]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h51Jp0H17350 for ; Sun, 1 Jun 2003 21:51:00 +0200 (MET DST) Received: from inria.fr (planar.net0.nerim.net [213.41.168.102]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 3530A62D31; Sun, 1 Jun 2003 21:50:55 +0200 (CEST) Date: Sun, 1 Jun 2003 21:53:27 +0200 Subject: Re: [Caml-list] Question about register_global_root Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) Cc: Chris Hecker , "Mary F. Fernandez" , caml-list@inria.fr, Jerome Simeon To: Maas-Maarten Zeeman From: Damien Doligez In-Reply-To: <3ED9DA78.4040601@wanadoo.nl> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.552) X-Spam: no; 0.00; damien:01 caml-list:01 hecker:01 malloc:01 sizeof:01 val:01 interfacing:01 implemented:01 chris:01 caml:01 doligez:01 unit:03 pointer:03 heap:03 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sunday, June 1, 2003, at 12:50 PM, Maas-Maarten Zeeman wrote: > Chris Hecker wrote: > >> >>> handlers = (value *) malloc(sizeof(value)); >>> register_global_root(handlers); >> >> >> Shouldn't you init *handlers to Val_unit before calling >> register_global_root() as well? > > The manual explicitly tells that register_global_root should be called > before any valid value is stored in it for the first time, like > Val_unit. See Rule 4 of Interfacing C with Objective Caml in the > manual. > > So I think it is ok the way it is implemented. I'm afraid Chris is right and the manual is wrong. You can store Val_unit before you call register_global_root, because Val_unit is not a pointer into the Caml heap. You must store a valid value before the first allocation that follows register_global_root. You can store an allocated value (a pointer into the Caml heap) before or after calling register_global_root, but it must be after the last allocation that precedes register_global_root, and before the first allocation that succeeds it. At any rate, storing Val_unit before you call register_global_root is safe and does not cost much CPU time. -- Damien ------------------- 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