summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-02 17:25:18 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-01-03 21:34:49 +0100
commit5888b0360833dac5fd1a3a368e6aa878bc43aeec (patch)
tree8ca015e64a2e25e7946a1aa5fe66dadc4e6fc15b
parent8b0af283f6e32cdaed93154b08dd6fb26973cc45 (diff)
downloadpsycopg2-5888b0360833dac5fd1a3a368e6aa878bc43aeec.tar.gz
Fixed "historical" reference leak in TimestampFromTicks
Added an internal function with C signature to avoid the creation of a tuple to be later unpacked. When the tuple was decref'd, Python 2.4 64 bits regularly segfaulted; Python 2.5 less regularly; don't know about other versions.
-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 08b0cd6..0ceb703 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -348,20 +348,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);
@@ -387,6 +380,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;
@@ -446,20 +454,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;
}