summaryrefslogtreecommitdiff
path: root/Zend/zend_object_handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_object_handlers.c')
-rw-r--r--Zend/zend_object_handlers.c995
1 files changed, 490 insertions, 505 deletions
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 0af8e278b2..d05c6b302c 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -33,8 +33,11 @@
#define DEBUG_OBJECT_HANDLERS 0
-#define Z_OBJ_P(zval_p) \
- ((zend_object*)(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(zval_p)].bucket.obj.object))
+/* guard flags */
+#define IN_GET (1<<0)
+#define IN_SET (1<<1)
+#define IN_UNSET (1<<2)
+#define IN_ISSET (1<<3)
#define Z_OBJ_PROTECT_RECURSION(zval_p) \
do { \
@@ -68,6 +71,7 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
{
if (!zobj->properties) {
HashPosition pos;
+ zval tmp;
zend_property_info *prop_info;
zend_class_entry *ce = zobj->ce;
@@ -75,26 +79,28 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
zend_hash_init(zobj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
if (ce->default_properties_count) {
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- zend_hash_get_current_data_ex(&ce->properties_info, (void**)&prop_info, &pos) == SUCCESS;
+ (prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL;
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
if (/*prop_info->ce == ce &&*/
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
prop_info->offset >= 0 &&
- zobj->properties_table[prop_info->offset]) {
- zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]);
+ Z_TYPE(zobj->properties_table[prop_info->offset]) != IS_UNDEF) {
+ ZVAL_INDIRECT(&tmp, &zobj->properties_table[prop_info->offset]);
+ zend_hash_add(zobj->properties, prop_info->name, &tmp);
}
}
while (ce->parent && ce->parent->default_properties_count) {
ce = ce->parent;
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
- zend_hash_get_current_data_ex(&ce->properties_info, (void**)&prop_info, &pos) == SUCCESS;
+ (prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL;
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
if (prop_info->ce == ce &&
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
(prop_info->flags & ZEND_ACC_PRIVATE) != 0 &&
prop_info->offset >= 0 &&
- zobj->properties_table[prop_info->offset]) {
- zend_hash_quick_add(zobj->properties, prop_info->name, prop_info->name_length+1, prop_info->h, (void**)&zobj->properties_table[prop_info->offset], sizeof(zval*), (void**)&zobj->properties_table[prop_info->offset]);
+ Z_TYPE(zobj->properties_table[prop_info->offset]) != IS_UNDEF) {
+ ZVAL_INDIRECT(&tmp, &zobj->properties_table[prop_info->offset]);
+ zend_hash_add(zobj->properties, prop_info->name, &tmp);
}
}
}
@@ -114,7 +120,7 @@ ZEND_API HashTable *zend_std_get_properties(zval *object TSRMLS_DC) /* {{{ */
}
/* }}} */
-ZEND_API HashTable *zend_std_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) /* {{{ */
+ZEND_API HashTable *zend_std_get_gc(zval *object, zval **table, int *n TSRMLS_DC) /* {{{ */
{
if (Z_OBJ_HANDLER_P(object, get_properties) != zend_std_get_properties) {
*table = NULL;
@@ -143,9 +149,8 @@ ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp TSRMLS_DC
}
/* }}} */
-static zval *zend_std_call_getter(zval *object, zval *member TSRMLS_DC) /* {{{ */
+static void zend_std_call_getter(zval *object, zval *member, zval *retval TSRMLS_DC) /* {{{ */
{
- zval *retval = NULL;
zend_class_entry *ce = Z_OBJCE_P(object);
/* __get handler is called with one argument:
@@ -156,21 +161,20 @@ static zval *zend_std_call_getter(zval *object, zval *member TSRMLS_DC) /* {{{ *
SEPARATE_ARG_IF_REF(member);
- zend_call_method_with_1_params(&object, ce, &ce->__get, ZEND_GET_FUNC_NAME, &retval, member);
+ ZVAL_UNDEF(retval);
+ zend_call_method_with_1_params(object, ce, &ce->__get, ZEND_GET_FUNC_NAME, retval, member);
- zval_ptr_dtor(&member);
+ zval_ptr_dtor(member);
- if (retval) {
+ if (Z_REFCOUNTED_P(retval)) {
Z_DELREF_P(retval);
}
-
- return retval;
}
/* }}} */
static int zend_std_call_setter(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */
{
- zval *retval = NULL;
+ zval retval;
int result;
zend_class_entry *ce = Z_OBJCE_P(object);
@@ -183,13 +187,14 @@ static int zend_std_call_setter(zval *object, zval *member, zval *value TSRMLS_D
it should return whether the call was successfull or not
*/
- zend_call_method_with_2_params(&object, ce, &ce->__set, ZEND_SET_FUNC_NAME, &retval, member, value);
+ ZVAL_UNDEF(&retval);
+ zend_call_method_with_2_params(object, ce, &ce->__set, ZEND_SET_FUNC_NAME, &retval, member, value);
- zval_ptr_dtor(&member);
- zval_ptr_dtor(&value);
+ zval_ptr_dtor(member);
+ zval_ptr_dtor(value);
- if (retval) {
- result = i_zend_is_true(retval TSRMLS_CC) ? SUCCESS : FAILURE;
+ if (Z_TYPE(retval) != IS_UNDEF) {
+ result = i_zend_is_true(&retval TSRMLS_CC) ? SUCCESS : FAILURE;
zval_ptr_dtor(&retval);
return result;
} else {
@@ -208,15 +213,14 @@ static void zend_std_call_unsetter(zval *object, zval *member TSRMLS_DC) /* {{{
SEPARATE_ARG_IF_REF(member);
- zend_call_method_with_1_params(&object, ce, &ce->__unset, ZEND_UNSET_FUNC_NAME, NULL, member);
+ zend_call_method_with_1_params(object, ce, &ce->__unset, ZEND_UNSET_FUNC_NAME, NULL, member);
- zval_ptr_dtor(&member);
+ zval_ptr_dtor(member);
}
/* }}} */
-static zval *zend_std_call_issetter(zval *object, zval *member TSRMLS_DC) /* {{{ */
+static void zend_std_call_issetter(zval *object, zval *member, zval *retval TSRMLS_DC) /* {{{ */
{
- zval *retval = NULL;
zend_class_entry *ce = Z_OBJCE_P(object);
/* __isset handler is called with one argument:
@@ -227,11 +231,10 @@ static zval *zend_std_call_issetter(zval *object, zval *member TSRMLS_DC) /* {{{
SEPARATE_ARG_IF_REF(member);
- zend_call_method_with_1_params(&object, ce, &ce->__isset, ZEND_ISSET_FUNC_NAME, &retval, member);
-
- zval_ptr_dtor(&member);
+ ZVAL_UNDEF(retval);
+ zend_call_method_with_1_params(object, ce, &ce->__isset, ZEND_ISSET_FUNC_NAME, retval, member);
- return retval;
+ zval_ptr_dtor(member);
}
/* }}} */
@@ -273,7 +276,6 @@ static zend_always_inline struct _zend_property_info *zend_get_property_info_qui
zend_property_info *property_info;
zend_property_info *scope_property_info;
zend_bool denied_access = 0;
- ulong h;
if (key && (property_info = CACHED_POLYMORPHIC_PTR(key->cache_slot, ce)) != NULL) {
return property_info;
@@ -290,8 +292,7 @@ static zend_always_inline struct _zend_property_info *zend_get_property_info_qui
return NULL;
}
property_info = NULL;
- h = key ? key->hash_value : zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
- if (zend_hash_quick_find(&ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &property_info)==SUCCESS) {
+ if ((property_info = zend_hash_find_ptr(&ce->properties_info, Z_STR_P(member))) != NULL) {
if (UNEXPECTED((property_info->flags & ZEND_ACC_SHADOW) != 0)) {
/* if it's a shadow - go to access it's private */
property_info = NULL;
@@ -305,7 +306,7 @@ static zend_always_inline struct _zend_property_info *zend_get_property_info_qui
*/
} else {
if (UNEXPECTED((property_info->flags & ZEND_ACC_STATIC) != 0) && !silent) {
- zend_error(E_STRICT, "Accessing static property %s::$%s as non static", ce->name, Z_STRVAL_P(member));
+ zend_error(E_STRICT, "Accessing static property %s::$%s as non static", ce->name->val, Z_STRVAL_P(member));
}
if (key) {
CACHE_POLYMORPHIC_PTR(key->cache_slot, ce, property_info);
@@ -321,7 +322,7 @@ static zend_always_inline struct _zend_property_info *zend_get_property_info_qui
if (EG(scope) != ce
&& EG(scope)
&& is_derived_class(ce, EG(scope))
- && zend_hash_quick_find(&EG(scope)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, h, (void **) &scope_property_info)==SUCCESS
+ && (scope_property_info = zend_hash_find_ptr(&EG(scope)->properties_info, Z_STR_P(member))) != NULL
&& scope_property_info->flags & ZEND_ACC_PRIVATE) {
if (key) {
CACHE_POLYMORPHIC_PTR(key->cache_slot, ce, scope_property_info);
@@ -342,9 +343,7 @@ static zend_always_inline struct _zend_property_info *zend_get_property_info_qui
}
} else {
EG(std_property_info).flags = ZEND_ACC_PUBLIC;
- EG(std_property_info).name = Z_STRVAL_P(member);
- EG(std_property_info).name_length = Z_STRLEN_P(member);
- EG(std_property_info).h = h;
+ EG(std_property_info).name = Z_STR_P(member);
EG(std_property_info).ce = ce;
EG(std_property_info).offset = -1;
property_info = &EG(std_property_info);
@@ -359,15 +358,15 @@ ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce
}
/* }}} */
-ZEND_API int zend_check_property_access(zend_object *zobj, const char *prop_info_name, int prop_info_name_len TSRMLS_DC) /* {{{ */
+ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_info_name TSRMLS_DC) /* {{{ */
{
zend_property_info *property_info;
const char *class_name, *prop_name;
zval member;
int prop_name_len;
- zend_unmangle_property_name_ex(prop_info_name, prop_info_name_len, &class_name, &prop_name, &prop_name_len);
- ZVAL_STRINGL(&member, prop_name, prop_name_len, 0);
+ zend_unmangle_property_name_ex(prop_info_name->val, prop_info_name->len, &class_name, &prop_name, &prop_name_len);
+ ZVAL_STRINGL(&member, prop_name, prop_name_len);
property_info = zend_get_property_info_quick(zobj->ce, &member, 1, NULL TSRMLS_CC);
if (!property_info) {
return FAILURE;
@@ -376,7 +375,7 @@ ZEND_API int zend_check_property_access(zend_object *zobj, const char *prop_info
if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
/* we we're looking for a private prop but found a non private one of the same name */
return FAILURE;
- } else if (strcmp(prop_info_name+1, property_info->name+1)) {
+ } else if (strcmp(prop_info_name->val+1, property_info->name->val+1)) {
/* we we're looking for a private prop but found a private one of the same name but another class */
return FAILURE;
}
@@ -385,60 +384,53 @@ ZEND_API int zend_check_property_access(zend_object *zobj, const char *prop_info
}
/* }}} */
-static int zend_get_property_guard(zend_object *zobj, zend_property_info *property_info, zval *member, zend_guard **pguard) /* {{{ */
+static long *zend_get_property_guard(zend_object *zobj, zend_property_info *property_info, zval *member) /* {{{ */
{
zend_property_info info;
- zend_guard stub;
+ zval stub, *guard;
if (!property_info) {
property_info = &info;
- info.name = Z_STRVAL_P(member);
- info.name_length = Z_STRLEN_P(member);
- info.h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
- } else if(property_info->name[0] == '\0'){
+ info.name = Z_STR_P(member);
+ } else if(property_info->name->val[0] == '\0'){
const char *class_name = NULL, *prop_name = NULL;
- zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name);
- if(class_name) {
+ zend_unmangle_property_name(property_info->name->val, property_info->name->len, &class_name, &prop_name);
+ if (class_name) {
/* use unmangled name for protected properties */
- info.name = prop_name;
- info.name_length = strlen(prop_name);
- info.h = zend_get_hash_value(info.name, info.name_length+1);
+ info.name = STR_INIT(prop_name, strlen(prop_name), 0);
property_info = &info;
}
}
if (!zobj->guards) {
ALLOC_HASHTABLE(zobj->guards);
zend_hash_init(zobj->guards, 0, NULL, NULL, 0);
- } else if (zend_hash_quick_find(zobj->guards, property_info->name, property_info->name_length+1, property_info->h, (void **) pguard) == SUCCESS) {
- return SUCCESS;
- }
- stub.in_get = 0;
- stub.in_set = 0;
- stub.in_unset = 0;
- stub.in_isset = 0;
- return zend_hash_quick_add(zobj->guards, property_info->name, property_info->name_length+1, property_info->h, (void**)&stub, sizeof(stub), (void**) pguard);
+ } else if ((guard = zend_hash_find(zobj->guards, property_info->name)) != NULL) {
+ return &Z_LVAL_P(guard);
+ }
+
+ ZVAL_LONG(&stub, 0);
+ guard = zend_hash_add(zobj->guards, property_info->name, &stub);
+ return &Z_LVAL_P(guard);
}
/* }}} */
zval *zend_std_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_object *zobj;
- zval *tmp_member = NULL;
- zval **retval;
- zval *rv = NULL;
+ zval tmp_member;
+ zval *retval;
+ zval rv;
zend_property_info *property_info;
int silent;
silent = (type == BP_VAR_IS);
zobj = Z_OBJ_P(object);
+ ZVAL_UNDEF(&tmp_member);
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
+ ZVAL_DUP(&tmp_member, member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
key = NULL;
}
@@ -449,38 +441,42 @@ zval *zend_std_read_property(zval *object, zval *member, int type, const zend_li
/* make zend_get_property_info silent if we have getter - we may want to use it */
property_info = zend_get_property_info_quick(zobj->ce, member, silent || (zobj->ce->__get != NULL), key TSRMLS_CC);
- if (UNEXPECTED(!property_info) ||
- ((EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) ?
- (zobj->properties ?
- ((retval = (zval**)zobj->properties_table[property_info->offset]) == NULL) :
- (*(retval = &zobj->properties_table[property_info->offset]) == NULL)) :
- (UNEXPECTED(!zobj->properties) ||
- UNEXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE)))) {
- zend_guard *guard = NULL;
-
- if (zobj->ce->__get &&
- zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
- !guard->in_get) {
+ if (EXPECTED(property_info != NULL)) {
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0 &&
+ Z_TYPE(zobj->properties_table[property_info->offset]) != IS_UNDEF) {
+ retval = &zobj->properties_table[property_info->offset];
+ goto exit;
+ }
+ if (UNEXPECTED(!zobj->properties)) {
+ retval = zend_hash_find(zobj->properties, property_info->name);
+ if (retval) goto exit;
+ }
+ }
+
+ if (zobj->ce->__get) {
+ long *guard = zend_get_property_guard(zobj, property_info, member);
+ if (!((*guard) & IN_GET)) {
/* have getter - try with it! */
Z_ADDREF_P(object);
- if (PZVAL_IS_REF(object)) {
- SEPARATE_ZVAL(&object);
+ if (Z_ISREF_P(object)) {
+ SEPARATE_ZVAL(object);
}
- guard->in_get = 1; /* prevent circular getting */
- rv = zend_std_call_getter(object, member TSRMLS_CC);
- guard->in_get = 0;
+ *guard |= IN_GET; /* prevent circular getting */
+ zend_std_call_getter(object, member, &rv TSRMLS_CC);
+ *guard &= ~IN_GET;
+//???
+#if 0
if (rv) {
- retval = &rv;
+ retval = rv;
if (!Z_ISREF_P(rv) &&
(type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET)) {
if (Z_REFCOUNT_P(rv) > 0) {
zval *tmp = rv;
ALLOC_ZVAL(rv);
- *rv = *tmp;
- zval_copy_ctor(rv);
+ ZVAL_DUP(rv, tmp);
Z_UNSET_ISREF_P(rv);
Z_SET_REFCOUNT_P(rv, 0);
}
@@ -496,126 +492,108 @@ zval *zend_std_read_property(zval *object, zval *member, int type, const zend_li
} else {
Z_DELREF_P(object);
}
+#endif
} else {
- if (zobj->ce->__get && guard && guard->in_get == 1) {
- if (Z_STRVAL_P(member)[0] == '\0') {
- if (Z_STRLEN_P(member) == 0) {
- zend_error(E_ERROR, "Cannot access empty property");
- } else {
- zend_error(E_ERROR, "Cannot access property started with '\\0'");
- }
+ if (Z_STRVAL_P(member)[0] == '\0') {
+ if (Z_STRLEN_P(member) == 0) {
+ zend_error(E_ERROR, "Cannot access empty property");
+ } else {
+ zend_error(E_ERROR, "Cannot access property started with '\\0'");
}
}
- if (!silent) {
- zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
- }
- retval = &EG(uninitialized_zval_ptr);
}
+ } else {
+ if (!silent) {
+ zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name->val, Z_STRVAL_P(member));
+ }
+ retval = &EG(uninitialized_zval);
}
- if (UNEXPECTED(tmp_member != NULL)) {
- Z_ADDREF_PP(retval);
+exit:
+ if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
+ Z_ADDREF_P(retval);
zval_ptr_dtor(&tmp_member);
- Z_DELREF_PP(retval);
+ Z_DELREF_P(retval);
}
- return *retval;
+ return retval;
}
/* }}} */
ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_object *zobj;
- zval *tmp_member = NULL;
- zval **variable_ptr;
+ zval tmp_member;
+ zval *variable_ptr;
zend_property_info *property_info;
zobj = Z_OBJ_P(object);
+ ZVAL_UNDEF(&tmp_member);
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
+ ZVAL_DUP(&tmp_member, member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
key = NULL;
}
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__set != NULL), key TSRMLS_CC);
- if (EXPECTED(property_info != NULL) &&
- ((EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) ?
- (zobj->properties ?
- ((variable_ptr = (zval**)zobj->properties_table[property_info->offset]) != NULL) :
- (*(variable_ptr = &zobj->properties_table[property_info->offset]) != NULL)) :
- (EXPECTED(zobj->properties != NULL) &&
- EXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &variable_ptr) == SUCCESS)))) {
- /* if we already have this value there, we don't actually need to do anything */
- if (EXPECTED(*variable_ptr != value)) {
- /* if we are assigning reference, we shouldn't move it, but instead assign variable
- to the same pointer */
- if (PZVAL_IS_REF(*variable_ptr)) {
- zval garbage = **variable_ptr; /* old value should be destroyed */
-
- /* To check: can't *variable_ptr be some system variable like error_zval here? */
- Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value);
- (*variable_ptr)->value = value->value;
- if (Z_REFCOUNT_P(value) > 0) {
- zval_copy_ctor(*variable_ptr);
+ if (EXPECTED(property_info != NULL)) {
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0 &&
+ Z_TYPE(zobj->properties_table[property_info->offset]) != IS_UNDEF) {
+ variable_ptr = &zobj->properties_table[property_info->offset];
+ goto found;
+ }
+ if (UNEXPECTED(!zobj->properties)) {
+ variable_ptr = zend_hash_find(zobj->properties, property_info->name);
+found:
+ /* if we already have this value there, we don't actually need to do anything */
+ if (EXPECTED(variable_ptr != value)) {
+ /* if we are assigning reference, we shouldn't move it, but instead assign variable
+ to the same pointer */
+ if (Z_ISREF_P(variable_ptr)) {
+ zval garbage;
+
+ ZVAL_COPY_VALUE(&garbage, Z_REFVAL_P(variable_ptr)); /* old value should be destroyed */
+
+ /* To check: can't *variable_ptr be some system variable like error_zval here? */
+ ZVAL_COPY_VALUE(Z_REFVAL_P(variable_ptr), value);
+ if (Z_REFCOUNT_P(value) > 0) {
+ zval_copy_ctor(Z_REFVAL_P(variable_ptr));
+ }
+ zval_dtor(&garbage);
} else {
- efree(value);
- }
- zval_dtor(&garbage);
- } else {
- zval *garbage = *variable_ptr;
+ zval garbage;
- /* if we assign referenced variable, we should separate it */
- Z_ADDREF_P(value);
- if (PZVAL_IS_REF(value)) {
- SEPARATE_ZVAL(&value);
+ ZVAL_COPY_VALUE(&garbage, Z_REFVAL_P(variable_ptr));
+
+ /* if we assign referenced variable, we should separate it */
+ Z_ADDREF_P(value);
+ if (Z_ISREF_P(value)) {
+ SEPARATE_ZVAL(value);
+ }
+ ZVAL_COPY_VALUE(variable_ptr, value);
+ zval_ptr_dtor(&garbage);
}
- *variable_ptr = value;
- zval_ptr_dtor(&garbage);
}
}
- } else {
- zend_guard *guard = NULL;
+ }
+
+ if (zobj->ce->__set) {
+ long *guard = zend_get_property_guard(zobj, property_info, member);
- if (zobj->ce->__set &&
- zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
- !guard->in_set) {
+ if (!((*guard) & IN_SET)) {
Z_ADDREF_P(object);
- if (PZVAL_IS_REF(object)) {
- SEPARATE_ZVAL(&object);
+ if (Z_ISREF_P(object)) {
+ SEPARATE_ZVAL(object);
}
- guard->in_set = 1; /* prevent circular setting */
+ (*guard) |= IN_SET; /* prevent circular setting */
if (zend_std_call_setter(object, member, value TSRMLS_CC) != SUCCESS) {
/* for now, just ignore it - __set should take care of warnings, etc. */
}
- guard->in_set = 0;
- zval_ptr_dtor(&object);
- } else if (EXPECTED(property_info != NULL)) {
- /* if we assign referenced variable, we should separate it */
- Z_ADDREF_P(value);
- if (PZVAL_IS_REF(value)) {
- SEPARATE_ZVAL(&value);
- }
- if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) {
- if (!zobj->properties) {
- zobj->properties_table[property_info->offset] = value;
- } else if (zobj->properties_table[property_info->offset]) {
- *(zval**)zobj->properties_table[property_info->offset] = value;
- } else {
- zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &value, sizeof(zval *), (void**)&zobj->properties_table[property_info->offset]);
- }
- } else {
- if (!zobj->properties) {
- rebuild_object_properties(zobj);
- }
- zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &value, sizeof(zval *), NULL);
- }
- } else if (zobj->ce->__set && guard && guard->in_set == 1) {
+ (*guard) &= ~IN_SET;
+ zval_ptr_dtor(object);
+ } else {
if (Z_STRVAL_P(member)[0] == '\0') {
if (Z_STRLEN_P(member) == 0) {
zend_error(E_ERROR, "Cannot access empty property");
@@ -624,9 +602,31 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, c
}
}
}
+ } else if (EXPECTED(property_info != NULL)) {
+ /* if we assign referenced variable, we should separate it */
+ Z_ADDREF_P(value);
+ if (Z_ISREF_P(value)) {
+ SEPARATE_ZVAL(value);
+ }
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0) {
+
+ ZVAL_COPY_VALUE(&zobj->properties_table[property_info->offset], value);
+ if (zobj->properties) {
+ zval tmp;
+
+ ZVAL_INDIRECT(&tmp, &zobj->properties_table[property_info->offset]);
+ zend_hash_update(zobj->properties, property_info->name, &tmp);
+ }
+ } else {
+ if (!zobj->properties) {
+ rebuild_object_properties(zobj);
+ }
+ zend_hash_update(zobj->properties, property_info->name, value);
+ }
}
- if (UNEXPECTED(tmp_member != NULL)) {
+ if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
zval_ptr_dtor(&tmp_member);
}
}
@@ -635,33 +635,36 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, c
zval *zend_std_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */
{
zend_class_entry *ce = Z_OBJCE_P(object);
- zval *retval;
+ zval retval, tmp;
if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
if(offset == NULL) {
/* [] construct */
- ALLOC_INIT_ZVAL(offset);
+ ZVAL_UNDEF(&tmp);
+ offset = &tmp;
} else {
SEPARATE_ARG_IF_REF(offset);
}
- zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
+ zend_call_method_with_1_params(object, ce, NULL, "offsetget", &retval, offset);
- zval_ptr_dtor(&offset);
+ zval_ptr_dtor(offset);
- if (UNEXPECTED(!retval)) {
+ if (UNEXPECTED(Z_TYPE(retval) == IS_UNDEF)) {
if (UNEXPECTED(!EG(exception))) {
- zend_error_noreturn(E_ERROR, "Undefined offset for object of type %s used as array", ce->name);
+ zend_error_noreturn(E_ERROR, "Undefined offset for object of type %s used as array", ce->name->val);
}
- return 0;
+ return NULL;
}
/* Undo PZVAL_LOCK() */
- Z_DELREF_P(retval);
+ Z_DELREF(retval);
- return retval;
+ // TODO: FIXME???
+ //???return &retval;
+ return NULL;
} else {
- zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name);
- return 0;
+ zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
+ return NULL;
}
}
/* }}} */
@@ -669,17 +672,19 @@ zval *zend_std_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /*
static void zend_std_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) /* {{{ */
{
zend_class_entry *ce = Z_OBJCE_P(object);
+ zval tmp;
if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
if (!offset) {
- ALLOC_INIT_ZVAL(offset);
+ ZVAL_UNDEF(&tmp);
+ offset = &tmp;
} else {
SEPARATE_ARG_IF_REF(offset);
}
- zend_call_method_with_2_params(&object, ce, NULL, "offsetset", NULL, offset, value);
- zval_ptr_dtor(&offset);
+ zend_call_method_with_2_params(object, ce, NULL, "offsetset", NULL, offset, value);
+ zval_ptr_dtor(offset);
} else {
- zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name);
+ zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
}
}
/* }}} */
@@ -687,46 +692,47 @@ static void zend_std_write_dimension(zval *object, zval *offset, zval *value TSR
static int zend_std_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */
{
zend_class_entry *ce = Z_OBJCE_P(object);
- zval *retval;
+ zval retval;
int result;
if (EXPECTED(instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC) != 0)) {
SEPARATE_ARG_IF_REF(offset);
- zend_call_method_with_1_params(&object, ce, NULL, "offsetexists", &retval, offset);
- if (EXPECTED(retval != NULL)) {
- result = i_zend_is_true(retval TSRMLS_CC);
+ zend_call_method_with_1_params(object, ce, NULL, "offsetexists", &retval, offset);
+ if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
+ result = i_zend_is_true(&retval TSRMLS_CC);
zval_ptr_dtor(&retval);
if (check_empty && result && EXPECTED(!EG(exception))) {
- zend_call_method_with_1_params(&object, ce, NULL, "offsetget", &retval, offset);
- if (retval) {
- result = i_zend_is_true(retval TSRMLS_CC);
+ zend_call_method_with_1_params(object, ce, NULL, "offsetget", &retval, offset);
+ if (EXPECTED(Z_TYPE(retval) != IS_UNDEF)) {
+ result = i_zend_is_true(&retval TSRMLS_CC);
zval_ptr_dtor(&retval);
}
}
} else {
result = 0;
}
- zval_ptr_dtor(&offset);
+ zval_ptr_dtor(offset);
} else {
- zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name);
+ zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
return 0;
}
return result;
}
/* }}} */
-static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */
+static zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_object *zobj;
zval tmp_member;
- zval **retval;
+ zval *retval;
zend_property_info *property_info;
+ long *guard;
zobj = Z_OBJ_P(object);
+ ZVAL_UNDEF(&tmp_member);
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
- tmp_member = *member;
- zval_copy_ctor(&tmp_member);
+ ZVAL_DUP(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
key = NULL;
@@ -738,52 +744,50 @@ static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, int type
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__get != NULL), key TSRMLS_CC);
- if (UNEXPECTED(!property_info) ||
- ((EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) ?
- (zobj->properties ?
- ((retval = (zval**)zobj->properties_table[property_info->offset]) == NULL) :
- (*(retval = &zobj->properties_table[property_info->offset]) == NULL)) :
- (UNEXPECTED(!zobj->properties) ||
- UNEXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE)))) {
- zval *new_zval;
- zend_guard *guard;
-
- if (!zobj->ce->__get ||
- zend_get_property_guard(zobj, property_info, member, &guard) != SUCCESS ||
- (property_info && guard->in_get)) {
- /* we don't have access controls - will just add it */
- new_zval = &EG(uninitialized_zval);
-
- if(UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
- zend_error(E_NOTICE, "Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
- }
- Z_ADDREF_P(new_zval);
- if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) {
- if (!zobj->properties) {
- zobj->properties_table[property_info->offset] = new_zval;
- retval = &zobj->properties_table[property_info->offset];
- } else if (zobj->properties_table[property_info->offset]) {
- *(zval**)zobj->properties_table[property_info->offset] = new_zval;
- retval = (zval**)zobj->properties_table[property_info->offset];
- } else {
- zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &new_zval, sizeof(zval *), (void**)&zobj->properties_table[property_info->offset]);
- retval = (zval**)zobj->properties_table[property_info->offset];
- }
- } else {
- if (!zobj->properties) {
- rebuild_object_properties(zobj);
- }
- zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &new_zval, sizeof(zval *), (void **) &retval);
+ if (EXPECTED(property_info != NULL)) {
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0 &&
+ Z_TYPE(zobj->properties_table[property_info->offset]) != IS_UNDEF) {
+ retval = &zobj->properties_table[property_info->offset];
+ goto exit;
+ }
+ if (UNEXPECTED(!zobj->properties)) {
+ retval = zend_hash_find(zobj->properties, property_info->name);
+ if (retval) goto exit;
+ }
+ }
+
+ if (!zobj->ce->__get ||
+ (guard = zend_get_property_guard(zobj, property_info, member)) ||
+ (property_info && ((*guard) & IN_GET))) {
+
+ /* we don't have access controls - will just add it */
+ if(UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
+ zend_error(E_NOTICE, "Undefined property: %s::$%s", zobj->ce->name->val, Z_STRVAL_P(member));
+ }
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0) {
+ retval = &zobj->properties_table[property_info->offset];
+ ZVAL_NULL(retval);
+ if (zobj->properties) {
+ zval tmp;
+ ZVAL_INDIRECT(&tmp, retval);
+ zend_hash_update(zobj->properties, property_info->name, &tmp);
}
} else {
- /* we do have getter - fail and let it try again with usual get/set */
- retval = NULL;
+ if (!zobj->properties) {
+ rebuild_object_properties(zobj);
+ }
+ zend_hash_update(zobj->properties, property_info->name, retval);
}
+ } else {
+ /* we do have getter - fail and let it try again with usual get/set */
+ retval = NULL;
}
- if (UNEXPECTED(member == &tmp_member)) {
- zval_dtor(member);
+
+exit:
+ if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
+ zval_dtor(&tmp_member);
}
return retval;
}
@@ -792,18 +796,16 @@ static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, int type
static void zend_std_unset_property(zval *object, zval *member, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_object *zobj;
- zval *tmp_member = NULL;
+ zval tmp_member;
zend_property_info *property_info;
zobj = Z_OBJ_P(object);
+ ZVAL_UNDEF(&tmp_member);
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
+ ZVAL_DUP(&tmp_member, member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
key = NULL;
}
@@ -811,44 +813,41 @@ static void zend_std_unset_property(zval *object, zval *member, const zend_liter
if (EXPECTED(property_info != NULL) &&
EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- !zobj->properties &&
- property_info->offset >= 0 &&
- EXPECTED(zobj->properties_table[property_info->offset] != NULL)) {
+ property_info->offset >= 0) {
zval_ptr_dtor(&zobj->properties_table[property_info->offset]);
- zobj->properties_table[property_info->offset] = NULL;
- } else if (UNEXPECTED(!property_info) ||
- !zobj->properties ||
- UNEXPECTED(zend_hash_quick_del(zobj->properties, property_info->name, property_info->name_length+1, property_info->h) == FAILURE)) {
- zend_guard *guard = NULL;
-
- if (zobj->ce->__unset &&
- zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
- !guard->in_unset) {
- /* have unseter - try with it! */
- Z_ADDREF_P(object);
- if (PZVAL_IS_REF(object)) {
- SEPARATE_ZVAL(&object);
- }
- guard->in_unset = 1; /* prevent circular unsetting */
- zend_std_call_unsetter(object, member TSRMLS_CC);
- guard->in_unset = 0;
- zval_ptr_dtor(&object);
- } else if (zobj->ce->__unset && guard && guard->in_unset == 1) {
- if (Z_STRVAL_P(member)[0] == '\0') {
- if (Z_STRLEN_P(member) == 0) {
- zend_error(E_ERROR, "Cannot access empty property");
- } else {
- zend_error(E_ERROR, "Cannot access property started with '\\0'");
+ ZVAL_UNDEF(&zobj->properties_table[property_info->offset]);
+ if (!zobj->properties) goto exit;
+ }
+ if (UNEXPECTED(!property_info) ||
+ !zobj->properties ||
+ UNEXPECTED(zend_hash_del(zobj->properties, property_info->name) == FAILURE)) {
+
+ if (zobj->ce->__unset) {
+ long *guard = zend_get_property_guard(zobj, property_info, member);
+ if (!((*guard) & IN_UNSET)) {
+ /* have unseter - try with it! */
+ Z_ADDREF_P(object);
+ if (Z_ISREF_P(object)) {
+ SEPARATE_ZVAL(object);
+ }
+ (*guard) |= IN_UNSET; /* prevent circular unsetting */
+ zend_std_call_unsetter(object, member TSRMLS_CC);
+ (*guard) &= ~IN_UNSET;
+ zval_ptr_dtor(object);
+ } else {
+ if (Z_STRVAL_P(member)[0] == '\0') {
+ if (Z_STRLEN_P(member) == 0) {
+ zend_error(E_ERROR, "Cannot access empty property");
+ } else {
+ zend_error(E_ERROR, "Cannot access property started with '\\0'");
+ }
}
}
}
- } else if (EXPECTED(property_info != NULL) &&
- EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) {
- zobj->properties_table[property_info->offset] = NULL;
}
- if (UNEXPECTED(tmp_member != NULL)) {
+exit:
+ if (UNEXPECTED(Z_TYPE(tmp_member) != IS_NULL)) {
zval_ptr_dtor(&tmp_member);
}
}
@@ -860,10 +859,10 @@ static void zend_std_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{
if (instanceof_function_ex(ce, zend_ce_arrayaccess, 1 TSRMLS_CC)) {
SEPARATE_ARG_IF_REF(offset);
- zend_call_method_with_1_params(&object, ce, NULL, "offsetunset", NULL, offset);
- zval_ptr_dtor(&offset);
+ zend_call_method_with_1_params(object, ce, NULL, "offsetunset", NULL, offset);
+ zval_ptr_dtor(offset);
} else {
- zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name);
+ zend_error_noreturn(E_ERROR, "Cannot use object of type %s as array", ce->name->val);
}
}
/* }}} */
@@ -871,39 +870,36 @@ static void zend_std_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{
ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
{
zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->function_state.function;
- zval *method_name_ptr, *method_args_ptr;
- zval *method_result_ptr = NULL;
+ zval method_name, method_args;
+ zval method_result;
zend_class_entry *ce = Z_OBJCE_P(this_ptr);
- ALLOC_ZVAL(method_args_ptr);
- INIT_PZVAL(method_args_ptr);
- array_init_size(method_args_ptr, ZEND_NUM_ARGS());
+ array_init_size(&method_args, ZEND_NUM_ARGS());
- if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE)) {
- zval_dtor(method_args_ptr);
+ if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), &method_args TSRMLS_CC) == FAILURE)) {
+ zval_dtor(&method_args);
zend_error_noreturn(E_ERROR, "Cannot get arguments for __call");
RETURN_FALSE;
}
- ALLOC_ZVAL(method_name_ptr);
- INIT_PZVAL(method_name_ptr);
- ZVAL_STRING(method_name_ptr, func->function_name, 0); /* no dup - it's a copy */
+ ZVAL_STR(&method_name, func->function_name); /* no dup - it's a copy */
/* __call handler is called with two arguments:
method name
array of method parameters
*/
- zend_call_method_with_2_params(&this_ptr, ce, &ce->__call, ZEND_CALL_FUNC_NAME, &method_result_ptr, method_name_ptr, method_args_ptr);
+ ZVAL_UNDEF(&method_result);
+ zend_call_method_with_2_params(this_ptr, ce, &ce->__call, ZEND_CALL_FUNC_NAME, &method_result, &method_name, &method_args);
- if (method_result_ptr) {
- RETVAL_ZVAL_FAST(method_result_ptr);
- zval_ptr_dtor(&method_result_ptr);
+ if (Z_TYPE(method_result) != IS_UNDEF) {
+ RETVAL_ZVAL_FAST(&method_result);
+ zval_ptr_dtor(&method_result);
}
/* now destruct all auxiliaries */
- zval_ptr_dtor(&method_args_ptr);
- zval_ptr_dtor(&method_name_ptr);
+ zval_ptr_dtor(&method_args);
+ zval_ptr_dtor(&method_name);
/* destruct the function also, then - we have allocated it in get_method */
efree(func);
@@ -914,8 +910,10 @@ ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
* Returns the function address that should be called, or NULL
* if no such function exists.
*/
-static inline zend_function *zend_check_private_int(zend_function *fbc, zend_class_entry *ce, char *function_name_strval, int function_name_strlen, ulong hash_value TSRMLS_DC) /* {{{ */
+static inline zend_function *zend_check_private_int(zend_function *fbc, zend_class_entry *ce, zend_string *function_name TSRMLS_DC) /* {{{ */
{
+ zval *func;
+
if (!ce) {
return 0;
}
@@ -936,10 +934,12 @@ static inline zend_function *zend_check_private_int(zend_function *fbc, zend_cla
ce = ce->parent;
while (ce) {
if (ce == EG(scope)) {
- if (zend_hash_quick_find(&ce->function_table, function_name_strval, function_name_strlen+1, hash_value, (void **) &fbc)==SUCCESS
- && fbc->op_array.fn_flags & ZEND_ACC_PRIVATE
- && fbc->common.scope == EG(scope)) {
- return fbc;
+ if ((func = zend_hash_find(&ce->function_table, function_name))) {
+ fbc = Z_FUNC_P(func);
+ if (fbc->common.fn_flags & ZEND_ACC_PRIVATE
+ && fbc->common.scope == EG(scope)) {
+ return fbc;
+ }
}
break;
}
@@ -949,9 +949,9 @@ static inline zend_function *zend_check_private_int(zend_function *fbc, zend_cla
}
/* }}} */
-ZEND_API int zend_check_private(zend_function *fbc, zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
+ZEND_API int zend_check_private(zend_function *fbc, zend_class_entry *ce, zend_string *function_name TSRMLS_DC) /* {{{ */
{
- return zend_check_private_int(fbc, ce, function_name_strval, function_name_strlen, zend_hash_func(function_name_strval, function_name_strlen+1) TSRMLS_CC) != NULL;
+ return zend_check_private_int(fbc, ce, function_name TSRMLS_CC) != NULL;
}
/* }}} */
@@ -984,7 +984,7 @@ ZEND_API int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope)
}
/* }}} */
-static inline union _zend_function *zend_get_user_call_function(zend_class_entry *ce, const char *method_name, int method_len) /* {{{ */
+static inline union _zend_function *zend_get_user_call_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
{
zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
call_user_call->type = ZEND_INTERNAL_FUNCTION;
@@ -994,42 +994,40 @@ static inline union _zend_function *zend_get_user_call_function(zend_class_entry
call_user_call->num_args = 0;
call_user_call->scope = ce;
call_user_call->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
- call_user_call->function_name = estrndup(method_name, method_len);
+ call_user_call->function_name = STR_COPY(method_name);
return (union _zend_function *)call_user_call;
}
/* }}} */
-static union _zend_function *zend_std_get_method(zval **object_ptr, char *method_name, int method_len, const zend_literal *key TSRMLS_DC) /* {{{ */
+static union _zend_function *zend_std_get_method(zval *object, zend_string *method_name, const zend_literal *key TSRMLS_DC) /* {{{ */
{
+ zval *func;
zend_function *fbc;
- zval *object = *object_ptr;
zend_object *zobj = Z_OBJ_P(object);
- ulong hash_value;
- char *lc_method_name;
- ALLOCA_FLAG(use_heap)
+ zend_string *lc_method_name;
if (EXPECTED(key != NULL)) {
- lc_method_name = Z_STRVAL(key->constant);
- hash_value = key->hash_value;
+ lc_method_name = Z_STR(key->constant);
} else {
- lc_method_name = do_alloca(method_len+1, use_heap);
/* Create a zend_copy_str_tolower(dest, src, src_length); */
- zend_str_tolower_copy(lc_method_name, method_name, method_len);
- hash_value = zend_hash_func(lc_method_name, method_len+1);
+//??? lc_method_name = do_alloca(method_len+1, use_heap);
+ lc_method_name = STR_ALLOC(method_name->len, 0);
+ zend_str_tolower_copy(lc_method_name->val, method_name->val, method_name->len);
}
- if (UNEXPECTED(zend_hash_quick_find(&zobj->ce->function_table, lc_method_name, method_len+1, hash_value, (void **)&fbc) == FAILURE)) {
+ if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
if (UNEXPECTED(!key)) {
- free_alloca(lc_method_name, use_heap);
+ STR_FREE(lc_method_name);
}
if (zobj->ce->__call) {
- return zend_get_user_call_function(zobj->ce, method_name, method_len);
+ return zend_get_user_call_function(zobj->ce, method_name);
} else {
return NULL;
}
}
+ fbc = Z_FUNC_P(func);
/* Check access level */
if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
zend_function *updated_fbc;
@@ -1037,14 +1035,14 @@ static union _zend_function *zend_std_get_method(zval **object_ptr, char *method
/* Ensure that if we're calling a private function, we're allowed to do so.
* If we're not and __call() handler exists, invoke it, otherwise error out.
*/
- updated_fbc = zend_check_private_int(fbc, Z_OBJ_HANDLER_P(object, get_class_entry)(object TSRMLS_CC), lc_method_name, method_len, hash_value TSRMLS_CC);
+ updated_fbc = zend_check_private_int(fbc, Z_OBJ_HANDLER_P(object, get_class_entry)(object TSRMLS_CC), lc_method_name TSRMLS_CC);
if (EXPECTED(updated_fbc != NULL)) {
fbc = updated_fbc;
} else {
if (zobj->ce->__call) {
- fbc = zend_get_user_call_function(zobj->ce, method_name, method_len);
+ fbc = zend_get_user_call_function(zobj->ce, method_name);
} else {
- zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
+ zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name->val, EG(scope) ? EG(scope)->name->val : "");
}
}
} else {
@@ -1054,12 +1052,12 @@ static union _zend_function *zend_std_get_method(zval **object_ptr, char *method
if (EG(scope) &&
is_derived_class(fbc->common.scope, EG(scope)) &&
fbc->op_array.fn_flags & ZEND_ACC_CHANGED) {
- zend_function *priv_fbc;
-
- if (zend_hash_quick_find(&EG(scope)->function_table, lc_method_name, method_len+1, hash_value, (void **) &priv_fbc)==SUCCESS
- && priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
- && priv_fbc->common.scope == EG(scope)) {
- fbc = priv_fbc;
+ if ((func = zend_hash_find(&EG(scope)->function_table, lc_method_name)) != SUCCESS) {
+ zend_function *priv_fbc = Z_FUNC_P(func);
+ if (priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
+ && priv_fbc->common.scope == EG(scope)) {
+ fbc = priv_fbc;
+ }
}
}
if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
@@ -1068,16 +1066,16 @@ static union _zend_function *zend_std_get_method(zval **object_ptr, char *method
*/
if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), EG(scope)))) {
if (zobj->ce->__call) {
- fbc = zend_get_user_call_function(zobj->ce, method_name, method_len);
+ fbc = zend_get_user_call_function(zobj->ce, method_name);
} else {
- zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
+ zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name->val, EG(scope) ? EG(scope)->name->val : "");
}
}
}
}
if (UNEXPECTED(!key)) {
- free_alloca(lc_method_name, use_heap);
+ STR_FREE(lc_method_name);
}
return fbc;
}
@@ -1086,45 +1084,42 @@ static union _zend_function *zend_std_get_method(zval **object_ptr, char *method
ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
{
zend_internal_function *func = (zend_internal_function *)EG(current_execute_data)->function_state.function;
- zval *method_name_ptr, *method_args_ptr;
- zval *method_result_ptr = NULL;
+ zval method_name, method_args;
+ zval method_result;
zend_class_entry *ce = EG(scope);
- ALLOC_ZVAL(method_args_ptr);
- INIT_PZVAL(method_args_ptr);
- array_init_size(method_args_ptr, ZEND_NUM_ARGS());
+ array_init_size(&method_args, ZEND_NUM_ARGS());
- if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE)) {
- zval_dtor(method_args_ptr);
+ if (UNEXPECTED(zend_copy_parameters_array(ZEND_NUM_ARGS(), &method_args TSRMLS_CC) == FAILURE)) {
+ zval_dtor(&method_args);
zend_error_noreturn(E_ERROR, "Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME);
RETURN_FALSE;
}
- ALLOC_ZVAL(method_name_ptr);
- INIT_PZVAL(method_name_ptr);
- ZVAL_STRING(method_name_ptr, func->function_name, 0); /* no dup - it's a copy */
+ ZVAL_STR(&method_name, func->function_name); /* no dup - it's a copy */
/* __callStatic handler is called with two arguments:
method name
array of method parameters
*/
- zend_call_method_with_2_params(NULL, ce, &ce->__callstatic, ZEND_CALLSTATIC_FUNC_NAME, &method_result_ptr, method_name_ptr, method_args_ptr);
+ ZVAL_UNDEF(&method_result);
+ zend_call_method_with_2_params(NULL, ce, &ce->__callstatic, ZEND_CALLSTATIC_FUNC_NAME, &method_result, &method_name, &method_args);
- if (method_result_ptr) {
- RETVAL_ZVAL_FAST(method_result_ptr);
- zval_ptr_dtor(&method_result_ptr);
+ if (Z_TYPE(method_result) != IS_UNDEF) {
+ RETVAL_ZVAL_FAST(&method_result);
+ zval_ptr_dtor(&method_result);
}
/* now destruct all auxiliaries */
- zval_ptr_dtor(&method_args_ptr);
- zval_ptr_dtor(&method_name_ptr);
+ zval_ptr_dtor(&method_args);
+ zval_ptr_dtor(&method_name);
/* destruct the function also, then - we have allocated it in get_method */
efree(func);
}
/* }}} */
-static inline union _zend_function *zend_get_user_callstatic_function(zend_class_entry *ce, const char *method_name, int method_len) /* {{{ */
+static inline union _zend_function *zend_get_user_callstatic_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
{
zend_internal_function *callstatic_user_call = emalloc(sizeof(zend_internal_function));
callstatic_user_call->type = ZEND_INTERNAL_FUNCTION;
@@ -1134,7 +1129,7 @@ static inline union _zend_function *zend_get_user_callstatic_function(zend_class
callstatic_user_call->num_args = 0;
callstatic_user_call->scope = ce;
callstatic_user_call->fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC | ZEND_ACC_CALL_VIA_HANDLER;
- callstatic_user_call->function_name = estrndup(method_name, method_len);
+ callstatic_user_call->function_name = STR_COPY(method_name);
return (zend_function *)callstatic_user_call;
}
@@ -1142,48 +1137,50 @@ static inline union _zend_function *zend_get_user_callstatic_function(zend_class
/* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
-ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, const char *function_name_strval, int function_name_strlen, const zend_literal *key TSRMLS_DC) /* {{{ */
+ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_string *function_name, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_function *fbc = NULL;
- char *lc_class_name, *lc_function_name = NULL;
- ulong hash_value;
- ALLOCA_FLAG(use_heap)
+ char *lc_class_name;
+ zend_string *lc_function_name;
if (EXPECTED(key != NULL)) {
- lc_function_name = Z_STRVAL(key->constant);
- hash_value = key->hash_value;
+ lc_function_name = Z_STR(key->constant);
} else {
- lc_function_name = do_alloca(function_name_strlen+1, use_heap);
+ //???lc_function_name = do_alloca(function_name_strlen+1, use_heap);
/* Create a zend_copy_str_tolower(dest, src, src_length); */
- zend_str_tolower_copy(lc_function_name, function_name_strval, function_name_strlen);
- hash_value = zend_hash_func(lc_function_name, function_name_strlen+1);
+ lc_function_name = STR_ALLOC(function_name->len, 0);
+ zend_str_tolower_copy(lc_function_name->val, function_name->val, function_name->len);
}
- if (function_name_strlen == ce->name_length && ce->constructor) {
- lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length);
+ if (function_name->len == ce->name->len && ce->constructor) {
+ lc_class_name = zend_str_tolower_dup(ce->name->val, ce->name->len);
/* Only change the method to the constructor if the constructor isn't called __construct
* we check for __ so we can be binary safe for lowering, we should use ZEND_CONSTRUCTOR_FUNC_NAME
*/
- if (!memcmp(lc_class_name, lc_function_name, function_name_strlen) && memcmp(ce->constructor->common.function_name, "__", sizeof("__") - 1)) {
+ if (!memcmp(lc_class_name, lc_function_name->val, function_name->len) && memcmp(ce->constructor->common.function_name->val, "__", sizeof("__") - 1)) {
fbc = ce->constructor;
}
efree(lc_class_name);
}
- if (EXPECTED(!fbc) &&
- UNEXPECTED(zend_hash_quick_find(&ce->function_table, lc_function_name, function_name_strlen+1, hash_value, (void **) &fbc)==FAILURE)) {
- if (UNEXPECTED(!key)) {
- free_alloca(lc_function_name, use_heap);
- }
- if (ce->__call &&
- EG(This) &&
- Z_OBJ_HT_P(EG(This))->get_class_entry &&
- instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) {
- return zend_get_user_call_function(ce, function_name_strval, function_name_strlen);
- } else if (ce->__callstatic) {
- return zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
+ if (EXPECTED(!fbc)) {
+ zval *func = zend_hash_find(&ce->function_table, lc_function_name);
+ if (EXPECTED(func != NULL)) {
+ fbc = Z_FUNC_P(func);
} else {
- return NULL;
+ if (UNEXPECTED(!key)) {
+ STR_FREE(lc_function_name);
+ }
+ if (ce->__call &&
+ Z_TYPE(EG(This)) == IS_OBJECT &&
+ Z_OBJ_HT(EG(This))->get_class_entry &&
+ instanceof_function(Z_OBJCE(EG(This)), ce TSRMLS_CC)) {
+ return zend_get_user_call_function(ce, function_name);
+ } else if (ce->__callstatic) {
+ return zend_get_user_callstatic_function(ce, function_name);
+ } else {
+ return NULL;
+ }
}
}
@@ -1201,14 +1198,14 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, const c
/* Ensure that if we're calling a private function, we're allowed to do so.
*/
- updated_fbc = zend_check_private_int(fbc, EG(scope), lc_function_name, function_name_strlen, hash_value TSRMLS_CC);
+ updated_fbc = zend_check_private_int(fbc, EG(scope), lc_function_name TSRMLS_CC);
if (EXPECTED(updated_fbc != NULL)) {
fbc = updated_fbc;
} else {
if (ce->__callstatic) {
- fbc = zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
+ fbc = zend_get_user_callstatic_function(ce, function_name);
} else {
- zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name_strval, EG(scope) ? EG(scope)->name : "");
+ zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name->val, EG(scope) ? EG(scope)->name->val : "");
}
}
} else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
@@ -1216,45 +1213,35 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, const c
*/
if (UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), EG(scope)))) {
if (ce->__callstatic) {
- fbc = zend_get_user_callstatic_function(ce, function_name_strval, function_name_strlen);
+ fbc = zend_get_user_callstatic_function(ce, function_name);
} else {
- zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name_strval, EG(scope) ? EG(scope)->name : "");
+ zend_error_noreturn(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), function_name->val, EG(scope) ? EG(scope)->name->val : "");
}
}
}
if (UNEXPECTED(!key)) {
- free_alloca(lc_function_name, use_heap);
+ STR_FREE(lc_function_name);
}
return fbc;
}
/* }}} */
-ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, const char *property_name, int property_name_len, zend_bool silent, const zend_literal *key TSRMLS_DC) /* {{{ */
+ZEND_API zval *zend_std_get_static_property(zend_class_entry *ce, zend_string *property_name, zend_bool silent, const zend_literal *key TSRMLS_DC) /* {{{ */
{
zend_property_info *property_info;
- ulong hash_value;
if (UNEXPECTED(!key) ||
(property_info = CACHED_POLYMORPHIC_PTR(key->cache_slot, ce)) == NULL) {
- if (EXPECTED(key != NULL)) {
- hash_value = key->hash_value;
- } else {
- hash_value = zend_hash_func(property_name, property_name_len+1);
- }
- if (UNEXPECTED(zend_hash_quick_find(&ce->properties_info, property_name, property_name_len+1, hash_value, (void **) &property_info)==FAILURE)) {
+ if (UNEXPECTED((property_info = zend_hash_find_ptr(&ce->properties_info, property_name)) == NULL)) {
if (!silent) {
- zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name, property_name);
+ zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name->val, property_name->val);
}
return NULL;
}
-#if DEBUG_OBJECT_HANDLERS
- zend_printf("Access type for %s::%s is %s\n", ce->name, property_name, zend_visibility_string(property_info->flags));
-#endif
-
if (UNEXPECTED(!zend_verify_property_access(property_info, ce TSRMLS_CC))) {
if (!silent) {
zend_error_noreturn(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name, property_name);
@@ -1277,9 +1264,9 @@ ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, const char *p
}
if (UNEXPECTED(CE_STATIC_MEMBERS(ce) == NULL) ||
- UNEXPECTED(CE_STATIC_MEMBERS(ce)[property_info->offset] == NULL)) {
+ UNEXPECTED(Z_TYPE(CE_STATIC_MEMBERS(ce)[property_info->offset]) == IS_UNDEF)) {
if (!silent) {
- zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name, property_name);
+ zend_error_noreturn(E_ERROR, "Access to undeclared static property: %s::$%s", ce->name->val, property_name->val);
}
return NULL;
}
@@ -1288,9 +1275,9 @@ ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, const char *p
}
/* }}} */
-ZEND_API zend_bool zend_std_unset_static_property(zend_class_entry *ce, const char *property_name, int property_name_len, const zend_literal *key TSRMLS_DC) /* {{{ */
+ZEND_API zend_bool zend_std_unset_static_property(zend_class_entry *ce, zend_string *property_name, const zend_literal *key TSRMLS_DC) /* {{{ */
{
- zend_error_noreturn(E_ERROR, "Attempt to unset static property %s::$%s", ce->name, property_name);
+ zend_error_noreturn(E_ERROR, "Attempt to unset static property %s::$%s", ce->name->val, property_name->val);
return 0;
}
/* }}} */
@@ -1347,38 +1334,38 @@ static int zend_std_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
if (!zobj1->properties && !zobj2->properties) {
int i;
- Z_OBJ_PROTECT_RECURSION(o1);
- Z_OBJ_PROTECT_RECURSION(o2);
+//??? Z_OBJ_PROTECT_RECURSION(o1);
+//??? Z_OBJ_PROTECT_RECURSION(o2);
for (i = 0; i < zobj1->ce->default_properties_count; i++) {
- if (zobj1->properties_table[i]) {
- if (zobj2->properties_table[i]) {
+ if (Z_TYPE(zobj1->properties_table[i]) != IS_UNDEF) {
+ if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
zval result;
- if (compare_function(&result, zobj1->properties_table[i], zobj2->properties_table[i] TSRMLS_CC)==FAILURE) {
- Z_OBJ_UNPROTECT_RECURSION(o1);
- Z_OBJ_UNPROTECT_RECURSION(o2);
+ if (compare_function(&result, &zobj1->properties_table[i], &zobj2->properties_table[i] TSRMLS_CC)==FAILURE) {
+//??? Z_OBJ_UNPROTECT_RECURSION(o1);
+//??? Z_OBJ_UNPROTECT_RECURSION(o2);
return 1;
}
if (Z_LVAL(result) != 0) {
- Z_OBJ_UNPROTECT_RECURSION(o1);
- Z_OBJ_UNPROTECT_RECURSION(o2);
+//??? Z_OBJ_UNPROTECT_RECURSION(o1);
+//??? Z_OBJ_UNPROTECT_RECURSION(o2);
return Z_LVAL(result);
}
} else {
- Z_OBJ_UNPROTECT_RECURSION(o1);
- Z_OBJ_UNPROTECT_RECURSION(o2);
+//??? Z_OBJ_UNPROTECT_RECURSION(o1);
+//??? Z_OBJ_UNPROTECT_RECURSION(o2);
return 1;
}
} else {
- if (zobj2->properties_table[i]) {
- Z_OBJ_UNPROTECT_RECURSION(o1);
- Z_OBJ_UNPROTECT_RECURSION(o2);
+ if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
+//??? Z_OBJ_UNPROTECT_RECURSION(o1);
+//??? Z_OBJ_UNPROTECT_RECURSION(o2);
return 1;
}
}
}
- Z_OBJ_UNPROTECT_RECURSION(o1);
- Z_OBJ_UNPROTECT_RECURSION(o2);
+//??? Z_OBJ_UNPROTECT_RECURSION(o1);
+//??? Z_OBJ_UNPROTECT_RECURSION(o2);
return 0;
} else {
if (!zobj1->properties) {
@@ -1396,63 +1383,74 @@ static int zend_std_has_property(zval *object, zval *member, int has_set_exists,
{
zend_object *zobj;
int result;
- zval **value = NULL;
- zval *tmp_member = NULL;
+ zval *value = NULL;
+ zval tmp_member;
zend_property_info *property_info;
zobj = Z_OBJ_P(object);
+ ZVAL_UNDEF(&tmp_member);
if (UNEXPECTED(Z_TYPE_P(member) != IS_STRING)) {
- ALLOC_ZVAL(tmp_member);
- *tmp_member = *member;
- INIT_PZVAL(tmp_member);
- zval_copy_ctor(tmp_member);
- convert_to_string(tmp_member);
- member = tmp_member;
+ ZVAL_DUP(&tmp_member, member);
+ convert_to_string(&tmp_member);
+ member = &tmp_member;
key = NULL;
}
-#if DEBUG_OBJECT_HANDLERS
- fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
-#endif
-
property_info = zend_get_property_info_quick(zobj->ce, member, 1, key TSRMLS_CC);
- if (UNEXPECTED(!property_info) ||
- ((EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
- property_info->offset >= 0) ?
- (zobj->properties ?
- ((value = (zval**)zobj->properties_table[property_info->offset]) == NULL) :
- (*(value = &zobj->properties_table[property_info->offset]) == NULL)) :
- (UNEXPECTED(!zobj->properties) ||
- UNEXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &value) == FAILURE)))) {
- zend_guard *guard;
-
- result = 0;
- if ((has_set_exists != 2) &&
- zobj->ce->__isset &&
- zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
- !guard->in_isset) {
- zval *rv;
+ if (EXPECTED(property_info != NULL)) {
+ if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
+ property_info->offset >= 0 &&
+ Z_TYPE(zobj->properties_table[property_info->offset]) != IS_UNDEF) {
+ value = &zobj->properties_table[property_info->offset];
+ goto found;
+ }
+ if (UNEXPECTED(!zobj->properties)) {
+ value = zend_hash_find(zobj->properties, property_info->name);
+found:
+ switch (has_set_exists) {
+ case 0:
+ result = (Z_TYPE_P(value) != IS_NULL);
+ break;
+ default:
+ result = zend_is_true(value TSRMLS_CC);
+ break;
+ case 2:
+ result = 1;
+ break;
+ }
+ }
+ goto exit;
+ }
+
+ result = 0;
+ if ((has_set_exists != 2) && zobj->ce->__isset) {
+ long *guard = zend_get_property_guard(zobj, property_info, member);
+
+ if (!((*guard) & IN_ISSET)) {
+ zval rv;
/* have issetter - try with it! */
Z_ADDREF_P(object);
- if (PZVAL_IS_REF(object)) {
- SEPARATE_ZVAL(&object);
+ if (Z_ISREF_P(object)) {
+ SEPARATE_ZVAL(object);
}
- guard->in_isset = 1; /* prevent circular getting */
- rv = zend_std_call_issetter(object, member TSRMLS_CC);
- if (rv) {
- result = zend_is_true(rv TSRMLS_CC);
+ (*guard) |= IN_ISSET; /* prevent circular getting */
+ ZVAL_UNDEF(&rv);
+ zend_std_call_issetter(object, member, &rv TSRMLS_CC);
+ if (Z_TYPE(rv) != IS_UNDEF) {
+ result = zend_is_true(&rv TSRMLS_CC);
zval_ptr_dtor(&rv);
if (has_set_exists && result) {
- if (EXPECTED(!EG(exception)) && zobj->ce->__get && !guard->in_get) {
- guard->in_get = 1;
- rv = zend_std_call_getter(object, member TSRMLS_CC);
- guard->in_get = 0;
- if (rv) {
- Z_ADDREF_P(rv);
- result = i_zend_is_true(rv TSRMLS_CC);
+ if (EXPECTED(!EG(exception)) && zobj->ce->__get && !((*guard) & IN_GET)) {
+ (*guard) |= IN_GET;
+ ZVAL_UNDEF(&rv);
+ zend_std_call_getter(object, member, &rv TSRMLS_CC);
+ (*guard) &= ~IN_GET;
+ if (Z_TYPE(rv) != IS_UNDEF) {
+ Z_ADDREF(rv);
+ result = i_zend_is_true(&rv TSRMLS_CC);
zval_ptr_dtor(&rv);
} else {
result = 0;
@@ -1462,24 +1460,13 @@ static int zend_std_has_property(zval *object, zval *member, int has_set_exists,
}
}
}
- guard->in_isset = 0;
- zval_ptr_dtor(&object);
- }
- } else {
- switch (has_set_exists) {
- case 0:
- result = (Z_TYPE_PP(value) != IS_NULL);
- break;
- default:
- result = zend_is_true(*value TSRMLS_CC);
- break;
- case 2:
- result = 1;
- break;
+ (*guard) &= ~IN_ISSET;
+ zval_ptr_dtor(object);
}
}
- if (UNEXPECTED(tmp_member != NULL)) {
+exit:
+ if (UNEXPECTED(Z_TYPE(tmp_member) != IS_UNDEF)) {
zval_ptr_dtor(&tmp_member);
}
return result;
@@ -1495,7 +1482,7 @@ zend_class_entry *zend_std_object_get_class(const zval *object TSRMLS_DC) /* {{{
}
/* }}} */
-int zend_std_object_get_class_name(const zval *object, const char **class_name, zend_uint *class_name_len, int parent TSRMLS_DC) /* {{{ */
+zend_string* zend_std_object_get_class_name(const zval *object, int parent TSRMLS_DC) /* {{{ */
{
zend_object *zobj;
zend_class_entry *ce;
@@ -1503,67 +1490,64 @@ int zend_std_object_get_class_name(const zval *object, const char **class_name,
if (parent) {
if (!zobj->ce->parent) {
- return FAILURE;
+ return NULL;
}
ce = zobj->ce->parent;
} else {
ce = zobj->ce;
}
- *class_name_len = ce->name_length;
- *class_name = estrndup(ce->name, ce->name_length);
- return SUCCESS;
+ return STR_COPY(ce->name);
}
/* }}} */
ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int type TSRMLS_DC) /* {{{ */
{
- zval *retval;
+ zval retval;
zend_class_entry *ce;
switch (type) {
case IS_STRING:
+ ZVAL_UNDEF(&retval);
ce = Z_OBJCE_P(readobj);
if (ce->__tostring &&
- (zend_call_method_with_0_params(&readobj, ce, &ce->__tostring, "__tostring", &retval) || EG(exception))) {
+ (zend_call_method_with_0_params(readobj, ce, &ce->__tostring, "__tostring", &retval) || EG(exception))) {
if (UNEXPECTED(EG(exception) != NULL)) {
- if (retval) {
+ if (Z_TYPE(retval) != IS_UNDEF) {
zval_ptr_dtor(&retval);
}
EG(exception) = NULL;
- zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name);
+ zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name->val);
return FAILURE;
}
- if (EXPECTED(Z_TYPE_P(retval) == IS_STRING)) {
- INIT_PZVAL(writeobj);
+ if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
+//??? INIT_PZVAL(writeobj);
if (readobj == writeobj) {
zval_dtor(readobj);
}
- ZVAL_ZVAL(writeobj, retval, 1, 1);
+ ZVAL_ZVAL(writeobj, &retval, 1, 1);
if (Z_TYPE_P(writeobj) != type) {
convert_to_explicit_type(writeobj, type);
}
return SUCCESS;
} else {
zval_ptr_dtor(&retval);
- INIT_PZVAL(writeobj);
+//??? INIT_PZVAL(writeobj);
if (readobj == writeobj) {
zval_dtor(readobj);
}
ZVAL_EMPTY_STRING(writeobj);
- zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ce->name);
+ zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ce->name->val);
return SUCCESS;
}
}
return FAILURE;
case IS_BOOL:
- INIT_PZVAL(writeobj);
ZVAL_BOOL(writeobj, 1);
return SUCCESS;
case IS_LONG:
ce = Z_OBJCE_P(readobj);
- zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name);
- INIT_PZVAL(writeobj);
+ zend_error(E_NOTICE, "Object of class %s could not be converted to int", ce->name->val);
if (readobj == writeobj) {
zval_dtor(readobj);
}
@@ -1571,43 +1555,44 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
return SUCCESS;
case IS_DOUBLE:
ce = Z_OBJCE_P(readobj);
- zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name);
- INIT_PZVAL(writeobj);
+ zend_error(E_NOTICE, "Object of class %s could not be converted to double", ce->name->val);
if (readobj == writeobj) {
zval_dtor(readobj);
}
ZVAL_DOUBLE(writeobj, 1);
return SUCCESS;
default:
- INIT_PZVAL(writeobj);
- Z_TYPE_P(writeobj) = IS_NULL;
+ ZVAL_NULL(writeobj);
break;
}
return FAILURE;
}
/* }}} */
-int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
+int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval *zobj_ptr TSRMLS_DC) /* {{{ */
{
+ zval *func;
zend_class_entry *ce;
+
if (Z_TYPE_P(obj) != IS_OBJECT) {
return FAILURE;
}
ce = Z_OBJCE_P(obj);
- if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void**)fptr_ptr) == FAILURE) {
+ if ((func = zend_hash_str_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1)) == NULL) {
return FAILURE;
}
+ *fptr_ptr = Z_FUNC_P(func);
*ce_ptr = ce;
if ((*fptr_ptr)->common.fn_flags & ZEND_ACC_STATIC) {
if (zobj_ptr) {
- *zobj_ptr = NULL;
+ ZVAL_UNDEF(zobj_ptr);
}
} else {
if (zobj_ptr) {
- *zobj_ptr = obj;
+ ZVAL_COPY_VALUE(zobj_ptr, obj);
}
}
return SUCCESS;
@@ -1615,8 +1600,8 @@ int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **f
/* }}} */
ZEND_API zend_object_handlers std_object_handlers = {
- zend_objects_store_add_ref, /* add_ref */
- zend_objects_store_del_ref, /* del_ref */
+ zend_object_free, /* free_obj */
+ zend_object_std_dtor, /* dtor_obj */
zend_objects_clone_obj, /* clone_obj */
zend_std_read_property, /* read_property */