Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 738236d

Browse files
committed
Issue #11067: Add PyType_GetFlags, to support PyUnicode_Check
in the limited ABI
1 parent 9b142aa commit 738236d

7 files changed

Lines changed: 32 additions & 1 deletion

File tree

Doc/c-api/type.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ Type Objects
3535
3636
Clear the internal lookup cache. Return the current version tag.
3737
38+
.. c:function:: long PyType_GetFlags(PyTypeObject* type)
39+
40+
Return the :attr:`tp_flags` member of *type*. This function is primarily
41+
meant for use with `Py_LIMITED_API`; the individual flag bits are
42+
guaranteed to be stable across Python releases, but access to
43+
:attr:`tp_flags` itself is not part of the limited API.
44+
45+
.. versionadded:: 3.2
3846
3947
.. c:function:: void PyType_Modified(PyTypeObject *type)
4048

Include/object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
437437
PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
438438
PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
439439

440+
PyAPI_FUNC(long) PyType_GetFlags(PyTypeObject*);
441+
440442
#define PyType_Check(op) \
441443
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
442444
#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
@@ -589,7 +591,11 @@ given type object has a specified feature.
589591
Py_TPFLAGS_HAVE_VERSION_TAG | \
590592
0)
591593

594+
#ifdef Py_LIMITED_API
595+
#define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
596+
#else
592597
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
598+
#endif
593599
#define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
594600

595601

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #11067: Add PyType_GetFlags, to support PyUnicode_Check
14+
in the limited ABI.
15+
1316
- Issue #11118: Fix bogus export of None in python3.dll.
1417

1518
Library

Modules/xxlimited.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ Xxo_dealloc(XxoObject *self)
5050
static PyObject *
5151
Xxo_demo(XxoObject *self, PyObject *args)
5252
{
53-
if (!PyArg_ParseTuple(args, ":demo"))
53+
PyObject *o = NULL;
54+
if (!PyArg_ParseTuple(args, "|O:demo", &o))
5455
return NULL;
56+
/* Test availability of fast type checks */
57+
if (o != NULL && PyUnicode_Check(o)) {
58+
Py_INCREF(o);
59+
return o;
60+
}
5561
Py_INCREF(Py_None);
5662
return Py_None;
5763
}

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,12 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds)
19041904
return res;
19051905
}
19061906

1907+
long
1908+
PyType_GetFlags(PyTypeObject *type)
1909+
{
1910+
return type->tp_flags;
1911+
}
1912+
19071913
static PyObject *
19081914
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
19091915
{

PC/python3.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ EXPORTS
513513
PyType_FromSpec=python32.PyType_FromSpec
514514
PyType_GenericAlloc=python32.PyType_GenericAlloc
515515
PyType_GenericNew=python32.PyType_GenericNew
516+
PyType_GetFlags=python32.PyType_GetFlags
516517
PyType_IsSubtype=python32.PyType_IsSubtype
517518
PyType_Modified=python32.PyType_Modified
518519
PyType_Ready=python32.PyType_Ready

PC/python32stub.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ PyType_ClearCache
513513
PyType_FromSpec
514514
PyType_GenericAlloc
515515
PyType_GenericNew
516+
PyType_GetFlags
516517
PyType_IsSubtype
517518
PyType_Modified
518519
PyType_Ready

0 commit comments

Comments
 (0)