Skip to content

Commit 6f63dff

Browse files
gh-117657: Make PyType_HasFeature (exported version) atomic (#120484)
Make PyType_HasFeature (exported version) atomic
1 parent 99d62f9 commit 6f63dff

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
@@ -756,7 +756,11 @@ PyType_HasFeature(PyTypeObject *type, unsigned long feature)
756756
// PyTypeObject is opaque in the limited C API
757757
flags = PyType_GetFlags(type);
758758
#else
759-
flags = type->tp_flags;
759+
# ifdef Py_GIL_DISABLED
760+
flags = _Py_atomic_load_ulong_relaxed(&type->tp_flags);
761+
# else
762+
flags = type->tp_flags;
763+
# endif
760764
#endif
761765
return ((flags & feature) != 0);
762766
}

Objects/typeobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds)
35993599
unsigned long
36003600
PyType_GetFlags(PyTypeObject *type)
36013601
{
3602-
return type->tp_flags;
3602+
return FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags);
36033603
}
36043604

36053605

0 commit comments

Comments
 (0)