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.c170
1 files changed, 68 insertions, 102 deletions
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c
index ce6284439c..58c034163e 100644
--- a/Zend/zend_objects.c
+++ b/Zend/zend_objects.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
- | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
+ | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -28,14 +28,27 @@
ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce TSRMLS_DC)
{
+ GC_REFCOUNT(object) = 1;
+ GC_TYPE_INFO(object) = IS_OBJECT;
object->ce = ce;
object->properties = NULL;
- object->properties_table = NULL;
object->guards = NULL;
+ zend_objects_store_put(object TSRMLS_CC);
+ if (EXPECTED(ce->default_properties_count != 0)) {
+ zval *p = object->properties_table;
+ zval *end = p + ce->default_properties_count;
+
+ do {
+ ZVAL_UNDEF(p);
+ p++;
+ } while (p != end);
+ }
}
ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC)
{
+ int i;
+
if (object->guards) {
zend_hash_destroy(object->guards);
FREE_HASHTABLE(object->guards);
@@ -43,29 +56,19 @@ ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC)
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);
+ }
+ for (i = 0; i < object->ce->default_properties_count; i++) {
+ zval_ptr_dtor(&object->properties_table[i]);
}
}
-ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC)
+ZEND_API void zend_objects_destroy_object(zend_object *object TSRMLS_DC)
{
zend_function *destructor = object ? object->ce->destructor : NULL;
if (destructor) {
- zval *old_exception;
- zval *obj;
- zend_object_store_bucket *obj_bucket;
+ zend_object *old_exception;
+ zval obj;
if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
@@ -74,11 +77,11 @@ 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,
+ zend_error(EG(current_execute_data) ? 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");
+ ce->name->val,
+ EG(scope) ? EG(scope)->name->val : "",
+ EG(current_execute_data) ? "" : " during shutdown ignored");
return;
}
} else {
@@ -87,25 +90,18 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
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,
+ zend_error(EG(current_execute_data) ? 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");
+ ce->name->val,
+ EG(scope) ? EG(scope)->name->val : "",
+ EG(current_execute_data) ? "" : " during shutdown ignored");
return;
}
}
}
- MAKE_STD_ZVAL(obj);
- Z_TYPE_P(obj) = IS_OBJECT;
- Z_OBJ_HANDLE_P(obj) = handle;
- obj_bucket = &EG(objects_store).object_buckets[handle];
- if (!obj_bucket->bucket.obj.handlers) {
- obj_bucket->bucket.obj.handlers = &std_object_handlers;
- }
- Z_OBJ_HT_P(obj) = obj_bucket->bucket.obj.handlers;
- zval_copy_ctor(obj);
+ ZVAL_OBJ(&obj, object);
+ Z_ADDREF(obj);
/* Make sure that destructors are protected from previously thrown exceptions.
* For example, if an exception was thrown in a function and when the function's
@@ -113,7 +109,7 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
*/
old_exception = NULL;
if (EG(exception)) {
- if (Z_OBJ_HANDLE_P(EG(exception)) == handle) {
+ if (EG(exception) == object) {
zend_error(E_ERROR, "Attempt to destruct pending exception");
} else {
old_exception = EG(exception);
@@ -132,104 +128,74 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
}
}
-ZEND_API void zend_objects_free_object_storage(zend_object *object TSRMLS_DC)
+ZEND_API zend_object *zend_objects_new(zend_class_entry *ce TSRMLS_DC)
{
- zend_object_std_dtor(object TSRMLS_CC);
- efree(object);
-}
+ zend_object *object = emalloc(sizeof(zend_object) + sizeof(zval) * (ce->default_properties_count - 1));
-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;
- return retval;
-}
-
-ZEND_API zend_object *zend_objects_get_address(const zval *zobject TSRMLS_DC)
-{
- return (zend_object *)zend_object_store_get_object(zobject TSRMLS_CC);
+ zend_object_std_init(object, ce TSRMLS_CC);
+ object->handlers = &std_object_handlers;
+ return object;
}
-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_API void zend_objects_clone_members(zend_object *new_object, zend_object *old_object TSRMLS_DC)
{
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);
- }
+ if (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]);
- }
- }
+ zval_ptr_dtor(&new_object->properties_table[i]);
+ ZVAL_COPY_VALUE(&new_object->properties_table[i], &old_object->properties_table[i]);
+ zval_add_ref(&new_object->properties_table[i]);
}
}
if (old_object->properties) {
+ zval *prop, new_prop;
+ zend_ulong num_key;
+ zend_string *key;
+
if (!new_object->properties) {
ALLOC_HASHTABLE(new_object->properties);
- zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_init(new_object->properties, zend_hash_num_elements(old_object->properties), 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;
- }
- }
+
+ ZEND_HASH_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) {
+ if (Z_TYPE_P(prop) == IS_INDIRECT) {
+ ZVAL_INDIRECT(&new_prop, new_object->properties_table + (Z_INDIRECT_P(prop) - old_object->properties_table));
+ } else {
+ ZVAL_COPY_VALUE(&new_prop, prop);
+ zval_add_ref(&new_prop);
}
- }
+ if (key) {
+ zend_hash_update(new_object->properties, key, &new_prop);
+ } else {
+ zend_hash_index_update(new_object->properties, num_key, &new_prop);
+ }
+ } ZEND_HASH_FOREACH_END();
}
if (old_object->ce->clone) {
- zval *new_obj;
-
- MAKE_STD_ZVAL(new_obj);
- new_obj->type = IS_OBJECT;
- new_obj->value.obj = new_obj_val;
- zval_copy_ctor(new_obj);
+ zval new_obj;
+ ZVAL_OBJ(&new_obj, new_object);
+ zval_copy_ctor(&new_obj);
zend_call_method_with_0_params(&new_obj, old_object->ce, &old_object->ce->clone, ZEND_CLONE_FUNC_NAME, NULL);
-
zval_ptr_dtor(&new_obj);
}
}
-ZEND_API zend_object_value zend_objects_clone_obj(zval *zobject TSRMLS_DC)
+ZEND_API zend_object *zend_objects_clone_obj(zval *zobject TSRMLS_DC)
{
- zend_object_value new_obj_val;
zend_object *old_object;
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
* 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);
+ old_object = Z_OBJ_P(zobject);
+ new_object = zend_objects_new(old_object->ce TSRMLS_CC);
- zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
+ zend_objects_clone_members(new_object, old_object TSRMLS_CC);
- return new_obj_val;
+ return new_object;
}
/*