Skip to content

Commit 024e4e1

Browse files
committed
gh-150942: Use reference-stealing append in BytesIO.readlines
1 parent ef0affb commit 024e4e1

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Modules/_io/bytesio.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Python.h"
22
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
3+
#include "pycore_list.h" // _PyList_AppendTakeRef()
34
#include "pycore_object.h"
45
#include "pycore_pyatomic_ft_wrappers.h"
56
#include "pycore_sysmodule.h" // _PySys_GetSizeOf()
@@ -663,11 +664,9 @@ _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg)
663664
line = PyBytes_FromStringAndSize(output, n);
664665
if (!line)
665666
goto on_error;
666-
if (PyList_Append(result, line) == -1) {
667-
Py_DECREF(line);
667+
if (_PyList_AppendTakeRef((PyListObject *)result, line) < 0) {
668668
goto on_error;
669669
}
670-
Py_DECREF(line);
671670
size += n;
672671
if (maxsize > 0 && size >= maxsize)
673672
break;

0 commit comments

Comments
 (0)