Skip to content

Commit cc54001

Browse files
author
Erlend Egeberg Aasland
authored
bpo-40170: Always define PyIter_Check() as a function (GH-24548)
1 parent 17dbd40 commit cc54001

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

Doc/c-api/iter.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ There are two functions specifically for working with iterators.
99

1010
.. c:function:: int PyIter_Check(PyObject *o)
1111
12-
Return true if the object *o* supports the iterator protocol. This
13-
function always succeeds.
12+
Return non-zero if the object *o* supports the iterator protocol, and ``0``
13+
otherwise. This function always succeeds.
1414
1515
1616
.. c:function:: PyObject* PyIter_Next(PyObject *o)

Include/abstract.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ PyAPI_FUNC(PyObject *) PyObject_Format(PyObject *obj,
324324
returns itself. */
325325
PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
326326

327-
/* Returns 1 if the object 'obj' provides iterator protocols, and 0 otherwise.
327+
/* Returns non-zero if the object 'obj' provides iterator protocols, and 0 otherwise.
328328
329329
This function always succeeds. */
330330
PyAPI_FUNC(int) PyIter_Check(PyObject *);

Include/cpython/abstract.h

-6
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,6 @@ PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,
325325
/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */
326326
PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);
327327

328-
/* ==== Iterators ================================================ */
329-
330-
#define PyIter_Check(obj) \
331-
(Py_TYPE(obj)->tp_iternext != NULL && \
332-
Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented)
333-
334328
/* === Sequence protocol ================================================ */
335329

336330
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:c:func:`PyIter_Check` is now always declared as a function, in order to hide implementation
2+
details. The macro accessed :c:member:`PyTypeObject.tp_iternext` directly.
3+
Patch by Erlend E. Aasland.

Objects/abstract.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2732,12 +2732,12 @@ PyObject_GetIter(PyObject *o)
27322732
}
27332733
}
27342734

2735-
#undef PyIter_Check
2736-
2737-
int PyIter_Check(PyObject *obj)
2735+
int
2736+
PyIter_Check(PyObject *obj)
27382737
{
2739-
return Py_TYPE(obj)->tp_iternext != NULL &&
2740-
Py_TYPE(obj)->tp_iternext != &_PyObject_NextNotImplemented;
2738+
PyTypeObject *tp = Py_TYPE(obj);
2739+
return (tp->tp_iternext != NULL &&
2740+
tp->tp_iternext != &_PyObject_NextNotImplemented);
27412741
}
27422742

27432743
/* Return next item.

0 commit comments

Comments
 (0)