]> granicus.if.org Git - php/commitdiff
Use better data structures (incomplete)
authorDmitry Stogov <dmitry@zend.com>
Wed, 19 Feb 2014 08:03:01 +0000 (12:03 +0400)
committerDmitry Stogov <dmitry@zend.com>
Wed, 19 Feb 2014 08:03:01 +0000 (12:03 +0400)
Zend/zend_builtin_functions.c
Zend/zend_compile.c
Zend/zend_exceptions.c
Zend/zend_execute.c
Zend/zend_execute_API.c
Zend/zend_interfaces.c
Zend/zend_object_handlers.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

index 53780784fd55b9caab6870b1a132338528fc3b39..8daa7cdda48166df4b89194ba5090921433d6b8b 100644 (file)
@@ -1968,10 +1968,10 @@ static void debug_backtrace_get_args(zval *curpos, zval *arg_array TSRMLS_DC)
        while (--arg_count >= 0) {
                arg = p++;
                if (arg) {
-                       if (Z_TYPE_P(arg) != IS_OBJECT) {
-                               SEPARATE_ZVAL_TO_MAKE_IS_REF(arg);
-                       }
-                       Z_ADDREF_P(arg);
+//???                  if (Z_TYPE_P(arg) != IS_OBJECT) {
+//???                          SEPARATE_ZVAL_TO_MAKE_IS_REF(arg);
+//???                  }
+                       if (IS_REFCOUNTED(Z_TYPE_P(arg))) Z_ADDREF_P(arg);
                        add_next_index_zval(arg_array, arg);
                } else {
                        add_next_index_null(arg_array);
index 809f05f243809f1db98d1b7e0240b35fd7dcb708..327d4ce083f86300222d0952059cc4c70a5ba3a7 100644 (file)
@@ -889,7 +889,7 @@ void zend_do_abstract_method(const znode *function_name, znode *modifiers, const
 
        if (Z_LVAL(modifiers->u.constant) & ZEND_ACC_ABSTRACT) {
                if(Z_LVAL(modifiers->u.constant) & ZEND_ACC_PRIVATE) {
-                       zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private", method_type, CG(active_class_entry)->name, Z_STRVAL(function_name->u.constant));
+                       zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private", method_type, CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant));
                }
                if (Z_LVAL(body->u.constant) == ZEND_ACC_ABSTRACT) {
                        zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
@@ -899,11 +899,11 @@ void zend_do_abstract_method(const znode *function_name, znode *modifiers, const
                        SET_UNUSED(opline->op2);
                } else {
                        /* we had code in the function body */
-                       zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body", method_type, CG(active_class_entry)->name, Z_STRVAL(function_name->u.constant));
+                       zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body", method_type, CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant));
                }
        } else {
                if (Z_LVAL(body->u.constant) == ZEND_ACC_ABSTRACT) {
-                       zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body", CG(active_class_entry)->name, Z_STRVAL(function_name->u.constant));
+                       zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body", CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant));
                }
        }
 }
@@ -1540,7 +1540,7 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
        if (is_method) {
                if (CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) {
                        if ((Z_LVAL(fn_flags_znode->u.constant) & ~(ZEND_ACC_STATIC|ZEND_ACC_PUBLIC))) {
-                               zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method %s::%s() must be omitted", CG(active_class_entry)->name, Z_STRVAL(function_name->u.constant));
+                               zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method %s::%s() must be omitted", CG(active_class_entry)->name->val, Z_STRVAL(function_name->u.constant));
                        }
                        Z_LVAL(fn_flags_znode->u.constant) |= ZEND_ACC_ABSTRACT; /* propagates to the rest of the parser */
                }
@@ -5118,7 +5118,7 @@ void zend_do_begin_class_declaration(const znode *class_token, znode *class_name
                zend_do_build_namespace_name(&tmp, &tmp, class_name TSRMLS_CC);
                *class_name = tmp;
                STR_FREE(lcname);
-               STR_ALLOC(Z_STRLEN(class_name->u.constant), 0);
+               lcname = STR_ALLOC(Z_STRLEN(class_name->u.constant), 0);
                zend_str_tolower_copy(lcname->val, Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant));
        }
 
@@ -5407,7 +5407,7 @@ void zend_do_declare_property(znode *var_name, const znode *value, zend_uint acc
 
        if (access_type & ZEND_ACC_FINAL) {
                zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, the final modifier is allowed only for methods and classes",
-                                  CG(active_class_entry)->name, Z_STRVAL(var_name->u.constant));
+                                  CG(active_class_entry)->name->val, Z_STRVAL(var_name->u.constant));
        }
 
        if ((existing_property_info = zend_hash_find_ptr(&CG(active_class_entry)->properties_info, Z_STR(var_name->u.constant))) != NULL) {
index 196b9aa3208b06af1cd2edace6caa29bbf1b533c..9473751ae431228f3806e90642d2f8bc71ab917a 100644 (file)
@@ -363,9 +363,10 @@ ZEND_METHOD(error_exception, getSeverity)
 
 static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
 {
-       zend_string *str;
+       zend_string *str, **str_ptr;
 
-       str = va_arg(args, zend_string*);
+       str_ptr = va_arg(args, zend_string**);
+       str = *str_ptr;
 
        /* the trivial way would be to do:
         * conver_to_string_ex(arg);
@@ -373,6 +374,9 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze
         * but that could cause some E_NOTICE and also damn long lines.
         */
 
+       if (Z_TYPE_P(arg) == IS_REFERENCE) {
+               arg = Z_REFVAL_P(arg);
+       }
        switch (Z_TYPE_P(arg)) {
                case IS_NULL:
                        TRACE_APPEND_STR("NULL, ");
@@ -449,6 +453,7 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze
                default:
                        break;
        }
+       *str_ptr = str;
        return ZEND_HASH_APPLY_KEEP;
 }
 /* }}} */
@@ -460,14 +465,15 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args
        long line;
        HashTable *ht = Z_ARRVAL_P(frame);
        zval *file, *tmp;
-       zend_string *str;
+       zend_string *str, **str_ptr;
 
        if (Z_TYPE_P(frame) != IS_ARRAY) {
                zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h);
                return ZEND_HASH_APPLY_KEEP;
        }
 
-       str = va_arg(args, zend_string*);
+       str_ptr = va_arg(args, zend_string**);
+       str = *str_ptr;
        num = va_arg(args, int*);
 
        s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1);
@@ -507,7 +513,7 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args
        if (tmp) {
                if (Z_TYPE_P(tmp) == IS_ARRAY) {
                        int last_len = str->len;
-                       zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, str);
+                       zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, &str);
                        if (last_len != str->len) {
                                str->len -= 2; /* remove last ', ' */
                        }
@@ -516,6 +522,7 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args
                }
        }
        TRACE_APPEND_STR(")\n");
