mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Fixed Python 2.4 segfault related to decimal implementation
This commit is contained in:
parent
17a4cc9f67
commit
855674faf1
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user