Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/c-api/iter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
erlend-aasland marked this conversation as resolved.


.. c:function:: PyObject* PyIter_Next(PyObject *o)
Expand Down
4 changes: 1 addition & 3 deletions Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ 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)
PyAPI_FUNC(int) PyIter_Check(PyObject *);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated

/* === Sequence protocol ================================================ */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:c:func:`PyIter_Check` macro is now a function, in order to hide implementation
details. The macro accessed :c:member:`PyTypeObject.tp_iternext` directly.
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
Patch by Erlend E. Aasland.
10 changes: 5 additions & 5 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
}

/* Return next item.
Expand Down