Skip to content

Simplify and fix generator tree management #6344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Zend/tests/generators/backtrace_multi_yield_from.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Generator backtrace with multi yield from
--FILE--
<?php

function gen() {
yield 1;
debug_print_backtrace();
yield 2;
}

function from($gen) {
yield from $gen;
}

$gen1 = gen();
$gen2 = from($gen1);
$gen3 = from($gen2);
var_dump($gen3->current());
$gen2->next();
var_dump($gen2->current());
$gen2->next();
var_dump($gen2->current());

?>
--EXPECTF--
int(1)
int(1)
#0 gen() called at [%s:10]
#1 from(Generator Object ())
#2 Generator->next() called at [%s:19]
int(2)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the output here is incorrect (only one next() call should be needed above). However, this is a pre-existing bug in PHP 7.4 and not related to this change.

28 changes: 28 additions & 0 deletions Zend/tests/generators/bug80240.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Bug #80240: Use after free multi yield from
--FILE--
<?php

function gen() {
yield 0;
yield from gen();
}

function bar($gen) {
yield from $gen;
}

$gen = gen();
$a = bar($gen);
$b = bar($gen);
$a->rewind();
$b->rewind();
$a->next();
unset($gen);
unset($a);
unset($b);

?>
===DONE===
--EXPECT--
===DONE===
24 changes: 24 additions & 0 deletions Zend/tests/generators/yield_from_chain_dtor_order.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Leaf link may need to be invalidated depending on dtor order
--FILE--
<?php

function gen2() {
yield 1;
}
function gen() {
yield from gen2();
}
function bar($g) {
yield from $g;
}

$gen = gen();
$bar = bar($gen);
var_dump($bar->current());
$copy = $bar;
unset($gen);

?>
--EXPECT--
int(1)
Loading