summaryrefslogtreecommitdiff
path: root/Zend/zend_objects.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_objects.c')
-rw-r--r--Zend/zend_objects.c92
1 files changed, 71 insertions, 21 deletions
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c
index fbee312d38..f7470fa578 100644
--- a/Zend/zend_objects.c
+++ b/Zend/zend_objects.c
@@ -28,10 +28,9 @@
ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce TSRMLS_DC)
{
- ALLOC_HASHTABLE(object->properties);
- zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
-
- object->ce = ce;
+ object->ce = ce;
+ object->properties = NULL;
+ object->properties_table = NULL;
object->guards = NULL;
}
@@ -39,11 +38,23 @@ ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC)
{
if (object->guards) {
zend_hash_destroy(object->guards);
- FREE_HASHTABLE(object->guards);
+ FREE_HASHTABLE(object->guards);
}
if (object->properties) {
zend_hash_destroy(object->properties);
FREE_HASHTABLE(object->properties);
+ if (object->properties_table) {
+ efree(object->properties_table);
+ }
+ } else if (object->properties_table) {
+ int i;
+
+ for (i = 0; i < object->ce->default_properties_count; i++) {
+ if (object->properties_table[i]) {
+ zval_ptr_dtor(&object->properties_table[i]);
+ }
+ }
+ efree(object->properties_table);
}
}
@@ -63,23 +74,23 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
if (object->ce != EG(scope)) {
zend_class_entry *ce = object->ce;
- zend_error(EG(in_execution) ? E_ERROR : E_WARNING,
- "Call to private %s::__destruct() from context '%s'%s",
- ce->name,
- EG(scope) ? EG(scope)->name : "",
+ zend_error(EG(in_execution) ? E_ERROR : E_WARNING,
+ "Call to private %s::__destruct() from context '%s'%s",
+ ce->name,
+ EG(scope) ? EG(scope)->name : "",
EG(in_execution) ? "" : " during shutdown ignored");
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))) {
+ if (!zend_check_protected(zend_get_function_root_class(destructor), EG(scope))) {
zend_class_entry *ce = object->ce;
- zend_error(EG(in_execution) ? E_ERROR : E_WARNING,
- "Call to protected %s::__destruct() from context '%s'%s",
- ce->name,
- EG(scope) ? EG(scope)->name : "",
+ zend_error(EG(in_execution) ? E_ERROR : E_WARNING,
+ "Call to protected %s::__destruct() from context '%s'%s",
+ ce->name,
+ EG(scope) ? EG(scope)->name : "",
EG(in_execution) ? "" : " during shutdown ignored");
return;
}
@@ -128,14 +139,16 @@ ZEND_API void zend_objects_free_object_storage(zend_object *object TSRMLS_DC)
}
ZEND_API zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type TSRMLS_DC)
-{
+{
zend_object_value retval;
*object = emalloc(sizeof(zend_object));
(*object)->ce = class_type;
+ (*object)->properties = NULL;
+ (*object)->properties_table = NULL;
+ (*object)->guards = NULL;
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)->guards = NULL;
return retval;
}
@@ -146,7 +159,47 @@ ZEND_API zend_object *zend_objects_get_address(const zval *zobject TSRMLS_DC)
ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC)
{
- zend_hash_copy(new_object->properties, old_object->properties, zval_copy_property_ctor(old_object->ce), (void *) NULL /* Not used anymore */, sizeof(zval *));
+ int i;
+
+ if (old_object->properties_table) {
+ if (!new_object->properties_table) {
+ new_object->properties_table = emalloc(sizeof(zval*) * old_object->ce->default_properties_count);
+ memset(new_object->properties_table, 0, sizeof(zval*) * old_object->ce->default_properties_count);
+ }
+ for (i = 0; i < old_object->ce->default_properties_count; i++) {
+ if (!new_object->properties) {
+ if (new_object->properties_table[i]) {
+ zval_ptr_dtor(&new_object->properties_table[i]);
+ }
+ }
+ if (!old_object->properties) {
+ new_object->properties_table[i] = old_object->properties_table[i];
+ if (new_object->properties_table[i]) {
+ Z_ADDREF_P(new_object->properties_table[i]);
+ }
+ }
+ }
+ }
+ if (old_object->properties) {
+ if (!new_object->properties) {
+ ALLOC_HASHTABLE(new_object->properties);
+ zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ }
+ zend_hash_copy(new_object->properties, old_object->properties, (copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, sizeof(zval *));
+ if (old_object->properties_table) {
+ HashPosition pos;
+ zend_property_info *prop_info;
+ for (zend_hash_internal_pointer_reset_ex(&old_object->ce->properties_info, &pos);
+ zend_hash_get_current_data_ex(&old_object->ce->properties_info, (void**)&prop_info, &pos) == SUCCESS;
+ zend_hash_move_forward_ex(&old_object->ce->properties_info, &pos)) {
+ if ((prop_info->flags & ZEND_ACC_STATIC) == 0) {
+ if (zend_hash_quick_find(new_object->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&new_object->properties_table[prop_info->offset]) == FAILURE) {
+ new_object->properties_table[prop_info->offset] = NULL;
+ }
+ }
+ }
+ }
+ }
if (old_object->ce->clone) {
zval *new_obj;
@@ -169,14 +222,11 @@ ZEND_API zend_object_value zend_objects_clone_obj(zval *zobject TSRMLS_DC)
zend_object *new_object;
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
- /* assume that create isn't overwritten, so when clone depends on the
+ /* assume that create isn't overwritten, so when clone depends on the
* overwritten one then it must itself be overwritten */
old_object = zend_objects_get_address(zobject TSRMLS_CC);
new_obj_val = zend_objects_new(&new_object, old_object->ce TSRMLS_CC);
- ALLOC_HASHTABLE(new_object->properties);
- zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
-
zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
return new_obj_val;