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 PAA08546; Thu, 1 Apr 2004 15:39:23 +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 PAA05915 for ; Thu, 1 Apr 2004 15:39:22 +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 i31DblYM024295; Thu, 1 Apr 2004 15:37:47 +0200 Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA08166; Thu, 1 Apr 2004 15:37:46 +0200 (MET DST) Date: Thu, 1 Apr 2004 15:37:46 +0200 From: Xavier Leroy To: Richard Cole Cc: caml-list@inria.fr Subject: Re: [Caml-list] Indeterminate Initialization: Is it a Bug? Message-ID: <20040401153746.B6842@pauillac.inria.fr> References: <406BDB2E.2000807@itee.uq.edu.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <406BDB2E.2000807@itee.uq.edu.au>; from rcole@itee.uq.edu.au on Thu, Apr 01, 2004 at 07:04:46PM +1000 X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 bug:01 funky:01 funky:01 printf:01 fprintf:01 stderr:01 stderr:01 mli:01 mli:01 val:01 initialized:01 whereby:01 link-time:01 unreferenced:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 16 > There seems to be a difference in initialization behaviour using the > native compiler depending on whether a module contains non "external" > calls. [...] > The output doesn't contain "Funky.Init". The problem is that the > initialization code in the funky module didn't get called. If I wrap the > functions as in: > > #!/bin/bash > echo ' > external ml_funky: int -> int = "ml_funky" ;; > let funky x = ml_funky x ;; > Printf.fprintf stderr "Init.\n"; flush stderr ;; > ' > funky.ml A simpler solution is to define "funky" as an external in the .ml file but declare it as a regular value in the .mli file: .ml: external funky: int -> int = "ml_funky" .mli: val funky: int -> int > So I have the following question: Is there some way to guarrentee that > modules are initialized exactly once? Does the development team see the > current situation, whereby intialization depends on wheher there is a > non external method in the module that is called, as a problem? Can it > be fixed? The behavior you observe is a consequence of the link-time elimination of unreferenced .cma or .cmxa members. An "external" declaration in a module interface is like a type declaration: using it elsewhere doesn't create a reference to the implementation of the defining module. You can turn off this link-time elimination using the -linkall flag, either at library creation time (ocamlmklib), or at link-time (ocamlopt). Then, all modules will be initialized exactly once and in the order given, like you expect. - Xavier Leroy ------------------- 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