File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1507,20 +1507,22 @@ def test_zip_longest_result_gc(self):
15071507
15081508 def test_zip_longest_reentrant_iterator (self ):
15091509 # A re-entrant iterator exhaust must not cause use-after-free.
1510- entered = False
1511- class ReentrantIter :
1512- def __init__ (self , it ):
1510+ class ExhaustingIter :
1511+ def __init__ (self , it , sibling ):
15131512 self .it = it
1513+ self .sibling = sibling
1514+ self .first = True
15141515 def __iter__ (self ):
15151516 return self
15161517 def __next__ (self ):
1517- nonlocal entered
1518- if not entered :
1519- entered = True
1520- for _ in zl :
1518+ val = next ( self . it )
1519+ if self . first :
1520+ self . first = False
1521+ for _ in self . sibling :
15211522 pass
1522- return next (self .it )
1523- zl = zip_longest (ReentrantIter (iter ([1 ])), iter ([2 , 3 ]))
1523+ return val
1524+ sib = iter ([2 , 3 ])
1525+ zl = zip_longest (ExhaustingIter (iter ([1 , 4 ]), sib ), sib )
15241526 list (zl )
15251527
15261528 @support .cpython_only
You can’t perform that action at this time.
0 commit comments