summaryrefslogtreecommitdiff
path: root/psycopg/adapter_pdecimal.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2010-02-28 20:52:03 +0100
committerFederico Di Gregorio <fog@initd.org>2010-02-28 20:52:03 +0100
commit855674faf15ae486d42a9081cf55647c1e1e10c3 (patch)
tree4e70a54d8baa9ac8f7994a9c8c986f9f1fe393e7 /psycopg/adapter_pdecimal.c
parent17a4cc9f67b58baf1eb379f5fd303021467178b0 (diff)
downloadpsycopg2-855674faf15ae486d42a9081cf55647c1e1e10c3.tar.gz
Fixed Python 2.4 segfault related to decimal implementation
Diffstat (limited to 'psycopg/adapter_pdecimal.c')
-rw-r--r--psycopg/adapter_pdecimal.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/psycopg/adapter_pdecimal.c b/psycopg/adapter_pdecimal.c
index 11d2595..6bcccb5 100644
--- a/psycopg/adapter_pdecimal.c
+++ b/psycopg/adapter_pdecimal.c
@@ -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;
}