Skip to content

Commit b750977

Browse files
committed
Fix binding allocation
1 parent 360f44e commit b750977

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Zend/tests/pattern_matching/is/binding.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ class NotBox {
1515
) {}
1616
}
1717

18+
class Many {
19+
public function __construct(
20+
public $a = 1,
21+
public $b = 2,
22+
public $c = 3,
23+
public $d = 4,
24+
public $e = 5,
25+
public $f = 6,
26+
public $g = 7,
27+
public $h = 8,
28+
public $i = 9,
29+
public $j = 10,
30+
) {}
31+
}
32+
1833
var_dump(10 is $a);
1934
var_dump($a);
2035

@@ -33,6 +48,12 @@ var_dump($a);
3348
var_dump([] is $a @ string);
3449
var_dump($a);
3550

51+
var_dump(new Many() is Many { $a, $b, $c, $d });
52+
var_dump($a, $b, $c, $d, isset($e));
53+
54+
var_dump(new Many() is Many { $a, $b, $c, $d, $e, $f, $g, $h, $i, $j });
55+
var_dump($a, $b, $c, $d, $e, $f, $g, $h, $i, $j);
56+
3657
?>
3758
--EXPECT--
3859
bool(true)
@@ -47,3 +68,20 @@ bool(true)
4768
int(43)
4869
bool(false)
4970
int(43)
71+
bool(true)
72+
int(1)
73+
int(2)
74+
int(3)
75+
int(4)
76+
bool(false)
77+
bool(true)
78+
int(1)
79+
int(2)
80+
int(3)
81+
int(4)
82+
int(5)
83+
int(6)
84+
int(7)
85+
int(8)
86+
int(9)
87+
int(10)

Zend/tests/pattern_matching/is/binding_destruct.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ $foo = new Foo();
1313
$bar = 'bar';
1414

1515
try {
16-
42 is $foo or $bar;
16+
42 is $foo & $bar;
1717
} catch (Exception $e) {
1818
echo $e->getMessage(), "\n";
1919
}
2020

21-
// FIXME: This will change once bindings are delayed
2221
var_dump($foo);
2322
var_dump($bar);
2423

Zend/zend_pattern_matching.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,14 @@ static pm_result match_binding(zval *zv, zend_ast *pattern)
175175
if (!bindings) {
176176
bindings = &context->bindings_spare;
177177
context->bindings = bindings;
178+
context->last_bindings = bindings;
178179
} else if (bindings->num_used == ZEND_PM_BINDINGS_SLOTS) {
179180
zend_pm_bindings *new_bindings = emalloc(sizeof(zend_pm_bindings));
180-
new_bindings->next = bindings;
181+
new_bindings->num_used = 0;
182+
new_bindings->next = NULL;
183+
context->last_bindings->next = new_bindings;
184+
context->last_bindings = new_bindings;
181185
bindings = new_bindings;
182-
context->bindings = bindings;
183186
}
184187

185188
zend_pm_binding *binding = &bindings->list[bindings->num_used++];
@@ -317,7 +320,6 @@ static void pm_context_free(bool free_values)
317320
if (bindings != &context->bindings_spare) {
318321
efree(bindings);
319322
}
320-
bindings = bindings->next;
321323
bindings = next;
322324
}
323325

Zend/zend_pattern_matching.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct _zend_pm_bindings {
3636
typedef struct _zend_pm_context zend_pm_context;
3737
typedef struct _zend_pm_context {
3838
zend_pm_bindings *bindings;
39+
zend_pm_bindings *last_bindings;
3940
zend_pm_bindings bindings_spare;
4041
zend_pm_context *prev;
4142
} zend_pm_context;

0 commit comments

Comments
 (0)