mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 17:34:08 +03:00
Fixed refcount of None if namedtuples are not available
This commit is contained in:
parent
026899e0c1
commit
ff61cf25b6
|
@ -685,15 +685,11 @@ psyco_make_description_type(void)
|
||||||
/* Try to import collections.namedtuple */
|
/* Try to import collections.namedtuple */
|
||||||
if (!(coll = PyImport_ImportModule("collections"))) {
|
if (!(coll = PyImport_ImportModule("collections"))) {
|
||||||
Dprintf("psyco_make_description_type: collections import failed");
|
Dprintf("psyco_make_description_type: collections import failed");
|
||||||
PyErr_Clear();
|
goto error;
|
||||||
rv = Py_None;
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
if (!(nt = PyObject_GetAttrString(coll, "namedtuple"))) {
|
if (!(nt = PyObject_GetAttrString(coll, "namedtuple"))) {
|
||||||
Dprintf("psyco_make_description_type: no collections.namedtuple");
|
Dprintf("psyco_make_description_type: no collections.namedtuple");
|
||||||
PyErr_Clear();
|
goto error;
|
||||||
rv = Py_None;
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build the namedtuple */
|
/* Build the namedtuple */
|
||||||
|
@ -705,6 +701,13 @@ exit:
|
||||||
Py_XDECREF(nt);
|
Py_XDECREF(nt);
|
||||||
|
|
||||||
return rv;
|
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 (!(psycoEncodings = PyDict_New())) { goto exit; }
|
||||||
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
|
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
|
||||||
psyco_null = Bytes_FromString("NULL");
|
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 */
|
/* set some module's parameters */
|
||||||
PyModule_AddStringConstant(module, "__version__", PSYCOPG_VERSION);
|
PyModule_AddStringConstant(module, "__version__", PSYCOPG_VERSION);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user