+       *str_ptr = str;
        return ZEND_HASH_APPLY_KEEP;
 }
 /* }}} */
@@ -534,7 +541,7 @@ ZEND_METHOD(exception, getTraceAsString)
        str = STR_ALLOC(0, 0);
 
        trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
-       zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, str, &num);
+       zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, &str, &num);
 
        len = sprintf(s_tmp, "#%d {main}", num);
        TRACE_APPEND_STRL(s_tmp, len);
@@ -615,12 +622,12 @@ ZEND_METHOD(exception, __toString)
 
                if (Z_STRLEN(message) > 0) {
                        len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s",
-                                                               Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line),
+                                                               Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line),
                                                                (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
                                                                len ? "\n\nNext " : "", prev_str);
                } else {
                        len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s",
-                                                               Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line),
+                                                               Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line),
                                                                (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
                                                                len ? "\n\nNext " : "", prev_str);
                }
index d61cd0586d9d0b4085988c7894ca844cdc3bc671..3299c1f6823fe7fd34830a73b3994140be21658a 100644 (file)
@@ -1143,7 +1143,8 @@ fetch_from_array:
                        } else {
                                retval = zend_fetch_dimension_address_inner(Z_ARRVAL_P(container), dim, dim_type, type TSRMLS_CC);
                        }
-                       ZVAL_COPY(result, retval);
+//???                  ZVAL_COPY(result, retval);
+                       ZVAL_INDIRECT(result, retval);
                        return;
                        break;
 
