Skip to content

Commit 2c150d0

Browse files
arnaud-lbTimWolla
andcommitted
Add tests
Co-authored-by: Tim Düsterhus <[email protected]>
1 parent ad64fc7 commit 2c150d0

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

Zend/tests/gh19543-001.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-19543 001: GC treats ZEND_WEAKREF_TAG_MAP references as WeakMap references
3+
--FILE--
4+
<?php
5+
6+
$e = new Exception();
7+
$a = new stdClass();
8+
zend_weakmap_attach($e, $a);
9+
unset($a);
10+
gc_collect_cycles();
11+
12+
?>
13+
==DONE==
14+
--EXPECT--
15+
==DONE==

Zend/tests/gh19543-002.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-19543 001: GC treats ZEND_WEAKREF_TAG_MAP references as WeakMap references
3+
--FILE--
4+
<?php
5+
6+
$e = new Exception();
7+
$a = new stdClass();
8+
zend_weakmap_attach($e, $a);
9+
unset($a);
10+
$e2 = $e;
11+
unset($e2); // add to roots
12+
gc_collect_cycles();
13+
14+
?>
15+
==DONE==
16+
--EXPECT--
17+
==DONE==

ext/zend_test/php_test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ZEND_BEGIN_MODULE_GLOBALS(zend_test)
5050
int observer_fiber_switch;
5151
int observer_fiber_destroy;
5252
int observer_execute_internal;
53-
HashTable global_weakmap;
53+
HashTable *global_weakmap;
5454
int replace_zend_execute_ex;
5555
int register_passes;
5656
bool print_stderr_mshutdown;

ext/zend_test/test.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static ZEND_FUNCTION(zend_weakmap_attach)
381381
Z_PARAM_ZVAL(value)
382382
ZEND_PARSE_PARAMETERS_END();
383383

384-
if (zend_weakrefs_hash_add(&ZT_G(global_weakmap), obj, value)) {
384+
if (zend_weakrefs_hash_add(ZT_G(global_weakmap), obj, value)) {
385385
Z_TRY_ADDREF_P(value);
386386
RETURN_TRUE;
387387
}
@@ -396,13 +396,13 @@ static ZEND_FUNCTION(zend_weakmap_remove)
396396
Z_PARAM_OBJ(obj)
397397
ZEND_PARSE_PARAMETERS_END();
398398

399-
RETURN_BOOL(zend_weakrefs_hash_del(&ZT_G(global_weakmap), obj) == SUCCESS);
399+
RETURN_BOOL(zend_weakrefs_hash_del(ZT_G(global_weakmap), obj) == SUCCESS);
400400
}
401401

402402
static ZEND_FUNCTION(zend_weakmap_dump)
403403
{
404404
ZEND_PARSE_PARAMETERS_NONE();
405-
RETURN_ARR(zend_array_dup(&ZT_G(global_weakmap)));
405+
RETURN_ARR(zend_array_dup(ZT_G(global_weakmap)));
406406
}
407407

408408
static ZEND_FUNCTION(zend_get_current_func_name)
@@ -1424,15 +1424,17 @@ PHP_MSHUTDOWN_FUNCTION(zend_test)
14241424

14251425
PHP_RINIT_FUNCTION(zend_test)
14261426
{
1427-
zend_hash_init(&ZT_G(global_weakmap), 8, NULL, ZVAL_PTR_DTOR, 0);
1427+
ZT_G(global_weakmap) = emalloc(sizeof(HashTable));
1428+
zend_hash_init(ZT_G(global_weakmap), 8, NULL, ZVAL_PTR_DTOR, 0);
14281429
ZT_G(observer_nesting_depth) = 0;
14291430
zend_test_mm_custom_handlers_rinit();
14301431
return SUCCESS;
14311432
}
14321433

14331434
PHP_RSHUTDOWN_FUNCTION(zend_test)
14341435
{
1435-
zend_weakrefs_hash_destroy(&ZT_G(global_weakmap));
1436+
zend_weakrefs_hash_destroy(ZT_G(global_weakmap));
1437+
efree(ZT_G(global_weakmap));
14361438

14371439
if (ZT_G(zend_test_heap)) {
14381440
free(ZT_G(zend_test_heap));
@@ -1637,7 +1639,7 @@ static PHP_FUNCTION(zend_test_compile_to_ast)
16371639

16381640
zend_arena *ast_arena;
16391641
zend_ast *ast = zend_compile_string_to_ast(str, &ast_arena, ZSTR_EMPTY_ALLOC());
1640-
1642+
16411643
zend_string *result = zend_ast_export("", ast, "");
16421644

16431645
zend_ast_destroy(ast);

0 commit comments

Comments
 (0)