Skip to content

Commit a0a6f11

Browse files
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFlags() (GH-19378)" (GH-21390)
This partially reverts commit 45ec5b9. (cherry picked from commit b26a0db) Co-authored-by: Victor Stinner <[email protected]>
1 parent 1d1c574 commit a0a6f11

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Include/object.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,16 @@ times.
618618

619619

620620
static inline int
621-
PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
622-
return ((PyType_GetFlags(type) & feature) != 0);
621+
PyType_HasFeature(PyTypeObject *type, unsigned long feature)
622+
{
623+
unsigned long flags;
624+
#ifdef Py_LIMITED_API
625+
// PyTypeObject is opaque in the limited C API
626+
flags = PyType_GetFlags(type);
627+
#else
628+
flags = type->tp_flags;
629+
#endif
630+
return ((flags & feature) != 0);
623631
}
624632

625633
#define PyType_FastSubclass(type, flag) PyType_HasFeature(type, flag)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Revert :c:func:`PyType_HasFeature` change: it reads again directly the
2+
:c:member:`PyTypeObject.tp_flags` member when the limited C API is not used,
3+
rather than always calling :c:func:`PyType_GetFlags` which hides implementation
4+
details.

0 commit comments

Comments
 (0)