Skip to content

Commit 710c01b

Browse files
authored
gh-112069: Make PySet_GET_SIZE to be atomic safe. (gh-118053)
gh-112069: Make PySet_GET_SIZE to be atomic operation
1 parent 8f25cc9 commit 710c01b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Include/cpython/setobject.h

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ typedef struct {
6262
(assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))
6363

6464
static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
65+
#ifdef Py_GIL_DISABLED
66+
return _Py_atomic_load_ssize_relaxed(&(_PySet_CAST(so)->used));
67+
#else
6568
return _PySet_CAST(so)->used;
69+
#endif
6670
}
6771
#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))

Objects/setobject.c

-1
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,6 @@ set_issuperset_impl(PySetObject *so, PyObject *other)
20802080
Py_RETURN_TRUE;
20812081
}
20822082

2083-
// TODO: Make thread-safe in free-threaded builds
20842083
static PyObject *
20852084
set_richcompare(PySetObject *v, PyObject *w, int op)
20862085
{

0 commit comments

Comments
 (0)