Fixed Python 2.4 segfault related to decimal implementation

This commit is contained in:
Federico Di Gregorio 2010-02-28 20:52:03 +01:00
parent 17a4cc9f67
commit 855674faf1
2 changed files with 25 additions and 3 deletions

View File

@ -1,3 +1,10 @@
2010-02-28 Federico Di Gregorio <fog@initd.org>
* psycopg/adapt_decimal.c: Python 2.4 decimal type does not support
.isfinite() and two different calls to ._isinfinity() and ._isnan() are
required. This fixes both a test failure and a segfault.
2010-02-15 Federico Di Gregorio <fog@initd.org>
* Added new Decimal adapter that correctly converts NaN and infinity

View File

@ -42,14 +42,29 @@
static PyObject *
pdecimal_str(pdecimalObject *self)
{
PyObject *res = NULL;
PyObject *check = PyObject_CallMethod(self->wrapped, "is_finite", NULL);
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)
res = PyObject_Str(self->wrapped);
else
res = PyString_FromString("'NaN'::numeric");
#endif
end:
Py_DECREF(check);
return res;
}