More straightforward semantics for psyco_GetDecimalType

Raise an exception when returning NULL, leave the caller cleaning it.
This commit is contained in:
Daniele Varrazzo 2018-12-31 00:28:58 +01:00
parent 2ad2b27065
commit 594df09a63
2 changed files with 4 additions and 6 deletions

View File

@ -148,6 +148,7 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
Py_DECREF(decimalType); Py_DECREF(decimalType);
} }
else { else {
PyErr_Clear();
res = PyObject_CallFunction((PyObject*)&PyFloat_Type, "s", buffer); res = PyObject_CallFunction((PyObject*)&PyFloat_Type, "s", buffer);
} }
PyMem_Free(buffer); PyMem_Free(buffer);

View File

@ -427,12 +427,10 @@ psyco_is_main_interp(void)
/* psyco_GetDecimalType /* psyco_GetDecimalType
Return a new reference to the adapter for decimal type. Return a new reference to the decimal type.
If decimals should be used but the module import fails, fall back on The function returns a cached version of the object, but only in the main
the float type. interpreter because subinterpreters are confusing.
If decimals are not to be used, return NULL.
*/ */
PyObject * PyObject *
@ -456,7 +454,6 @@ psyco_GetDecimalType(void)
Py_DECREF(decimal); Py_DECREF(decimal);
} }
else { else {
PyErr_Clear();
decimalType = NULL; decimalType = NULL;
} }