cvs: ZendEngine2 / zend_objects.c

From: Date: Wed, 02 Jul 2003 23:53:53 +0000
Subject: cvs: ZendEngine2 / zend_objects.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1441@lists.php.net to get a copy of this message
helly Wed Jul 2 19:53:53 2003 EDT Modified files: /ZendEngine2 zend_objects.c Log: Reorganize this a bit to ensure the object memory is destructed before showing the error. Index: ZendEngine2/zend_objects.c diff -u ZendEngine2/zend_objects.c:1.32 ZendEngine2/zend_objects.c:1.33 --- ZendEngine2/zend_objects.c:1.32 Wed Jul 2 03:24:10 2003 +++ ZendEngine2/zend_objects.c Wed Jul 2 19:53:53 2003 @@ -17,14 +17,21 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects.c,v 1.32 2003/07/02 07:24:10 helly Exp $ */ +/* $Id: zend_objects.c,v 1.33 2003/07/02 23:53:53 helly Exp $ */ #include "zend.h" #include "zend_globals.h" #include "zend_variables.h" #include "zend_API.h" -static inline void zend_objects_call_destructor(zend_object *object, zend_object_handle handle TSRMLS_DC) +static inline void zend_nuke_object(zend_object *object TSRMLS_DC) +{ + zend_hash_destroy(object->properties); + FREE_HASHTABLE(object->properties); + efree(object); +} + +ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC) { zend_function *destructor = object->ce->destructor; @@ -34,34 +41,40 @@ zval *retval_ptr; HashTable symbol_table; + if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) { + if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { + /* Ensure that if we're calling a private function, we're allowed to do so. + */ + if (object->ce != EG(scope)) { + zend_nuke_object(object TSRMLS_CC); /* unfortunately we *must* destroy it now anyway */ + zend_error(E_ERROR, "Call to private destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); + return; + } + } else { + /* Ensure that if we're calling a protected function, we're allowed to do so. + */ + if (!zend_check_protected(destructor->common.scope, EG(scope))) { + zend_nuke_object(object TSRMLS_CC); /* unfortunately we *must* destroy it now anyway */ + zend_error(E_ERROR, "Call to protected destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); + return; + } + } + } + MAKE_STD_ZVAL(obj); obj->type = IS_OBJECT; obj->value.obj.handle = handle; obj->value.obj.handlers = &std_object_handlers; zval_copy_ctor(obj); + ZEND_INIT_SYMTABLE(&symbol_table); + /* FIXME: Optimize this so that we use the old_object->ce->destructor function pointer instead of the name */ MAKE_STD_ZVAL(destructor_func_name); destructor_func_name->type = IS_STRING; destructor_func_name->value.str.val = estrndup("__destruct", sizeof("__destruct")-1); destructor_func_name->value.str.len = sizeof("__destruct")-1; - if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { - /* Ensure that if we're calling a private function, we're allowed to do so. - */ - if (object->ce != EG(scope)) { - zend_error(E_ERROR, "Call to private destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); - } - } else if ((destructor->common.fn_flags & ZEND_ACC_PROTECTED)) { - /* Ensure that if we're calling a protected function, we're allowed to do so. - */ - if (!zend_check_protected(destructor->common.scope, EG(scope))) { - zend_error(E_ERROR, "Call to protected destructor from context '%s'", EG(scope) ? EG(scope)->name : ""); - } - } - - ZEND_INIT_SYMTABLE(&symbol_table); - call_user_function_ex(NULL, &obj, destructor_func_name, &retval_ptr, 0, NULL, 0, &symbol_table TSRMLS_CC); zend_hash_destroy(&symbol_table); @@ -71,16 +84,7 @@ zval_ptr_dtor(&retval_ptr); } } -} - - -ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC) -{ - zend_objects_call_destructor(object, handle TSRMLS_CC); - /* Nuke the object */ - zend_hash_destroy(object->properties); - FREE_HASHTABLE(object->properties); - efree(object); + zend_nuke_object(object TSRMLS_CC); } ZEND_API zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type TSRMLS_DC)

« previous php.zend-engine.cvs (#1441) next »