diff options
Diffstat (limited to 'Zend/zend_execute.c')
| -rw-r--r-- | Zend/zend_execute.c | 478 |
1 files changed, 240 insertions, 238 deletions
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index c7aac2f1a..3b27bcefb 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.716.2.12 2006/02/26 10:53:38 helly Exp $ */ +/* $Id: zend_execute.c,v 1.716.2.12.2.12 2006/10/02 11:09:52 tony2001 Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -31,11 +31,14 @@ #include "zend_ptr_stack.h" #include "zend_constants.h" #include "zend_extensions.h" -#include "zend_fast_cache.h" #include "zend_ini.h" #include "zend_exceptions.h" +#include "zend_interfaces.h" #include "zend_vm.h" +/* Virtual current working directory support */ +#include "tsrm_virtual_cwd.h" + #define _CONST_CODE 0 #define _TMP_CODE 1 #define _VAR_CODE 2 @@ -123,16 +126,16 @@ static inline void zend_pzval_unlock_free_func(zval *z) #define INIT_PZVAL_COPY(z,v) \ (z)->value = (v)->value; \ - (z)->type = (v)->type; \ + Z_TYPE_P(z) = Z_TYPE_P(v); \ (z)->refcount = 1; \ - (z)->is_ref = 0; + (z)->is_ref = 0; #define MAKE_REAL_ZVAL_PTR(val) \ do { \ zval *_tmp; \ ALLOC_ZVAL(_tmp); \ _tmp->value = (val)->value; \ - _tmp->type = (val)->type; \ + Z_TYPE_P(_tmp) = Z_TYPE_P(val); \ _tmp->refcount = 1; \ _tmp->is_ref = 0; \ val = _tmp; \ @@ -150,10 +153,10 @@ ZEND_API zval** zend_get_compiled_variable_value(zend_execute_data *execute_data static inline void zend_get_cv_address(zend_compiled_variable *cv, zval ***ptr, temp_variable *Ts TSRMLS_DC) { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &new_zval, sizeof(zval *), (void **)ptr); + zval *new_zval = &EG(uninitialized_zval); + + new_zval->refcount++; + zend_hash_quick_update(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, &new_zval, sizeof(zval *), (void **)ptr); } static inline zval *_get_zval_ptr_tmp(znode *node, temp_variable *Ts, zend_free_op *should_free TSRMLS_DC) @@ -199,7 +202,7 @@ static inline zval *_get_zval_ptr_var(znode *node, temp_variable *Ts, zend_free_ static inline zval *_get_zval_ptr_cv(znode *node, temp_variable *Ts, int type TSRMLS_DC) { zval ***ptr = &CV_OF(node->u.var); - + if (!*ptr) { zend_compiled_variable *cv = &CV_DEF_OF(node->u.var); if (zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { @@ -267,7 +270,7 @@ static inline zval **_get_zval_ptr_ptr_var(znode *node, temp_variable *Ts, zend_ static inline zval **_get_zval_ptr_ptr_cv(znode *node, temp_variable *Ts, int type TSRMLS_DC) { zval ***ptr = &CV_OF(node->u.var); - + if (!*ptr) { zend_compiled_variable *cv = &CV_DEF_OF(node->u.var); if (zend_hash_quick_find(EG(active_symbol_table), cv->name, cv->name_len+1, cv->hash_value, (void **)ptr)==FAILURE) { @@ -364,7 +367,7 @@ static inline void zend_switch_free(zend_op *opline, temp_variable *Ts TSRMLS_DC PZVAL_UNLOCK_FREE(T->str_offset.str); } else { zval_ptr_dtor(&T(opline->op1.u.var).var.ptr); - if (opline->extended_value) { /* foreach() free */ + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { /* foreach() free */ zval_ptr_dtor(&T(opline->op1.u.var).var.ptr); } } @@ -433,9 +436,10 @@ static void zend_assign_to_variable_reference(zval **variable_ptr_ptr, zval **va static inline void make_real_object(zval **object_ptr TSRMLS_DC) { /* this should modify object only if it's empty */ - if ((*object_ptr)->type == IS_NULL - || ((*object_ptr)->type == IS_BOOL && (*object_ptr)->value.lval==0) - || ((*object_ptr)->type == IS_STRING && (*object_ptr)->value.str.len == 0)) { + if (Z_TYPE_PP(object_ptr) == IS_NULL + || (Z_TYPE_PP(object_ptr) == IS_BOOL && Z_LVAL_PP(object_ptr)==0) + || (Z_TYPE_PP(object_ptr) == IS_STRING && Z_STRLEN_PP(object_ptr) == 0)) { + if (!PZVAL_IS_REF(*object_ptr)) { SEPARATE_ZVAL(object_ptr); } @@ -445,95 +449,79 @@ static inline void make_real_object(zval **object_ptr TSRMLS_DC) } } -static inline void zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zval *arg TSRMLS_DC) +static inline char * zend_verify_arg_class_kind(zend_arg_info *cur_arg_info, char **class_name, zend_class_entry **pce TSRMLS_DC) +{ + *pce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD) TSRMLS_CC); + + *class_name = (*pce) ? (*pce)->name: cur_arg_info->class_name; + if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) { + return "implement interface "; + } else { + return "be an instance of "; + } +} + +static inline int zend_verify_arg_error(zend_function *zf, zend_uint arg_num, zend_arg_info *cur_arg_info, char *need_msg, char *need_kind, char *given_msg, char *given_kind TSRMLS_DC) { - zend_arg_info *cur_arg_info; zend_execute_data *ptr = EG(current_execute_data)->prev_execute_data; - char *fclass, *fsep, *fname; + char *fname = zf->common.function_name; + char *fsep; + char *fclass; + + if (zf->common.scope) { + fsep = "::"; + fclass = zf->common.scope->name; + } else { + fsep = ""; + fclass = ""; + } + + if (ptr && ptr->op_array) { + zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind, ptr->op_array->filename, ptr->opline->lineno); + } else { + zend_error(E_RECOVERABLE_ERROR, "Argument %d passed to %s%s%s() must %s%s, %s%s given", arg_num, fclass, fsep, fname, need_msg, need_kind, given_msg, given_kind); + } + return 0; +} + +static inline int zend_verify_arg_type(zend_function *zf, zend_uint arg_num, zval *arg TSRMLS_DC) +{ + zend_arg_info *cur_arg_info; + char *need_msg; + zend_class_entry *ce; if (!zf->common.arg_info || arg_num>zf->common.num_args) { - return; + return 1; } cur_arg_info = &zf->common.arg_info[arg_num-1]; - fname = zf->common.function_name; - fsep = zf->common.scope ? "::" : ""; - fclass = zf->common.scope ? zf->common.scope->name : ""; if (cur_arg_info->class_name) { + char *class_name; + if (!arg) { - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s", arg_num, fclass, fsep, fname, cur_arg_info->class_name); - } + need_msg = zend_verify_arg_class_kind(cur_arg_info, &class_name, &ce TSRMLS_CC); + return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, "none", "" TSRMLS_CC); } - switch (Z_TYPE_P(arg)) { - case IS_NULL: - if (!cur_arg_info->allow_null) { - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must not be null, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must not be null", arg_num, fclass, fsep, fname); - } - } - break; - case IS_OBJECT: { - zend_class_entry *ce = zend_fetch_class(cur_arg_info->class_name, cur_arg_info->class_name_len, ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - if (!instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) { - char *error_msg; - - if (ce->ce_flags & ZEND_ACC_INTERFACE) { - error_msg = "implement interface"; - } else { - error_msg = "be an instance of"; - } - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must %s %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, error_msg, ce->name, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must %s %s", arg_num, fclass, fsep, fname, error_msg, ce->name); - } - } - } - break; - default: - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s, called in %s on line %d and defined", arg_num, fclass, fsep, fname, cur_arg_info->class_name, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an object of class %s", arg_num, fclass, fsep, fname, cur_arg_info->class_name); - } - break; + if (Z_TYPE_P(arg) == IS_OBJECT) { + need_msg = zend_verify_arg_class_kind(cur_arg_info, &class_name, &ce TSRMLS_CC); + if (!ce || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) { + return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, "instance of ", Z_OBJCE_P(arg)->name TSRMLS_CC); + } + } else if (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null) { + need_msg = zend_verify_arg_class_kind(cur_arg_info, &class_name, &ce TSRMLS_CC); + return zend_verify_arg_error(zf, arg_num, cur_arg_info, need_msg, class_name, zend_zval_type_name(arg), "" TSRMLS_CC); } } else if (cur_arg_info->array_type_hint) { if (!arg) { - if(ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an array, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an array", arg_num, fclass, fsep, fname); - } + return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", "", "none", "" TSRMLS_CC); } - switch (Z_TYPE_P(arg)) { - case IS_NULL: - if (!cur_arg_info->allow_null) { - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must not be null, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must not be null", arg_num, fclass, fsep, fname); - } - } - break; - case IS_ARRAY: - break; - default: - if (ptr && ptr->op_array) { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an array, called in %s on line %d and defined", arg_num, fclass, fsep, fname, ptr->op_array->filename, ptr->opline->lineno); - } else { - zend_error_noreturn(E_ERROR, "Argument %d passed to %s%s%s() must be an array", arg_num, fclass, fsep, fname); - } - break; + if (Z_TYPE_P(arg) != IS_ARRAY && (Z_TYPE_P(arg) != IS_NULL || !cur_arg_info->allow_null)) { + return zend_verify_arg_error(zf, arg_num, cur_arg_info, "be an array", "", zend_zval_type_name(arg), "" TSRMLS_CC); } } + return 1; } @@ -557,8 +545,8 @@ static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode make_real_object(object_ptr TSRMLS_CC); /* this should modify object only if it's empty */ object = *object_ptr; - - if (object->type != IS_OBJECT || (opcode == ZEND_ASSIGN_OBJ && !Z_OBJ_HT_P(object)->write_property)) { + + if (Z_TYPE_P(object) != IS_OBJECT || (opcode == ZEND_ASSIGN_OBJ && !Z_OBJ_HT_P(object)->write_property)) { zend_error(E_WARNING, "Attempt to assign property of non-object"); FREE_OP(free_op2); if (!RETURN_VALUE_UNUSED(result)) { @@ -607,7 +595,7 @@ static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode value->refcount = 0; zval_copy_ctor(value); } - + value->refcount++; if (opcode == ZEND_ASSIGN_OBJ) { @@ -625,7 +613,7 @@ static inline void zend_assign_to_object(znode *result, zval **object_ptr, znode } Z_OBJ_HT_P(object)->write_dimension(object, property_name, value TSRMLS_CC); } - + if (result && !RETURN_VALUE_UNUSED(result)) { T(result->u.var).var.ptr = value; T(result->u.var).var.ptr_ptr = &T(result->u.var).var.ptr; /* this is so that we could use it in FETCH_DIM_R, etc. - see bug #27876 */ @@ -646,11 +634,12 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 zend_free_op free_op1; zval **variable_ptr_ptr = get_zval_ptr_ptr(op1, Ts, &free_op1, BP_VAR_W); zval *variable_ptr; - + if (!variable_ptr_ptr) { temp_variable *T = &T(op1->u.var); - if (T->str_offset.str->type == IS_STRING) do { + if (Z_TYPE_P(T->str_offset.str) == IS_STRING) + do { zval tmp; zval *final_value = value; @@ -658,23 +647,23 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 zend_error(E_WARNING, "Illegal string offset: %d", T->str_offset.offset); break; } - if ((int)T->str_offset.offset >= T->str_offset.str->value.str.len) { + if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) { zend_uint i; - if (T->str_offset.str->value.str.len==0) { - STR_FREE(T->str_offset.str->value.str.val); - T->str_offset.str->value.str.val = (char *) emalloc(T->str_offset.offset+1+1); + if (Z_STRLEN_P(T->str_offset.str)==0) { + STR_FREE(Z_STRVAL_P(T->str_offset.str)); + Z_STRVAL_P(T->str_offset.str) = (char *) emalloc(T->str_offset.offset+1+1); } else { - T->str_offset.str->value.str.val = (char *) erealloc(T->str_offset.str->value.str.val, T->str_offset.offset+1+1); + Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1); } - for (i=T->str_offset.str->value.str.len; i<T->str_offset.offset; i++) { - T->str_offset.str->value.str.val[i] = ' '; + for (i=Z_STRLEN_P(T->str_offset.str); i<T->str_offset.offset; i++) { + Z_STRVAL_P(T->str_offset.str)[i] = ' '; } - T->str_offset.str->value.str.val[T->str_offset.offset+1] = 0; - T->str_offset.str->value.str.len = T->str_offset.offset+1; + Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0; + Z_STRLEN_P(T->str_offset.str) = T->str_offset.offset+1; } - if (value->type!=IS_STRING) { + if (Z_TYPE_P(value)!=IS_STRING) { tmp = *value; if (op2->op_type & (IS_VAR|IS_CV)) { zval_copy_ctor(&tmp); @@ -683,14 +672,14 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 final_value = &tmp; } - T->str_offset.str->value.str.val[T->str_offset.offset] = final_value->value.str.val[0]; - + Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(final_value)[0]; + if (op2->op_type == IS_TMP_VAR) { if (final_value == &T(op2->u.var).tmp_var) { /* we can safely free final_value here * because separation is done only * in case op2->op_type == IS_VAR */ - STR_FREE(final_value->value.str.val); + STR_FREE(Z_STRVAL_P(final_value)); } } if (final_value == &tmp) { @@ -702,7 +691,7 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 */ } while (0); /* zval_ptr_dtor(&T->str_offset.str); Nuke this line if it doesn't cause a leak */ - + /* T(result->u.var).var.ptr_ptr = &EG(uninitialized_zval_ptr); */ if (!RETURN_VALUE_UNUSED(result)) { T(result->u.var).var.ptr_ptr = &value; @@ -728,65 +717,64 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 return; } - if(Z_TYPE_P(variable_ptr) == IS_OBJECT && Z_OBJ_HANDLER_P(variable_ptr, set)) { - /* TODO? ze1_compatibility_mode support */ + if (Z_TYPE_P(variable_ptr) == IS_OBJECT && Z_OBJ_HANDLER_P(variable_ptr, set)) { Z_OBJ_HANDLER_P(variable_ptr, set)(variable_ptr_ptr, value TSRMLS_CC); goto done_setting_var; } - - if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { - char *class_name; - zend_uint class_name_len; - int dup; - - dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); - - if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { - zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); - } else if (PZVAL_IS_REF(variable_ptr)) { - if (variable_ptr != value) { - zend_uint refcount = variable_ptr->refcount; - zval garbage; - if (type != IS_TMP_VAR) { - value->refcount++; - } - garbage = *variable_ptr; - *variable_ptr = *value; - variable_ptr->refcount = refcount; - variable_ptr->is_ref = 1; - zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); - variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); - if (type != IS_TMP_VAR) { - value->refcount--; - } - zendi_zval_dtor(garbage); - } - } else { - if (variable_ptr != value) { - value->refcount++; - variable_ptr->refcount--; - if (variable_ptr->refcount == 0) { - zendi_zval_dtor(*variable_ptr); - } else { - ALLOC_ZVAL(variable_ptr); - *variable_ptr_ptr = variable_ptr; - } - *variable_ptr = *value; - INIT_PZVAL(variable_ptr); - zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); - variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); - zval_ptr_dtor(&value); - } - } - if (!dup) { - efree(class_name); - } - } else if (PZVAL_IS_REF(variable_ptr)) { + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else if (PZVAL_IS_REF(variable_ptr)) { + if (variable_ptr != value) { + zend_uint refcount = variable_ptr->refcount; + zval garbage; + + if (type != IS_TMP_VAR) { + value->refcount++; + } + garbage = *variable_ptr; + *variable_ptr = *value; + variable_ptr->refcount = refcount; + variable_ptr->is_ref = 1; + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + if (type != IS_TMP_VAR) { + value->refcount--; + } + zendi_zval_dtor(garbage); + } + } else { + if (variable_ptr != value) { + value->refcount++; + variable_ptr->refcount--; + if (variable_ptr->refcount == 0) { + zendi_zval_dtor(*variable_ptr); + } else { + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + } + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + zval_ptr_dtor(&value); + } + } + if (!dup) { + efree(class_name); + } + } else if (PZVAL_IS_REF(variable_ptr)) { if (variable_ptr!=value) { zend_uint refcount = variable_ptr->refcount; zval garbage; - + if (type!=IS_TMP_VAR) { value->refcount++; } @@ -812,7 +800,7 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 variable_ptr->refcount++; } else if (PZVAL_IS_REF(value)) { zval tmp; - + tmp = *value; zval_copy_ctor(&tmp); tmp.refcount=1; @@ -859,13 +847,13 @@ static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2 } (*variable_ptr_ptr)->is_ref=0; } - + done_setting_var: if (result && !RETURN_VALUE_UNUSED(result)) { T(result->u.var).var.ptr_ptr = variable_ptr_ptr; PZVAL_LOCK(*variable_ptr_ptr); AI_USE_PTR(T(result->u.var).var); - } + } FREE_OP_VAR_PTR(free_op1); } @@ -874,32 +862,32 @@ static inline void zend_receive(zval **variable_ptr_ptr, zval *value TSRMLS_DC) { zval *variable_ptr = *variable_ptr_ptr; - if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { - char *class_name; - zend_uint class_name_len; - int dup; - - dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); - - if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { - zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); - } else { - variable_ptr->refcount--; - ALLOC_ZVAL(variable_ptr); - *variable_ptr_ptr = variable_ptr; - *variable_ptr = *value; - INIT_PZVAL(variable_ptr); - zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); - variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); - } - if (!dup) { - efree(class_name); - } - } else { - variable_ptr->refcount--; - *variable_ptr_ptr = value; - value->refcount++; - } + if (EG(ze1_compatibility_mode) && Z_TYPE_P(value) == IS_OBJECT) { + char *class_name; + zend_uint class_name_len; + int dup; + + dup = zend_get_object_classname(value, &class_name, &class_name_len TSRMLS_CC); + + if (Z_OBJ_HANDLER_P(value, clone_obj) == NULL) { + zend_error_noreturn(E_ERROR, "Trying to clone an uncloneable object of class %s", class_name); + } else { + variable_ptr->refcount--; + ALLOC_ZVAL(variable_ptr); + *variable_ptr_ptr = variable_ptr; + *variable_ptr = *value; + INIT_PZVAL(variable_ptr); + zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name); + variable_ptr->value.obj = Z_OBJ_HANDLER_P(value, clone_obj)(value TSRMLS_CC); + } + if (!dup) { + efree(class_name); + } + } else { + variable_ptr->refcount--; + *variable_ptr_ptr = value; + value->refcount++; + } } /* Utility Functions for Extensions */ @@ -960,6 +948,7 @@ static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, zval *dim offset_key = ""; offset_key_length = 0; goto fetch_string_dim; + case IS_STRING: offset_key = dim->value.str.val; @@ -989,17 +978,17 @@ fetch_string_dim: } break; case IS_RESOURCE: - zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", dim->value.lval, dim->value.lval); + zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(dim), Z_LVAL_P(dim)); /* Fall Through */ case IS_DOUBLE: - case IS_BOOL: + case IS_BOOL: case IS_LONG: { long index; - if (dim->type == IS_DOUBLE) { - index = (long)dim->value.dval; + if (Z_TYPE_P(dim) == IS_DOUBLE) { + index = (long)Z_DVAL_P(dim); } else { - index = dim->value.lval; + index = Z_LVAL_P(dim); } if (zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) { switch (type) { @@ -1024,7 +1013,7 @@ fetch_string_dim: } } break; - default: + default: zend_error(E_WARNING, "Illegal offset type"); switch (type) { case BP_VAR_R: @@ -1048,7 +1037,7 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container if (!container_ptr) { zend_error_noreturn(E_ERROR, "Cannot use string offset as an array"); } - + container = *container_ptr; if (container == EG(error_zval_ptr)) { @@ -1062,9 +1051,9 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container return; } - if (container->type==IS_NULL - || (container->type==IS_BOOL && container->value.lval==0) - || (container->type==IS_STRING && container->value.str.len==0)) { + if (Z_TYPE_P(container)==IS_NULL + || (Z_TYPE_P(container)==IS_BOOL && Z_LVAL_P(container)==0) + || (Z_TYPE_P(container)==IS_STRING && Z_STRLEN_P(container)==0)) { switch (type) { case BP_VAR_RW: case BP_VAR_W: @@ -1078,7 +1067,7 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container } } - switch (container->type) { + switch (Z_TYPE_P(container)) { zval **retval; case IS_ARRAY: @@ -1090,13 +1079,13 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container zval *new_zval = &EG(uninitialized_zval); new_zval->refcount++; - if (zend_hash_next_index_insert(container->value.ht, &new_zval, sizeof(zval *), (void **) &retval) == FAILURE) { + if (zend_hash_next_index_insert(Z_ARRVAL_P(container), &new_zval, sizeof(zval *), (void **) &retval) == FAILURE) { zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied"); retval = &EG(error_zval_ptr); - new_zval->refcount--; + new_zval->refcount--; } } else { - retval = zend_fetch_dimension_address_inner(container->value.ht, dim, type TSRMLS_CC); + retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, type TSRMLS_CC); } if (result) { result->var.ptr_ptr = retval; @@ -1121,7 +1110,20 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container zend_error_noreturn(E_ERROR, "[] operator not supported for strings"); } - if (dim->type != IS_LONG) { + if (Z_TYPE_P(dim) != IS_LONG) { + switch(Z_TYPE_P(dim)) { + /* case IS_LONG: */ + case IS_STRING: + case IS_DOUBLE: + case IS_NULL: + case IS_BOOL: + /* do nothing */ + break; + default: + zend_error(E_WARNING, "Illegal offset type"); + break; + } + tmp = *dim; zval_copy_ctor(&tmp); convert_to_long(&tmp); @@ -1141,7 +1143,7 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container container = *container_ptr; result->str_offset.str = container; PZVAL_LOCK(container); - result->str_offset.offset = dim->value.lval; + result->str_offset.offset = Z_LVAL_P(dim); result->var.ptr_ptr = NULL; if (type == BP_VAR_R || type == BP_VAR_IS) { AI_USE_PTR(result->var); @@ -1155,19 +1157,19 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container zend_error_noreturn(E_ERROR, "Cannot use object as array"); } else { zval *overloaded_result; - + if (dim_is_tmp_var) { zval *orig = dim; MAKE_REAL_ZVAL_PTR(dim); ZVAL_NULL(orig); - } + } overloaded_result = Z_OBJ_HT_P(container)->read_dimension(container, dim, type TSRMLS_CC); if (overloaded_result) { switch (type) { case BP_VAR_RW: case BP_VAR_W: - if (overloaded_result->type != IS_OBJECT + if (Z_TYPE_P(overloaded_result) != IS_OBJECT && !overloaded_result->is_ref) { zend_error_noreturn(E_ERROR, "Objects used as arrays in post/pre increment/decrement must return values by reference"); } @@ -1193,7 +1195,7 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container return; } break; - default: { + default: { switch (type) { case BP_VAR_UNSET: zend_error(E_WARNING, "Cannot unset offset in a non-array variable"); @@ -1224,7 +1226,7 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container static void zend_fetch_property_address(temp_variable *result, zval **container_ptr, zval *prop_ptr, int type TSRMLS_DC) { zval *container; - + container = *container_ptr; if (container == EG(error_zval_ptr)) { if (result) { @@ -1234,9 +1236,9 @@ static void zend_fetch_property_address(temp_variable *result, zval **container_ return; } /* this should modify object only if it's empty */ - if (container->type == IS_NULL - || (container->type == IS_BOOL && container->value.lval==0) - || (container->type == IS_STRING && container->value.str.len == 0)) { + if (Z_TYPE_P(container) == IS_NULL + || (Z_TYPE_P(container) == IS_BOOL && Z_LVAL_P(container)==0) + || (Z_TYPE_P(container) == IS_STRING && Z_STRLEN_P(container)==0)) { switch (type) { case BP_VAR_RW: case BP_VAR_W: @@ -1248,8 +1250,8 @@ static void zend_fetch_property_address(temp_variable *result, zval **container_ break; } } - - if (container->type != IS_OBJECT) { + + if (Z_TYPE_P(container) != IS_OBJECT) { if (result) { if (type == BP_VAR_R || type == BP_VAR_IS) { result->var.ptr_ptr = &EG(uninitialized_zval_ptr); @@ -1260,14 +1262,14 @@ static void zend_fetch_property_address(temp_variable *result, zval **container_ } return; } - + if (Z_OBJ_HT_P(container)->get_property_ptr_ptr) { zval **ptr_ptr = Z_OBJ_HT_P(container)->get_property_ptr_ptr(container, prop_ptr TSRMLS_CC); - if(NULL == ptr_ptr) { + if (NULL == ptr_ptr) { zval *ptr; if (Z_OBJ_HT_P(container)->read_property && - (ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, BP_VAR_W TSRMLS_CC)) != NULL) { + (ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC)) != NULL) { if (result) { result->var.ptr = ptr; result->var.ptr_ptr = &result->var.ptr; @@ -1280,7 +1282,7 @@ static void zend_fetch_property_address(temp_variable *result, zval **container_ } } else if (Z_OBJ_HT_P(container)->read_property) { if (result) { - result->var.ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, BP_VAR_W TSRMLS_CC); + result->var.ptr = Z_OBJ_HT_P(container)->read_property(container, prop_ptr, type TSRMLS_CC); result->var.ptr_ptr = &result->var.ptr; } } else { @@ -1289,10 +1291,10 @@ static void zend_fetch_property_address(temp_variable *result, zval **container_ result->var.ptr_ptr = &EG(error_zval_ptr); } } - + if (result) { PZVAL_LOCK(*result->var.ptr_ptr); - } + } } static inline zend_brk_cont_element* zend_brk_cont(zval *nest_levels_zval, int array_offset, zend_op_array *op_array, temp_variable *Ts TSRMLS_DC) @@ -1347,7 +1349,7 @@ static int zend_check_symbol(zval **pz TSRMLS_DC) } else if (Z_TYPE_PP(pz) == IS_ARRAY) { zend_hash_apply(Z_ARRVAL_PP(pz), (apply_func_t) zend_check_symbol TSRMLS_CC); } else if (Z_TYPE_PP(pz) == IS_OBJECT) { - + /* OBJ-TBI - doesn't support new object model! */ zend_hash_apply(Z_OBJPROP_PP(pz), (apply_func_t) zend_check_symbol TSRMLS_CC); } @@ -1369,13 +1371,13 @@ ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_v } #define ZEND_VM_NEXT_OPCODE() \ - CHECK_SYMBOL_TABLES() \ - EX(opline)++; \ - ZEND_VM_CONTINUE() + CHECK_SYMBOL_TABLES() \ + EX(opline)++; \ + ZEND_VM_CONTINUE() #define ZEND_VM_SET_OPCODE(new_op) \ - CHECK_SYMBOL_TABLES() \ - EX(opline) = new_op + CHECK_SYMBOL_TABLES() \ + EX(opline) = new_op #define ZEND_VM_JMP(new_op) \ CHECK_SYMBOL_TABLES() \ @@ -1383,21 +1385,21 @@ ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_v ZEND_VM_CONTINUE() #define ZEND_VM_INC_OPCODE() \ - if (!EG(exception)) { \ - CHECK_SYMBOL_TABLES() \ - EX(opline)++; \ - } + if (!EG(exception)) { \ + CHECK_SYMBOL_TABLES() \ + EX(opline)++; \ + } #define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \ - free_alloca(EX(CVs)); \ - if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \ - free_alloca(EX(Ts)); \ - } else { \ - efree(EX(Ts)); \ - } \ - EG(in_execution) = EX(original_in_execution); \ - EG(current_execute_data) = EX(prev_execute_data); \ - ZEND_VM_RETURN() + free_alloca(EX(CVs)); \ + if (EX(op_array)->T < TEMP_VAR_STACK_LIMIT) { \ + free_alloca(EX(Ts)); \ + } else { \ + efree(EX(Ts)); \ + } \ + EG(in_execution) = EX(original_in_execution); \ + EG(current_execute_data) = EX(prev_execute_data); \ + ZEND_VM_RETURN() #include "zend_vm_execute.h" |
