Skip to content

Commit b26a0db

Browse files
authored
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFlags() (GH-19378)" (GH-21390)
This partially reverts commit 45ec5b9.
1 parent aebc049 commit b26a0db

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
@@ -637,8 +637,16 @@ times.
637637

638638

639639
static inline int
640-
PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
641-
return ((PyType_GetFlags(type) & feature) != 0);
640+
PyType_HasFeature(PyTypeObject *type, unsigned long feature)
641+
{
642+
unsigned long flags;
643+
#ifdef Py_LIMITED_API
644+
// PyTypeObject is opaque in the limited C API
645+
flags = PyType_GetFlags(type);
646+
#else
647+
flags = type->tp_flags;
648+
#endif
649+
return ((flags & feature) != 0);
642650
}
643651

644652
#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)