8000 bpo-42972: Fully implement GC protocol for sqlite3 heap types by erlend-aasland · Pull Request #26104 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42972: Fully implement GC protocol for sqlite3 heap types #26104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 25, 2021
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.Cursor type now implements GC protocol
  • Loading branch information
Erlend E. Aasland committed May 13, 2021
commit 866060958c17a4ab6f677362ac357433dc6fca91
44 changes: 32 additions & 12 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,46 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self,
return 0;
}

static void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
static int
cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
{
PyTypeObject *tp = Py_TYPE(self);
Py_VISIT(self->connection);
Py_VISIT(self->row_cast_map);
Py_VISIT(self->row_factory);
Py_VISIT(self->next_row);
Py_VISIT(Py_TYPE(self));
return 0;
}

static int
cursor_clear(pysqlite_Cursor *self)
{
/* Reset the statement if the user has not closed the cursor */
if (self->statement) {
pysqlite_statement_reset(self->statement);
Py_DECREF(self->statement);
Py_CLEAR(self->statement);
}

Py_XDECREF(self->connection);
Py_XDECREF(self->row_cast_map);
Py_XDECREF(self->description);
Py_XDECREF(self->lastrowid);
Py_XDECREF(self->row_factory);
Py_XDECREF(self->next_row);
Py_CLEAR(self->connection);
Py_CLEAR(self->row_cast_map);
Py_CLEAR(self->description);
Py_CLEAR(self->lastrowid);
Py_CLEAR(self->row_factory);
Py_CLEAR(self->next_row);

if (self->in_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject*)self);
}

return 0;
}

static void
cursor_dealloc(pysqlite_Cursor *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
tp->tp_clear((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -1006,21 +1025,22 @@ static const char cursor_doc[] =
PyDoc_STR("SQLite database cursor class.");

static PyType_Slot cursor_slots[] = {
{Py_tp_dealloc, pysqlite_cursor_dealloc},
{Py_tp_dealloc, cursor_dealloc},
{Py_tp_doc, (void *)cursor_doc},
{Py_tp_iter, PyObject_SelfIter},
{Py_tp_iternext, pysqlite_cursor_iternext},
{Py_tp_methods, cursor_methods},
{Py_tp_members, cursor_members},
{Py_tp_new, PyType_GenericNew},
{Py_tp_init, pysqlite_cursor_init},
{Py_tp_traverse, cursor_traverse},
{Py_tp_clear, cursor_clear},
{0, NULL},
};

static PyType_Spec cursor_spec = {
.name = MODULE_NAME ".Cursor",
.basicsize = sizeof(pysqlite_Cursor),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.slots = cursor_slots,
};

Expand Down
0