summaryrefslogtreecommitdiff
path: root/psycopg/adapter_qstring.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2008-07-26 15:10:02 +0200
committerFederico Di Gregorio <fog@initd.org>2008-07-26 15:10:02 +0200
commitceee4c816fde88fa4ab32074b923bf4d31cd3598 (patch)
tree6aefd58fd5d4e2565eeeb70c27938a8f5dfc3bf6 /psycopg/adapter_qstring.c
parente95a4d9d2ee995715f09431039360de6717e4738 (diff)
parenta2f3e4a3acd58afb09438be186e5fb0a98620820 (diff)
downloadpsycopg2-ceee4c816fde88fa4ab32074b923bf4d31cd3598.tar.gz
Merge from jh
Diffstat (limited to 'psycopg/adapter_qstring.c')
-rw-r--r--psycopg/adapter_qstring.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index f469fe4..e1eb4e1 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -213,10 +213,10 @@ qstring_prepare(qstringObject *self, PyObject *args)
Dprintf("qstring_prepare: set encoding to %s", conn->encoding);
}
- Py_XDECREF(self->conn);
+ Py_CLEAR(self->conn);
if (conn) {
+ Py_INCREF(conn);
self->conn = (PyObject*)conn;
- Py_INCREF(self->conn);
}
Py_INCREF(Py_None);
@@ -277,8 +277,8 @@ qstring_setup(qstringObject *self, PyObject *str, const char *enc)
/* FIXME: remove this orrible strdup */
if (enc) self->encoding = strdup(enc);
+ Py_INCREF(str);
self->wrapped = str;
- Py_INCREF(self->wrapped);
Dprintf("qstring_setup: good qstring object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
@@ -287,14 +287,25 @@ qstring_setup(qstringObject *self, PyObject *str, const char *enc)
return 0;
}
+static int
+qstring_traverse(PyObject *obj, visitproc visit, void *arg)
+{
+ qstringObject *self = (qstringObject *)obj;
+
+ Py_VISIT(self->wrapped);
+ Py_VISIT(self->buffer);
+ Py_VISIT(self->conn);
+ return 0;
+}
+
static void
qstring_dealloc(PyObject* obj)
{
qstringObject *self = (qstringObject *)obj;
- Py_XDECREF(self->wrapped);
- Py_XDECREF(self->buffer);
- Py_XDECREF(self->conn);
+ Py_CLEAR(self->wrapped);
+ Py_CLEAR(self->buffer);
+ Py_CLEAR(self->conn);
if (self->encoding) free(self->encoding);
@@ -327,7 +338,7 @@ qstring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
qstring_del(PyObject* self)
{
- PyObject_Del(self);
+ PyObject_GC_Del(self);
}
static PyObject *
@@ -366,11 +377,11 @@ PyTypeObject qstringType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
qstringType_doc, /*tp_doc*/
- 0, /*tp_traverse*/
+ qstring_traverse, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/