summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_procedure.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2024-05-07 18:15:00 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2024-05-07 18:15:00 -0400
commitbe18a12b663181f304d49022a452e31e4df42ff2 (patch)
treedde4796b8533453cce35289270982ac3071cb91e /src/pl/plpython/plpy_procedure.h
parent05ffe9398b758bbb8d30cc76e9bbc638dab2d477 (diff)
Don't corrupt plpython's "TD" dictionary in a recursive trigger call.
If a plpython-language trigger caused another one to be invoked, the "TD" dictionary created for the inner one would overwrite the outer one's "TD" dictionary. This is more or less the same problem that 1d2fe56e4 fixed for ordinary functions in plpython, so fix it the same way, by saving and restoring "TD" during a recursive invocation. This fix makes an ABI-incompatible change in struct PLySavedArgs. I'm not too worried about that because it seems highly unlikely that any extension is messing with those structs. We could imagine doing something weird to preserve nominal ABI compatibility in the back branches, like keeping the saved TD object in an extra element of namedargs[]. However, that would only be very nominal compatibility: if anything *is* touching PLySavedArgs, it would likely do the wrong thing due to not knowing about the additional value. So I judge it not worth the ugliness to do something different there. (I also changed struct PLyProcedure, but its added field fits into formerly-padding space, so that should be safe.) Per bug #18456 from Jacques Combrink. This bug is very ancient, so back-patch to all supported branches. Discussion: https://postgr.es/m/3008982.1714853799@sss.pgh.pa.us
Diffstat (limited to 'src/pl/plpython/plpy_procedure.h')
-rw-r--r--src/pl/plpython/plpy_procedure.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/pl/plpython/plpy_procedure.h b/src/pl/plpython/plpy_procedure.h
index 8968b5c92e5..5db854fc8bd 100644
--- a/src/pl/plpython/plpy_procedure.h
+++ b/src/pl/plpython/plpy_procedure.h
@@ -16,6 +16,7 @@ typedef struct PLySavedArgs
{
struct PLySavedArgs *next; /* linked-list pointer */
PyObject *args; /* "args" element of globals dict */
+ PyObject *td; /* "TD" element of globals dict, if trigger */
int nargs; /* length of namedargs array */
PyObject *namedargs[FLEXIBLE_ARRAY_MEMBER]; /* named args */
} PLySavedArgs;
@@ -32,6 +33,7 @@ typedef struct PLyProcedure
bool fn_readonly;
bool is_setof; /* true, if function returns result set */
bool is_procedure;
+ bool is_trigger; /* called as trigger? */
PLyObToDatum result; /* Function result output conversion info */
PLyDatumToOb result_in; /* For converting input tuples in a trigger */
char *src; /* textual procedure code, after mangling */