mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
commit
8ba6a833de
27
Zend/tests/generators/bug78434.phpt
Normal file
27
Zend/tests/generators/bug78434.phpt
Normal file
@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
Bug #78434: Generator skips first item after valid() call
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$function = function () {
|
||||
yield 0;
|
||||
};
|
||||
|
||||
$wrapper = function () use ($function) {
|
||||
$generator = $function();
|
||||
$generator->valid();
|
||||
yield from $generator;
|
||||
|
||||
$generator = $function();
|
||||
$generator->valid();
|
||||
yield from $generator;
|
||||
};
|
||||
|
||||
foreach ($wrapper() as $value) {
|
||||
echo $value, "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
0
|
||||
0
|
@ -10,9 +10,6 @@ function from($levels) {
|
||||
}
|
||||
|
||||
function gen($gen, $level) {
|
||||
if ($level % 2) {
|
||||
yield $gen->current();
|
||||
}
|
||||
yield from $gen;
|
||||
}
|
||||
|
||||
|
@ -610,6 +610,7 @@ void zend_generator_yield_from(zend_generator *generator, zend_generator *from)
|
||||
generator->node.parent = from;
|
||||
zend_generator_get_current(generator);
|
||||
GC_DELREF(&from->std);
|
||||
generator->flags |= ZEND_GENERATOR_DO_INIT;
|
||||
}
|
||||
|
||||
ZEND_API zend_generator *zend_generator_update_current(zend_generator *generator, zend_generator *leaf)
|
||||
@ -786,6 +787,7 @@ try_again:
|
||||
|
||||
if (UNEXPECTED((orig_generator->flags & ZEND_GENERATOR_DO_INIT) != 0 && !Z_ISUNDEF(generator->value))) {
|
||||
/* We must not advance Generator if we yield from a Generator being currently run */
|
||||
orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -865,15 +867,15 @@ try_again:
|
||||
goto try_again;
|
||||
}
|
||||
}
|
||||
|
||||
orig_generator->flags &= ~ZEND_GENERATOR_DO_INIT;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */
|
||||
{
|
||||
if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPECTED(generator->node.parent == NULL)) {
|
||||
generator->flags |= ZEND_GENERATOR_DO_INIT;
|
||||
zend_generator_resume(generator);
|
||||
generator->flags &= ~ZEND_GENERATOR_DO_INIT;
|
||||
generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user