]> granicus.if.org Git - php/commitdiff
Don't add_ref in add_*_str functions
authorXinchen Hui <laruence@gmail.com>
Tue, 25 Feb 2014 07:47:24 +0000 (15:47 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 25 Feb 2014 07:47:24 +0000 (15:47 +0800)
Zend/zend_API.c
Zend/zend_builtin_functions.c
ext/spl/php_spl.c
ext/standard/array.c
ext/standard/basic_functions.c
ext/standard/string.c

index 455fe5412fd8dee53b7fae6dc813a3eb9b6ff3cf..77d80cc44e4f254b4a07004944eae828eabeb18b 100644 (file)
@@ -1339,7 +1339,6 @@ ZEND_API int add_assoc_str_ex(zval *arg, const char *key, uint key_len, zend_str
        zval *ret, tmp;
 
        ZVAL_STR(&tmp, str);
-       STR_ADDREF(str);
        ret = zend_symtable_str_update(Z_ARRVAL_P(arg), key, key_len, &tmp);
        return ret ? SUCCESS : FAILURE;
 }
@@ -1506,7 +1505,7 @@ ZEND_API int add_next_index_str(zval *arg, zend_string *str) /* {{{ */
 {
        zval tmp;
 
-       ZVAL_STR(&tmp, STR_COPY(str));
+       ZVAL_STR(&tmp, str);
        return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp) ? SUCCESS : FAILURE;
 }
 /* }}} */
@@ -1582,7 +1581,7 @@ ZEND_API zval *add_get_index_str(zval *arg, ulong index, zend_string *str) /* {{
        zval tmp;
 
 //???  ZVAL_STRING(tmp, str, duplicate);
-       ZVAL_STR(&tmp, STR_COPY(str));
+       ZVAL_STR(&tmp, str);
        return zend_hash_index_update(Z_ARRVAL_P(arg), index, &tmp);
 }
 /* }}} */
@@ -3297,8 +3296,8 @@ ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRML
                if (Z_TYPE_P(callable) == IS_STRING && fcc.calling_scope) {
                        zval_dtor(callable);
                        array_init(callable);
-                       add_next_index_str(callable, fcc.calling_scope->name);
-                       add_next_index_str(callable, fcc.function_handler->common.function_name);
+                       add_next_index_str(callable, STR_COPY(fcc.calling_scope->name));
+                       add_next_index_str(callable, STR_COPY(fcc.function_handler->common.function_name));
                }
                if (fcc.function_handler &&
                        ((fcc.function_handler->type == ZEND_INTERNAL_FUNCTION &&
index d5df1174edd9de939ae0344c7cc8fa881acc6c83..ed8fddbfb21efab19252aa307540a9464a060576 100644 (file)
@@ -613,7 +613,7 @@ ZEND_FUNCTION(each)
        /* add the key elements */
        switch (zend_hash_get_current_key_ex(target_hash, &key, &num_key, 0, NULL)) {
                case HASH_KEY_IS_STRING:
-                       inserted_pointer = add_get_index_str(return_value, 0, key);
+                       inserted_pointer = add_get_index_str(return_value, 0, STR_COPY(key));
                        break;
                case HASH_KEY_IS_LONG:
                        inserted_pointer = add_get_index_long(return_value, 0, num_key);
@@ -1427,7 +1427,7 @@ ZEND_FUNCTION(get_included_files)
        array_init(return_value);
        zend_hash_internal_pointer_reset(&EG(included_files));
        while (zend_hash_get_current_key_ex(&EG(included_files), &entry, NULL, 0, NULL) == HASH_KEY_IS_STRING) {
-               add_next_index_str(return_value, entry);
+               add_next_index_str(return_value, STR_COPY(entry));
                zend_hash_move_forward(&EG(included_files));
        }
 }
@@ -1601,9 +1601,9 @@ static int copy_class_or_interface_name(zend_class_entry **pce TSRMLS_DC, int nu
                if (ce->refcount > 1 && 
                    (ce->name->len != hash_key->key->len - 1 || 
                     !same_name(hash_key->key->val, ce->name->val, ce->name->len))) {
-                       add_next_index_str(array, hash_key->key);
+                       add_next_index_str(array, STR_COPY(hash_key->key));
                } else {
-                       add_next_index_str(array, ce->name);
+                       add_next_index_str(array, STR_COPY(ce->name));
                }
        }
        return ZEND_HASH_APPLY_KEEP;
@@ -1669,9 +1669,9 @@ static int copy_function_name(zend_function *func TSRMLS_DC, int num_args, va_li
        }
 
        if (func->type == ZEND_INTERNAL_FUNCTION) {
-               add_next_index_str(internal_ar, hash_key->key);
+               add_next_index_str(internal_ar, STR_COPY(hash_key->key));
        } else if (func->type == ZEND_USER_FUNCTION) {
-               add_next_index_str(user_ar, hash_key->key);
+               add_next_index_str(user_ar, STR_COPY(hash_key->key));
        }
 
        return 0;
@@ -2219,7 +2219,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
                                        break;
                                }                                   
                                if (prev->op_array) {
-                                       add_assoc_str_ex(&stack_frame, "file", sizeof("file")-1, prev->op_array->filename);
+                                       add_assoc_str_ex(&stack_frame, "file", sizeof("file")-1, STR_COPY(prev->op_array->filename));
                                        add_assoc_long_ex(&stack_frame, "line", sizeof("line")-1, prev->opline->lineno);
                                        break;
                                }
@@ -2244,10 +2244,10 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 
                        if (Z_TYPE(ptr->object) == IS_OBJECT) {
                                if (ptr->function_state.function->common.scope) {
-                                       add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, ptr->function_state.function->common.scope->name);
+                                       add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, STR_COPY(ptr->function_state.function->common.scope->name));
                                } else {
                                        class_name = zend_get_object_classname(&ptr->object TSRMLS_CC);
-                                       add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, class_name);
+                                       add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, STR_COPY(class_name));
                                        
                                }
                                if ((options & DEBUG_BACKTRACE_PROVIDE_OBJECT) != 0) {
@@ -2257,7 +2257,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int
 
                                add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "->", 1);
                        } else if (ptr->function_state.function->common.scope) {
-                               add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, ptr->function_state.function->common.scope->name);
+                               add_assoc_str_ex(&stack_frame, "class", sizeof("class")-1, STR_COPY(ptr->function_state.function->common.scope->name));
                                add_assoc_string_ex(&stack_frame, "type", sizeof("type")-1, "::", 1);
                        }
 
@@ -2408,7 +2408,7 @@ ZEND_FUNCTION(get_extension_funcs)
                                array_init(return_value);
                                array = 1;
                        }
-                       add_next_index_str(return_value, zif->common.function_name);
+                       add_next_index_str(return_value, STR_COPY(zif->common.function_name));
                }
                zend_hash_move_forward_ex(CG(function_table), &iterator);
        }
index 90d4e2f054ff19d59681f765a5f94b3bab2b83a9..26f39eb5134f271a74830128fb04096705c930b3 100644 (file)
@@ -744,18 +744,18 @@ PHP_FUNCTION(spl_autoload_functions)
                                        Z_ADDREF_P(alfi->obj);
                                        add_next_index_zval(&tmp, alfi->obj);
                                } else {
-                                       add_next_index_str(&tmp, alfi->ce->name);
+                                       add_next_index_str(&tmp, STR_COPY(alfi->ce->name));
                                }
-                               add_next_index_str(&tmp, alfi->func_ptr->common.function_name);
+                               add_next_index_str(&tmp, STR_COPY(alfi->func_ptr->common.function_name));
                                add_next_index_zval(return_value, &tmp);
                        } else {
                                if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) {
-                                       add_next_index_str(return_value, alfi->func_ptr->common.function_name);
+                                       add_next_index_str(return_value, STR_COPY(alfi->func_ptr->common.function_name));
                                } else {
                                        zend_string *key;
                                        ulong dummy;
                                        zend_hash_get_current_key_ex(SPL_G(autoload_functions), &key, &dummy, 0, &function_pos); 
-                                       add_next_index_str(return_value, key);
+                                       add_next_index_str(return_value, STR_COPY(key));
                                }
                        }
 
@@ -765,7 +765,7 @@ PHP_FUNCTION(spl_autoload_functions)
        }
 
        array_init(return_value);
-       add_next_index_str(return_value, EG(autoload_func)->common.function_name);
+       add_next_index_str(return_value, STR_COPY(EG(autoload_func)->common.function_name));
 } /* }}} */
 
 /* {{{ proto string spl_object_hash(object obj)
index ed56b28cf9b46e245decdfe3d00e9524f3cc3c75..69f2fe515b064225ea531238819030f970b8fc22 100644 (file)
@@ -4045,7 +4045,7 @@ PHP_FUNCTION(array_rand)
                        } else {
                                /* Append the result to the return value. */
                                if (key_type == HASH_KEY_IS_STRING) {
-                                       add_next_index_str(return_value, string_key);
+                                       add_next_index_str(return_value, STR_COPY(string_key));
                                } else {
                                        add_next_index_long(return_value, num_key);
                                }
index 388042bc7990436633ca3d8ef9c64d9dbc1d487f..3f5fb28897dd2853c1906163b7c6af3590ad372c 100644 (file)
@@ -4581,7 +4581,6 @@ static int add_config_entry_cb(zval *entry TSRMLS_DC, int num_args, va_list args
 
        if (Z_TYPE_P(entry) == IS_STRING) {
                if (hash_key->key) {
-//???
                        add_assoc_str_ex(retval, hash_key->key->val, hash_key->key->len, STR_COPY(Z_STR_P(entry)));
                } else {
                        add_index_str(retval, hash_key->h, STR_COPY(Z_STR_P(entry)));
@@ -4589,7 +4588,6 @@ static int add_config_entry_cb(zval *entry TSRMLS_DC, int num_args, va_list args
        } else if (Z_TYPE_P(entry) == IS_ARRAY) {
                array_init(&tmp);
                zend_hash_apply_with_arguments(Z_ARRVAL_P(entry) TSRMLS_CC, (apply_func_args_t) add_config_entry_cb, 1, tmp);
-//???
                add_assoc_zval_ex(retval, hash_key->key->val, hash_key->key->len, &tmp);
        }
        return 0;
index 3c6532d5f4e562b1636fceebdc8b8da79e877cbb..d484eed02295dba90ce1a30995a12a537bbdec86 100644 (file)
@@ -1542,7 +1542,7 @@ PHP_FUNCTION(pathinfo)
 
        if (have_basename) {
                ret = php_basename(path, path_len, NULL, 0 TSRMLS_CC);
-               add_assoc_str(&tmp, "basename", ret);
+               add_assoc_str(&tmp, "basename", STR_COPY(ret));
        }
 
        if ((opt & PHP_PATHINFO_EXTENSION) == PHP_PATHINFO_EXTENSION) {
@@ -2537,7 +2537,7 @@ PHP_FUNCTION(substr_replace)
                        result->val[result->len] = '\0';
 
                        if (zend_hash_get_current_key_ex(Z_ARRVAL_P(str), &str_index, &num_index, 0, &pos_str) == HASH_KEY_IS_STRING) {
-                               add_assoc_str(return_value, str_index->val, result);
+                               add_assoc_str_ex(return_value, str_index->val, str_index->len, result);
                        } else {
                                add_index_str(return_value, num_index, result);
                        }