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 KAA01529; Sat, 28 Aug 2004 10:17:46 +0200 (MET DST) 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 KAA00629 for ; Sat, 28 Aug 2004 10:17:45 +0200 (MET DST) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i7S8Hht1023980; Sat, 28 Aug 2004 10:17:43 +0200 Received: by yquem.inria.fr (Postfix, from userid 18180) id 60269BC21; Sat, 28 Aug 2004 10:17:43 +0200 (CEST) Date: Sat, 28 Aug 2004 10:17:43 +0200 From: Xavier Leroy To: David McClain Cc: skaller@users.sourceforge.net, Brian Hurt , caml-list Subject: Re: [Caml-list] C++ Throws Message-ID: <20040828081743.GA1229@yquem.inria.fr> References: <000901c48c93$9bc9eec0$0201000a@dylan> <1093657249.15255.1712.camel@pelican.wigram> <001201c48cb5$73239ee0$0401000a@dylan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001201c48cb5$73239ee0$0401000a@dylan> User-Agent: Mutt/1.3.28i X-Miltered: at concorde with ID 41303FA7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 pointers:01 unwind:01 run-time:01 exemplified:01 modula-:01 prolog:01 ramsey:01 pldi:01 simonpj:01 converge:01 catch-all:01 callbacks:01 callback:01 catch-all:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I do find it amazing that C++ would be dumb enough to try to scaffold raw > stack frames, instead of using some kind of dynamic link pointers to reach > each frame. There are indeed two "schools" of exception handling: one that unwind stack frames one by one until an exception handler is found, and one that maintains at run-time a chaining between exception handling blocks on the stack, so that no stack searching is necessary when an exception is thrown. The first school is exemplified by C++, Modula-3, Java and C#; the second school by Lisp, Caml and to some extent Prolog (if you view backtracking as a generalization of exception handling). A good description of the two approaches is the following paper: "A Single Intermediate Language That Supports Multiple Implementations of Exceptions",, Norman Ramsey and Simon Peyton Jones, PLDI 2000. http://research.microsoft.com/Users/simonpj/Papers/c--/c--exn.htm The two approaches have very different performance trade-offs. To make things worse, many people from the first school are not even aware of the second approach. So, as usual, there is no hope to see the world converge on a single exception mechanism. > How in the world would any kind of cross-language > interoperability ever function if this were the case. Cross--language exception interoperability is certainly a challenge. There are C compilers (MSVC, Tru64 cc) that provide C++-style exception handling compatible with C++, but that's not too hard given that the same compilers double as C++ compilers :-) Some ABI (Application Binary Interfaces) specify the format of stack descriptors and the unwinding algorithm, but not all. The only portable way is to install catch-all exception handlers at the boundaries between the two languages whose job is to convert exceptions from one language into exceptions from the other language. The Caml bytecode interpreter does something like this when interoperating with C, using setjmp/longjmp to represent exceptions on the C side. For C++ to Caml callbacks, you can use callback_exn to invoke the Caml code; it reifies whatever Caml exceptions can get out of the Caml code as special return values, which the C++ wrapper can test and then throw the appropriate C++ exception. For the reverse direction (Caml calling C++), I'm afraid the only solution is to use a C++ catch-all clause to turn C++ exceptions into Caml exceptions. Hope this clarifies the issue. - Xavier Leroy ------------------- 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