-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generator GC if yield from parent chain does not reach root
Parents may be unlinked while another generator sharing part of the chain is running. As such, we cannot assume that the parent chain goes all the way to the root. Instead walk backwards from root to leaf, like we also do during destruction.
- Loading branch information
Showing
2 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
Generator GC when the yield from parent chain does not reach the root | ||
--FILE-- | ||
<?php | ||
|
||
function root() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
function delegate($gen) { | ||
yield from $gen; | ||
} | ||
|
||
$gen = delegate(delegate(root())); | ||
$gen1 = delegate(delegate($gen)); | ||
$gen2 = delegate(delegate($gen)); | ||
var_dump($gen1->current()); | ||
var_dump($gen2->current()); | ||
$gen1->next(); | ||
$gen1->next(); | ||
gc_collect_cycles(); | ||
|
||
?> | ||
--EXPECT-- | ||
int(1) | ||
int(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters