From: Dmitry Stogov Date: Tue, 31 Oct 2017 07:43:10 +0000 (+0300) Subject: Added zend_hash_add_new_mem/zend_hash_str_add_new_mem. Use them to add new elements... X-Git-Tag: php-7.3.0alpha1~1133 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e839246820f36da7eeadf37421457147393cf29;p=php Added zend_hash_add_new_mem/zend_hash_str_add_new_mem. Use them to add new elements into PCRE cache (we checked the existance before). --- diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index ca1be3b0d0..def2fe576d 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -634,6 +634,19 @@ static zend_always_inline void *zend_hash_add_mem(HashTable *ht, zend_string *ke return NULL; } +static zend_always_inline void *zend_hash_add_new_mem(HashTable *ht, zend_string *key, void *pData, size_t size) +{ + zval tmp, *zv; + + ZVAL_PTR(&tmp, NULL); + if ((zv = zend_hash_add_new(ht, key, &tmp))) { + Z_PTR_P(zv) = pemalloc(size, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); + memcpy(Z_PTR_P(zv), pData, size); + return Z_PTR_P(zv); + } + return NULL; +} + static zend_always_inline void *zend_hash_str_add_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size) { zval tmp, *zv; @@ -647,6 +660,19 @@ static zend_always_inline void *zend_hash_str_add_mem(HashTable *ht, const char return NULL; } +static zend_always_inline void *zend_hash_str_add_new_mem(HashTable *ht, const char *str, size_t len, void *pData, size_t size) +{ + zval tmp, *zv; + + ZVAL_PTR(&tmp, NULL); + if ((zv = zend_hash_str_add_new(ht, str, len, &tmp))) { + Z_PTR_P(zv) = pemalloc(size, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); + memcpy(Z_PTR_P(zv), pData, size); + return Z_PTR_P(zv); + } + return NULL; +} + static zend_always_inline void *zend_hash_update_mem(HashTable *ht, zend_string *key, void *pData, size_t size) { void *p; diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 44b5ff55b0..adedcd8d9f 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -592,7 +592,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) * See bug #63180 */ if (!ZSTR_IS_INTERNED(key) || !(GC_FLAGS(key) & IS_STR_PERMANENT)) { - pce = zend_hash_str_update_mem(&PCRE_G(pcre_cache), + pce = zend_hash_str_add_new_mem(&PCRE_G(pcre_cache), ZSTR_VAL(key), ZSTR_LEN(key), &new_entry, sizeof(pcre_cache_entry)); #if HAVE_SETLOCALE if (key != regex) { @@ -600,7 +600,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex) } #endif } else { - pce = zend_hash_update_mem(&PCRE_G(pcre_cache), key, &new_entry, sizeof(pcre_cache_entry)); + pce = zend_hash_add_new_mem(&PCRE_G(pcre_cache), key, &new_entry, sizeof(pcre_cache_entry)); } return pce;