Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sqlite.Row type now implements GC protocol
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed May 13, 2021
commit 13bc519a06221896f7c2bf0718743a4f1d61bc73
27 changes: 21 additions & 6 deletions Modules/_sqlite/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,27 @@ class _sqlite3.Row "pysqlite_Row *" "pysqlite_RowType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=384227da65f250fd]*/

static void
pysqlite_row_dealloc(pysqlite_Row *self)
static int
row_clear(pysqlite_Row *self)
{
PyTypeObject *tp = Py_TYPE(self);
Py_CLEAR(self->data);
Py_CLEAR(self->description);
return 0;
}

Py_XDECREF(self->data);
Py_XDECREF(self->description);
static int
row_traverse(pysqlite_Row *self, visitproc visit, void *arg)
Comment thread
erlend-aasland marked this conversation as resolved.
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static void
pysqlite_row_dealloc(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
tp->tp_clear(self);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -231,13 +244,15 @@ static PyType_Slot row_slots[] = {
{Py_sq_length, pysqlite_row_length},
{Py_sq_item, pysqlite_row_item},
{Py_tp_new, pysqlite_row_new},
{Py_tp_traverse, row_traverse},
{Py_tp_clear, row_clear},
{0, NULL},
};

static PyType_Spec row_spec = {
.name = MODULE_NAME ".Row",
.basicsize = sizeof(pysqlite_Row),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.slots = row_slots,
};

Expand Down