caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David McClain" <dmcclain1@mindspring.com>
To: <skaller@users.sourceforge.net>
Cc: "Brian Hurt" <bhurt@spnz.org>, "caml-list" <caml-list@inria.fr>
Subject: Re: [Caml-list] C++ Throws
Date: Fri, 27 Aug 2004 21:13:52 -0700	[thread overview]
Message-ID: <001201c48cb5$73239ee0$0401000a@dylan> (raw)
In-Reply-To: <1093657249.15255.1712.camel@pelican.wigram>

Okay Skaller... (John, isn't it?) Smarty pants... you may be very correct
about most of this, but I can show you that an unhandled throw is being
turned into a call to abort() from which there is no recovery.

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 C++. How in the world would any kind of cross-language
interoperability ever function if this were the case. Mind you I'm not
disputing your estimate here, it's just that I find it a bit incredulous.

But whatever, at least with pseudo-functional closures I can handle this
problem the way that seems most natural, and down at the module level where
it probably belongs, even if it is more expensive in code and runtime. What
matters is programmer productivity and being able to prevent the application
from aborting just because of an indexing error. This is an interactive
application and abrupt aborts aren't very pleasant for the user, nor are
they necessary.

- DM

----- Original Message ----- 
From: "skaller" <skaller@users.sourceforge.net>
To: "David McClain" <dmcclain1@mindspring.com>
Cc: "Brian Hurt" <bhurt@spnz.org>; "caml-list" <caml-list@inria.fr>
Sent: Friday, August 27, 2004 18:40
Subject: Re: [Caml-list] C++ Throws


> On Sat, 2004-08-28 at 10:11, David McClain wrote:
> > Hi Brian,
> >
> > Yes, that technique is the one that I said previously works just fine. I
was
> > hoping for a higher level generic handler, instead of wrapping each
> > individual lib call with this try-catch block.
> >
> > I have been doing C++ to OCaml for years now with no difficulty. The
catch
> > here is that OCaml appears to be interposing between the established
higher
> > level catch handlers and the source of the throw exceptions. It appears
to
> > insist on not allowing any lower dynamic exceptions to propagate above
its
> > interface with a C call.
>
> No, I doubt that. What's actually happening is quite the opposite.
> C++ stack unwinding involves synchonously destroying stack
> objects and NOT returning control until the handler is reached.
>
> But you've stuck some Ocaml stack frames in the way.
> Far from Ocaml 'grabbing control', it isn't doing anything.
> Ocaml isn't ever getting control -- C++ knows nothing
> and just keeps going -- it doesn't execute the
> 'return' instruction for the callers program counter,
> it throws it away.
>
> Actually it's more complex than that -- EH has two jobs:
> (a) locate the handler
> (b) unwind the stack up to it then give it control
>
> It is allowed to unwind the stack whilst looking
> for the handler.
>
> It is also allowed to locate the handler FIRST,
> and THEN unwind. In particular if there is NO handler,
> it is allowed to core dump on the spot without unwinding
> anything -- the reason being that you then get a dump
> which actually includes debugging information :)
>
> Either way it is C++ which will either abort()
> because it can't find a handler, or corrupt
> your system and lock up or crash, if it it actually
> get stuck misinterpreting the Ocaml stack frames
> either during unwinding or trying to find
> the stack frames .. don't even count on abort()
> being called.
>
> I think it is possible to write generic handler,
> but only if you have detailed implemention details
> from you compiler vendor on how EH is implemented
> on your platform :(
>
>
> -- 
> John Skaller, mailto:skaller@users.sf.net
> voice: 061-2-9660-0850,
> snail: PO BOX 401 Glebe NSW 2037 Australia
> Checkout the Felix programming language http://felix.sf.net
>
>
>
> -------------------
> 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
>


-------------------
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


  reply	other threads:[~2004-08-28  4:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-27 22:31 David McClain
2004-08-27 23:24 ` Brian Hurt
2004-08-28  0:11   ` David McClain
2004-08-28  1:40     ` skaller
2004-08-28  4:13       ` David McClain [this message]
2004-08-28  4:55         ` David Brown
2004-08-28  7:44           ` Ville-Pertti Keinonen
2004-08-28  7:48           ` Radu-Mihail Obada
2004-08-28  8:17         ` Xavier Leroy
2004-08-28  9:24           ` skaller
2004-08-28  9:31         ` skaller
2004-08-28  0:22   ` David McClain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001201c48cb5$73239ee0$0401000a@dylan' \
    --to=dmcclain1@mindspring.com \
    --cc=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    --cc=skaller@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).