mirror of
https://github.com/php/php-src.git
synced 2025-01-27 14:13:41 +08:00
Change destructor implementation (details will follow on internals@)
This commit is contained in:
parent
24eb1f6eb2
commit
f5f7d569a0
@ -208,7 +208,7 @@ void shutdown_executor(TSRMLS_D)
|
||||
}
|
||||
*/
|
||||
zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC);
|
||||
|
||||
zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
|
||||
zend_hash_graceful_reverse_destroy(&EG(symbol_table));
|
||||
} zend_end_try();
|
||||
|
||||
@ -271,6 +271,7 @@ void shutdown_executor(TSRMLS_D)
|
||||
FREE_HASHTABLE(*EG(symtable_cache_ptr));
|
||||
EG(symtable_cache_ptr)--;
|
||||
}
|
||||
zend_objects_store_free_object_storage(&EG(objects_store) TSRMLS_CC);
|
||||
} zend_end_try();
|
||||
|
||||
zend_try {
|
||||
|
@ -54,7 +54,7 @@ ZEND_API void zend_register_iterator_wrapper(TSRMLS_D)
|
||||
zend_iterator_class_entry.name = "__iterator_wrapper";
|
||||
}
|
||||
|
||||
static void iter_wrapper_dtor(void *object, zend_object_handle handle TSRMLS_DC)
|
||||
static void iter_wrapper_free_storage(void *object TSRMLS_DC)
|
||||
{
|
||||
zend_object_iterator *iter = (zend_object_iterator*)object;
|
||||
iter->funcs->dtor(iter TSRMLS_CC);
|
||||
@ -66,7 +66,7 @@ ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC)
|
||||
|
||||
MAKE_STD_ZVAL(wrapped);
|
||||
Z_TYPE_P(wrapped) = IS_OBJECT;
|
||||
wrapped->value.obj.handle = zend_objects_store_put(iter, iter_wrapper_dtor, NULL TSRMLS_CC);
|
||||
wrapped->value.obj.handle = zend_objects_store_put(iter, NULL, iter_wrapper_free_storage, NULL TSRMLS_CC);
|
||||
wrapped->value.obj.handlers = &iterator_object_handlers;
|
||||
|
||||
return wrapped;
|
||||
|
@ -78,6 +78,10 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
|
||||
|
||||
zend_call_method_with_0_params(&obj, object->ce, NULL, "__destruct", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API void zend_objects_free_object_storage(zend_object *object TSRMLS_DC)
|
||||
{
|
||||
zend_nuke_object(object TSRMLS_CC);
|
||||
}
|
||||
|
||||
@ -87,7 +91,7 @@ ZEND_API zend_object_value zend_objects_new(zend_object **object, zend_class_ent
|
||||
|
||||
*object = emalloc(sizeof(zend_object));
|
||||
(*object)->ce = class_type;
|
||||
retval.handle = zend_objects_store_put(*object, (zend_objects_store_dtor_t) zend_objects_destroy_object, NULL TSRMLS_CC);
|
||||
retval.handle = zend_objects_store_put(*object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
|
||||
retval.handlers = &std_object_handlers;
|
||||
(*object)->in_get = 0;
|
||||
(*object)->in_set = 0;
|
||||
|
@ -54,14 +54,22 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void zend_objects_store_nuke_objects()
|
||||
ZEND_API void zend_objects_store_free_object_storage(zend_objects_store *objects TSRMLS_DC)
|
||||
{
|
||||
zend_uint i = 1;
|
||||
|
||||
for (i = 1; i < objects->top ; i++) {
|
||||
struct _store_object *obj = &objects->object_buckets[i].bucket.obj;
|
||||
if (obj->free_storage) {
|
||||
obj->free_storage(obj->object, i TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Store objects API */
|
||||
|
||||
ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_store_dtor_t dtor, zend_objects_store_clone_t clone TSRMLS_DC)
|
||||
ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_store_dtor_t dtor, zend_objects_free_object_storage_t free_storage, zend_objects_store_clone_t clone TSRMLS_DC)
|
||||
{
|
||||
zend_object_handle handle;
|
||||
struct _store_object *obj;
|
||||
@ -82,6 +90,7 @@ ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_st
|
||||
obj->refcount = 1;
|
||||
obj->object = object;
|
||||
obj->dtor = dtor;
|
||||
obj->free_storage = free_storage;
|
||||
obj->clone = clone;
|
||||
|
||||
#if ZEND_DEBUG_OBJECTS
|
||||
@ -116,6 +125,7 @@ ZEND_API void zend_objects_store_del_ref(zval *zobject TSRMLS_DC)
|
||||
obj->dtor(obj->object, handle TSRMLS_CC);
|
||||
}
|
||||
if (obj->refcount == 0) {
|
||||
obj->free_storage(obj->object TSRMLS_CC);
|
||||
ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST();
|
||||
}
|
||||
}
|
||||
@ -145,7 +155,7 @@ ZEND_API zend_object_value zend_objects_store_clone_obj(zval *zobject TSRMLS_DC)
|
||||
|
||||
obj->clone(obj->object, &new_object TSRMLS_CC);
|
||||
|
||||
retval.handle = zend_objects_store_put(new_object, obj->dtor, obj->clone TSRMLS_CC);
|
||||
retval.handle = zend_objects_store_put(new_object, obj->dtor, obj->free_storage, obj->clone TSRMLS_CC);
|
||||
retval.handlers = Z_OBJ_HT_P(zobject);
|
||||
|
||||
return retval;
|
||||
@ -167,7 +177,7 @@ typedef struct _zend_proxy_object {
|
||||
|
||||
static zend_object_handlers zend_object_proxy_handlers;
|
||||
|
||||
ZEND_API void zend_objects_proxy_dtor(zend_proxy_object *object, zend_object_handle handle TSRMLS_DC)
|
||||
ZEND_API void zend_objects_proxy_free_storage(zend_proxy_object *object TSRMLS_DC)
|
||||
{
|
||||
zval_ptr_dtor(&object->object);
|
||||
zval_ptr_dtor(&object->property);
|
||||
@ -195,7 +205,7 @@ ZEND_API zval **zend_object_create_proxy(zval *object, zval *member TSRMLS_DC)
|
||||
|
||||
MAKE_STD_ZVAL(retval);
|
||||
retval->type = IS_OBJECT;
|
||||
Z_OBJ_HANDLE_P(retval) = zend_objects_store_put(pobj, (zend_objects_store_dtor_t)zend_objects_proxy_dtor, (zend_objects_store_clone_t)zend_objects_proxy_clone TSRMLS_CC);
|
||||
Z_OBJ_HANDLE_P(retval) = zend_objects_store_put(pobj, NULL, (zend_objects_store_dtor_t) zend_objects_proxy_free_storage, (zend_objects_store_clone_t) zend_objects_proxy_clone TSRMLS_CC);
|
||||
Z_OBJ_HT_P(retval) = &zend_object_proxy_handlers;
|
||||
pretval = emalloc(sizeof(zval *));
|
||||
*pretval = retval;
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "zend.h"
|
||||
|
||||
typedef void (*zend_objects_store_dtor_t)(void *object, zend_object_handle handle TSRMLS_DC);
|
||||
typedef void (*zend_objects_free_object_storage_t)(zend_object *object TSRMLS_DC);
|
||||
|
||||
typedef void (*zend_objects_store_clone_t)(void *object, void **object_clone TSRMLS_DC);
|
||||
|
||||
typedef struct _zend_object_store_bucket {
|
||||
@ -33,6 +35,7 @@ typedef struct _zend_object_store_bucket {
|
||||
struct _store_object {
|
||||
void *object;
|
||||
zend_objects_store_dtor_t dtor;
|
||||
zend_objects_free_object_storage_t free_storage;
|
||||
zend_objects_store_clone_t clone;
|
||||
zend_uint refcount;
|
||||
} obj;
|
||||
@ -55,14 +58,15 @@ ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects TS
|
||||
ZEND_API void zend_objects_store_destroy(zend_objects_store *objects);
|
||||
|
||||
/* Store API functions */
|
||||
ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_store_dtor_t dtor, zend_objects_store_clone_t clone TSRMLS_DC);
|
||||
ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_store_dtor_t dtor, zend_objects_free_object_storage_t storage, zend_objects_store_clone_t clone TSRMLS_DC);
|
||||
|
||||
ZEND_API void zend_objects_store_add_ref(zval *object TSRMLS_DC);
|
||||
ZEND_API void zend_objects_store_del_ref(zval *object TSRMLS_DC);
|
||||
ZEND_API void zend_objects_store_delete_obj(zval *object TSRMLS_DC);
|
||||
ZEND_API zend_object_value zend_objects_store_clone_obj(zval *object TSRMLS_DC);
|
||||
ZEND_API void *zend_object_store_get_object(zval *object TSRMLS_DC);
|
||||
|
||||
ZEND_API void zend_objects_store_free_object_storage(zend_objects_store *objects TSRMLS_DC);
|
||||
|
||||
#define ZEND_OBJECTS_STORE_HANDLERS zend_objects_store_add_ref, zend_objects_store_del_ref, zend_objects_store_clone_obj
|
||||
|
||||
ZEND_API zval **zend_object_create_proxy(zval *object, zval *member TSRMLS_DC);
|
||||
|
@ -223,7 +223,7 @@ static zend_object_value reflection_objects_new(zend_class_entry *class_type TSR
|
||||
|
||||
ALLOC_HASHTABLE(intern->zo.properties);
|
||||
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||
retval.handle = zend_objects_store_put(intern, reflection_objects_dtor, reflection_objects_clone TSRMLS_CC);
|
||||
retval.handle = zend_objects_store_put(intern, reflection_objects_dtor, NULL, reflection_objects_clone TSRMLS_CC);
|
||||
retval.handlers = &reflection_object_handlers;
|
||||
return retval;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ static zend_object_value reflection_objects_new(zend_class_entry *class_type TSR
|
||||
|
||||
ALLOC_HASHTABLE(intern->zo.properties);
|
||||
zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||
retval.handle = zend_objects_store_put(intern, reflection_objects_dtor, reflection_objects_clone TSRMLS_CC);
|
||||
retval.handle = zend_objects_store_put(intern, reflection_objects_dtor, NULL, reflection_objects_clone TSRMLS_CC);
|
||||
retval.handlers = &reflection_object_handlers;
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user