[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ and stack unwinding/destruction

From: David Fang
Subject: Re: C++ and stack unwinding/destruction
Date: Tue, 20 Mar 2007 00:11:35 -0500 (EST)

> "David Fang" wrote:
> > C++ relies heavily on constructor-destructor duality
> > [...]
> > The implementation of guile's C-style exceptions using
> > setjmp/longjmp, however breaks this universal law.
> > [...]
> > In the event of scm_error_scm(), the destructors that
> > *should* be called in the frame of this function are
> > just skipped.
> I do not have much time to dig into the list's archive,
> so I do not know what is in the inconclusive thread;
> anyway, you have to use 'scm_c_catch()' and the C++'s
> 'catch'.

        First, thanks for the informative answer.

> You have to separate the Guile/C code from the C++ code:
> * when calling C++ from Guile/C: put C++ code inside
>   a 'catch' and convert the C++ exception into the
>   Guile/C arguments to 'scm_error()';
> * when calling Guile/C from C++: put the Guile/C code
>   into a separate function and use 'scm_c_catch()' in
>   the C++ function to invoke it.
> I do it all the time when I register a Guile/C callback
> into an external C library and I cannot let the dynwind
> mechanism go through the foreign functions.

        So this means I should be able to stop the dynwind from plowing
through any pure C++ function, in theory, right?  I was hoping there would
be something cleaner, but having some way is better than none.  I'm just
saddened that the C++ semantics I could asssume for 'free' (compiler
managed) would be as automatic, but this is C we're talking about.  :-/

> When I need to invoke a Scheme function from the callback
> I use something like this:
--------------->8 snip 8<---------------
> when I register the callback I allocate a 'frame_t' and
> initialise the 's_function' field with the SCM procedure
> If later I need to retrhow the Guile error I use:
--------------->8 snip 8<---------------

        I'll digest your example some more and hopefully give it a shot.
(I'm still itching to upgrade the libguile API for C++, if I only had the
time to futz with it...)

David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
        -- (2400 baud? Netscape 3.0?? lynx??? No problem!)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]