php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch 50816-2.diff for Scripting Engine problem Bug #50816Patch version 2011-07-29 04:14 UTC Return to Bug #50816 | Download this patchThis patch is obsolete Obsoleted by patches: This patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: pierrick@php.netIndex: Zend/tests/bug45742.phpt =================================================================== --- Zend/tests/bug45742.phpt (revision 313904) +++ Zend/tests/bug45742.phpt (working copy) @@ -20,5 +20,5 @@ --EXPECT-- array(1) { [1]=> - int(23) + int(42) } Index: Zend/zend_hash.c =================================================================== --- Zend/zend_hash.c (revision 313904) +++ Zend/zend_hash.c (working copy) @@ -1206,6 +1206,63 @@ } } +ZEND_API int zend_hash_del_key_if_before(HashTable *ht, int key_type, const char *str_index, uint str_length, ulong num_index, HashPosition *pos) +{ + Bucket *p; + + p = pos ? (*pos) : ht->pInternalPointer; + + IS_CONSISTENT(ht); + CHECK_INIT(ht); + + if (p) { + if (key_type == HASH_KEY_IS_LONG) { + + Bucket *q = ht->arBuckets[num_index & ht->nTableMask]; + + while (q != NULL) { + if ((q->h == num_index) && (q->nKeyLength == 0)) { + p = p->pListLast; + while(p) { + if (p == q) { + zend_hash_index_del(ht, p->h); + return SUCCESS; + } + p = p->pListLast; + } + return SUCCESS; + } + q = q->pNext; + } + + } else if (key_type == HASH_KEY_IS_STRING) { + ulong h = zend_inline_hash_func(str_index, str_length); + Bucket *q = ht->arBuckets[h & ht->nTableMask]; + + while (q != NULL) { + if (q->arKey == p->arKey || + ((q->h == h) && (q->nKeyLength == str_length) && !memcmp(q->arKey, str_index, str_length))) { + + p = p->pListLast; + while(p) { + if (p == q) + { + zend_hash_del(ht, p->arKey, p->nKeyLength); + return SUCCESS; + } + p = p->pListLast; + } + return SUCCESS; + } + q = q->pNext; + } + + } + } + + return SUCCESS; +} + /* This function changes key of currevt element without changing elements' * order. If element with target key already exists, it will be deleted first. */ Index: Zend/zend_hash.h =================================================================== --- Zend/zend_hash.h (revision 313904) +++ Zend/zend_hash.h (working copy) @@ -156,7 +156,9 @@ zend_hash_del_key_or_index(ht, arKey, nKeyLength, h, HASH_DEL_KEY_QUICK) #define zend_hash_index_del(ht, h) \ zend_hash_del_key_or_index(ht, NULL, 0, h, HASH_DEL_INDEX) +ZEND_API int zend_hash_del_key_if_before(HashTable *ht, int key_type, const char *str_index, uint str_length, ulong num_index, HashPosition *pos); + ZEND_API ulong zend_get_hash_value(const char *arKey, uint nKeyLength); /* Data retreival */ @@ -183,6 +185,7 @@ ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos); ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, const char *str_index, uint str_length, ulong num_index, int mode, HashPosition *pos); + typedef struct _HashPointer { HashPosition pos; ulong h; Index: Zend/zend_execute_API.c =================================================================== --- Zend/zend_execute_API.c (revision 313904) +++ Zend/zend_execute_API.c (working copy) @@ -658,16 +658,20 @@ switch (Z_TYPE(const_value)) { case IS_STRING: + zend_hash_del_key_if_before(Z_ARRVAL_P(p), HASH_KEY_IS_STRING, Z_STRVAL(const_value), Z_STRLEN(const_value) + 1, 0, NULL); ret = zend_symtable_update_current_key(Z_ARRVAL_P(p), Z_STRVAL(const_value), Z_STRLEN(const_value) + 1, HASH_UPDATE_KEY_IF_BEFORE); break; case IS_BOOL: case IS_LONG: + zend_hash_del_key_if_before(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, Z_LVAL(const_value), NULL); ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, Z_LVAL(const_value), HASH_UPDATE_KEY_IF_BEFORE, NULL); break; case IS_DOUBLE: + zend_hash_del_key_if_before(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, zend_dval_to_lval(Z_DVAL(const_value)), NULL); ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, zend_dval_to_lval(Z_DVAL(const_value)), HASH_UPDATE_KEY_IF_BEFORE, NULL); break; case IS_NULL: + zend_hash_del_key_if_before(Z_ARRVAL_P(p), HASH_KEY_IS_STRING, "", 1, 0, NULL); ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_STRING, "", 1, 0, HASH_UPDATE_KEY_IF_BEFORE, NULL); break; default: |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Thu Nov 21 16:01:29 2024 UTC |