Skip to content

Commit 594df09

Browse files
committed
More straightforward semantics for psyco_GetDecimalType
Raise an exception when returning NULL, leave the caller cleaning it.
1 parent 2ad2b27 commit 594df09

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

psycopg/typecast_basic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
148148
Py_DECREF(decimalType);
149149
}
150150
else {
151+
PyErr_Clear();
151152
res = PyObject_CallFunction((PyObject*)&PyFloat_Type, "s", buffer);
152153
}
153154
PyMem_Free(buffer);

psycopg/utils.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,10 @@ psyco_is_main_interp(void)
427427

428428
/* psyco_GetDecimalType
429429
430-
Return a new reference to the adapter for decimal type.
430+
Return a new reference to the decimal type.
431431
432-
If decimals should be used but the module import fails, fall back on
433-
the float type.
434-
435-
If decimals are not to be used, return NULL.
432+
The function returns a cached version of the object, but only in the main
433+
interpreter because subinterpreters are confusing.
436434
*/
437435

438436
PyObject *
@@ -456,7 +454,6 @@ psyco_GetDecimalType(void)
456454
Py_DECREF(decimal);
457455
}
458456
else {
459-
PyErr_Clear();
460457
decimalType = NULL;
461458
}
462459

0 commit comments

Comments
 (0)