-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add ZEND_API for weakmap functionality via zend_weakrefs_hash_add/del #7600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. Do you think it would make sense to add a basic test to zend_test (which just calls add/del internally)?
ZEND_API zend_result zend_weakrefs_hash_del(HashTable *ht, zend_object *key) { | ||
zend_result result = zend_hash_index_del(ht, (zend_ulong) key); | ||
if (result == SUCCESS) { | ||
zend_weakref_unregister(key, ZEND_WEAKREF_ENCODE(ht, ZEND_WEAKREF_TAG_MAP)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_weakref_unregister already does the hash del, so it might make sense to replace your hash_index_del here with hash_index_exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. And yeah will provide a small test for it.
@nikic has test now - looks good for merge then, right? |
var_dump(zend_weakmap_remove($id2)); | ||
var_dump(zend_weakmap_remove($id2)); | ||
|
||
var_dump(zend_weakmap_dump()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to unset($id1)
and dump again here, to shows the actual weak part :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
facepalm :-D
@@ -0,0 +1,36 @@ | |||
--TEST-- | |||
Test internal weakmap API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a SKIPIF (8.0) or EXTENSIONS (8.1) section.
Exposes a simple API for weakmap functionality (weakref functionality can be trivially emulated by adding a dummy element instead) as ZEND_API to be trivially usable in extensions.
The implementation does not actually change (it's the first element of the struct), but I'm now explicitly passing &zend_weakmap->ht instead of zend_weakmap directly, to make it clearer that the weakmap implementation is generic with respect to the zend_weakmap structure and only cares about the HashTable pointer.