Re: Writing triggers in C++

From: "bjarne" <bjarne(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Writing triggers in C++
Date: 2007-02-14 19:06:45
Message-ID: 1171480005.055206.203510@s48g2000cws.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Feb 14, 11:26 am, f(dot)(dot)(dot)(at)phlo(dot)org ("Florian G. Pflug") wrote:
> Neil Conway wrote:
> > On Wed, 2007-02-14 at 13:19 -0300, Alvaro Herrera wrote:
> >> Probably stack allocation doesn't matter much, as I think that would be
> >> unwinded by the longjmp call. I don't know a lot about C++, but if
> >> there are allocations in the data area then those would probably not be
> >> freed. But it makes me wonder -- is longjmp very compatible with C++
> >> exceptions at all?
>
> > "C-style stack unwinding (using setjmp and longjmp from <csetjmp>) is
> > incompatible with exception-handling and is best avoided." (Stroustrup,
> > p. 433).
>
> > Which presumably means that in practice, the interaction between these
> > features is implementation-defined.
>
> Well, as long as you don't longjmp "past" an C++ catch block, and don't
> throw an C++ exception "past" an setjmp handler, there should be no
> problem I think. Or at least I can't imagine how a problem could arise..
>

Also, don't jump out of (past) the scope of any local variable with a
destructor.

If you are in a C++ program, use exceptions. If you are in a C
program, fake the equivalent using setjmp/longjmp. Don't mix the two -
it's too tricky.

-- Bjarne Stroustrup; http://www.research.att.com/~bs

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2007-02-14 19:07:56 Re: Plan for compressed varlena headers
Previous Message Jeff Davis 2007-02-14 18:59:22 Re: Fixing insecure security definer functions