Skip to content
This repository was archived by the owner on Jul 7, 2018. It is now read-only.

Commit c5e2b53

Browse files
committed
Prepare intenal impl. for abstract reference
1 parent 35784ca commit c5e2b53

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

php_weak_reference.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ php_weak_reference_t *php_weak_reference_init(zval *this_ptr, zval *referent_zv,
385385

386386
referent = php_weak_referent_get_or_create(referent_zv);
387387

388-
php_weak_reference_attach(reference, referent);
388+
reference->register_reference(reference, referent);
389389

390390
if (NULL != notifier_zv) {
391391
ZVAL_COPY(&reference->notifier, notifier_zv);
@@ -494,6 +494,9 @@ static zend_object *php_weak_reference_ctor(zend_class_entry *ce) /* {{{ */
494494

495495
reference->std.handlers = &php_weak_reference_object_handlers;
496496

497+
reference->register_reference = php_weak_reference_attach;
498+
reference->unregister_reference = php_weak_reference_maybe_unregister;
499+
497500
return &reference->std;
498501
} /* }}} */
499502

@@ -514,7 +517,7 @@ static zend_object *php_weak_reference_clone_obj(zval *object) /* {{{ */
514517
new_reference->notifier_type = old_reference->notifier_type;
515518

516519
if (old_reference->referent) {
517-
php_weak_reference_attach(new_reference, old_reference->referent);
520+
old_reference->register_reference(new_reference, old_reference->referent);
518521
}
519522

520523
zend_objects_clone_members(new_object, old_object);

php_weak_reference.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extern zend_class_entry *php_weak_reference_class_entry;
2727
typedef struct _php_weak_referent_t php_weak_referent_t;
2828
typedef struct _php_weak_reference_t php_weak_reference_t;
2929

30+
typedef void (*php_weak_register)(php_weak_reference_t *reference, php_weak_referent_t *referent);
31+
typedef void (*php_weak_unregister)(php_weak_reference_t *reference);
3032

3133
extern php_weak_reference_t *php_weak_reference_fetch_object(zend_object *obj);
3234
extern php_weak_referent_t *php_weak_referent_find_ptr(zend_ulong h);
@@ -48,8 +50,8 @@ struct _php_weak_referent_t {
4850
zend_object_handlers custom_handlers;
4951
const zend_object_handlers *original_handlers;
5052

51-
HashTable weak_references;
5253
HashTable soft_references;
54+
HashTable weak_references;
5355
};
5456

5557
struct _php_weak_reference_t {
@@ -58,6 +60,9 @@ struct _php_weak_reference_t {
5860
zval notifier;
5961
int notifier_type;
6062

63+
php_weak_register register_reference;
64+
php_weak_unregister unregister_reference;
65+
6166
zval this_ptr;
6267
zend_object std;
6368
};

0 commit comments

Comments
 (0)