]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Make PyType_HasFeature (exported version) atomic (#120484)
authorKen Jin <kenjin@python.org>
Sat, 15 Jun 2024 14:39:22 +0000 (22:39 +0800)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 14:39:22 +0000 (22:39 +0800)
Make PyType_HasFeature (exported version) atomic

Include/object.h
Objects/typeobject.c

index 4a39ada8c7daa4327adbff598a7350a371823bb0..f71aaee7efe6ee61906208ea75ce72a43564dbee 100644 (file)
@@ -756,7 +756,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 98e00bd25c3205bb229c0c70fa1bb3b046147af1..eb296414bb7befc089f00fa2d42cf80aa62ef3d2 100644 (file)
@@ -3599,7 +3599,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);
 }