From bb58ea348ca2c49a00417c75cc6cd64b5734a885 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 18 Feb 2014 18:10:54 +0400 Subject: [PATCH] Use better data structures (incomplete) --- Zend/zend_compile.h | 7 ++++--- Zend/zend_execute.c | 2 +- Zend/zend_generators.c | 16 +++++++--------- Zend/zend_vm_def.h | 20 ++++++++++---------- Zend/zend_vm_execute.h | 26 +++++++++++++------------- sapi/phpdbg/phpdbg_frame.c | 12 ++++++------ 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 563be71629..050cc47993 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -384,9 +384,10 @@ struct _zend_execute_data { zval old_error_reporting; zend_bool nested; zval *return_value; -//??? zend_class_entry *current_scope; -//??? zend_class_entry *current_called_scope; -//??? zval *current_this; +//??? + zend_class_entry *current_scope; + zend_class_entry *current_called_scope; + zval current_this; struct _zend_op *fast_ret; /* used by FAST_CALL/FAST_RET (finally keyword) */ zend_object *delayed_exception; call_slot *call_slots; diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index cf3f84e2b5..ee450f7330 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1572,7 +1572,7 @@ static zend_always_inline zend_execute_data *i_create_execute_data_from_op_array EG(argument_stack)->top = (zval*)zend_vm_stack_frame_base(execute_data); ZVAL_UNDEF(&EX(object)); -//??? EX(current_this) = NULL; + ZVAL_UNDEF(&EX(current_this)); ZVAL_UNDEF(&EX(old_error_reporting)); EX(symbol_table) = EG(active_symbol_table); EX(call) = NULL; diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 491fbe24a7..d6b4a3b0ad 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -116,9 +116,7 @@ ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished zend_clean_and_cache_symbol_table(execute_data->symbol_table TSRMLS_CC); } -//??? if (execute_data->current_this) { -//??? zval_ptr_dtor(&execute_data->current_this); -//??? } + zval_ptr_dtor(&execute_data->current_this); /* A fatal error / die occurred during the generator execution. Trying to clean * up the stack may not be safe in this case. */ @@ -294,10 +292,10 @@ ZEND_API void zend_generator_create_zval(zend_op_array *op_array, zval *return_v } /* Back up executor globals. */ -//??? execute_data->current_scope = EG(scope); -//??? execute_data->current_called_scope = EG(called_scope); + execute_data->current_scope = EG(scope); + execute_data->current_called_scope = EG(called_scope); execute_data->symbol_table = EG(active_symbol_table); -//??? execute_data->current_this = EG(This); + ZVAL_COPY_VALUE(&execute_data->current_this, &EG(This)); /* Save execution context in generator object. */ generator = (zend_generator *) Z_OBJ_P(return_value); @@ -347,9 +345,9 @@ ZEND_API void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ EG(opline_ptr) = &generator->execute_data->opline; EG(active_op_array) = generator->execute_data->op_array; EG(active_symbol_table) = generator->execute_data->symbol_table; -//??? EG(This) = generator->execute_data->current_this; -//??? EG(scope) = generator->execute_data->current_scope; -//??? EG(called_scope) = generator->execute_data->current_called_scope; + ZVAL_COPY_VALUE(&EG(This), &generator->execute_data->current_this); + EG(scope) = generator->execute_data->current_scope; + EG(called_scope) = generator->execute_data->current_called_scope; EG(argument_stack) = generator->stack; /* We want the backtrace to look as if the generator function was diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 04c57366f1..bf8d19c404 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -1804,9 +1804,9 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) } zval_ptr_dtor(&EG(This)); } -//??? EG(This) = EX(current_this); -//??? EG(scope) = EX(current_scope); -//??? EG(called_scope) = EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &EX(current_this)); + EG(scope) = EX(current_scope); + EG(called_scope) = EX(current_called_scope); EX(call)--; @@ -1869,9 +1869,9 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY) if (fbc->type == ZEND_USER_FUNCTION || fbc->common.scope) { should_change_scope = 1; -//??? EX(current_this) = EG(This); -//??? EX(current_scope) = EG(scope); -//??? EX(current_called_scope) = EG(called_scope); + ZVAL_COPY_VALUE(&EX(current_this), &EG(This)); + EX(current_scope) = EG(scope); + EX(current_called_scope) = EG(called_scope); EG(This) = EX(object); EG(scope) = (fbc->type == ZEND_USER_FUNCTION || Z_TYPE(EX(object)) == IS_UNDEF) ? fbc->common.scope : NULL; EG(called_scope) = EX(call)->called_scope; @@ -1991,9 +1991,9 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY) } zval_ptr_dtor(&EG(This)); } -//??? EG(This) = EX(current_this); -//??? EG(scope) = EX(current_scope); -//??? EG(called_scope) = EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &EX(current_this)); + EG(scope) = EX(current_scope); + EG(called_scope) = EX(current_called_scope); } EX(call)--; @@ -2752,7 +2752,7 @@ ZEND_VM_HANDLER(62, ZEND_RETURN, CONST|TMP|VAR|CV, ANY) } else { ZVAL_COPY_VALUE(EX(return_value), retval_ptr); if (OP1_TYPE == IS_CV) { - Z_ADDREF_P(retval_ptr); + if (IS_REFCOUNTED(Z_TYPE_P(retval_ptr))) Z_ADDREF_P(retval_ptr); } } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index edcd3c9bb4..d4b6341526 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -444,9 +444,9 @@ static int ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS) } zval_ptr_dtor(&EG(This)); } -//??? EG(This) = EX(current_this); -//??? EG(scope) = EX(current_scope); -//??? EG(called_scope) = EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &EX(current_this)); + EG(scope) = EX(current_scope); + EG(called_scope) = EX(current_called_scope); EX(call)--; @@ -509,9 +509,9 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR if (fbc->type == ZEND_USER_FUNCTION || fbc->common.scope) { should_change_scope = 1; -//??? EX(current_this) = EG(This); -//??? EX(current_scope) = EG(scope); -//??? EX(current_called_scope) = EG(called_scope); + ZVAL_COPY_VALUE(&EX(current_this), &EG(This)); + EX(current_scope) = EG(scope); + EX(current_called_scope) = EG(called_scope); EG(This) = EX(object); EG(scope) = (fbc->type == ZEND_USER_FUNCTION || Z_TYPE(EX(object)) == IS_UNDEF) ? fbc->common.scope : NULL; EG(called_scope) = EX(call)->called_scope; @@ -631,9 +631,9 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR } zval_ptr_dtor(&EG(This)); } -//??? EG(This) = EX(current_this); -//??? EG(scope) = EX(current_scope); -//??? EG(called_scope) = EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &EX(current_this)); + EG(scope) = EX(current_scope); + EG(called_scope) = EX(current_called_scope); } EX(call)--; @@ -2564,7 +2564,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG } else { ZVAL_COPY_VALUE(EX(return_value), retval_ptr); if (IS_CONST == IS_CV) { - Z_ADDREF_P(retval_ptr); + if (IS_REFCOUNTED(Z_TYPE_P(retval_ptr))) Z_ADDREF_P(retval_ptr); } } } @@ -7531,7 +7531,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } else { ZVAL_COPY_VALUE(EX(return_value), retval_ptr); if (IS_TMP_VAR == IS_CV) { - Z_ADDREF_P(retval_ptr); + if (IS_REFCOUNTED(Z_TYPE_P(retval_ptr))) Z_ADDREF_P(retval_ptr); } } } @@ -12416,7 +12416,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } else { ZVAL_COPY_VALUE(EX(return_value), retval_ptr); if (IS_VAR == IS_CV) { - Z_ADDREF_P(retval_ptr); + if (IS_REFCOUNTED(Z_TYPE_P(retval_ptr))) Z_ADDREF_P(retval_ptr); } } } @@ -29009,7 +29009,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) } else { ZVAL_COPY_VALUE(EX(return_value), retval_ptr); if (IS_CV == IS_CV) { - Z_ADDREF_P(retval_ptr); + if (IS_REFCOUNTED(Z_TYPE_P(retval_ptr))) Z_ADDREF_P(retval_ptr); } } } diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index 036bd3cea8..133eaff1ab 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -40,9 +40,9 @@ void phpdbg_restore_frame(TSRMLS_D) /* {{{ */ EG(opline_ptr) = &PHPDBG_EX(opline); EG(active_op_array) = PHPDBG_EX(op_array); EG(active_symbol_table) = PHPDBG_EX(symbol_table); - //!!!EG(This) = PHPDBG_EX(current_this); - //!!!EG(scope) = PHPDBG_EX(current_scope); - //!!!EG(called_scope) = PHPDBG_EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &PHPDBG_EX(current_this)); + EG(scope) = PHPDBG_EX(current_scope); + EG(called_scope) = PHPDBG_EX(current_called_scope); } /* }}} */ void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */ @@ -82,9 +82,9 @@ void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */ EG(opline_ptr) = &PHPDBG_EX(opline); EG(active_op_array) = PHPDBG_EX(op_array); EG(active_symbol_table) = PHPDBG_EX(symbol_table); - //!!!EG(This) = PHPDBG_EX(current_this); - //!!!EG(scope) = PHPDBG_EX(current_scope); - //!!!EG(called_scope) = PHPDBG_EX(current_called_scope); + ZVAL_COPY_VALUE(&EG(This), &PHPDBG_EX(current_this)); + EG(scope) = PHPDBG_EX(current_scope); + EG(called_scope) = PHPDBG_EX(current_called_scope); } phpdbg_notice("Switched to frame #%d", frame); -- 2.40.0