diff options
| author | James Henstridge <james@jamesh.id.au> | 2008-12-27 00:03:11 +0900 |
|---|---|---|
| committer | James Henstridge <james@jamesh.id.au> | 2008-12-27 00:03:11 +0900 |
| commit | 83b03e5e3691baa45d49f6bee0e115203be01707 (patch) | |
| tree | 783a7d4bed4834fecd83985550786b0a282628bc /psycopg/psycopgmodule.c | |
| parent | 345a254ca05b0b07f5fc3dbb0520ae00a35fb923 (diff) | |
| download | psycopg2-83b03e5e3691baa45d49f6bee0e115203be01707.tar.gz | |
If we are depending on Python 2.4, we don't need to make decimal module
support conditional.
Diffstat (limited to 'psycopg/psycopgmodule.c')
| -rw-r--r-- | psycopg/psycopgmodule.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index d991a6a..43e0402 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -280,8 +280,11 @@ psyco_adapters_init(PyObject *mod) microprotocols_add(&PyUnicode_Type, NULL, (PyObject*)&qstringType); microprotocols_add(&PyBuffer_Type, NULL, (PyObject*)&binaryType); microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType); + microprotocols_add((PyTypeObject*)psyco_GetDecimalType(), + NULL, (PyObject*)&asisType); - /* as above, we use the callable objects from the psycopg module */ + /* the module has already been initialized, so we can obtain the callable + objects directly from its dictionary :) */ call = PyMapping_GetItemString(mod, "DateFromPy"); microprotocols_add((PyTypeObject*)pyDateTypeP, NULL, call); call = PyMapping_GetItemString(mod, "TimeFromPy"); @@ -292,18 +295,12 @@ psyco_adapters_init(PyObject *mod) microprotocols_add((PyTypeObject*)pyDeltaTypeP, NULL, call); #ifdef HAVE_MXDATETIME - /* the module has already been initialized, so we can obtain the callable - objects directly from its dictionary :) */ + /* as above, we use the callable objects from the psycopg module */ call = PyMapping_GetItemString(mod, "TimestampFromMx"); microprotocols_add(mxDateTimeP->DateTime_Type, NULL, call); call = PyMapping_GetItemString(mod, "TimeFromMx"); microprotocols_add(mxDateTimeP->DateTimeDelta_Type, NULL, call); #endif - -#ifdef HAVE_DECIMAL - microprotocols_add((PyTypeObject*)psyco_GetDecimalType(), - NULL, (PyObject*)&asisType); -#endif } /* psyco_encodings_fill @@ -583,9 +580,7 @@ psyco_GetDecimalType(void) { PyObject *decimalType = NULL; static PyObject *cachedType = NULL; - -#ifdef HAVE_DECIMAL - PyObject *decimal = PyImport_ImportModule("decimal"); + PyObject *decimal; /* Use the cached object if running from the main interpreter. */ int can_cache = psyco_is_main_interp(); @@ -595,6 +590,7 @@ psyco_GetDecimalType(void) } /* Get a new reference to the Decimal type. */ + decimal = PyImport_ImportModule("decimal"); if (decimal) { decimalType = PyObject_GetAttrString(decimal, "Decimal"); Py_DECREF(decimal); @@ -607,11 +603,10 @@ psyco_GetDecimalType(void) /* Store the object from future uses. */ if (can_cache && !cachedType) { + Py_INCREF(decimalType); cachedType = decimalType; } -#endif /* HAVE_DECIMAL */ - return decimalType; } |
