On Thu, Jun 18, 2009 at 7:41 AM, David Baelde<david.bae...@gmail.com> wrote:
> Also, note that the call to read that raises the error is from the
> same module that tries to catch the exception.
>
> I'm lost, I'd like to understand when the exception is registered: at
> runtime initialization? In this case, only one should ever be
> registered (at least it seems easy to enforce). Or is it statically
> registered somehow?

There are two things going on: First, exception tags in OCaml aren't
registered; they consist only of a block containing a distinguished
string. You can see this if you compile unix.ml with -dlambda:

  (let (Unix_error/197 (makeblock 0 "Unix.Unix_error"))

(Enforcing that there is only one of these seems a little bit delicate
with respect to module abstraction.)

Second, exceptions raised from C use Callback.register_exception,
which registers the exception (that is, the block containing the
distinguished string) globally. If you link Unix twice, loading the
second one overwrites the registration of the first. Now an exception
raised from C, by either Unix, cannot be caught by the first Unix but
only by the second.

I complained about this a while back and suggested that the bytecode
linker prevent you from linking the same module twice, but it occurs
to me now that it's necessary to allow this for the toplevel. (Still
perhaps there could be a flag for strict checking.)

I think the best solution is to be sure you have not linked Unix
twice. The objinfo tool (under tools/ in the OCaml distribution) is
useful for checking libraries; for linked binaries it's probably
easiest just to check the link command.

Jake

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to