@@ -1240,7 +1241,8 @@ convert_to_array:
 //???                                  }
 //???                                  AI_SET_PTR(result, overloaded_result);
 //???                                  PZVAL_LOCK(overloaded_result);
-                                       ZVAL_COPY(result, overloaded_result);
+//???                                  ZVAL_COPY(result, overloaded_result);
+                                       ZVAL_INDIRECT(result, overloaded_result);
                                } else {
                                        result = &EG(error_zval);
                                }
index bf43338546d050e44fb9232eb80d38396c3d118b..bbed28d7833b63fd24abf93c2024f8ae990ce0ed 100644 (file)
@@ -511,7 +511,7 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
                                        actual_len -= (actual - Z_STRVAL_P(p));
                                        if (inline_change) {
                                                zend_string *s = STR_INIT(actual, actual_len, 0);
-                                               STR_RELEASE(Z_STR_P(p));
+//???                                          STR_RELEASE(Z_STR_P(p));
                                                Z_STR_P(p) = s;
                                        }
                                }
@@ -531,12 +531,12 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
                                                zend_error(E_ERROR, "Undefined constant '%s'", save->val);
                                        }
                                        if (inline_change) {
-                                               STR_RELEASE(save);
+//???                                          STR_RELEASE(save);
                                        }
                                        save = NULL;
                                }
                                if (inline_change && save && save->val != actual) {
-                                       STR_RELEASE(save);
+//???                                  STR_RELEASE(save);
                                }
                                zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'",  actual,  actual);
                                p->type = IS_STRING;
@@ -546,12 +546,12 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
                        }
                } else {
                        if (inline_change) {
-                               STR_RELEASE(Z_STR_P(p));
+//???                          STR_RELEASE(Z_STR_P(p));
                        }
                        *p = const_value;
                }
 
