]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-117657: Make PyType_HasFeature (exported version) atomic (GH-120484) (...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 15 Jun 2024 15:06:54 +0000 (17:06 +0200)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 15:06:54 +0000 (15:06 +0000)
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 <kenjin@python.org>
Include/object.h
Objects/typeobject.c

index a687bf2f7cdd749e6bde768714a1e713f7ab69b9..7aaa8da8e8d1540b86498451da37e943a4ded532 100644 (file)
@@ -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);
 }
index 1f6c2828f1c697db575b78c72d09c2d20f915afd..1123ef6eb3d9b2b2d6944edfdfbdf81d85e04b04 100644 (file)
@@ -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);
 }