From 26693621ef29add6f86354a689dede000d9d962e Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Wed, 28 May 2008 17:45:37 +0800 Subject: [PATCH] * psycopg/cursor_type.c (cursor_setup): incref before setting attributes, to make things GC-safe. * psycopg/cursor_int.c (curs_reset): make clearing of description and casts attributes GC-safe. --- ChangeLog | 6 ++++++ psycopg/cursor_int.c | 8 ++++++-- psycopg/cursor_type.c | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b81b422e..2a58f1f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2008-05-28 James Henstridge + * psycopg/cursor_type.c (cursor_setup): incref before setting + attributes, to make things GC-safe. + + * psycopg/cursor_int.c (curs_reset): make clearing of description + and casts attributes GC-safe. + * psycopg/typecast.c (typecast_traverse): implement cyclic GC traversal for typecasters. diff --git a/psycopg/cursor_int.c b/psycopg/cursor_int.c index 483e2c44..9d3c861c 100644 --- a/psycopg/cursor_int.c +++ b/psycopg/cursor_int.c @@ -34,15 +34,19 @@ void curs_reset(cursorObject *self) { + PyObject *tmp; + /* initialize some variables to default values */ self->notuples = 1; self->rowcount = -1; self->row = 0; - Py_XDECREF(self->description); + tmp = self->description; Py_INCREF(Py_None); self->description = Py_None; + Py_XDECREF(tmp); - Py_XDECREF(self->casts); + tmp = self->casts; self->casts = NULL; + Py_XDECREF(tmp); } diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 03be9d90..1ff5b962 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -1590,8 +1590,8 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name) "argument 1 must be subclass of psycopg2._psycopg.connection"); return 1; } */ + Py_INCREF(conn); self->conn = conn; - Py_INCREF((PyObject*)self->conn); self->closed = 0; self->mark = conn->mark; @@ -1607,6 +1607,7 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name) self->string_types = NULL; self->binary_types = NULL; + Py_INCREF(Py_None); self->description = Py_None; Py_INCREF(Py_None); self->pgstatus = Py_None; @@ -1614,11 +1615,10 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name) self->tuple_factory = Py_None; Py_INCREF(Py_None); self->query = Py_None; - Py_INCREF(Py_None); /* default tzinfo factory */ + Py_INCREF(pyPsycopgTzFixedOffsetTimezone); self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone; - Py_INCREF(self->tzinfo_factory); Dprintf("cursor_setup: good cursor object at %p, refcnt = " FORMAT_CODE_PY_SSIZE_T,