]> granicus.if.org Git - php/commitdiff
Fixed zend_hash_append result duplicated key
authorXinchen Hui <laruence@php.net>
Sat, 7 Mar 2015 16:15:55 +0000 (00:15 +0800)
committerXinchen Hui <laruence@php.net>
Sat, 7 Mar 2015 16:21:02 +0000 (00:21 +0800)
actually, maybe we should precalculate before calling zend_hash_appen
when we are not sure whether the hash is caclculated(prop_info->name).

but it looks a little ugly.. (also for zend_string_copy)

Zend/zend.h
Zend/zend_execute_API.c
Zend/zend_hash.h
Zend/zend_inheritance.c
Zend/zend_object_handlers.c

index 4cf73225b74e925e2a345d6e8265d6408f25244b..94cab74af162b7c800bb9909e09aef0cd3e9e487 100644 (file)
@@ -31,9 +31,9 @@
 #include "zend_types.h"
 #include "zend_errors.h"
 #include "zend_alloc.h"
-#include "zend_hash.h"
 #include "zend_llist.h"
 #include "zend_string.h"
+#include "zend_hash.h"
 #include "zend_ast.h"
 #include "zend_gc.h"
 #include "zend_variables.h"
index 6dda9effa07732284a0c82def869478b8d1593f3..7cee3ba73d18032364dadb8279d1263010c5c71d 100644 (file)
@@ -1473,7 +1473,6 @@ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
                /*printf("Cache miss!  Initialized %x\n", EG(active_symbol_table));*/
        }
        for (i = 0; i < ex->func->op_array.last_var; i++) {
-               zend_string_addref(ex->func->op_array.vars[i]);
                _zend_hash_append_ind(symbol_table, ex->func->op_array.vars[i],
                        ZEND_CALL_VAR_NUM(ex, i));
        }
index 1e166ac8c3777aa9ef0cfd1e4788096a342bdc7f..02991a643bcb1974d8ffd7bef76770b5cb50feaf 100644 (file)
@@ -818,8 +818,8 @@ static zend_always_inline void _zend_hash_append(HashTable *ht, zend_string *key
        Bucket *p = ht->arData + idx;
 
        ZVAL_COPY_VALUE(&p->val, zv);
-       p->key = key;
-       p->h = key->h;
+       p->key = zend_string_copy(key);
+       p->h = zend_string_hash_val(key);
        nIndex = p->h & ht->nTableMask;
        Z_NEXT(p->val) = ht->arHash[nIndex];
        ht->arHash[nIndex] = idx;
@@ -834,8 +834,8 @@ static zend_always_inline void _zend_hash_append_ptr(HashTable *ht, zend_string
        Bucket *p = ht->arData + idx;
 
        ZVAL_PTR(&p->val, ptr);
-       p->key = key;
-       p->h = key->h;
+       p->key = zend_string_copy(key);
+       p->h = zend_string_hash_val(key);
        nIndex = p->h & ht->nTableMask;
        Z_NEXT(p->val) = ht->arHash[nIndex];
        ht->arHash[nIndex] = idx;
@@ -850,8 +850,8 @@ static zend_always_inline void _zend_hash_append_ind(HashTable *ht, zend_string
        Bucket *p = ht->arData + idx;
 
        ZVAL_INDIRECT(&p->val, ptr);
-       p->key = key;
-       p->h = key->h;
+       p->key = zend_string_copy(key);
+       p->h = zend_string_hash_val(key);
        nIndex = p->h & ht->nTableMask;
        Z_NEXT(p->val) = ht->arHash[nIndex];
        ht->arHash[nIndex] = idx;
index c48718c46cdb6303605c77b7692fb1de033980b6..e3ef17cc9012ed8142fcdb0f8442ce4e958901f6 100644 (file)
@@ -636,7 +636,6 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
                                child_info = parent_info;
                        }
                }
-               zend_string_addref(key);
                _zend_hash_append_ptr(&ce->properties_info, key, child_info);
        }
 }
@@ -704,7 +703,6 @@ static void do_inherit_class_constant(zend_string *name, zval *zv, zend_class_en
                        ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
                }
                Z_ADDREF_P(zv);
-               zend_string_addref(name);
                _zend_hash_append(&ce->constants_table, name, zv);
        }
 }
@@ -857,7 +855,6 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
                        zend_function *new_func = do_inherit_method(key, func, ce);
 
                        if (new_func) {
-                               zend_string_addref(key);
                                _zend_hash_append_ptr(&ce->function_table, key, new_func);
                        }
                } ZEND_HASH_FOREACH_END();
index af604e2675dd790ae0f3f6d5fcad8c8bfdacbb4f..a5c0bf0a033dd0f6d4709bd0e85f3813f0d50bf2 100644 (file)
@@ -84,7 +84,6 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
                                    (prop_info->flags & ZEND_ACC_STATIC) == 0 &&
                                    Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) != IS_UNDEF) {
 
-                                       zend_string_addref(prop_info->name);
                                        _zend_hash_append_ind(zobj->properties, prop_info->name, 
                                                OBJ_PROP(zobj, prop_info->offset));
                                }