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
Show file tree
Hide file tree
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.Statement type now implements GC protocol
  • Loading branch information
Erlend E. Aasland committed May 13, 2021
commit 20da08820134d0d62882d20b13bb0d223af800f3
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ pysqlite_connection_call(pysqlite_Connection *self, PyObject *args,

_pysqlite_drop_unused_statement_references(self);

statement = PyObject_New(pysqlite_Statement, pysqlite_StatementType);
statement = PyObject_GC_New(pysqlite_Statement, pysqlite_StatementType);
if (!statement) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation

if (self->statement->in_use) {
Py_SETREF(self->statement,
PyObject_New(pysqlite_Statement, pysqlite_StatementType));
PyObject_GC_New(pysqlite_Statement, pysqlite_StatementType));
if (!self->statement) {
goto error;
}
Expand Down
28 changes: 21 additions & 7 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,23 +372,36 @@ static void
pysqlite_statement_dealloc(pysqlite_Statement *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);

if (self->st) {
Py_BEGIN_ALLOW_THREADS
sqlite3_finalize(self->st);
Py_END_ALLOW_THREADS
self->st = NULL;
}

self->st = NULL;

Py_XDECREF(self->sql);
tp->tp_clear((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
}

static int
stmt_clear(pysqlite_Statement *self)
{
Py_CLEAR(self->sql);
if (self->in_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject*)self);
}
return 0;
}

tp->tp_free(self);
Py_DECREF(tp);
static int
stmt_traverse(pysqlite_Statement *self, visitproc visit, void *arg)
{
Py_VISIT(self->sql);
Py_VISIT(Py_TYPE(self));
return 0;
}

/*
Expand Down Expand Up @@ -468,14 +481,15 @@ static PyMemberDef stmt_members[] = {
static PyType_Slot stmt_slots[] = {
{Py_tp_members, stmt_members},
{Py_tp_dealloc, pysqlite_statement_dealloc},
{Py_tp_new, PyType_GenericNew},
{Py_tp_traverse, stmt_traverse},
{Py_tp_clear, stmt_clear},
{0, NULL},
};

static PyType_Spec stmt_spec = {
.name = MODULE_NAME ".Statement",
.basicsize = sizeof(pysqlite_Statement),
.flags = Py_TPFLAGS_DEFAULT,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.slots = stmt_slots,
};
PyTypeObject *pysqlite_StatementType = NULL;
Expand Down
0