Skip to content

Commit cbcb526

Browse files
[3.13] gh-117657: Make PyType_HasFeature (exported version) atomic (GH-120484) (#120554)
gh-117657: Make PyType_HasFeature (exported version) atomic (GH-120484) Make PyType_HasFeature (exported version) atomic (cherry picked from commit 6f63dff) Co-authored-by: Ken Jin <kenjin@python.org>
1 parent 13a5082 commit cbcb526

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Include/object.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,11 @@ PyType_HasFeature(PyTypeObject *type, unsigned long feature)
12381238
// PyTypeObject is opaque in the limited C API
12391239
flags = PyType_GetFlags(type);
12401240
#else
1241-
flags = type->tp_flags;
1241+
# ifdef Py_GIL_DISABLED
1242+
flags = _Py_atomic_load_ulong_relaxed(&type->tp_flags);
1243+
# else
1244+
flags = type->tp_flags;
1245+
# endif
12421246
#endif
12431247
return ((flags & feature) != 0);
12441248
}

Objects/typeobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3435,7 +3435,7 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds)
34353435
unsigned long
34363436
PyType_GetFlags(PyTypeObject *type)
34373437
{
3438-
return type->tp_flags;
3438+
return FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags);
34393439
}
34403440

34413441

0 commit comments

Comments
 (0)