diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-13 13:19:06 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-13 13:19:06 -0400 |
commit | ed75380bdae30dc1313aef44beafad860cf246c0 (patch) | |
tree | 564084e9eedb713dda711e35573ded9a3d5ff17d /src/pl/plpython/plpy_cursorobject.c | |
parent | 2e46bf67114586835f4a9908f1a1f08ee8ba83a8 (diff) | |
download | postgresql-ed75380bdae30dc1313aef44beafad860cf246c0.tar.gz postgresql-ed75380bdae30dc1313aef44beafad860cf246c0.zip |
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
Diffstat (limited to 'src/pl/plpython/plpy_cursorobject.c')
-rw-r--r-- | src/pl/plpython/plpy_cursorobject.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pl/plpython/plpy_cursorobject.c b/src/pl/plpython/plpy_cursorobject.c index 4226dc7d193..e8240b63c90 100644 --- a/src/pl/plpython/plpy_cursorobject.c +++ b/src/pl/plpython/plpy_cursorobject.c @@ -14,6 +14,7 @@ #include "plpy_cursorobject.h" #include "plpy_elog.h" +#include "plpy_main.h" #include "plpy_planobject.h" #include "plpy_procedure.h" #include "plpy_resultobject.h" @@ -119,6 +120,7 @@ PLy_cursor_query(const char *query) PG_TRY(); { + PLyExecutionContext *exec_ctx = PLy_current_execution_context(); SPIPlanPtr plan; Portal portal; @@ -130,7 +132,7 @@ PLy_cursor_query(const char *query) SPI_result_code_string(SPI_result)); portal = SPI_cursor_open(NULL, plan, NULL, NULL, - PLy_curr_procedure->fn_readonly); + exec_ctx->curr_proc->fn_readonly); SPI_freeplan(plan); if (portal == NULL) @@ -207,6 +209,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) PG_TRY(); { + PLyExecutionContext *exec_ctx = PLy_current_execution_context(); Portal portal; char *volatile nulls; volatile int j; @@ -253,7 +256,7 @@ PLy_cursor_plan(PyObject *ob, PyObject *args) } portal = SPI_cursor_open(NULL, plan->plan, plan->values, nulls, - PLy_curr_procedure->fn_readonly); + exec_ctx->curr_proc->fn_readonly); if (portal == NULL) elog(ERROR, "SPI_cursor_open() failed: %s", SPI_result_code_string(SPI_result)); |