From 594df09a63267fe2ce960459f5ce2362b6e27c67 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 31 Dec 2018 00:28:58 +0100 Subject: [PATCH] More straightforward semantics for psyco_GetDecimalType Raise an exception when returning NULL, leave the caller cleaning it. --- psycopg/typecast_basic.c | 1 + psycopg/utils.c | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/psycopg/typecast_basic.c b/psycopg/typecast_basic.c index ff4cf7b8..170ee454 100644 --- a/psycopg/typecast_basic.c +++ b/psycopg/typecast_basic.c @@ -148,6 +148,7 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs) Py_DECREF(decimalType); } else { + PyErr_Clear(); res = PyObject_CallFunction((PyObject*)&PyFloat_Type, "s", buffer); } PyMem_Free(buffer); diff --git a/psycopg/utils.c b/psycopg/utils.c index 7f8e0adf..81171bdc 100644 --- a/psycopg/utils.c +++ b/psycopg/utils.c @@ -427,12 +427,10 @@ psyco_is_main_interp(void) /* 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 float type. - - If decimals are not to be used, return NULL. + The function returns a cached version of the object, but only in the main + interpreter because subinterpreters are confusing. */ PyObject * @@ -456,7 +454,6 @@ psyco_GetDecimalType(void) Py_DECREF(decimal); } else { - PyErr_Clear(); decimalType = NULL; }