From 4975a9eb773d0b9525315801f3e2ed3f79c432fb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Jul 2020 10:04:32 +0200 Subject: [PATCH] Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFlags() (GH-19378)" This partially reverts commit 45ec5b99aefa54552947049086e87ec01bc2fc9a. --- Include/object.h | 12 ++++++++++-- .../C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst diff --git a/Include/object.h b/Include/object.h index 537567040f9871..10f1d6a3dff2dd 100644 --- a/Include/object.h +++ b/Include/object.h @@ -637,8 +637,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 index 00000000000000..760a3ff4d17b44 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-07-08-10-14-52.bpo-40170.N6Qx1i.rst @@ -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.