Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001961OCaml~DO NOT USE (was: OCaml general)public2003-12-04 16:142016-11-14 21:54
Assigned To 
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001961: Re: [Caml-list] Troubles with marshaled/unmarshaled exception
DescriptionThe short answer is: don't marshal exceptions.

The longer answer is that exception marshaling is nearly as hard as
function/closure marshaling. I'm sure the OCaml implementors can give a
more precise description, but here is my understanding.

    1. A program can have a large number of exceptions.
    2. Exception names are scoped. The following exceptions
       A.Foo and B.Foo are different. The same holds for
       compilation units/files that are separately compiled.

       module A = struct exception Foo end
       module B = struct exception Foo end

Just like normal unions, the exceptions are eventually represented as a
block with a tag and some values, but exception tags are resolved at
*link* time.

This explains why you can't marshal an exception in one process, send it
over a channel, unmarshal it in another process, and expect it to make
any sense at all, because the linker's tag selection is likely to be
different in the two processes.

Why doesn't it work within the same process? This is most likely
because the exception tag is a (pointer to a) normal OCaml value, but
pattern matching on the exception value uses pointer equality for the
tag. When you marshal/unmarshal, you deep-copy the tag, and pointer
equality no longer works (though normal equality works just fine).
There are excellent implementation reasons to use pointer equality on
tags; and faithfulness of marshaling is a low priority.

So, it is likely the marshaler could be changed so that exception
marshaling would work as you might expect, but it would be hard, and not
very worthwhile. Don't expect exception marshaling to work in a
portable manner...


Artem Prisyznuk wrote:

> Hello,
> I found strange behavior of pattern matching of
> marshaled/unmarshaled exception.
> Next code describe problem:
> let e = Failure "test";;
> let e' = Marshal.from_string (Marshal.to_string e []) 0;;
> let print_fun exc =
> match exc with
> Failure _ -> print_endline "Matching OK"
> | exc -> print_endline "Matching Fail";;
> print_fun e;;
> print_fun e';;
> Printf.printf "e = e' is %b\n" (e=e');;
> Output:
> Matching OK
> Matching Fail
> e = e' is true
> So second call print missing value.

Jason Hickey [^]
Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257

TagsNo tags attached.
Attached Files

- Relationships
has duplicate 0004978acknowledged exceptions lose identity after marshalling 
related to 0007413resolved marshaling of extensible variant types does not work 

-  Notes
administrator (administrator)
2003-12-08 20:38

answer to PR#1957

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2009-09-16 14:45 xclerc Status acknowledged => closed
2009-09-16 14:45 xclerc Resolution open => won't fix
2014-05-03 00:00 gasche Relationship added has duplicate 0004978
2016-11-14 21:54 gasche Relationship added related to 0007413
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker