Index: Doc/c-api/type.rst =================================================================== --- Doc/c-api/type.rst (revision 88333) +++ Doc/c-api/type.rst (working copy) @@ -35,7 +35,13 @@ Clear the internal lookup cache. Return the current version tag. +.. c:function:: long PyType_GetFlags(PyTypeObject* type) + Return the :attr:`tp_flags` member of *type*. This function is primarily + meant for use with `Py_LIMITED_API`; the individual flag bits are + guaranteed to be stable across Python releases, but access to + :attr:`tp_flags` itself is not part of the limited API. + .. c:function:: void PyType_Modified(PyTypeObject *type) Invalidate the internal lookup cache for the type and all of its Index: Include/object.h =================================================================== --- Include/object.h (revision 88333) +++ Include/object.h (working copy) @@ -437,6 +437,8 @@ PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ +PyAPI_FUNC(long) PyType_GetFlags(PyTypeObject*); + #define PyType_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type) @@ -589,7 +591,11 @@ Py_TPFLAGS_HAVE_VERSION_TAG | \ 0) +#ifdef Py_LIMITED_API +#define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0) +#else #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) +#endif #define PyType_FastSubclass(t,f) PyType_HasFeature(t,f) Index: Modules/xxlimited.c =================================================================== --- Modules/xxlimited.c (revision 88333) +++ Modules/xxlimited.c (working copy) @@ -50,8 +50,14 @@ static PyObject * Xxo_demo(XxoObject *self, PyObject *args) { - if (!PyArg_ParseTuple(args, ":demo")) + PyObject *o = NULL; + if (!PyArg_ParseTuple(args, "|O:demo", &o)) return NULL; + /* Test availability of fast type checks */ + if (o != NULL && PyUnicode_Check(o)) { + Py_INCREF(o); + return o; + } Py_INCREF(Py_None); return Py_None; } Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 88333) +++ Objects/typeobject.c (working copy) @@ -1904,6 +1904,12 @@ return res; } +long +PyType_GetFlags(PyTypeObject *type) +{ + return type->tp_flags; +} + static PyObject * type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { Index: PC/python3.def =================================================================== --- PC/python3.def (revision 88333) +++ PC/python3.def (working copy) @@ -513,6 +513,7 @@ PyType_FromSpec=python32.PyType_FromSpec PyType_GenericAlloc=python32.PyType_GenericAlloc PyType_GenericNew=python32.PyType_GenericNew + PyType_GetFlags=python32.PyType_GetFlags PyType_IsSubtype=python32.PyType_IsSubtype PyType_Modified=python32.PyType_Modified PyType_Ready=python32.PyType_Ready Index: PC/python32stub.def =================================================================== --- PC/python32stub.def (revision 88333) +++ PC/python32stub.def (working copy) @@ -513,6 +513,7 @@ PyType_FromSpec PyType_GenericAlloc PyType_GenericNew +PyType_GetFlags PyType_IsSubtype PyType_Modified PyType_Ready