Skip to content

Conversation

@corona10
Copy link
Member

@corona10corona10 commented Apr 18, 2024

@corona10
Copy link
MemberAuthor

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

casePy_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;
returnset_issubset(v, w);
casePy_NE:
r1=set_richcompare(v, w, Py_EQ);
if (r1==NULL)
returnNULL;
r2=PyObject_IsTrue(r1);
Py_DECREF(r1);
if (r2<0)
returnNULL;
returnPyBool_FromLong(!r2);
casePy_LE:

FYI, the same thing is applied for PyList_GET_SIZE, too.

staticinlinePy_ssize_tPyList_GET_SIZE(PyObject*op){
PyListObject*list=_PyList_CAST(op);
#ifdefPy_GIL_DISABLED
return_Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(list)->ob_size));
#else
returnPy_SIZE(list);
#endif
}

@corona10corona10 changed the title gh-112069: Make PySet_GET_SIZE to be atomic operationgh-112069: Make PySet_GET_SIZE to be atomic safe.Apr 18, 2024
@corona10corona10 merged commit 710c01b into python:mainApr 18, 2024
@corona10corona10 deleted the gh-112069-richcompare branch April 18, 2024 21:40
Sign up for freeto 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

@corona10@colesbury