From: Richard Cole <rcole@itee.uq.edu.au>
To: caml-list@inria.fr
Subject: [Caml-list] Indeterminate Initialization: Is it a Bug?
Date: Thu, 01 Apr 2004 19:04:46 +1000 [thread overview]
Message-ID: <406BDB2E.2000807@itee.uq.edu.au> (raw)
Hi,
There seems to be a difference in initialization behaviour using the
native compiler depending on whether a module contains non "external"
calls. Let me give an example:
#!/bin/bash
rm -f test_funky.ml funky.ml ml_funky.c *funky*.cm* *funky*.a *funky*.so
echo '
Printf.fprintf stderr "Test.Init\n"; flush stderr ;;
open Funky ;;
funky 4 ;;
' > test_funky.ml
echo '
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <stdio.h>
value ml_funky(value v)
{
CAMLparam1(v);
int i = Int_val(v) + 1;
fprintf(stderr, "ML_FUNKY!\n"); fflush(stderr);
CAMLreturn(Val_int(i));
};
' > ml_funky.c
echo '
external funky : int -> int = "ml_funky" ;;
Printf.fprintf stderr "Funky.Init.\n"; flush stderr ;;
' > funky.ml
gcc -Wall -c ml_funky.c -I/usr/local/godi/lib/ocaml/std-lib/
ocamlopt -c funky.ml
ocamlopt -c test_funky.ml
ocamlmklib -o funky ml_funky.o funky.cmx
ocamlopt -o test_funky.exe funky.cmxa test_funky.cmx -I .
./test_funky.exe
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
ocamlopt -c funky.ml
ocamlmklib -o funky ml_funky.o funky.cmx
ocamlopt -o test_funky.exe funky.cmxa test_funky.ml -I .
./test_funky.exe
Then the initialization code, namely the printf statement in flunky.ml
is called.
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?
I should mention that I'm using Godi with godi-ocaml version 3.07pl2 and
fairly vanilla Redhat 9. Is this problem replicatable on other platforms?
Why do I want to have intialization code always called in my modules.
Mostly because I want the following initialization code to work without
having to add a layer of indirection to my wrapper modules.
exception NotFound ;;
let _ = Callback.register "Funky.NotFound" NotFound ;;
best regards,
Richard.
-------------------
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
next reply other threads:[~2004-04-01 9:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 9:04 Richard Cole [this message]
2004-04-01 13:37 ` Xavier Leroy
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=406BDB2E.2000807@itee.uq.edu.au \
--to=rcole@itee.uq.edu.au \
--cc=caml-list@inria.fr \
/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;
as well as URLs for NNTP newsgroup(s).