summaryrefslogtreecommitdiff
path: root/psycopg/adapter_datetime.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-11-18 23:16:40 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-11-19 00:28:39 +0000
commit3e3aa676a9331aee9889f3ad21c75e784f35c31e (patch)
tree9903a87b81c98f82f06bd2bec40fe6eedcb4c9f4 /psycopg/adapter_datetime.c
parent576b01f6a39a321f866a2262073067d5378b1596 (diff)
downloadpsycopg2-3e3aa676a9331aee9889f3ad21c75e784f35c31e.tar.gz
datetime module initialized as it is supposed to be.
Dropped compiler warnings. It wouldn't blow up if any api was called. No need to pass type pointers around.
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r--psycopg/adapter_datetime.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c
index 7ba98f2..08b0cd6 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -39,18 +39,23 @@
#include "psycopg/adapter_datetime.h"
#include "psycopg/microprotocols_proto.h"
-
-/* the pointer to the datetime module API is initialized by the module init
- code, we just need to grab it */
-extern HIDDEN PyObject* pyDateTimeModuleP;
-extern HIDDEN PyObject *pyDateTypeP;
-extern HIDDEN PyObject *pyTimeTypeP;
-extern HIDDEN PyObject *pyDateTimeTypeP;
-extern HIDDEN PyObject *pyDeltaTypeP;
-
extern HIDDEN PyObject *pyPsycopgTzModule;
extern HIDDEN PyObject *pyPsycopgTzLOCAL;
+int
+psyco_adapter_datetime_init(void)
+{
+ Dprintf("psyco_adapter_datetime_init: datetime init");
+
+ PyDateTime_IMPORT;
+
+ if (!PyDateTimeAPI) {
+ PyErr_SetString(PyExc_ImportError, "datetime initialization failed");
+ return -1;
+ }
+ return 0;
+}
+
/* datetime_str, datetime_getquoted - return result of quoting */
static PyObject *
@@ -298,7 +303,8 @@ psyco_Date(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "iii", &year, &month, &day))
return NULL;
- obj = PyObject_CallFunction(pyDateTypeP, "iii", year, month, day);
+ obj = PyObject_CallFunction((PyObject*)PyDateTimeAPI->DateType,
+ "iii", year, month, day);
if (obj) {
res = PyObject_CallFunction((PyObject *)&pydatetimeType,
@@ -327,10 +333,10 @@ psyco_Time(PyObject *self, PyObject *args)
second = floor(second);
if (tzinfo == NULL)
- obj = PyObject_CallFunction(pyTimeTypeP, "iiii",
+ obj = PyObject_CallFunction((PyObject*)PyDateTimeAPI->TimeType, "iiii",
hours, minutes, (int)second, (int)round(micro));
else
- obj = PyObject_CallFunction(pyTimeTypeP, "iiiiO",
+ obj = PyObject_CallFunction((PyObject*)PyDateTimeAPI->TimeType, "iiiiO",
hours, minutes, (int)second, (int)round(micro), tzinfo);
if (obj) {
@@ -361,11 +367,13 @@ psyco_Timestamp(PyObject *self, PyObject *args)
second = floor(second);
if (tzinfo == NULL)
- obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiii",
+ obj = PyObject_CallFunction((PyObject*)PyDateTimeAPI->DateTimeType,
+ "iiiiiii",
year, month, day, hour, minute, (int)second,
(int)round(micro));
else
- obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiiiO",
+ obj = PyObject_CallFunction((PyObject*)PyDateTimeAPI->DateTimeType,
+ "iiiiiiiO",
year, month, day, hour, minute, (int)second,
(int)round(micro), tzinfo);
@@ -462,7 +470,7 @@ psyco_DateFromPy(PyObject *self, PyObject *args)
{
PyObject *obj;
- if (!PyArg_ParseTuple(args, "O!", pyDateTypeP, &obj))
+ if (!PyArg_ParseTuple(args, "O!", PyDateTimeAPI->DateType, &obj))
return NULL;
return PyObject_CallFunction((PyObject *)&pydatetimeType, "Oi", obj,
@@ -474,7 +482,7 @@ psyco_TimeFromPy(PyObject *self, PyObject *args)
{
PyObject *obj;
- if (!PyArg_ParseTuple(args, "O!", pyTimeTypeP, &obj))
+ if (!PyArg_ParseTuple(args, "O!", PyDateTimeAPI->TimeType, &obj))
return NULL;
return PyObject_CallFunction((PyObject *)&pydatetimeType, "Oi", obj,
@@ -486,7 +494,7 @@ psyco_TimestampFromPy(PyObject *self, PyObject *args)
{
PyObject *obj;
- if (!PyArg_ParseTuple(args, "O!", pyDateTimeTypeP, &obj))
+ if (!PyArg_ParseTuple(args, "O!", PyDateTimeAPI->DateTimeType, &obj))
return NULL;
return PyObject_CallFunction((PyObject *)&pydatetimeType, "Oi", obj,
@@ -498,7 +506,7 @@ psyco_IntervalFromPy(PyObject *self, PyObject *args)
{
PyObject *obj;
- if (!PyArg_ParseTuple(args, "O!", pyDeltaTypeP, &obj))
+ if (!PyArg_ParseTuple(args, "O!", PyDateTimeAPI->DeltaType, &obj))
return NULL;
return PyObject_CallFunction((PyObject *)&pydatetimeType, "Oi", obj,