summaryrefslogtreecommitdiff
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
parent17a4cc9f67b58baf1eb379f5fd303021467178b0 (diff)
downloadpsycopg2-855674faf15ae486d42a9081cf55647c1e1e10c3.tar.gz
Fixed Python 2.4 segfault related to decimal implementation
-rw-r--r--ChangeLog7
-rw-r--r--psycopg/adapter_pdecimal.c21
2 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 8ef4599..b3fdfcd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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;
}