summaryrefslogtreecommitdiff
path: root/psycopg/adapter_binary.c
diff options
context:
space:
mode:
Diffstat (limited to 'psycopg/adapter_binary.c')
-rw-r--r--psycopg/adapter_binary.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index 1fb9d40..306c9e5 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -257,8 +257,8 @@ binary_setup(binaryObject *self, PyObject *str)
self->buffer = NULL;
self->conn = NULL;
+ Py_INCREF(str);
self->wrapped = str;
- Py_INCREF(self->wrapped);
Dprintf("binary_setup: good binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
@@ -266,14 +266,25 @@ binary_setup(binaryObject *self, PyObject *str)
return 0;
}
+static int
+binary_traverse(PyObject *obj, visitproc visit, void *arg)
+{
+ binaryObject *self = (binaryObject *)obj;
+
+ Py_VISIT(self->wrapped);
+ Py_VISIT(self->buffer);
+ Py_VISIT(self->conn);
+ return 0;
+}
+
static void
binary_dealloc(PyObject* obj)
{
binaryObject *self = (binaryObject *)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);
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
@@ -303,7 +314,7 @@ binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
binary_del(PyObject* self)
{
- PyObject_Del(self);
+ PyObject_GC_Del(self);
}
static PyObject *
@@ -341,11 +352,11 @@ PyTypeObject binaryType = {
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*/
binaryType_doc, /*tp_doc*/
- 0, /*tp_traverse*/
+ binary_traverse, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/