Skip to content

Conversation

@takluyver
Copy link
Contributor

@takluyver takluyver commented Feb 1, 2026

This cleans up the code for an unused (as far as I can see) list of Cursor weakrefs.

Closes #144377

@takluyver takluyver force-pushed the sqlite-no-register-cursors branch from f65eac1 to 203cb74 Compare February 2, 2026 15:53
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please remove pycore_weakref.h include.

Py_ssize_t imax = PyList_GET_SIZE(self->cursors);
for (Py_ssize_t i = 0; i < imax; i++) {
PyObject* weakref = PyList_GET_ITEM(self->cursors, i);
if (_PyWeakref_IsDead(weakref)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the internal _PyWeakref_IsDead() function is no longer used, you can remove #include "pycore_weakref.h".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, but this made me realise that there's no equivalent function to clean up self->blobs, which otherwise is a parallel of self->cursors. So if you have a long-lived connection object and keep using conn.blobopen(), the list of weakrefs will grow indefinitely.

Is that a problem, or am I missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a problem, or am I missing something?

If you consider that it's an issue, please open a separated issue. It's not directly related to this change.

@vstinner vstinner merged commit 74c1f41 into python:main Feb 3, 2026
47 checks passed
@vstinner
Copy link
Member

vstinner commented Feb 3, 2026

Merged. Thanks for the cleanup change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite3 Connection maintains an unused list of weakrefs to Cursor objects

3 participants