mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
fixed crash in pdecimal_str with a few Python 2.5.x releases.
is_finite() is not available in 2.5.1, it is in 2.5.5 but is officially supported only since 2.6.
This commit is contained in:
parent
0d318179a9
commit
d601ab8239
|
@ -7,6 +7,9 @@
|
|||
* psycopg/microprotocols.c: use the adapter of an object superclass if
|
||||
available.
|
||||
|
||||
* psycopg/adapter_pdecimal.c: fixed crash in pdecimal_str with Python
|
||||
2.5.x releases in which is_finite() is not available.
|
||||
|
||||
2010-11-06 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
|
||||
* lib/extras.py: added NamedTupleCursor.
|
||||
|
|
1
NEWS-2.3
1
NEWS-2.3
|
@ -25,6 +25,7 @@ psycopg 2.3 aims to expose some new features introduced in PostgreSQL 9.0.
|
|||
|
||||
- Fixed use of `PQfreemem` instead of `free` in binary typecaster.
|
||||
- Fixed access to freed memory in `conn_get_isolation_level()`.
|
||||
- Fixed crash during Decimal adaptation with a few 2.5.x Python versions.
|
||||
|
||||
|
||||
What's new in psycopg 2.2.2
|
||||
|
|
|
@ -43,29 +43,41 @@ static PyObject *
|
|||
pdecimal_str(pdecimalObject *self)
|
||||
{
|
||||
PyObject *check, *res = NULL;
|
||||
#if PY_VERSION_HEX < 0x02050000
|
||||
check = PyObject_CallMethod(self->wrapped, "_isnan", NULL);
|
||||
if (PyInt_AsLong(check) == 1) {
|
||||
res = PyString_FromString("'NaN'::numeric");
|
||||
goto end;
|
||||
}
|
||||
Py_DECREF(check);
|
||||
check = PyObject_CallMethod(self->wrapped, "_isinfinity", NULL);
|
||||
if (abs(PyInt_AsLong(check)) == 1) {
|
||||
res = PyString_FromString("'NaN'::numeric");
|
||||
goto end;
|
||||
}
|
||||
res = PyObject_Str(self->wrapped);
|
||||
#else
|
||||
check = PyObject_CallMethod(self->wrapped, "is_finite", NULL);
|
||||
if (check == Py_True)
|
||||
if (check == Py_True) {
|
||||
res = PyObject_Str(self->wrapped);
|
||||
else
|
||||
goto end;
|
||||
}
|
||||
else if (check) {
|
||||
res = PyString_FromString("'NaN'::numeric");
|
||||
#endif
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* is_finite() was introduced 2.5.1 < somewhere <= 2.5.4.
|
||||
* We assume we are here because we didn't find the method. */
|
||||
PyErr_Clear();
|
||||
|
||||
if (!(check = PyObject_CallMethod(self->wrapped, "_isnan", NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (PyObject_IsTrue(check)) {
|
||||
res = PyString_FromString("'NaN'::numeric");
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
Py_DECREF(check);
|
||||
if (!(check = PyObject_CallMethod(self->wrapped, "_isinfinity", NULL))) {
|
||||
goto end;
|
||||
}
|
||||
if (PyObject_IsTrue(check)) {
|
||||
res = PyString_FromString("'NaN'::numeric");
|
||||
goto end;
|
||||
}
|
||||
|
||||
res = PyObject_Str(self->wrapped);
|
||||
|
||||
end:
|
||||
Py_XDECREF(check);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user