summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-02-23 18:41:31 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-02-23 18:50:06 +0000
commitff61cf25b694f9c41d09d650ca28102cc2152ea0 (patch)
tree3c57333a43b0da8095f551833b8b6241c8940289 /psycopg/psycopgmodule.c
parent026899e0c1479412b62dd42d6cc7c0e4fb051370 (diff)
downloadpsycopg2-ff61cf25b694f9c41d09d650ca28102cc2152ea0.tar.gz
Fixed refcount of None if namedtuples are not available
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 4177401..9f71d7e 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -685,15 +685,11 @@ psyco_make_description_type(void)
/* Try to import collections.namedtuple */
if (!(coll = PyImport_ImportModule("collections"))) {
Dprintf("psyco_make_description_type: collections import failed");
- PyErr_Clear();
- rv = Py_None;
- goto exit;
+ goto error;
}
if (!(nt = PyObject_GetAttrString(coll, "namedtuple"))) {
Dprintf("psyco_make_description_type: no collections.namedtuple");
- PyErr_Clear();
- rv = Py_None;
- goto exit;
+ goto error;
}
/* Build the namedtuple */
@@ -705,6 +701,13 @@ exit:
Py_XDECREF(nt);
return rv;
+
+error:
+ /* controlled error: we will fall back to regular tuples. Return None. */
+ PyErr_Clear();
+ rv = Py_None;
+ Py_INCREF(rv);
+ goto exit;
}
@@ -920,7 +923,7 @@ INIT_MODULE(_psycopg)(void)
if (!(psycoEncodings = PyDict_New())) { goto exit; }
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
psyco_null = Bytes_FromString("NULL");
- psyco_DescriptionType = psyco_make_description_type();
+ if (!(psyco_DescriptionType = psyco_make_description_type())) { goto exit; }
/* set some module's parameters */
PyModule_AddStringConstant(module, "__version__", PSYCOPG_VERSION);