Mailing List Archive

gh-112069: Make PySet_GET_SIZE to be atomic safe. (gh-118053)
https://github.com/python/cpython/commit/710c01be94ca7b2c96407f41f0e37e24701008b4
commit: 710c01be94ca7b2c96407f41f0e37e24701008b4
branch: main
author: Donghee Na <donghee.na@python.org>
committer: corona10 <donghee.na92@gmail.com>
date: 2024-04-19T06:40:28+09:00
summary:

gh-112069: Make PySet_GET_SIZE to be atomic safe. (gh-118053)

gh-112069: Make PySet_GET_SIZE to be atomic operation

files:
M Include/cpython/setobject.h
M Objects/setobject.c

diff --git a/Include/cpython/setobject.h b/Include/cpython/setobject.h
index 1778c778a05324..89565cb29212fc 100644
--- a/Include/cpython/setobject.h
+++ b/Include/cpython/setobject.h
@@ -62,6 +62,10 @@ typedef struct {
(assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))

static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
+#ifdef Py_GIL_DISABLED
+ return _Py_atomic_load_ssize_relaxed(&(_PySet_CAST(so)->used));
+#else
return _PySet_CAST(so)->used;
+#endif
}
#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 7af0ae166f9da3..d5030cec2d6206 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2080,7 +2080,6 @@ set_issuperset_impl(PySetObject *so, PyObject *other)
Py_RETURN_TRUE;
}

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

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com