Skip to content
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-112069: Make PySet_GET_SIZE to be atomic safe. #118053

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Apr 18, 2024

@corona10
Copy link
Member Author

tp_richcompare already set locks for two sets, so making PySet_GET_SIZE to be atomic safe will be enough.

cpython/Objects/setobject.c

Lines 2094 to 2111 in 94444ea

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
}

@corona10 corona10 changed the title gh-112069: Make PySet_GET_SIZE to be atomic operation gh-112069: Make PySet_GET_SIZE to be atomic safe. Apr 18, 2024
@corona10 corona10 merged commit 710c01b into python:main Apr 18, 2024
39 checks passed
@corona10 corona10 deleted the gh-112069-richcompare branch April 18, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants