mirror of
https://github.com/php/php-src.git
synced 2026-03-31 12:42:29 +02:00
Merge branch 'PHP-8.0'
* PHP-8.0: Short-circuit get_gc for currently running generator
This commit is contained in:
25
Zend/tests/generators/gc_running_generator.phpt
Normal file
25
Zend/tests/generators/gc_running_generator.phpt
Normal file
@@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
GC on running generator
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function gen() {
|
||||
yield;
|
||||
// Trigger GC while $v is being reassigned.
|
||||
$ary = [new stdClass, new stdClass, new stdClass];
|
||||
$ary[0]->foo = $ary;
|
||||
foreach ($ary as &$v) { }
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 10000; $i++) {
|
||||
// Make sure gen is registered as a GC root.
|
||||
$gen = gen();
|
||||
$gen2 = $gen;
|
||||
unset($gen);
|
||||
foreach ($gen2 as $v) {}
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
===DONE===
|
||||
@@ -324,6 +324,16 @@ static HashTable *zend_generator_get_gc(zend_object *object, zval **table, int *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) {
|
||||
/* If the generator is currently running, we certainly won't be able to GC any values it
|
||||
* holds on to. The execute_data state might be inconsistent during execution (e.g. because
|
||||
* GC has been triggered in the middle of a variable reassignment), so we should not try
|
||||
* to inspect it here. */
|
||||
*table = NULL;
|
||||
*n = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
op_array = &EX(func)->op_array;
|
||||
|
||||
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
|
||||
|
||||
Reference in New Issue
Block a user