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 WAA25751; Mon, 2 Jun 2003 22:05:49 +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 WAA25610 for ; Mon, 2 Jun 2003 22:05:47 +0200 (MET DST) Received: from smtp4.wanadoo.nl (smtp4.wanadoo.nl [194.134.35.175]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h52K5kH21984; Mon, 2 Jun 2003 22:05:47 +0200 (MET DST) Received: from wanadoo.nl (p6003.vwr.wanadoo.nl [62.234.197.123]) by smtp4.wanadoo.nl (Postfix) with ESMTP id 2600A3E62D; Mon, 2 Jun 2003 22:05:43 +0200 (CEST) Message-ID: <3EDBAD39.2040901@wanadoo.nl> Date: Mon, 02 Jun 2003 22:02:01 +0200 From: Maas-Maarten Zeeman User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 X-Accept-Language: en MIME-Version: 1.0 To: Harry Chomsky Cc: Damien Doligez , Chris Hecker , "Mary F. Fernandez" , caml-list@inria.fr, Jerome Simeon Subject: Re: [Caml-list] Question about register_global_root References: <004601c32923$0269fb00$0200a8c0@harry> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 damien:01 val:01 interfacing:01 allocations:01 initialized:01 allocating:01 alloc:01 precautions:99 chris:01 ocaml:01 caml:01 handler:01 doligez:01 raises:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Harry Chomsky wrote: >Damien Doligez wrote: > > >>On Sunday, June 1, 2003, at 12:50 PM, Maas-Maarten Zeeman wrote: >> >> >>>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. >>> >>> >>I'm afraid Chris is right and the manual is wrong. >>[...] >>You must store a valid value before the first allocation that follows >>register_global_root. >> >> > >I think that both Chris and the manual are right. The manual actually >instructs the programmer to register a global root v "just before a valid >value is stored in v for the first time". Key word: "just". In other >words, as Damien says, no allocations are allowed between registration and >storing a value. > >Apparently more than one reader of the manual has missed this detail. Would >it be clearer to say "immediately before" instead of "just before"? > > Maybe it is better to be even more explicit. Registration of a global variable v is achieved by calling register_global_root(&v), with v initialized to Val_unit, before allocating and storing a valid value in v for the first time. On the other hand, some ocaml libraries (which are also examples) which use register_global_root, do not always follow this rule. i.e. install_signal_handler uses it like this: signal_handlers = alloc(NSIG, 0); register_global_root(&signal_handlers); Is this also allowed? All this also raises a question about the remove_global_root call, are there any special precautions I need to take just before or just after calling remove_global_root? Or can it be called at any time? Maas ------------------- 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