From: | Xing Guo <higuoxing(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Nathan Bossart <nathandbossart(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: PL/Python: Fix return in the middle of PG_TRY() block. |
Date: | 2023-01-18 12:31:04 |
Message-ID: | CACpMh+Afa1KRJ6Of2LZivoaZsvR3QaLWPS2oLfzhDP7=iv6uBw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Jan 16, 2023 at 11:29 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Xing Guo <higuoxing(at)gmail(dot)com> writes:
> > Are there any unsafe codes in pltcl.c? The return statement is in the
> > PG_CATCH() block, I think the exception stack has been recovered in
> > PG_CATCH block so the return statement in PG_CATCH block should be ok?
>
> Yes, the stack has already been unwound at the start of a PG_CATCH
> (or PG_FINALLY) block, so there is no reason to avoid returning
> out of those.
>
> In principle you could also mess things up with a "continue", "break",
> or "goto" leading out of PG_TRY. That's probably far less likely
> than "return", but I wonder whether Andres' compiler hack will
> catch that.
>
> regards, tom lane
>
Thank you Tom,
Based on your comments, I've refactored my clang checker[1], now it can
warn about the following patterns:
1. return statement in PG_TRY(). We've catched all of them in this thread.
2. continue statement in PG_TRY() *unless* it's in for/while/do-while
statements.
3. break statement in PG_TRY() *unless* it's in for/while/do-while/switch
statements.
4. goto statement in PG_TRY() *unless* the label it points to is in the
same PG_TRY block.
Good news is that, there's no patterns (2, 3, 4) in Postgres source tree
and we've catched all of the return statements in the PG_TRY block in this
thread.
[1]
https://github.com/higuoxing/clang-plugins/blob/main/lib/ReturnInPgTryBlockChecker.cpp
Best Regards,
Xing
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2023-01-18 12:36:37 | Re: Extracting cross-version-upgrade knowledge from buildfarm client |
Previous Message | Alvaro Herrera | 2023-01-18 12:30:45 | Re: Doc: Rework contrib appendix -- informative titles, tweaked sentences |