Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit825ebc9

Browse files
Move return statements out of PG_TRY blocks.
If we exit a PG_TRY block early via "continue", "break", "goto", or"return", we'll skip unwinding its exception stack. This changemoves a couple of such "return" statements in PL/Python out ofPG_TRY blocks. This was introduced ind0aa965 and affects allsupported versions.We might also be able to add compile-time checks to preventrecurrence, but that is left as a future exercise.Reported-by: Mikhail Gribkov, Xing GuoAuthor: Xing GuoReviewed-by: Michael Paquier, Andres Freund, Tom LaneDiscussion:https://postgr.es/m/CAMEv5_v5Y%2B-D%3DCO1%2Bqoe16sAmgC4sbbQjz%2BUtcHmB6zcgS%2B5Ew%40mail.gmail.comDiscussion:https://postgr.es/m/CACpMh%2BCMsGMRKFzFMm3bYTzQmMU5nfEEoEDU2apJcc4hid36AQ%40mail.gmail.comBackpatch-through: 11 (all supported versions)
1 parentccb479e commit825ebc9

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

‎src/pl/plpython/plpy_exec.c

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,20 @@ static PyObject *
413413
PLy_function_build_args(FunctionCallInfofcinfo,PLyProcedure*proc)
414414
{
415415
PyObject*volatilearg=NULL;
416-
PyObject*volatileargs=NULL;
416+
PyObject*args;
417417
inti;
418418

419+
/*
420+
* Make any Py*_New() calls before the PG_TRY block so that we can quickly
421+
* return NULL on failure. We can't return within the PG_TRY block, else
422+
* we'd miss unwinding the exception stack.
423+
*/
424+
args=PyList_New(proc->nargs);
425+
if (!args)
426+
returnNULL;
427+
419428
PG_TRY();
420429
{
421-
args=PyList_New(proc->nargs);
422-
if (!args)
423-
returnNULL;
424-
425430
for (i=0;i<proc->nargs;i++)
426431
{
427432
PLyDatumToOb*arginfo=&proc->args[i];
@@ -685,19 +690,34 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
685690
*pltlevel,
686691
*pltrelid,
687692
*plttablename,
688-
*plttableschema;
689-
PyObject*pltargs,
693+
*plttableschema,
694+
*pltargs=NULL,
690695
*pytnew,
691-
*pytold;
692-
PyObject*volatilepltdata=NULL;
696+
*pytold,
697+
*pltdata;
693698
char*stroid;
694699

695-
PG_TRY();
700+
/*
701+
* Make any Py*_New() calls before the PG_TRY block so that we can quickly
702+
* return NULL on failure. We can't return within the PG_TRY block, else
703+
* we'd miss unwinding the exception stack.
704+
*/
705+
pltdata=PyDict_New();
706+
if (!pltdata)
707+
returnNULL;
708+
709+
if (tdata->tg_trigger->tgnargs)
696710
{
697-
pltdata=PyDict_New();
698-
if (!pltdata)
711+
pltargs=PyList_New(tdata->tg_trigger->tgnargs);
712+
if (!pltargs)
713+
{
714+
Py_DECREF(pltdata);
699715
returnNULL;
716+
}
717+
}
700718

719+
PG_TRY();
720+
{
701721
pltname=PLyUnicode_FromString(tdata->tg_trigger->tgname);
702722
PyDict_SetItemString(pltdata,"name",pltname);
703723
Py_DECREF(pltname);
@@ -837,12 +857,9 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
837857
inti;
838858
PyObject*pltarg;
839859

840-
pltargs=PyList_New(tdata->tg_trigger->tgnargs);
841-
if (!pltargs)
842-
{
843-
Py_DECREF(pltdata);
844-
returnNULL;
845-
}
860+
/* pltargs should have been allocated before the PG_TRY block. */
861+
Assert(pltargs);
862+
846863
for (i=0;i<tdata->tg_trigger->tgnargs;i++)
847864
{
848865
pltarg=PLyUnicode_FromString(tdata->tg_trigger->tgargs[i]);
@@ -863,6 +880,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
863880
}
864881
PG_CATCH();
865882
{
883+
Py_XDECREF(pltargs);
866884
Py_XDECREF(pltdata);
867885
PG_RE_THROW();
868886
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp