aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2005-12-29 21:47:32 +0000
committerNeil Conway <neilc@samurai.com>2005-12-29 21:47:32 +0000
commitedafb4f037e7fd0eee14aaf9f263f154af5a6f66 (patch)
tree8c675a8fadbdcde8973f4eea0ba4460f185f9636
parent195f1642285d59b4bd42ec2ba8bbcf46b8aedd93 (diff)
downloadpostgresql-edafb4f037e7fd0eee14aaf9f263f154af5a6f66.tar.gz
postgresql-edafb4f037e7fd0eee14aaf9f263f154af5a6f66.zip
Index: src/pl/plpython/plpython.c
=================================================================== RCS file: /Users/neilc/postgres/cvs_root/pgsql/src/pl/plpython/plpython.c,v retrieving revision 1.67 diff -c -r1.67 plpython.c *** src/pl/plpython/plpython.c 26 Dec 2005 04:28:48 -0000 1.67 --- src/pl/plpython/plpython.c 29 Dec 2005 16:54:57 -0000 *************** *** 2,8 **** * plpython.c - python as a procedural language for PostgreSQL * * This software is copyright by Andrew Bosma ! * but is really shameless cribbed from pltcl.c by Jan Weick, and * plperl.c by Mark Hollomon. * * The author hereby grants permission to use, copy, modify, --- 2,8 ---- * plpython.c - python as a procedural language for PostgreSQL * * This software is copyright by Andrew Bosma ! * but is really shamelessly cribbed from pltcl.c by Jan Wieck, and * plperl.c by Mark Hollomon. * * The author hereby grants permission to use, copy, modify, *************** *** 1996,2002 **** int i, rv; PLyPlanObject *plan; - char *nulls; MemoryContext oldcontext; if (list != NULL) --- 1996,2001 ---- *************** *** 2018,2024 **** if (nargs != plan->nargs) { char *sv; - PyObject *so = PyObject_Str(list); if (!so) --- 2017,2022 ---- *************** *** 2036,2048 **** oldcontext = CurrentMemoryContext; PG_TRY(); { ! nulls = palloc(nargs * sizeof(char)); for (i = 0; i < nargs; i++) { PyObject *elem, *so; - char *sv; elem = PySequence_GetItem(list, i); if (elem != Py_None) --- 2034,2045 ---- oldcontext = CurrentMemoryContext; PG_TRY(); { ! char *nulls = palloc(nargs * sizeof(char)); for (i = 0; i < nargs; i++) { PyObject *elem, *so; elem = PySequence_GetItem(list, i); if (elem != Py_None) *************** *** 2051,2070 **** if (!so) PLy_elog(ERROR, "function \"%s\" could not execute plan", PLy_procedure_name(PLy_curr_procedure)); ! sv = PyString_AsString(so); ! /* ! * FIXME -- if this elogs, we have Python reference leak ! */ ! plan->values[i] = ! FunctionCall3(&(plan->args[i].out.d.typfunc), ! CStringGetDatum(sv), ! ObjectIdGetDatum(plan->args[i].out.d.typioparam), ! Int32GetDatum(-1)); ! Py_DECREF(so); ! Py_DECREF(elem); nulls[i] = ' '; } else --- 2048,2073 ---- if (!so) PLy_elog(ERROR, "function \"%s\" could not execute plan", PLy_procedure_name(PLy_curr_procedure)); ! Py_DECREF(elem); ! PG_TRY(); ! { ! char *sv = PyString_AsString(so); ! plan->values[i] = ! FunctionCall3(&(plan->args[i].out.d.typfunc), ! CStringGetDatum(sv), ! ObjectIdGetDatum(plan->args[i].out.d.typioparam), ! Int32GetDatum(-1)); ! } ! PG_CATCH(); ! { ! Py_DECREF(so); ! PG_RE_THROW(); ! } ! PG_END_TRY(); + Py_DECREF(so); nulls[i] = ' '; } else
-rw-r--r--src/pl/plpython/plpython.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 5b585653813..f4c6985bc3a 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -2,7 +2,7 @@
* plpython.c - python as a procedural language for PostgreSQL
*
* This software is copyright by Andrew Bosma
- * but is really shameless cribbed from pltcl.c by Jan Weick, and
+ * but is really shamelessly cribbed from pltcl.c by Jan Wieck, and
* plperl.c by Mark Hollomon.
*
* The author hereby grants permission to use, copy, modify,
@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.67 2005/12/26 04:28:48 neilc Exp $
+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.68 2005/12/29 21:47:32 neilc Exp $
*
*********************************************************************
*/
@@ -1996,7 +1996,6 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
int i,
rv;
PLyPlanObject *plan;
- char *nulls;
MemoryContext oldcontext;
if (list != NULL)
@@ -2018,7 +2017,6 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
if (nargs != plan->nargs)
{
char *sv;
-
PyObject *so = PyObject_Str(list);
if (!so)
@@ -2036,13 +2034,12 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
oldcontext = CurrentMemoryContext;
PG_TRY();
{
- nulls = palloc(nargs * sizeof(char));
+ char *nulls = palloc(nargs * sizeof(char));
for (i = 0; i < nargs; i++)
{
PyObject *elem,
*so;
- char *sv;
elem = PySequence_GetItem(list, i);
if (elem != Py_None)
@@ -2051,20 +2048,26 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
if (!so)
PLy_elog(ERROR, "function \"%s\" could not execute plan",
PLy_procedure_name(PLy_curr_procedure));
- sv = PyString_AsString(so);
+ Py_DECREF(elem);
- /*
- * FIXME -- if this elogs, we have Python reference leak
- */
- plan->values[i] =
- FunctionCall3(&(plan->args[i].out.d.typfunc),
- CStringGetDatum(sv),
- ObjectIdGetDatum(plan->args[i].out.d.typioparam),
- Int32GetDatum(-1));
+ PG_TRY();
+ {
+ char *sv = PyString_AsString(so);
- Py_DECREF(so);
- Py_DECREF(elem);
+ plan->values[i] =
+ FunctionCall3(&(plan->args[i].out.d.typfunc),
+ CStringGetDatum(sv),
+ ObjectIdGetDatum(plan->args[i].out.d.typioparam),
+ Int32GetDatum(-1));
+ }
+ PG_CATCH();
+ {
+ Py_DECREF(so);
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+ Py_DECREF(so);
nulls[i] = ' ';
}
else