FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-40170: Convert PyIter_Check macro to a function by erlend-aasland · Pull Request #24548 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (2) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions Doc/c-api/iter.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
2 changes: 1 addition & 1 deletion Include/abstract.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
6 changes: 0 additions & 6 deletions Include/cpython/abstract.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions Objects/abstract.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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);
}

/* Return next item.
Expand Down

Back | FazBrowse Home | New Git URL