-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-106104: Use public weakref APIs in sqlite3 #106105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
#ifndef Py_BUILD_CORE_BUILTIN | ||
# define Py_BUILD_CORE_MODULE 1 | ||
#endif | ||
|
||
#include "blob.h" | ||
#include "util.h" | ||
#include "pycore_weakref.h" // _PyWeakref_GET_REF() | ||
|
||
#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self))) | ||
#include "clinic/blob.c.h" | ||
|
@@ -102,12 +97,18 @@ pysqlite_close_all_blobs(pysqlite_Connection *self) | |
{ | ||
for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) { | ||
PyObject *weakref = PyList_GET_ITEM(self->blobs, i); | ||
PyObject *blob = _PyWeakref_GET_REF(weakref); | ||
if (blob == NULL) { | ||
if (!PyWeakref_Check(weakref)) { | ||
continue; | ||
} | ||
close_blob((pysqlite_Blob *)blob); | ||
Py_DECREF(blob); | ||
PyObject *blob; | ||
if (PyWeakref_GetRef(weakref, &blob) < 0) { | ||
PyErr_WriteUnraisable((PyObject *)self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make _PyErr_WriteUnraisableMsg() public, since this one logs a message which is hard to get, it gives no context. |
||
continue; | ||
} | ||
if (blob) { | ||
close_blob((pysqlite_Blob *)blob); | ||
Py_DECREF(blob); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,6 @@ | |
* 3. This notice may not be removed or altered from any source distribution. | ||
*/ | ||
|
||
#ifndef Py_BUILD_CORE_BUILTIN | ||
# define Py_BUILD_CORE_MODULE 1 | ||
#endif | ||
|
||
#include "module.h" | ||
#include "structmember.h" // PyMemberDef | ||
#include "connection.h" | ||
|
@@ -33,7 +29,6 @@ | |
#include "blob.h" | ||
#include "prepare_protocol.h" | ||
#include "util.h" | ||
#include "pycore_weakref.h" // _PyWeakref_IS_DEAD() | ||
|
||
#include <stdbool.h> | ||
|
||
|
@@ -987,13 +982,22 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self) | |
} | ||
|
||
for (Py_ssize_t i = 0; i < PyList_Size(self->cursors); i++) { | ||
PyObject* weakref = PyList_GetItem(self->cursors, i); | ||
if (_PyWeakref_IS_DEAD(weakref)) { | ||
PyObject *weakref = PyList_GetItem(self->cursors, i); | ||
if (!PyWeakref_Check(weakref)) { | ||
continue; | ||
} | ||
if (PyList_Append(new_list, weakref) != 0) { | ||
Py_DECREF(new_list); | ||
return; | ||
PyObject *item; | ||
if (PyWeakref_GetRef(weakref, &item) < 0) { | ||
PyErr_WriteUnraisable((PyObject *)self); | ||
continue; | ||
} | ||
if (item) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest |
||
int rc = PyList_Append(new_list, item); | ||
Py_DECREF(item); | ||
if (rc < 0) { | ||
Py_DECREF(new_list); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that blobs contain something which is not a weakref?