* linking the same module more than once
@ 2008-08-07 23:23 Jake Donham
2008-08-08 0:13 ` [Caml-list] " Stéphane Glondu
2008-08-08 6:13 ` Alain Frisch
0 siblings, 2 replies; 4+ messages in thread
From: Jake Donham @ 2008-08-07 23:23 UTC (permalink / raw)
To: caml-list
Hi,
Consider the following code:
a.ml: let a () = raise (Unix.Unix_error (Unix.E2BIG, "", ""))
b.ml: try A.a () with Unix.Unix_error (_,_,_) -> ()
compiled with
ocamlc -o test unix.cma a.ml unix.cma b.ml
Run it:
> ./test
Fatal error: exception Unix.Unix_error(0, "", "")
With exceptions raised from C code this can even happen within the same module:
a.ml: let a () = try Unix.mkdir "/tmp" 0o777 with Unix.Unix_error
(_,_,_) -> ()
b.ml: A.a ()
There is no trouble linking a module more than once, but different
parts of the code can wind up linked to different instances of the
module, leading to the confusing behavior that exception handling
seems not to work (and generally that things you think are equal are
not). For exceptions raised from C code, since
Callback.register_exception is called twice, the C code has a
different instance from the ML code.
Ocamlopt catches multiple definitions; seems like ocamlc should also.
But I see bugs
http://caml.inria.fr/mantis/view.php?id=1522
http://caml.inria.fr/mantis/view.php?id=1657
suggesting that this is expected behavior. Is there some use for it?
(I ran into this trying to use the ocaml-ssl module, which for some
reason builds unix.cma into ssl.cma.)
Jake
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] linking the same module more than once
2008-08-07 23:23 linking the same module more than once Jake Donham
@ 2008-08-08 0:13 ` Stéphane Glondu
2008-08-08 6:13 ` Alain Frisch
1 sibling, 0 replies; 4+ messages in thread
From: Stéphane Glondu @ 2008-08-08 0:13 UTC (permalink / raw)
To: Jake Donham; +Cc: caml-list
Jake Donham wrote:
> [...]
> There is no trouble linking a module more than once, but different
> parts of the code can wind up linked to different instances of the
> module, leading to the confusing behavior that exception handling
> seems not to work (and generally that things you think are equal are
> not). [...]
This is a problem I faced myself. My advice is to make sure some module
is not linked twice in an executable. For this, I build a .cma with the
same objects as the executable (basically, add -a to the final linking
stage), and run ocamlobjinfo on the .cma.
Sometimes, it is not up to you. See for example:
http://caml.inria.fr/mantis/view.php?id=4568
> [...]
> (I ran into this trying to use the ocaml-ssl module, which for some
> reason builds unix.cma into ssl.cma.)
I've also noticed this and submitted a patch upstream for this.
Cheers,
--
Stéphane Glondu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] linking the same module more than once
2008-08-07 23:23 linking the same module more than once Jake Donham
2008-08-08 0:13 ` [Caml-list] " Stéphane Glondu
@ 2008-08-08 6:13 ` Alain Frisch
2008-08-08 16:28 ` Jake Donham
1 sibling, 1 reply; 4+ messages in thread
From: Alain Frisch @ 2008-08-08 6:13 UTC (permalink / raw)
To: Jake Donham; +Cc: caml-list
Jake Donham wrote:
> There is no trouble linking a module more than once, but different
> parts of the code can wind up linked to different instances of the
> module, leading to the confusing behavior that exception handling
> seems not to work (and generally that things you think are equal are
> not).
You should really avoid linking two modules with the same name. This can
lead to all kind of errors and the compiler will not always catch you if
they have the same signature. You can even break type safety by linking
two modules with the same name and signature but with different
implementations:
- without Dynlink: http://caml.inria.fr/mantis/view.php?id=4231
(quite simple with ocaml; more difficult with ocamlopt, but still
possible with -pack)
- with Dynlink: http://caml.inria.fr/mantis/view.php?id=4229
-- Alain
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] linking the same module more than once
2008-08-08 6:13 ` Alain Frisch
@ 2008-08-08 16:28 ` Jake Donham
0 siblings, 0 replies; 4+ messages in thread
From: Jake Donham @ 2008-08-08 16:28 UTC (permalink / raw)
To: Alain Frisch; +Cc: caml-list
On Thu, Aug 7, 2008 at 11:13 PM, Alain Frisch <alain@frisch.fr> wrote:
> You should really avoid linking two modules with the same name.
Yes, I agree vehemently :). I would like the bytecode linker to help
me out by (at least) warning me when I do it by accident.
Jake
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-08 16:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-07 23:23 linking the same module more than once Jake Donham
2008-08-08 0:13 ` [Caml-list] " Stéphane Glondu
2008-08-08 6:13 ` Alain Frisch
2008-08-08 16:28 ` Jake Donham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox