From 869f662cddcba81b03cb95651c7fdbe06f4b3458 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 5 Jun 2015 13:54:57 +0300 Subject: [PATCH] Use better zend_hash_* functions --- Zend/zend_hash.h | 9 +++++++++ ext/opcache/zend_accelerator_util_funcs.c | 4 ++-- ext/opcache/zend_shared_alloc.c | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 3ae3e4571b..e55ee9e61f 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -589,6 +589,15 @@ static zend_always_inline void *zend_hash_index_add_ptr(HashTable *ht, zend_ulon return zv ? Z_PTR_P(zv) : NULL; } +static zend_always_inline void *zend_hash_index_add_new_ptr(HashTable *ht, zend_ulong h, void *pData) +{ + zval tmp, *zv; + + ZVAL_PTR(&tmp, pData); + zv = zend_hash_index_add_new(ht, h, &tmp); + return zv ? Z_PTR_P(zv) : NULL; +} + static zend_always_inline void *zend_hash_index_update_ptr(HashTable *ht, zend_ulong h, void *pData) { zval tmp, *zv; diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 990639aeb4..9582b723a2 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -27,10 +27,10 @@ #if SIZEOF_SIZE_T <= SIZEOF_ZEND_LONG /* If sizeof(void*) == sizeof(ulong) we can use zend_hash index functions */ -# define accel_xlat_set(old, new) zend_hash_index_update_ptr(&ZCG(bind_hash), (zend_ulong)(zend_uintptr_t)(old), (new)) +# define accel_xlat_set(old, new) zend_hash_index_add_new_ptr(&ZCG(bind_hash), (zend_ulong)(zend_uintptr_t)(old), (new)) # define accel_xlat_get(old) zend_hash_index_find_ptr(&ZCG(bind_hash), (zend_ulong)(zend_uintptr_t)(old)) #else -# define accel_xlat_set(old, new) (zend_hash_str_add_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (zend_ulong)(zend_uintptr_t)(old), (void**)&(new)) +# define accel_xlat_set(old, new) (zend_hash_str_add_new_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (zend_ulong)(zend_uintptr_t)(old), (void**)&(new)) # define accel_xlat_get(old, new) ((new) = zend_hash_str_find_ptr(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (zend_ulong)(zend_uintptr_t)(old), (void**)&(new))) #endif diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index 19b51e7c59..ca50ab9219 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -435,7 +435,7 @@ void zend_shared_alloc_clear_xlat_table(void) void zend_shared_alloc_register_xlat_entry(const void *old, const void *new) { - zend_hash_index_update_ptr(&ZCG(xlat_table), (zend_ulong)old, (void*)new); + zend_hash_index_add_new_ptr(&ZCG(xlat_table), (zend_ulong)old, (void*)new); } void *zend_shared_alloc_get_xlat_entry(const void *old) -- 2.40.0