summaryrefslogtreecommitdiff
path: root/psycopg/adapter_datetime.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-03 21:43:02 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-03 21:43:02 +0100
commit80bd6e27946ed5b56b01687913369d6c895598cb (patch)
tree70f67cdc4c4e73a6e8ac7f4862d3d0b02a1ab99b /psycopg/adapter_datetime.c
parenta01700d478765e8dc6044336f21fe84808569a0d (diff)
parent627df159958330b54011e378427275b0494be013 (diff)
downloadpsycopg2-80bd6e27946ed5b56b01687913369d6c895598cb.tar.gz
Merge branch 'python2' into python3
Conflicts: NEWS-2.3 psycopg/connection_type.c tests/test_connection.py tests/types_basic.py
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r--psycopg/adapter_datetime.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c
index ddcd089..c1a976e 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -362,20 +362,13 @@ psyco_Time(PyObject *self, PyObject *args)
return res;
}
-PyObject *
-psyco_Timestamp(PyObject *self, PyObject *args)
+static PyObject *
+_psyco_Timestamp(int year, int month, int day,
+ int hour, int minute, double second, PyObject *tzinfo)
{
+ double micro;
+ PyObject *obj;
PyObject *res = NULL;
- PyObject *tzinfo = NULL;
- int year, month, day;
- int hour=0, minute=0; /* default to midnight */
- double micro, second=0.0;
-
- PyObject* obj = NULL;
-
- if (!PyArg_ParseTuple(args, "lii|iidO", &year, &month, &day,
- &hour, &minute, &second, &tzinfo))
- return NULL;
micro = (second - floor(second)) * 1000000.0;
second = floor(second);
@@ -401,6 +394,21 @@ psyco_Timestamp(PyObject *self, PyObject *args)
}
PyObject *
+psyco_Timestamp(PyObject *self, PyObject *args)
+{
+ PyObject *tzinfo = NULL;
+ int year, month, day;
+ int hour=0, minute=0; /* default to midnight */
+ double second=0.0;
+
+ if (!PyArg_ParseTuple(args, "lii|iidO", &year, &month, &day,
+ &hour, &minute, &second, &tzinfo))
+ return NULL;
+
+ return _psyco_Timestamp(year, month, day, hour, minute, second, tzinfo);
+}
+
+PyObject *
psyco_DateFromTicks(PyObject *self, PyObject *args)
{
PyObject *res = NULL;
@@ -460,20 +468,12 @@ psyco_TimestampFromTicks(PyObject *self, PyObject *args)
t = (time_t)floor(ticks);
ticks -= (double)t;
if (localtime_r(&t, &tm)) {
- PyObject *value = Py_BuildValue("iiiiidO",
- tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
- tm.tm_hour, tm.tm_min,
- (double)tm.tm_sec + ticks,
+ res = _psyco_Timestamp(
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, (double)tm.tm_sec + ticks,
pyPsycopgTzLOCAL);
- if (value) {
- /* FIXME: not decref'ing the value here is a memory leak
- but, on the other hand, if we decref we get a clean nice
- segfault (on my 64 bit Python 2.4 box). So this leaks
- will stay until after 2.0.7 when we'll try to plug it */
- res = psyco_Timestamp(self, value);
- }
}
-
+
return res;
}