Version française
Home     About     Download     Resources     Contact us    
Browse thread
linking the same module more than once
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jake Donham <jake@d...>
Subject: linking the same module more than once
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