]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #11067: Add PyType_GetFlags, to support PyUnicode_Check
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 5 Feb 2011 20:35:29 +0000 (20:35 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 5 Feb 2011 20:35:29 +0000 (20:35 +0000)
in the limited ABI

Doc/c-api/type.rst
Include/object.h
Misc/NEWS
Modules/xxlimited.c
Objects/typeobject.c
PC/python3.def
PC/python32stub.def

index 49dfb3f6712443712e528823018f904ebe68b244..b3386eaa8b524a9ed9bfe27b23f2819764277908 100644 (file)
@@ -35,6 +35,14 @@ Type Objects
 
    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.
+
+   .. versionadded:: 3.2
 
 .. c:function:: void PyType_Modified(PyTypeObject *type)
 
index 690f87bd32ed96f2fc0e0b4337a9ac087aef8185..99a773749531fd13acc953155ff17d15ba7b2ee0 100644 (file)
@@ -437,6 +437,8 @@ PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
 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 @@ given type object has a specified feature.
                  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 94b6964cee83bae15537aa9ce84d869e592505f4..7dbbcbb748fee051d81748168a96c0764269164a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2?
 Core and Builtins
 -----------------
 
+- Issue #11067: Add PyType_GetFlags, to support PyUnicode_Check
+  in the limited ABI.
+
 - Issue #11118: Fix bogus export of None in python3.dll.
 
 Library
index bd3f1783e6797d4825973b0894c9887bec1aeb8d..5a6df8f2d8fdb1a589bea98313510e8044916820 100644 (file)
@@ -50,8 +50,14 @@ Xxo_dealloc(XxoObject *self)
 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 db7828a2fc5022b4afc88367aa1d5043e7cbb307..e9c7591b818f70797923de2981be8031b41a5fab 100644 (file)
@@ -1904,6 +1904,12 @@ type_init(PyObject *cls, PyObject *args, PyObject *kwds)
     return res;
 }
 
+long
+PyType_GetFlags(PyTypeObject *type)
+{
+    return type->tp_flags;
+}
+
 static PyObject *
 type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
 {
index b8f483ce3cb551e67fad36c0acdd99d4c0d8e5cd..d02c5856b2fa03fc0f4dc57917f95d65817fbe63 100644 (file)
@@ -513,6 +513,7 @@ EXPORTS
   PyType_FromSpec=python32.PyType_FromSpec\r
   PyType_GenericAlloc=python32.PyType_GenericAlloc\r
   PyType_GenericNew=python32.PyType_GenericNew\r
+  PyType_GetFlags=python32.PyType_GetFlags\r
   PyType_IsSubtype=python32.PyType_IsSubtype\r
   PyType_Modified=python32.PyType_Modified\r
   PyType_Ready=python32.PyType_Ready\r
index e5850c0dcb252299dad9274032a3c1495c53b863..f8ac0994a0b203bceb1c6d665e0af7285d9756eb 100644 (file)
@@ -513,6 +513,7 @@ PyType_ClearCache
 PyType_FromSpec\r
 PyType_GenericAlloc\r
 PyType_GenericNew\r
+PyType_GetFlags\r
 PyType_IsSubtype\r
 PyType_Modified\r
 PyType_Ready\r