Bug report
Bug description:
Bug report
Bug description:
In Modules/_io/bufferedio.c, the buffered_iternext function has a fast path that calls _buffered_readline directly to avoid method call overhead.
However, due to an incorrect type check, this fast path is never executed.
tp = Py_TYPE(self);
if (Py_IS_TYPE(tp, state->PyBufferedReader_Type) ||
Py_IS_TYPE(tp, state->PyBufferedRandom_Type))
because Py_IS_TYPE will call Py_TYPE internally, will cause Py_TYPE(Py_TYPE(ob)) == type,
<class 'type'> != state->PyBufferedReader_Type
All iteration over buffered binary files is affected:
with open('data.txt', 'rb') as f:
for line in f:
process(line)
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
Bug report
Bug description:
In
Modules/_io/bufferedio.c, thebuffered_iternextfunction has a fast path that calls_buffered_readlinedirectly to avoid method call overhead.However, due to an incorrect type check, this fast path is never executed.
because
Py_IS_TYPEwill callPy_TYPEinternally, will causePy_TYPE(Py_TYPE(ob)) == type,<class 'type'> != state->PyBufferedReader_TypeAll iteration over buffered binary files is affected:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
buffered_iternext()#144381buffered_iternext()(GH-144381) #144389buffered_iternext()(GH-144381) #144390