* 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.
This commit is contained in:
James Henstridge 2008-05-28 17:45:37 +08:00
parent bbd101bb7e
commit 26693621ef
3 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,11 @@
2008-05-28 James Henstridge <james@jamesh.id.au> 2008-05-28 James Henstridge <james@jamesh.id.au>
* 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 * psycopg/typecast.c (typecast_traverse): implement cyclic GC
traversal for typecasters. traversal for typecasters.

View File

@ -34,15 +34,19 @@
void void
curs_reset(cursorObject *self) curs_reset(cursorObject *self)
{ {
PyObject *tmp;
/* initialize some variables to default values */ /* initialize some variables to default values */
self->notuples = 1; self->notuples = 1;
self->rowcount = -1; self->rowcount = -1;
self->row = 0; self->row = 0;
Py_XDECREF(self->description); tmp = self->description;
Py_INCREF(Py_None); Py_INCREF(Py_None);
self->description = Py_None; self->description = Py_None;
Py_XDECREF(tmp);
Py_XDECREF(self->casts); tmp = self->casts;
self->casts = NULL; self->casts = NULL;
Py_XDECREF(tmp);
} }

View File

@ -1590,8 +1590,8 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
"argument 1 must be subclass of psycopg2._psycopg.connection"); "argument 1 must be subclass of psycopg2._psycopg.connection");
return 1; return 1;
} */ } */
Py_INCREF(conn);
self->conn = conn; self->conn = conn;
Py_INCREF((PyObject*)self->conn);
self->closed = 0; self->closed = 0;
self->mark = conn->mark; self->mark = conn->mark;
@ -1607,6 +1607,7 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
self->string_types = NULL; self->string_types = NULL;
self->binary_types = NULL; self->binary_types = NULL;
Py_INCREF(Py_None);
self->description = Py_None; self->description = Py_None;
Py_INCREF(Py_None); Py_INCREF(Py_None);
self->pgstatus = Py_None; self->pgstatus = Py_None;
@ -1614,11 +1615,10 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
self->tuple_factory = Py_None; self->tuple_factory = Py_None;
Py_INCREF(Py_None); Py_INCREF(Py_None);
self->query = Py_None; self->query = Py_None;
Py_INCREF(Py_None);
/* default tzinfo factory */ /* default tzinfo factory */
Py_INCREF(pyPsycopgTzFixedOffsetTimezone);
self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone; self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone;
Py_INCREF(self->tzinfo_factory);
Dprintf("cursor_setup: good cursor object at %p, refcnt = " Dprintf("cursor_setup: good cursor object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T, FORMAT_CODE_PY_SSIZE_T,