diff options
author | mpage <mpage@meta.com> | 2024-04-08 14:58:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 14:58:38 (GMT) |
commit | df7317904849a41d51db39d92c5d431a18e22637 (patch) | |
tree | e7dddcb5006cb6f50b9f47477217043157a42e01 /Modules/_sqlite | |
parent | e16062dd3428a5846344e0a8c6ee2f352d34ce1b (diff) | |
download | cpython-df7317904849a41d51db39d92c5d431a18e22637.zip cpython-df7317904849a41d51db39d92c5d431a18e22637.tar.gz cpython-df7317904849a41d51db39d92c5d431a18e22637.tar.bz2 |
gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)
Most mutable data is protected by a striped lock that is keyed on the
referenced object's address. The weakref's hash is protected using the
weakref's per-object lock.
Note that this only affects free-threaded builds. Apart from some minor
refactoring, the added code is all either gated by `ifdef`s or is a no-op
(e.g. `Py_BEGIN_CRITICAL_SECTION`).
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/blob.c | 5 | ||||
-rw-r--r-- | Modules/_sqlite/connection.c | 4 |
2 files changed, 4 insertions, 5 deletions
diff --git a/Modules/_sqlite/blob.c b/Modules/_sqlite/blob.c index f099020..7deb58b 100644 --- a/Modules/_sqlite/blob.c +++ b/Modules/_sqlite/blob.c @@ -4,7 +4,6 @@ #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,8 +101,8 @@ 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) { + PyObject *blob; + if (!PyWeakref_GetRef(weakref, &blob)) { continue; } close_blob((pysqlite_Blob *)blob); diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index f97afcf..74984ca 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -38,7 +38,7 @@ #include "pycore_modsupport.h" // _PyArg_NoKeywords() #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() #include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing() -#include "pycore_weakref.h" // _PyWeakref_IS_DEAD() +#include "pycore_weakref.h" #include <stdbool.h> @@ -1065,7 +1065,7 @@ 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)) { + if (_PyWeakref_IsDead(weakref)) { continue; } if (PyList_Append(new_list, weakref) != 0) { |