1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-08 00:47:37 +03:00

Create a stack of pl/python "execution contexts".

This replaces the former global variable PLy_curr_procedure, and provides
a place to stash per-call-level information.  In particular we create a
per-call-level scratch memory context.

For the moment, the scratch context is just used to avoid leaking memory
from datatype output function calls in PLyDict_FromTuple.  There probably
will be more use-cases in future.

Although this is a fix for a pre-existing memory leakage bug, it seems
sufficiently invasive to not want to back-patch; it feels better as part
of the major rearrangement of plpython code that we've already done as
part of 9.2.

Jan Urbański
This commit is contained in:
Tom Lane
2012-03-13 13:19:06 -04:00
parent 2e46bf6711
commit ed75380bda
9 changed files with 141 additions and 40 deletions

View File

@@ -455,7 +455,9 @@ PLy_function_delete_args(PLyProcedure *proc)
static void
plpython_return_error_callback(void *arg)
{
if (PLy_curr_procedure)
PLyExecutionContext *exec_ctx = PLy_current_execution_context();
if (exec_ctx->curr_proc)
errcontext("while creating return value");
}
@@ -781,7 +783,9 @@ PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
static void
plpython_trigger_error_callback(void *arg)
{
if (PLy_curr_procedure)
PLyExecutionContext *exec_ctx = PLy_current_execution_context();
if (exec_ctx->curr_proc)
errcontext("while modifying trigger row");
}