Version française
Home     About     Download     Resources     Contact us    
Browse thread
Exception Unix_error problem in toplevel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bob Williams <a6b37331@t...>
Subject: Re: [Caml-list] Exception Unix_error problem in toplevel
On Fri, Feb 02, 2007 at 01:08:20PM +0100, ls-ocaml-developer-2006@m-e-leypold.de wrote:
> Bob Williams <a6a37331@telus.net> writes:
>
> I couldn't reproduce that on Debian Sarge (Stable is Sarge as of this
> date) neither with
> 
>  - Objective Caml version 3.08.3 -- as distributed with Sarge.
> 
> nor with
> 
>  - Objective Caml version 3.09.2 -- as compiled by me from GODI 2
>    months ago.
> 
> Are you running Testing or something like this? Since I assume that
> exceptions are represented just by integer "tags" at the VM level:
> Might there be a library mismatch in your case? (This is a question to
> the experts here, since my understanding was that that is prevented by
> checksums in the interfaces).
> 
> Whatever: If your ocaml comes from Debian (and not from GODI or
> similar), I suggest you report a bug to the Debian BTS, too. It woul
> be terrible, if we had to live with a buggy OCaml for the next 3 years
> :-) after the Etch release.
> 
> Regards -- Markus

Thank you, Markus, and thanks to everyone else who has tried to help.
Special thanks go to Daniel de Rauglaudre, who tried hard to reproduce
the problem.

The explanation for the weird behavior turns out to be partly my
fault, and partly a possible real bug in toplevel.

It turns out that

	ocaml unix.cma bug.cmo

loads "unix.cma" twice, because I have an .ocamlinit (left over from a
previous project) that also loads "unix.cma"!  My stupid fault, mea
culpa.

Now to the possible bug in toplevel.  According to section 6.8.2 of
the OCaml manual,

	exception Unix_error of ...

simply declares another variant of the built-in variant type "exn".  I
haven't looked into the implementation of OCaml, but I assume the
compiler statically assigns a tag number to every variant of a normal
variant type.  For exn, however, the tag numbers must be assigned at
load time or run time.

And that is the problem I stumbled over.  The second copy of
"unix.cma" allocates a new tag number for exception Unix_error.
However, the tag number of the *first* copy of Unix_error has already
been bound into "bug.cmo".  So when the second Unix_error is raised,
"bug.cmo" catches it but fails to see it as a Unix_error. 

My first impulse was to suggest that toplevel disallow the
redefinition of anything.  But Daniel has convinced me that reloading
an object file can be useful during development.  So how about this:
when toplevel redefines an exception, the exception's tag number
should not change.

Daniel mentioned a related problem, with similar pitfalls:

	type t = C;;
	... define function Foo using t ...
	type t = D;;
	... what should we do about Foo? ...

Foo is now clearly obsolete, as are any blocks on the heap that were
constructed by C.  What should be done here?