File tree Expand file tree Collapse file tree 3 files changed +23
-11
lines changed Expand file tree Collapse file tree 3 files changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -3498,6 +3498,7 @@ def test_io_after_close(self):
3498
3498
self .assertRaises (ValueError , f .readinto1 , bytearray (1024 ))
3499
3499
self .assertRaises (ValueError , f .readline )
3500
3500
self .assertRaises (ValueError , f .readlines )
3501
+ self .assertRaises (ValueError , f .readlines , 1 )
3501
3502
self .assertRaises (ValueError , f .seek , 0 )
3502
3503
self .assertRaises (ValueError , f .tell )
3503
3504
self .assertRaises (ValueError , f .truncate )
Original file line number Diff line number Diff line change @@ -32,12 +32,14 @@ Core and Builtins
32
32
Library
33
33
-------
34
34
35
+ - bpo-30068: _io._IOBase.readlines will check if it's closed first when
36
+ hint is present.
37
+
35
38
- bpo-29694: Fixed race condition in pathlib mkdir with flags
36
39
parents=True. Patch by Armin Rigo.
37
40
38
- - bpo-29692: Fixed arbitrary unchaining of RuntimeError exceptions in
39
- contextlib.contextmanager.
40
- Patch by Siddharth Velankar.
41
+ - bpo-29692: Fixed arbitrary unchaining of RuntimeError exceptions in
42
+ contextlib.contextmanager. Patch by Siddharth Velankar.
41
43
42
44
- bpo-29998: Pickling and copying ImportError now preserves name and path
43
45
attributes.
Original file line number Diff line number Diff line change @@ -650,7 +650,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
650
650
/*[clinic end generated code: output=2f50421677fa3dea input=1961c4a95e96e661]*/
651
651
{
652
652
Py_ssize_t length = 0 ;
653
- PyObject * result ;
653
+ PyObject * result , * it = NULL ;
654
654
655
655
result = PyList_New (0 );
656
656
if (result == NULL )
@@ -664,36 +664,45 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
664
664
PyObject * ret = _PyObject_CallMethodId (result , & PyId_extend , "O" , self );
665
665
666
666
if (ret == NULL ) {
667
- Py_DECREF (result );
668
- return NULL ;
667
+ goto error ;
669
668
}
670
669
Py_DECREF (ret );
671
670
return result ;
672
671
}
673
672
673
+ it = PyObject_GetIter (self );
674
+ if (it == NULL ) {
675
+ goto error ;
676
+ }
677
+
674
678
while (1 ) {
675
- PyObject * line = PyIter_Next (self );
679
+ PyObject * line = PyIter_Next (it );
676
680
if (line == NULL ) {
677
681
if (PyErr_Occurred ()) {
678
- Py_DECREF (result );
679
- return NULL ;
682
+ goto error ;
680
683
}
681
684
else
682
685
break ; /* StopIteration raised */
683
686
}
684
687
685
688
if (PyList_Append (result , line ) < 0 ) {
686
689
Py_DECREF (line );
687
- Py_DECREF (result );
688
- return NULL ;
690
+ goto error ;
689
691
}
690
692
length += PyObject_Size (line );
691
693
Py_DECREF (line );
692
694
693
695
if (length > hint )
694
696
break ;
695
697
}
698
+
699
+ Py_DECREF (it );
696
700
return result ;
701
+
702
+ error :
703
+ Py_XDECREF (it );
704
+ Py_DECREF (result );
705
+ return NULL ;
697
706
}
698
707
699
708
/*[clinic input]
You can’t perform that action at this time.
0 commit comments