]> granicus.if.org Git - php/commitdiff
Use better data structures (incomplete)
authorDmitry Stogov <dmitry@zend.com>
Tue, 18 Feb 2014 14:10:54 +0000 (18:10 +0400)
committerDmitry Stogov <dmitry@zend.com>
Tue, 18 Feb 2014 14:10:54 +0000 (18:10 +0400)
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_generators.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
sapi/phpdbg/phpdbg_frame.c

index 563be71629d7f6e0c1f28625f2a8fc932cfed5e8..050cc4799330d690b044f8cb1e5fdcf7536729c5 100644 (file)
@@ -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;
index cf3f84e2b5ab669d25e68bf3f839881cf963b5fd..ee450f7330183c6ccd7e309f311e063e4b0b20fb 100644 (file)
@@ -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;
index 491fbe24a70787bdc157faf6742d604c4393da00..d6b4a3b0adedabb06bc1f5bd64c046924992c456 100644 (file)
@@ -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
index 04c57366f13e63ecbd3a239c2c6cdf3dd1b32e5e..bf8d19c404aca0ad015982ba057012e0faf81b42 100644 (file)
@@ -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);
                        }
                }
        }
index edcd3c9bb4cc3771ecebde3f1627efa4877af8a6..d4b63415260d17111c7ba48dfd452f6226749cac 100644 (file)
@@ -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);
                        }
                }
        }
index 036bd3cea8f9c53bbc2f4d584255ce948a00abf1..133eaff1abbaab284186bd298a24f1629dcadb5d 100644 (file)
@@ -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);