From 1eeddac5bb1558722786462ccf1b86ff7ad24491 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Sat, 15 Jun 2024 22:39:22 +0800 Subject: [PATCH] gh-117657: Make PyType_HasFeature (exported version) atomic (GH-120484) Make PyType_HasFeature (exported version) atomic (cherry picked from commit 6f63dfff6f493b405f3422210a168369e1e7a35d) Co-authored-by: Ken Jin --- Include/object.h | 6 +++++- Objects/typeobject.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Include/object.h b/Include/object.h index a687bf2f7cdd74..7aaa8da8e8d154 100644 --- a/Include/object.h +++ b/Include/object.h @@ -1238,7 +1238,11 @@ PyType_HasFeature(PyTypeObject *type, unsigned long feature) // PyTypeObject is opaque in the limited C API flags = PyType_GetFlags(type); #else - flags = type->tp_flags; +# ifdef Py_GIL_DISABLED + flags = _Py_atomic_load_ulong_relaxed(&type->tp_flags); +# else + flags = type->tp_flags; +# endif #endif return ((flags & feature) != 0); } diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 1f6c2828f1c697..1123ef6eb3d9b2 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3435,7 +3435,7 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds) unsigned long PyType_GetFlags(PyTypeObject *type) { - return type->tp_flags; + return FT_ATOMIC_LOAD_ULONG_RELAXED(type->tp_flags); }