]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFlags() (GH-19378...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 8 Jul 2020 09:19:38 +0000 (02:19 -0700)
committerGitHub <noreply@github.com>
Wed, 8 Jul 2020 09:19:38 +0000 (02:19 -0700)
This partially reverts commit 45ec5b99aefa54552947049086e87ec01bc2fc9a.
(cherry picked from commit b26a0db8ea2de3a8a8e4b40e69fc8642c7d7cb68)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/object.h
Misc/NEWS.d/next/C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst [new file with mode: 0644]

index 514d934196f571462c9e7cb1dfaf2b59b548bf3c..9c1a7f479e44906a2cf5a9f69e12dbfc7e7cf557 100644 (file)
@@ -618,8 +618,16 @@ times.
 
 
 static inline int
-PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
-    return ((PyType_GetFlags(type) & feature) != 0);
+PyType_HasFeature(PyTypeObject *type, unsigned long feature)
+{
+    unsigned long flags;
+#ifdef Py_LIMITED_API
+    // PyTypeObject is opaque in the limited C API
+    flags = PyType_GetFlags(type);
+#else
+    flags = type->tp_flags;
+#endif
+    return ((flags & feature) != 0);
 }
 
 #define PyType_FastSubclass(type, flag) PyType_HasFeature(type, flag)
diff --git a/Misc/NEWS.d/next/C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst b/Misc/NEWS.d/next/C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst
new file mode 100644 (file)
index 0000000..760a3ff
--- /dev/null
@@ -0,0 +1,4 @@
+Revert :c:func:`PyType_HasFeature` change: it reads again directly the
+:c:member:`PyTypeObject.tp_flags` member when the limited C API is not used,
+rather than always calling :c:func:`PyType_GetFlags` which hides implementation
+details.