gh-112069: Make PySet_GET_SIZE to be atomic safe. by corona10 · Pull Request #118053 · python/cpython
tp_richcompare already set locks for two sets, so making PySet_GET_SIZE to be atomic safe will be enough.
| case Py_EQ: | |
| if (PySet_GET_SIZE(v) != PySet_GET_SIZE(w)) | |
| Py_RETURN_FALSE; | |
| if (v->hash != -1 && | |
| ((PySetObject *)w)->hash != -1 && | |
| v->hash != ((PySetObject *)w)->hash) | |
| Py_RETURN_FALSE; | |
| return set_issubset(v, w); | |
| case Py_NE: | |
| r1 = set_richcompare(v, w, Py_EQ); | |
| if (r1 == NULL) | |
| return NULL; | |
| r2 = PyObject_IsTrue(r1); | |
| Py_DECREF(r1); | |
| if (r2 < 0) | |
| return NULL; | |
| return PyBool_FromLong(!r2); | |
| case Py_LE: |
FYI, the same thing is applied for PyList_GET_SIZE, too.
| static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) { | |
| PyListObject *list = _PyList_CAST(op); | |
| #ifdef Py_GIL_DISABLED | |
| return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(list)->ob_size)); | |
| #else | |
| return Py_SIZE(list); | |
| #endif | |
| } |