]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40170: Always define PyIter_Check() as a function (GH-24548)
authorErlend Egeberg Aasland <erlend.aasland@innova.no>
Tue, 16 Feb 2021 15:05:58 +0000 (16:05 +0100)
committerGitHub <noreply@github.com>
Tue, 16 Feb 2021 15:05:58 +0000 (16:05 +0100)
Doc/c-api/iter.rst
Include/abstract.h
Include/cpython/abstract.h
Misc/NEWS.d/next/Core and Builtins/2021-02-15-15-06-43.bpo-40170.ZYeSii.rst [new file with mode: 0644]
Objects/abstract.c

index 74fb5578abd6e157b2bbd423d5da66e0a589f10d..5706777c41db482fb2532ee53250c4ddd810215f 100644 (file)
@@ -9,8 +9,8 @@ There are two functions specifically for working with iterators.
 
 .. c:function:: int PyIter_Check(PyObject *o)
 
-   Return true if the object *o* supports the iterator protocol.  This
-   function always succeeds.
+   Return non-zero if the object *o* supports the iterator protocol, and ``0``
+   otherwise.  This function always succeeds.
 
 
 .. c:function:: PyObject* PyIter_Next(PyObject *o)
index 0bd1ca936846feb3e71f8c7ef42ce4079dc5cd0a..a47c944060d3d0f38096f80da1734b939f3a2be4 100644 (file)
@@ -324,7 +324,7 @@ PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
    returns itself. */
 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
 
-/* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise.
+/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.
 
    This function always succeeds. */
 PyAPI_FUNC(int) PyIter_Check(PyObject *);
index 7a4219c8b338b4e0a4ed1f44d997d558019777bb..db5055d201107e118f46d37041bfc71f58184536 100644 (file)
@@ -325,12 +325,6 @@ PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
 /* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */
 PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
 
-/* ==== Iterators ================================================ */
-
-#define PyIter_Check(obj) \
-    (Py_TYPE(obj)->tp_iternext != NULL && \
-     Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented)
-
 /* === Sequence protocol ================================================ */
 
 /* Assume tp_as_sequence and sq_item exist and that 'i' does not
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-02-15-15-06-43.bpo-40170.ZYeSii.rst b/Misc/NEWS.d/next/Core and Builtins/2021-02-15-15-06-43.bpo-40170.ZYeSii.rst
new file mode 100644 (file)
index 0000000..df6f3dc
--- /dev/null
@@ -0,0 +1,3 @@
+:c:func:`PyIter_Check` is now always declared as a function, in order to hide implementation
+details. The macro accessed :c:member:`PyTypeObject.tp_iternext` directly.
+Patch by Erlend E. Aasland.
index 74a73ee469866d6f166f7aabbed9a629daffa46a..c93309b352774cb44a212c88acb82242ef616ff2 100644 (file)
@@ -2732,12 +2732,12 @@ PyObject_GetIter(PyObject *o)
     }
 }
 
-#undef PyIter_Check
-
-int PyIter_Check(PyObject *obj)
+int
+PyIter_Check(PyObject *obj)
 {
-    return Py_TYPE(obj)->tp_iternext != NULL &&
-           Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented;
+    PyTypeObject *tp = Py_TYPE(obj);
+    return (tp->tp_iternext != NULL &&
+            tp->tp_iternext != &_PyObject_NextNotImplemented);
 }
 
 /* Return next item.