mirror of https://github.com/python/cpython
bpo-40170: Always define PyIter_Check() as a function (GH-24548)
This commit is contained in:
parent
17dbd4078b
commit
cc54001c2e
|
@ -9,8 +9,8 @@ There are two functions specifically for working with iterators.
|
||||||
|
|
||||||
.. c:function:: int PyIter_Check(PyObject *o)
|
.. c:function:: int PyIter_Check(PyObject *o)
|
||||||
|
|
||||||
Return true if the object *o* supports the iterator protocol. This
|
Return non-zero if the object *o* supports the iterator protocol, and ``0``
|
||||||
function always succeeds.
|
otherwise. This function always succeeds.
|
||||||
|
|
||||||
|
|
||||||
.. c:function:: PyObject* PyIter_Next(PyObject *o)
|
.. c:function:: PyObject* PyIter_Next(PyObject *o)
|
||||||
|
|
|
@ -324,7 +324,7 @@ PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
|
||||||
returns itself. */
|
returns itself. */
|
||||||
PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
|
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. */
|
This function always succeeds. */
|
||||||
PyAPI_FUNC(int) PyIter_Check(PyObject *);
|
PyAPI_FUNC(int) PyIter_Check(PyObject *);
|
||||||
|
|
|
@ -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*". */
|
/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */
|
||||||
PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
|
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 ================================================ */
|
/* === Sequence protocol ================================================ */
|
||||||
|
|
||||||
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
|
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
|
||||||
|
|
|
@ -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.
|
|
@ -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 &&
|
PyTypeObject *tp = Py_TYPE(obj);
|
||||||
Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented;
|
return (tp->tp_iternext != NULL &&
|
||||||
|
tp->tp_iternext != &_PyObject_NextNotImplemented);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return next item.
|
/* Return next item.
|
||||||
|
|
Loading…
Reference in New Issue