File tree Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -3510,6 +3510,7 @@ def test_io_after_close(self):
3510
3510
self .assertRaises (ValueError , f .readinto1 , bytearray (1024 ))
3511
3511
self .assertRaises (ValueError , f .readline )
3512
3512
self .assertRaises (ValueError , f .readlines )
3513
+ self .assertRaises (ValueError , f .readlines , 1 )
3513
3514
self .assertRaises (ValueError , f .seek , 0 )
3514
3515
self .assertRaises (ValueError , f .tell )
3515
3516
self .assertRaises (ValueError , f .truncate )
Original file line number Diff line number Diff line change @@ -310,12 +310,14 @@ Extension Modules
310
310
Library
311
311
-------
312
312
313
+ - bpo-30068: _io._IOBase.readlines will check if it's closed first when
314
+ hint is present.
315
+
313
316
- bpo-29694: Fixed race condition in pathlib mkdir with flags
314
317
parents=True. Patch by Armin Rigo.
315
318
316
319
- bpo-29692: Fixed arbitrary unchaining of RuntimeError exceptions in
317
- contextlib.contextmanager.
318
- Patch by Siddharth Velankar.
320
+ contextlib.contextmanager. Patch by Siddharth Velankar.
319
321
320
322
- bpo-26187: Test that sqlite3 trace callback is not called multiple
321
323
times when schema is changing. Indirectly fixed by switching to
Original file line number Diff line number Diff line change @@ -643,7 +643,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
643
643
/*[clinic end generated code: output=2f50421677fa3dea input=9400c786ea9dc416]*/
644
644
{
645
645
Py_ssize_t length = 0 ;
646
- PyObject * result ;
646
+ PyObject * result , * it = NULL ;
647
647
648
648
result = PyList_New (0 );
649
649
if (result == NULL )
@@ -658,36 +658,45 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
658
658
self , NULL );
659
659
660
660
if (ret == NULL ) {
661
- Py_DECREF (result );
662
- return NULL ;
661
+ goto error ;
663
662
}
664
663
Py_DECREF (ret );
665
664
return result ;
666
665
}
667
666
667
+ it = PyObject_GetIter (self );
668
+ if (it == NULL ) {
669
+ goto error ;
670
+ }
671
+
668
672
while (1 ) {
669
- PyObject * line = PyIter_Next (self );
673
+ PyObject * line = PyIter_Next (it );
670
674
if (line == NULL ) {
671
675
if (PyErr_Occurred ()) {
672
- Py_DECREF (result );
673
- return NULL ;
676
+ goto error ;
674
677
}
675
678
else
676
679
break ; /* StopIteration raised */
677
680
}
678
681
679
682
if (PyList_Append (result , line ) < 0 ) {
680
683
Py_DECREF (line );
681
- Py_DECREF (result );
682
- return NULL ;
684
+ goto error ;
683
685
}
684
686
length += PyObject_Size (line );
685
687
Py_DECREF (line );
686
688
687
689
if (length > hint )
688
690
break ;
689
691
}
692
+
693
+ Py_DECREF (it );
690
694
return result ;
695
+
696
+ error :
697
+ Py_XDECREF (it );
698
+ Py_DECREF (result );
699
+ return NULL ;
691
700
}
692
701
693
702
/*[clinic input]
You can’t perform that action at this time.
0 commit comments