From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA18588; Fri, 5 Dec 2003 01:14:46 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA18382 for ; Fri, 5 Dec 2003 01:14:45 +0100 (MET) Received: from yukon.yapper.org (adsl-67-120-175-89.dsl.lsan03.pacbell.net [67.120.175.89]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hB50Ehr24230 for ; Fri, 5 Dec 2003 01:14:43 +0100 (MET) Received: from cs.caltech.edu (kenai.yapper.org [67.120.175.90]) by yukon.yapper.org (Postfix) with ESMTP id 6C3542AA; Thu, 4 Dec 2003 16:14:40 -0800 (PST) Message-ID: <3FCFCDF0.3070606@cs.caltech.edu> Date: Thu, 04 Dec 2003 16:14:40 -0800 From: Jason Hickey Organization: Caltech Computer Science User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Artem Prisyznuk Cc: caml-bugs@pauillac.inria.fr, caml-list@inria.fr Subject: Re: [Caml-list] Troubles with marshaled/unmarshaled exception References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; hickey:01 caml-list:01 marshaled:01 unmarshaled:01 marshaling:01 marshaling:01 foo:01 foo:01 struct:01 struct:01 unions:01 unmarshal:01 unmarshal:01 artem:01 marshaled:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk The 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. First, 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... Jason 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 http://www.cs.caltech.edu/~jyh Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners