cvs: ZendEngine2 / zend_compile.h zend_extensions.h zend_ptr_stack.h zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h /tests bug31177-2.phpt
| From: | Dmitry Stogov | Date: | Thu, 20 Oct 2005 07:24:00 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.h zend_extensions.h zend_ptr_stack.h zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h /tests bug31177-2.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4260@lists.php.net to get a copy of this message | ||
dmitry Thu Oct 20 03:24:00 2005 EDT
Modified files:
/ZendEngine2 zend_compile.h zend_extensions.h zend_ptr_stack.h
zend_vm_def.h zend_vm_execute.h zend_vm_opcodes.h
/ZendEngine2/tests bug31177-2.phpt
Log:
Fixed bug #31177 (menory leaks and corruption because of incorrect refcounting)
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.325&r2=1.326&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.325 ZendEngine2/zend_compile.h:1.326 --- ZendEngine2/zend_compile.h:1.325 Tue Sep 27 03:59:00 2005 +++ ZendEngine2/zend_compile.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.325 2005/09/27 07:59:00 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.326 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -296,7 +296,6 @@ union _temp_variable *Ts; zval ***CVs; zend_bool original_in_execution; - zend_class_entry *calling_scope; HashTable *symbol_table; struct _zend_execute_data *prev_execute_data; zval *old_error_reporting; http://cvs.php.net/diff.php/ZendEngine2/zend_extensions.h?r1=1.68&r2=1.69&ty=u Index: ZendEngine2/zend_extensions.h diff -u ZendEngine2/zend_extensions.h:1.68 ZendEngine2/zend_extensions.h:1.69 --- ZendEngine2/zend_extensions.h:1.68 Tue Aug 9 04:47:55 2005 +++ ZendEngine2/zend_extensions.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_extensions.h,v 1.68 2005/08/09 08:47:55 derick Exp $ */ +/* $Id: zend_extensions.h,v 1.69 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_EXTENSIONS_H #define ZEND_EXTENSIONS_H @@ -27,7 +27,7 @@ /* The first number is the engine version and the rest is the date. * This way engine 2 API no. is always greater than engine 1 API no.. */ -#define ZEND_EXTENSION_API_NO 220050809 +#define ZEND_EXTENSION_API_NO 220050920 typedef struct _zend_extension_version_info { int zend_extension_api_no; http://cvs.php.net/diff.php/ZendEngine2/zend_ptr_stack.h?r1=1.22&r2=1.23&ty=u Index: ZendEngine2/zend_ptr_stack.h diff -u ZendEngine2/zend_ptr_stack.h:1.22 ZendEngine2/zend_ptr_stack.h:1.23 --- ZendEngine2/zend_ptr_stack.h:1.22 Wed Aug 3 09:30:56 2005 +++ ZendEngine2/zend_ptr_stack.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_ptr_stack.h,v 1.22 2005/08/03 13:30:56 sniper Exp $ */ +/* $Id: zend_ptr_stack.h,v 1.23 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_PTR_STACK_H #define ZEND_PTR_STACK_H @@ -84,7 +84,14 @@ *a = *(--stack->top_element); *b = *(--stack->top_element); *c = *(--stack->top_element); - stack->top -= 3;; + stack->top -= 3; +} + +static inline void zend_ptr_stack_2_pop(zend_ptr_stack *stack, void **a, void **b) +{ + *a = *(--stack->top_element); + *b = *(--stack->top_element); + stack->top -= 2; } static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr) http://cvs.php.net/diff.php/ZendEngine2/zend_vm_def.h?r1=1.81&r2=1.82&ty=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.81 ZendEngine2/zend_vm_def.h:1.82 --- ZendEngine2/zend_vm_def.h:1.81 Mon Oct 10 06:54:42 2005 +++ ZendEngine2/zend_vm_def.h Thu Oct 20 03:23:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.81 2005/10/10 10:54:42 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.82 2005/10/20 07:23:57 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -889,11 +889,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -1663,7 +1663,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = GET_OP2_ZVAL_PTR(BP_VAR_R); @@ -1674,8 +1674,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_R); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -1706,12 +1704,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - FREE_OP2(); FREE_OP1_IF_VAR(); @@ -1724,7 +1716,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(OP2_TYPE != IS_UNUSED) { @@ -1758,8 +1750,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1780,7 +1770,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (OP2_TYPE == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1805,7 +1795,6 @@ FREE_OP2(); } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1822,6 +1811,7 @@ zval *current_this; int return_value_used = RETURN_VALUE_USED(opline); zend_bool should_change_scope; + zend_op *ctor_opline; if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) { /* FIXME: output identifiers properly */ @@ -1839,7 +1829,7 @@ current_this = EG(This); EG(This) = EX(object); current_scope = EG(scope); - EG(scope) = EX(calling_scope); + EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL; } else { should_change_scope = 0; } @@ -1968,16 +1958,18 @@ } } + ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EG(This)) { - if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { - EG(This)->refcount--; + if (EG(exception) && ctor_opline) { + if (RETURN_VALUE_USED(ctor_opline)) { + EG(This)->refcount--; + } if (EG(This)->refcount == 1) { zend_object_store_ctor_failed(EG(This) TSRMLS_CC); } - if (should_change_scope && EG(This) != current_this) { - zval_ptr_dtor(&EG(This)); - } - } else if (should_change_scope) { + } + if (should_change_scope) { zval_ptr_dtor(&EG(This)); } } @@ -1986,7 +1978,7 @@ EG(This) = current_this; EG(scope) = current_scope; } - zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); EX(function_state).function = (zend_function *) EX(op_array); EG(function_state_ptr) = &EX(function_state); @@ -2014,14 +2006,13 @@ zend_free_op free_op1; zval *fname = GET_OP1_ZVAL_PTR(BP_VAR_R); - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) { /* FIXME: output identifiers properly */ zend_error_noreturn(E_ERROR, "Unknown function: %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname)); } EX(object) = NULL; - EX(calling_scope) = EX(function_state).function->common.scope; FREE_OP1(); @@ -2478,17 +2469,12 @@ EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr; EX_T(opline->result.u.var).var.ptr = object_zval; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline); /* We are not handling overloaded classes right now */ EX(object) = object_zval; EX(fbc) = constructor; - if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */ - EX(calling_scope) = constructor->common.scope; - } else { - EX(calling_scope) = NULL; - } ZEND_VM_NEXT_OPCODE(); } } @@ -3762,10 +3748,15 @@ } while (EX(fbc)) { + zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EX(object)) { + if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) { + EX(object)->refcount--; + } zval_ptr_dtor(&EX(object)); } - zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } /* restore previous error_reporting value */ http://cvs.php.net/diff.php/ZendEngine2/zend_vm_execute.h?r1=1.84&r2=1.85&ty=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.84 ZendEngine2/zend_vm_execute.h:1.85 --- ZendEngine2/zend_vm_execute.h:1.84 Mon Oct 10 06:54:43 2005 +++ ZendEngine2/zend_vm_execute.h Thu Oct 20 03:23:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.84 2005/10/10 10:54:43 dmitry Exp $ */ +/* $Id: zend_vm_execute.h,v 1.85 2005/10/20 07:23:57 dmitry Exp $ */ static opcode_handler_t zend_user_opcode_handlers[256] = {(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL}; @@ -133,6 +133,7 @@ zval *current_this; int return_value_used = RETURN_VALUE_USED(opline); zend_bool should_change_scope; + zend_op *ctor_opline; if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) { /* FIXME: output identifiers properly */ @@ -150,7 +151,7 @@ current_this = EG(This); EG(This) = EX(object); current_scope = EG(scope); - EG(scope) = EX(calling_scope); + EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL; } else { should_change_scope = 0; } @@ -279,16 +280,18 @@ } } + ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EG(This)) { - if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { - EG(This)->refcount--; + if (EG(exception) && ctor_opline) { + if (RETURN_VALUE_USED(ctor_opline)) { + EG(This)->refcount--; + } if (EG(This)->refcount == 1) { zend_object_store_ctor_failed(EG(This) TSRMLS_CC); } - if (should_change_scope && EG(This) != current_this) { - zval_ptr_dtor(&EG(This)); - } - } else if (should_change_scope) { + } + if (should_change_scope) { zval_ptr_dtor(&EG(This)); } } @@ -297,7 +300,7 @@ EG(This) = current_this; EG(scope) = current_scope; } - zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); EX(function_state).function = (zend_function *) EX(op_array); EG(function_state_ptr) = &EX(function_state); @@ -419,17 +422,12 @@ EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr; EX_T(opline->result.u.var).var.ptr = object_zval; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline); /* We are not handling overloaded classes right now */ EX(object) = object_zval; EX(fbc) = constructor; - if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */ - EX(calling_scope) = constructor->common.scope; - } else { - EX(calling_scope) = NULL; - } ZEND_VM_NEXT_OPCODE(); } } @@ -557,10 +555,15 @@ } while (EX(fbc)) { + zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EX(object)) { + if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) { + EX(object)->refcount--; + } zval_ptr_dtor(&EX(object)); } - zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } /* restore previous error_reporting value */ @@ -639,7 +642,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_CONST != IS_UNUSED) { @@ -673,8 +676,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -695,7 +696,7 @@ unsigned int function_name_strlen, lcname_len; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_CONST == IS_CONST) { function_name = &opline->op2.u.constant; @@ -720,7 +721,6 @@ } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -835,7 +835,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_TMP_VAR != IS_UNUSED) { @@ -869,8 +869,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -891,7 +889,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_TMP_VAR == IS_CONST) { function_name = &opline->op2.u.constant; @@ -916,7 +914,6 @@ zval_dtor(free_op2.var); } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -988,7 +985,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_VAR != IS_UNUSED) { @@ -1022,8 +1019,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1044,7 +1039,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_VAR == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1069,7 +1064,6 @@ if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1140,7 +1134,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_UNUSED != IS_UNUSED) { @@ -1174,8 +1168,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1223,7 +1215,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_CV != IS_UNUSED) { @@ -1257,8 +1249,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1279,7 +1269,7 @@ unsigned int function_name_strlen, lcname_len; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_CV == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1304,7 +1294,6 @@ } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1372,11 +1361,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -1621,14 +1610,13 @@ zval *fname = &opline->op1.u.constant; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) { /* FIXME: output identifiers properly */ zend_error_noreturn(E_ERROR, "Unknown function: %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname)); } EX(object) = NULL; - EX(calling_scope) = EX(function_state).function->common.scope; return zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); } @@ -3878,11 +3866,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -5146,7 +5134,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -5157,8 +5145,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -5189,12 +5175,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -5589,7 +5569,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -5600,8 +5580,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -5632,12 +5610,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -6034,7 +6006,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -6045,8 +6017,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -6077,12 +6047,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -6561,7 +6525,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -6572,8 +6536,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -6604,12 +6566,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -6923,11 +6879,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -9140,7 +9096,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -9151,8 +9107,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -9183,12 +9137,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); @@ -10635,7 +10583,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -10646,8 +10594,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -10678,12 +10624,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -12170,7 +12110,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -12181,8 +12121,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -12213,12 +12151,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -14111,7 +14043,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -14122,8 +14054,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -14154,12 +14084,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); @@ -15326,7 +15250,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -15337,8 +15261,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -15369,12 +15291,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -16476,7 +16392,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -16487,8 +16403,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -16519,12 +16433,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -17584,7 +17492,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -17595,8 +17503,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -17627,12 +17533,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -19058,7 +18958,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -19069,8 +18969,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -19101,12 +18999,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -19696,11 +19588,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -21737,7 +21629,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -21748,8 +21640,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -21780,12 +21670,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -23224,7 +23108,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -23235,8 +23119,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -23267,12 +23149,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -24750,7 +24626,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -24761,8 +24637,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -24793,12 +24667,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -26681,7 +26549,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -26692,8 +26560,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -26724,12 +26590,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_opcodes.h?r1=1.61&r2=1.62&ty=u Index: ZendEngine2/zend_vm_opcodes.h diff -u ZendEngine2/zend_vm_opcodes.h:1.61 ZendEngine2/zend_vm_opcodes.h:1.62 --- ZendEngine2/zend_vm_opcodes.h:1.61 Mon Oct 10 06:54:44 2005 +++ ZendEngine2/zend_vm_opcodes.h Thu Oct 20 03:23:58 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.61 2005/10/10 10:54:44 dmitry Exp $ */ +/* $Id: zend_vm_opcodes.h,v 1.62 2005/10/20 07:23:58 dmitry Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1 http://cvs.php.net/diff.php/ZendEngine2/tests/bug31177-2.phpt?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/tests/bug31177-2.phpt diff -u /dev/null ZendEngine2/tests/bug31177-2.phpt:1.2 --- /dev/null Thu Oct 20 03:24:00 2005 +++ ZendEngine2/tests/bug31177-2.phpt Thu Oct 20 03:23:58 2005 @@ -0,0 +1,18 @@ +--TEST-- +Bug #31177 (menory corruption because of incorrect refcounting) +--FILE-- +<?php +class foo { + function foo($n=0) { + if($n) throw new Exception("new"); + } +} +$x = new foo(); +try { + $y=$x->foo(1); +} catch (Exception $e) { + var_dump($x); +} +--EXPECT-- +object(foo)#1 (0) { +}
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.h?r1=1.325&r2=1.326&ty=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.325 ZendEngine2/zend_compile.h:1.326 --- ZendEngine2/zend_compile.h:1.325 Tue Sep 27 03:59:00 2005 +++ ZendEngine2/zend_compile.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.325 2005/09/27 07:59:00 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.326 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -296,7 +296,6 @@ union _temp_variable *Ts; zval ***CVs; zend_bool original_in_execution; - zend_class_entry *calling_scope; HashTable *symbol_table; struct _zend_execute_data *prev_execute_data; zval *old_error_reporting; http://cvs.php.net/diff.php/ZendEngine2/zend_extensions.h?r1=1.68&r2=1.69&ty=u Index: ZendEngine2/zend_extensions.h diff -u ZendEngine2/zend_extensions.h:1.68 ZendEngine2/zend_extensions.h:1.69 --- ZendEngine2/zend_extensions.h:1.68 Tue Aug 9 04:47:55 2005 +++ ZendEngine2/zend_extensions.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_extensions.h,v 1.68 2005/08/09 08:47:55 derick Exp $ */ +/* $Id: zend_extensions.h,v 1.69 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_EXTENSIONS_H #define ZEND_EXTENSIONS_H @@ -27,7 +27,7 @@ /* The first number is the engine version and the rest is the date. * This way engine 2 API no. is always greater than engine 1 API no.. */ -#define ZEND_EXTENSION_API_NO 220050809 +#define ZEND_EXTENSION_API_NO 220050920 typedef struct _zend_extension_version_info { int zend_extension_api_no; http://cvs.php.net/diff.php/ZendEngine2/zend_ptr_stack.h?r1=1.22&r2=1.23&ty=u Index: ZendEngine2/zend_ptr_stack.h diff -u ZendEngine2/zend_ptr_stack.h:1.22 ZendEngine2/zend_ptr_stack.h:1.23 --- ZendEngine2/zend_ptr_stack.h:1.22 Wed Aug 3 09:30:56 2005 +++ ZendEngine2/zend_ptr_stack.h Thu Oct 20 03:23:57 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_ptr_stack.h,v 1.22 2005/08/03 13:30:56 sniper Exp $ */ +/* $Id: zend_ptr_stack.h,v 1.23 2005/10/20 07:23:57 dmitry Exp $ */ #ifndef ZEND_PTR_STACK_H #define ZEND_PTR_STACK_H @@ -84,7 +84,14 @@ *a = *(--stack->top_element); *b = *(--stack->top_element); *c = *(--stack->top_element); - stack->top -= 3;; + stack->top -= 3; +} + +static inline void zend_ptr_stack_2_pop(zend_ptr_stack *stack, void **a, void **b) +{ + *a = *(--stack->top_element); + *b = *(--stack->top_element); + stack->top -= 2; } static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr) http://cvs.php.net/diff.php/ZendEngine2/zend_vm_def.h?r1=1.81&r2=1.82&ty=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.81 ZendEngine2/zend_vm_def.h:1.82 --- ZendEngine2/zend_vm_def.h:1.81 Mon Oct 10 06:54:42 2005 +++ ZendEngine2/zend_vm_def.h Thu Oct 20 03:23:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.81 2005/10/10 10:54:42 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.82 2005/10/20 07:23:57 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -889,11 +889,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -1663,7 +1663,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = GET_OP2_ZVAL_PTR(BP_VAR_R); @@ -1674,8 +1674,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_R); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -1706,12 +1704,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - FREE_OP2(); FREE_OP1_IF_VAR(); @@ -1724,7 +1716,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(OP2_TYPE != IS_UNUSED) { @@ -1758,8 +1750,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1780,7 +1770,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (OP2_TYPE == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1805,7 +1795,6 @@ FREE_OP2(); } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1822,6 +1811,7 @@ zval *current_this; int return_value_used = RETURN_VALUE_USED(opline); zend_bool should_change_scope; + zend_op *ctor_opline; if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) { /* FIXME: output identifiers properly */ @@ -1839,7 +1829,7 @@ current_this = EG(This); EG(This) = EX(object); current_scope = EG(scope); - EG(scope) = EX(calling_scope); + EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL; } else { should_change_scope = 0; } @@ -1968,16 +1958,18 @@ } } + ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EG(This)) { - if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { - EG(This)->refcount--; + if (EG(exception) && ctor_opline) { + if (RETURN_VALUE_USED(ctor_opline)) { + EG(This)->refcount--; + } if (EG(This)->refcount == 1) { zend_object_store_ctor_failed(EG(This) TSRMLS_CC); } - if (should_change_scope && EG(This) != current_this) { - zval_ptr_dtor(&EG(This)); - } - } else if (should_change_scope) { + } + if (should_change_scope) { zval_ptr_dtor(&EG(This)); } } @@ -1986,7 +1978,7 @@ EG(This) = current_this; EG(scope) = current_scope; } - zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); EX(function_state).function = (zend_function *) EX(op_array); EG(function_state_ptr) = &EX(function_state); @@ -2014,14 +2006,13 @@ zend_free_op free_op1; zval *fname = GET_OP1_ZVAL_PTR(BP_VAR_R); - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) { /* FIXME: output identifiers properly */ zend_error_noreturn(E_ERROR, "Unknown function: %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname)); } EX(object) = NULL; - EX(calling_scope) = EX(function_state).function->common.scope; FREE_OP1(); @@ -2478,17 +2469,12 @@ EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr; EX_T(opline->result.u.var).var.ptr = object_zval; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline); /* We are not handling overloaded classes right now */ EX(object) = object_zval; EX(fbc) = constructor; - if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */ - EX(calling_scope) = constructor->common.scope; - } else { - EX(calling_scope) = NULL; - } ZEND_VM_NEXT_OPCODE(); } } @@ -3762,10 +3748,15 @@ } while (EX(fbc)) { + zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EX(object)) { + if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) { + EX(object)->refcount--; + } zval_ptr_dtor(&EX(object)); } - zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } /* restore previous error_reporting value */ http://cvs.php.net/diff.php/ZendEngine2/zend_vm_execute.h?r1=1.84&r2=1.85&ty=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.84 ZendEngine2/zend_vm_execute.h:1.85 --- ZendEngine2/zend_vm_execute.h:1.84 Mon Oct 10 06:54:43 2005 +++ ZendEngine2/zend_vm_execute.h Thu Oct 20 03:23:57 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_execute.h,v 1.84 2005/10/10 10:54:43 dmitry Exp $ */ +/* $Id: zend_vm_execute.h,v 1.85 2005/10/20 07:23:57 dmitry Exp $ */ static opcode_handler_t zend_user_opcode_handlers[256] = {(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL,(opcode_handler_t)NULL}; @@ -133,6 +133,7 @@ zval *current_this; int return_value_used = RETURN_VALUE_USED(opline); zend_bool should_change_scope; + zend_op *ctor_opline; if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) { /* FIXME: output identifiers properly */ @@ -150,7 +151,7 @@ current_this = EG(This); EG(This) = EX(object); current_scope = EG(scope); - EG(scope) = EX(calling_scope); + EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL; } else { should_change_scope = 0; } @@ -279,16 +280,18 @@ } } + ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EG(This)) { - if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) { - EG(This)->refcount--; + if (EG(exception) && ctor_opline) { + if (RETURN_VALUE_USED(ctor_opline)) { + EG(This)->refcount--; + } if (EG(This)->refcount == 1) { zend_object_store_ctor_failed(EG(This) TSRMLS_CC); } - if (should_change_scope && EG(This) != current_this) { - zval_ptr_dtor(&EG(This)); - } - } else if (should_change_scope) { + } + if (should_change_scope) { zval_ptr_dtor(&EG(This)); } } @@ -297,7 +300,7 @@ EG(This) = current_this; EG(scope) = current_scope; } - zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); EX(function_state).function = (zend_function *) EX(op_array); EG(function_state_ptr) = &EX(function_state); @@ -419,17 +422,12 @@ EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr; EX_T(opline->result.u.var).var.ptr = object_zval; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline); /* We are not handling overloaded classes right now */ EX(object) = object_zval; EX(fbc) = constructor; - if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */ - EX(calling_scope) = constructor->common.scope; - } else { - EX(calling_scope) = NULL; - } ZEND_VM_NEXT_OPCODE(); } } @@ -557,10 +555,15 @@ } while (EX(fbc)) { + zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack)); + if (EX(object)) { + if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) { + EX(object)->refcount--; + } zval_ptr_dtor(&EX(object)); } - zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc)); + zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc)); } /* restore previous error_reporting value */ @@ -639,7 +642,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_CONST != IS_UNUSED) { @@ -673,8 +676,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -695,7 +696,7 @@ unsigned int function_name_strlen, lcname_len; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_CONST == IS_CONST) { function_name = &opline->op2.u.constant; @@ -720,7 +721,6 @@ } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -835,7 +835,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_TMP_VAR != IS_UNUSED) { @@ -869,8 +869,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -891,7 +889,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_TMP_VAR == IS_CONST) { function_name = &opline->op2.u.constant; @@ -916,7 +914,6 @@ zval_dtor(free_op2.var); } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -988,7 +985,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_VAR != IS_UNUSED) { @@ -1022,8 +1019,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1044,7 +1039,7 @@ unsigned int function_name_strlen, lcname_len; zend_free_op free_op2; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_VAR == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1069,7 +1064,6 @@ if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1140,7 +1134,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_UNUSED != IS_UNUSED) { @@ -1174,8 +1168,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1223,7 +1215,7 @@ zval *function_name; zend_class_entry *ce; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); ce = EX_T(opline->op1.u.var).class_entry; if(IS_CV != IS_UNUSED) { @@ -1257,8 +1249,6 @@ EX(fbc) = ce->constructor; } - EX(calling_scope) = EX(fbc)->common.scope; - if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) { EX(object) = NULL; } else { @@ -1279,7 +1269,7 @@ unsigned int function_name_strlen, lcname_len; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (IS_CV == IS_CONST) { function_name = &opline->op2.u.constant; @@ -1304,7 +1294,6 @@ } - EX(calling_scope) = function->common.scope; EX(object) = NULL; EX(fbc) = function; @@ -1372,11 +1361,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -1621,14 +1610,13 @@ zval *fname = &opline->op1.u.constant; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) { /* FIXME: output identifiers properly */ zend_error_noreturn(E_ERROR, "Unknown function: %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname)); } EX(object) = NULL; - EX(calling_scope) = EX(function_state).function->common.scope; return zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); } @@ -3878,11 +3866,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -5146,7 +5134,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -5157,8 +5145,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -5189,12 +5175,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -5589,7 +5569,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -5600,8 +5580,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -5632,12 +5610,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -6034,7 +6006,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -6045,8 +6017,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -6077,12 +6047,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -6561,7 +6525,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -6572,8 +6536,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -6604,12 +6566,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -6923,11 +6879,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -9140,7 +9096,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -9151,8 +9107,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -9183,12 +9137,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); @@ -10635,7 +10583,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -10646,8 +10594,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -10678,12 +10624,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -12170,7 +12110,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -12181,8 +12121,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -12213,12 +12151,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -14111,7 +14043,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -14122,8 +14054,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -14154,12 +14084,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); @@ -15326,7 +15250,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -15337,8 +15261,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -15369,12 +15291,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -16476,7 +16392,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -16487,8 +16403,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -16519,12 +16433,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -17584,7 +17492,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -17595,8 +17503,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -17627,12 +17533,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -19058,7 +18958,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -19069,8 +18969,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -19101,12 +18999,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -19696,11 +19588,11 @@ /* Convert inline HTML blocks to the output encoding, but only if necessary. */ if (opline->extended_value && strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status), - EG(active_op_array)->script_encoding)) { + EX(op_array)->script_encoding)) { zval z_conv; UConverter *script_enc_conv = NULL; - if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) { - zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding); + if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) { + zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding); } zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status); z_conv.type = IS_BINARY; @@ -21737,7 +21629,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = &opline->op2.u.constant; @@ -21748,8 +21640,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -21780,12 +21670,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } @@ -23224,7 +23108,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -23235,8 +23119,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -23267,12 +23149,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - zval_dtor(free_op2.var); ZEND_VM_NEXT_OPCODE(); @@ -24750,7 +24626,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC); @@ -24761,8 +24637,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -24793,12 +24667,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - if (free_op2.var) {zval_ptr_dtor(&free_op2.var);}; ZEND_VM_NEXT_OPCODE(); @@ -26681,7 +26549,7 @@ /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope)); + zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL); function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC); @@ -26692,8 +26560,6 @@ function_name_strval = Z_UNIVAL_P(function_name); function_name_strlen = Z_UNILEN_P(function_name); - EX(calling_scope) = EG(scope); - EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (EX(object) && EX(object)->type == IS_OBJECT) { @@ -26724,12 +26590,6 @@ } } - if (EX(fbc)->type == ZEND_USER_FUNCTION) { - EX(calling_scope) = EX(fbc)->common.scope; - } else { - EX(calling_scope) = NULL; - } - ZEND_VM_NEXT_OPCODE(); } http://cvs.php.net/diff.php/ZendEngine2/zend_vm_opcodes.h?r1=1.61&r2=1.62&ty=u Index: ZendEngine2/zend_vm_opcodes.h diff -u ZendEngine2/zend_vm_opcodes.h:1.61 ZendEngine2/zend_vm_opcodes.h:1.62 --- ZendEngine2/zend_vm_opcodes.h:1.61 Mon Oct 10 06:54:44 2005 +++ ZendEngine2/zend_vm_opcodes.h Thu Oct 20 03:23:58 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_opcodes.h,v 1.61 2005/10/10 10:54:44 dmitry Exp $ */ +/* $Id: zend_vm_opcodes.h,v 1.62 2005/10/20 07:23:58 dmitry Exp $ */ #define ZEND_NOP 0 #define ZEND_ADD 1 http://cvs.php.net/diff.php/ZendEngine2/tests/bug31177-2.phpt?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/tests/bug31177-2.phpt diff -u /dev/null ZendEngine2/tests/bug31177-2.phpt:1.2 --- /dev/null Thu Oct 20 03:24:00 2005 +++ ZendEngine2/tests/bug31177-2.phpt Thu Oct 20 03:23:58 2005 @@ -0,0 +1,18 @@ +--TEST-- +Bug #31177 (menory corruption because of incorrect refcounting) +--FILE-- +<?php +class foo { + function foo($n=0) { + if($n) throw new Exception("new"); + } +} +$x = new foo(); +try { + $y=$x->foo(1); +} catch (Exception $e) { + var_dump($x); +} +--EXPECT-- +object(foo)#1 (0) { +}