-               Z_SET_REFCOUNT_P(p, refcount);
+               if (IS_REFCOUNTED(Z_TYPE_P(p))) Z_SET_REFCOUNT_P(p, refcount);
 //???          Z_SET_ISREF_TO_P(p, is_ref);
        } else if (Z_TYPE_P(p) == IS_CONSTANT_ARRAY) {
                zval *element, new_val;
index c8898e1694edb947bfc0469a328d540d7bbe0fd4..75f6165c3b93048fbdd0dd432e39054c31f36c86 100644 (file)
@@ -40,8 +40,12 @@ ZEND_API zval* zend_call_method(zval *object, zend_class_entry *obj_ce, zend_fun
 
        zval params[2];
 
-       ZVAL_COPY_VALUE(&params[0], arg1);
-       ZVAL_COPY_VALUE(&params[1], arg2);
+       if (param_count > 0) {
+               ZVAL_COPY_VALUE(&params[0], arg1);
+       }
+       if (param_count > 1) {
+               ZVAL_COPY_VALUE(&params[1], arg2);
+       }
 
        fci.size = sizeof(fci);
        /*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
index 6d58cb7d26999aa6cd8eeec3ace1d16101141eab..7cb16e18bd9c473476fa15ef9632ca61b7401481 100644 (file)
@@ -566,12 +566,14 @@ found:
                                } else {
                                        zval garbage;
 
-                                       ZVAL_COPY_VALUE(&garbage, Z_REFVAL_P(variable_ptr));
+                                       ZVAL_COPY_VALUE(&garbage, variable_ptr);
 
                                        /* if we assign referenced variable, we should separate it */
-                                       Z_ADDREF_P(value);
-                                       if (Z_ISREF_P(value)) {
-                                               SEPARATE_ZVAL(value);
+                                       if (IS_REFCOUNTED(Z_TYPE_P(value))) {
+                                               Z_ADDREF_P(value);
+                                               if (Z_ISREF_P(value)) {
+                                                       SEPARATE_ZVAL(value);
+                                               }
                                        }
                                        ZVAL_COPY_VALUE(variable_ptr, value);
                                        zval_ptr_dtor(&garbage);
@@ -605,9 +607,11 @@ found:
                }
        } else if (EXPECTED(property_info != NULL)) {
                /* if we assign referenced variable, we should separate it */
-               Z_ADDREF_P(value);
-               if (Z_ISREF_P(value)) {
-                       SEPARATE_ZVAL(value);
+               if (IS_REFCOUNTED(Z_TYPE_P(value))) {
+                       Z_ADDREF_P(value);
+                       if (Z_ISREF_P(value)) {
+                               SEPARATE_ZVAL(value);
+                       }
                }
                if (EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
                    property_info->offset >= 0) {
index 29ec69924242aefb1abe0d11652f9baabb07cc75..58dcb48ce83402409757372dd0ececdac4717083 100644 (file)
@@ -4727,7 +4727,6 @@ ZEND_VM_HANDLER(158, ZEND_JMP_SET_VAR, CONST|TMP|VAR|CV, ANY)
        if (i_zend_is_true(value TSRMLS_CC)) {
                if (OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) {
                        ZVAL_COPY(EX_VAR(opline->result.var), value);
-                       Z_ADDREF_P(value);
                } else {
                        ZVAL_COPY_VALUE(EX_VAR(opline->result.var), value);
                        if (!IS_OP1_TMP_FREE()) {
index 6bc43bf750b290df1370845c7d1e2f5d09312023..cd0395c6c61cc7b51e18bb56b19b733a39ac9036 100644 (file)
@@ -3155,7 +3155,6 @@ static int ZEND_FASTCALL  ZEND_JMP_SET_VAR_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLE
        if (i_zend_is_true(value TSRMLS_CC)) {
                if (IS_CONST == IS_VAR || IS_CONST == IS_CV) {
                        ZVAL_COPY(EX_VAR(opline->result.var), value);
-                       Z_ADDREF_P(value);
                } else {
                        ZVAL_COPY_VALUE(EX_VAR(opline->result.var), value);
                        if (!0) {
@@ -8152,7 +8151,6 @@ static int ZEND_FASTCALL  ZEND_JMP_SET_VAR_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_
        if (i_zend_is_true(value TSRMLS_CC)) {
                if (IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) {
                        ZVAL_COPY(EX_VAR(opline->result.var), value);
-                       Z_ADDREF_P(value);
                } else {
                        ZVAL_COPY_VALUE(EX_VAR(opline->result.var), value);
                        if (!1) {
@@ -13240,7 +13238,6 @@ static int ZEND_FASTCALL  ZEND_JMP_SET_VAR_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_
        if (i_zend_is_true(value TSRMLS_CC)) {
                if (IS_VAR == IS_VAR || IS_VAR == IS_CV) {
                        ZVAL_COPY(EX_VAR(opline->result.var), value);
-                       Z_ADDREF_P(value);
                } else {
                        ZVAL_COPY_VALUE(EX_VAR(opline->result.var), value);
                        if (!0) {
@@ -29691,7 +29688,6 @@ static int ZEND_FASTCALL  ZEND_JMP_SET_VAR_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_A
        if (i_zend_is_true(value TSRMLS_CC)) {
                if (IS_CV == IS_VAR || IS_CV == IS_CV) {
                        ZVAL_COPY(EX_VAR(opline->result.var), value);
-                       Z_ADDREF_P(value);
                } else {
                        ZVAL_COPY_VALUE(EX_VAR(opline->result.var), value);
                        if (!0) {