Core dumped in Zend/zend_weakrefs.c
Description
The following code:
<?php
class HasDtor {
public function __destruct() {
global $w, $all;
for ($i = 0; $i < 10; $fusion++) {
$v = new stdClass();
$all[] = $v;
$w[$v] = $i;
}
}
}
$w = new WeakMap();
$w[$o] = new HasDtor();
Resulted in this output:
/php-src/Zend/zend_weakrefs.c:198: void zend_weakrefs_notify(zend_object *): Assertion `tagged_ptr && "Tracking of the IS_OBJ_WEAKLY_REFERENCE flag should be precise"' failed.
Aborted (core dumped)
PHP Version
PHP 8.4.0-dev
Operating System
ubuntu 22.04
Arnaud has discovered this recently in a related issue. This has a seemingly simple fix.
diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c
index 3f2e517f3f..18213b732d 100644
--- a/Zend/zend_weakrefs.c
+++ b/Zend/zend_weakrefs.c
@@ -94,11 +94,10 @@ static void zend_weakref_unref(zend_object *object, void *tagged_ptr) {
}
static void zend_weakref_register(zend_object *object, void *payload) {
- GC_ADD_FLAGS(object, IS_OBJ_WEAKLY_REFERENCED);
-
zend_ulong obj_key = zend_object_to_weakref_key(object);
zval *zv = zend_hash_index_lookup(&EG(weakrefs), obj_key);
if (Z_TYPE_P(zv) == IS_NULL) {
+ GC_ADD_FLAGS(object, IS_OBJ_WEAKLY_REFERENCED);
ZVAL_PTR(zv, payload);
return;
}
@arnaud-lb Do you think this is worth fixing in isolation?
No, I don't think it's worth it, given this will be fixed separately
@arnaud-lb Can you add this as an issue that will be fixed to the corresponding PR?
Two years have passed and I still haven't seen the PR so I can study how they handle it separately. Sad.
@zhalker See https://github.com/arnaud-lb/php-src/pull/31.
@iluuu1994 @arnaud-lb Correct me if I'm wrong, but after the 3584a98bda0 fix we no longer need to do anything here and the issue can be closed, right?
Looks like it. Thanks.