diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2014-06-05 12:44:04 +0200 |
---|---|---|
committer | mrmilosz <milosz@milosz.ca> | 2015-12-12 17:51:45 -0500 |
commit | 021f6d22ad5995a24439befdf5acde2590556cf4 (patch) | |
tree | 99ff670f051fa48dd1c57f05a15ccd13f73f0b45 | |
parent | 7302f348bc7ec7121e04aae70eb8e7705b971334 (diff) | |
download | psycopg2-021f6d22ad5995a24439befdf5acde2590556cf4.tar.gz |
More straightforward param refcount handling in callproc
-rw-r--r-- | psycopg/cursor_type.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index b65b7d2..06a43f1 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -1022,6 +1022,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) char *sql = NULL; Py_ssize_t procname_len, i, nparameters = 0, sl = 0; PyObject *parameters = Py_None; + PyObject *pvals = NULL; PyObject *operation = NULL; PyObject *res = NULL; @@ -1057,9 +1058,8 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) /* a Dict is complicated; the parameter names go into the query */ if (using_dict) { #if PG_VERSION_NUM >= 90000 - if (!(pnames = PyDict_Keys(parameters))) { - goto exit; - } + if (!(pnames = PyDict_Keys(parameters))) { goto exit; } + if (!(pvals = PyDict_Values(parameters))) { goto exit; } sl = procname_len + 17 + nparameters * 5 - (nparameters ? 1 : 0); @@ -1104,9 +1104,6 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) sql[sl-2] = ')'; sql[sl-1] = '\0'; - if (!(parameters = PyDict_Values(parameters))) { - goto exit; - } #else PyErr_SetString(PyExc_NotImplementedError, "named parameters require psycopg2 compiled against libpq 9.0+"); @@ -1116,6 +1113,9 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) /* a list (or None, or empty data structure) is a little bit simpler */ else { + Py_INCREF(parameters); + pvals = parameters; + sl = procname_len + 17 + nparameters * 3 - (nparameters ? 1 : 0); sql = (char*)PyMem_Malloc(sl); @@ -1136,11 +1136,9 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) goto exit; } - if (0 <= _psyco_curs_execute(self, operation, parameters, - self->conn->async, 0)) { - if (using_dict) { - Py_DECREF(parameters); - } + if (0 <= _psyco_curs_execute( + self, operation, pvals, self->conn->async, 0)) { + /* return None from this until it's DBAPI compliant... */ res = Py_None; } @@ -1159,6 +1157,7 @@ exit: Py_XDECREF(pnames); #endif Py_XDECREF(operation); + Py_XDECREF(pvals); PyMem_Free((void*)sql); return res; } |