Skip to content

Commit f449138

Browse files
committed
add test for GC with include in suspended coroutine to check symTable double DELREF
1 parent 152833a commit f449138

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
GC with include in suspended coroutine - symTable double DELREF
3+
--FILE--
4+
<?php
5+
6+
use function Async\spawn;
7+
use function Async\suspend;
8+
use function Async\await;
9+
10+
class Cycle {
11+
public $self;
12+
}
13+
14+
try {
15+
$coroutine = spawn(function() {
16+
$parent1 = "value1";
17+
$parent2 = "value2";
18+
19+
for ($i = 0; $i < 10000; $i++) {
20+
$obj = new Cycle();
21+
$obj->self = $obj;
22+
}
23+
24+
// Suspend - coroutine is now in suspended state
25+
suspend();
26+
27+
// Include inherits parent symTable
28+
// Bug: GC may add same variables twice -> double DELREF
29+
include __DIR__ . '/011-gc_include_symtable_double_delref_included.inc';
30+
31+
echo "parent1: {$parent1}\n";
32+
echo "parent2: {$parent2}\n";
33+
echo "included: {$included}\n";
34+
35+
return "done";
36+
});
37+
38+
$result = await($coroutine);
39+
echo "result: {$result}\n";
40+
41+
} catch (Error $e) {
42+
echo "Error: " . $e->getMessage() . "\n";
43+
}
44+
45+
echo "OK\n";
46+
gc_collect_cycles();
47+
?>
48+
--EXPECTF--
49+
parent1: value1
50+
parent2: value2
51+
included: included_value
52+
result: done
53+
OK
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
// Included file for GC test
3+
$included = "included_value";

0 commit comments

Comments
 (0)