From: Xavier Leroy <xavier.leroy@inria.fr>
To: Richard Cole <rcole@itee.uq.edu.au>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Indeterminate Initialization: Is it a Bug?
Date: Thu, 1 Apr 2004 15:37:46 +0200 [thread overview]
Message-ID: <20040401153746.B6842@pauillac.inria.fr> (raw)
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
> 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
prev parent reply other threads:[~2004-04-01 13:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 9:04 Richard Cole
2004-04-01 13:37 ` Xavier Leroy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040401153746.B6842@pauillac.inria.fr \
--to=xavier.leroy@inria.fr \
--cc=caml-list@inria.fr \
--cc=rcole@itee.uq.edu.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox