|
3 | 3 | #include <assert.h> |
4 | 4 |
|
5 | 5 | static void Reader_dealloc(hiredis_ReaderObject *self); |
| 6 | +static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg); |
6 | 7 | static int Reader_init(hiredis_ReaderObject *self, PyObject *args, PyObject *kwds); |
7 | 8 | static PyObject *Reader_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
8 | 9 | static PyObject *Reader_feed(hiredis_ReaderObject *self, PyObject *args); |
@@ -44,9 +45,9 @@ PyTypeObject hiredis_ReaderType = { |
44 | 45 | 0, /*tp_getattro*/ |
45 | 46 | 0, /*tp_setattro*/ |
46 | 47 | 0, /*tp_as_buffer*/ |
47 | | - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
| 48 | + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ |
48 | 49 | "Hiredis protocol reader", /*tp_doc */ |
49 | | - 0, /*tp_traverse */ |
| 50 | + (traverseproc)Reader_traverse,/*tp_traverse */ |
50 | 51 | 0, /*tp_clear */ |
51 | 52 | 0, /*tp_richcompare */ |
52 | 53 | 0, /*tp_weaklistoffset */ |
@@ -209,16 +210,24 @@ redisReplyObjectFunctions hiredis_ObjectFunctions = { |
209 | 210 | }; |
210 | 211 |
|
211 | 212 | static void Reader_dealloc(hiredis_ReaderObject *self) { |
| 213 | + PyObject_GC_UnTrack(self); |
212 | 214 | // we don't need to free self->encoding as the buffer is managed by Python |
213 | 215 | // https://docs.python.org/3/c-api/arg.html#strings-and-buffers |
214 | 216 | redisReaderFree(self->reader); |
215 | | - Py_XDECREF(self->protocolErrorClass); |
216 | | - Py_XDECREF(self->replyErrorClass); |
217 | | - Py_XDECREF(self->notEnoughDataObject); |
| 217 | + Py_CLEAR(self->protocolErrorClass); |
| 218 | + Py_CLEAR(self->replyErrorClass); |
| 219 | + Py_CLEAR(self->notEnoughDataObject); |
218 | 220 |
|
219 | 221 | ((PyObject *)self)->ob_type->tp_free((PyObject*)self); |
220 | 222 | } |
221 | 223 |
|
| 224 | +static int Reader_traverse(hiredis_ReaderObject *self, visitproc visit, void *arg) { |
| 225 | + Py_VISIT(self->protocolErrorClass); |
| 226 | + Py_VISIT(self->replyErrorClass); |
| 227 | + Py_VISIT(self->notEnoughDataObject); |
| 228 | + return 0; |
| 229 | +} |
| 230 | + |
222 | 231 | static int _Reader_set_exception(PyObject **target, PyObject *value) { |
223 | 232 | int callable; |
224 | 233 | callable = PyCallable_Check(value); |
|
0 commit comments