From 320ad8774a84af0f5b9ab7e3d9f018697adf3614 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 14 Sep 2021 12:05:22 +0300 Subject: [PATCH 01/21] Use more compact representation for packed arrays. Store just an array of zvals without keys. Because of smaller data set, this patch may show performance improvement on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser) The patch has a number of disadvantages: - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET). - ZEND_HASH_FOREACH_* macros became more expensive (bigger and slower), because they have to support both representations (hash and packed). CLI PHP became 37KB bigger just because of these macros. - zend_hash_sort_ex() may require converting packed arrays to hash. - zend_hash_minmax() prototype was changed to compare only values. --- Zend/zend_gc.c | 370 ++++--- Zend/zend_generators.c | 52 +- Zend/zend_hash.c | 989 ++++++++++++------ Zend/zend_hash.h | 158 ++- Zend/zend_list.c | 7 +- Zend/zend_types.h | 32 +- Zend/zend_vm_def.h | 190 ++-- Zend/zend_vm_execute.h | 255 +++-- ext/ffi/ffi.c | 34 +- .../dateformat/dateformat_format_object.cpp | 62 +- ext/opcache/jit/zend_jit_arm64.dasc | 226 ++-- ext/opcache/jit/zend_jit_trace.c | 15 + ext/opcache/jit/zend_jit_x86.dasc | 230 ++-- ext/opcache/zend_file_cache.c | 68 +- ext/opcache/zend_persist.c | 60 +- ext/opcache/zend_persist_calc.c | 53 +- ext/pcre/php_pcre.c | 4 +- ext/snmp/snmp.c | 40 +- ext/spl/php_spl.c | 1 + ext/spl/spl_directory.c | 13 +- ext/standard/array.c | 698 +++++++----- ext/standard/string.c | 100 +- 22 files changed, 2519 insertions(+), 1138 deletions(-) diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index 5c7a73aa2736f..a473c84d2d4e6 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -692,7 +692,6 @@ ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref) static void gc_scan_black(zend_refcounted *ref, gc_stack *stack) { HashTable *ht = NULL; - Bucket *p, *end; zval *zv; GC_STACK_DCL(stack); @@ -765,37 +764,63 @@ static void gc_scan_black(zend_refcounted *ref, gc_stack *stack) handle_ht: if (!ht->nNumUsed) goto next; - p = ht->arData; - end = p + ht->nNumUsed; - while (1) { - end--; - zv = &end->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); + if (HT_IS_PACKED(ht)) { + zval *end; + + zv = ht->arPacked; + end = zv + ht->nNumUsed; + while (1) { + end--; + if (Z_REFCOUNTED_P(end)) { + break; + } + if (zv == end) goto next; + } + while (zv != end) { + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_ADDREF(ref); + if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { + GC_REF_SET_BLACK(ref); + GC_STACK_PUSH(ref); + } + } + zv++; } - if (Z_REFCOUNTED_P(zv)) { - break; + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + while (1) { + end--; + zv = &end->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + break; + } + if (p == end) goto next; + } + while (p != end) { + zv = &p->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_ADDREF(ref); + if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { + GC_REF_SET_BLACK(ref); + GC_STACK_PUSH(ref); + } + } + p++; } - if (p == end) goto next; - } - while (p != end) { zv = &p->val; if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } - if (Z_REFCOUNTED_P(zv)) { - ref = Z_COUNTED_P(zv); - GC_ADDREF(ref); - if (!GC_REF_CHECK_COLOR(ref, GC_BLACK)) { - GC_REF_SET_BLACK(ref); - GC_STACK_PUSH(ref); - } - } - p++; - } - zv = &p->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); } ref = Z_COUNTED_P(zv); GC_ADDREF(ref); @@ -814,7 +839,6 @@ static void gc_scan_black(zend_refcounted *ref, gc_stack *stack) static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack) { HashTable *ht = NULL; - Bucket *p, *end; zval *zv; GC_STACK_DCL(stack); @@ -889,37 +913,63 @@ static void gc_mark_grey(zend_refcounted *ref, gc_stack *stack) handle_ht: if (!ht->nNumUsed) goto next; - p = ht->arData; - end = p + ht->nNumUsed; - while (1) { - end--; - zv = &end->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); + if (HT_IS_PACKED(ht)) { + zval *end; + + zv = ht->arPacked; + end = zv + ht->nNumUsed; + while (1) { + end--; + if (Z_REFCOUNTED_P(end)) { + break; + } + if (zv == end) goto next; } - if (Z_REFCOUNTED_P(zv)) { - break; + while (zv != end) { + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_DELREF(ref); + if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { + GC_REF_SET_COLOR(ref, GC_GREY); + GC_STACK_PUSH(ref); + } + } + zv++; + } + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + while (1) { + end--; + zv = &end->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + break; + } + if (p == end) goto next; + } + while (p != end) { + zv = &p->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_DELREF(ref); + if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { + GC_REF_SET_COLOR(ref, GC_GREY); + GC_STACK_PUSH(ref); + } + } + p++; } - if (p == end) goto next; - } - while (p != end) { zv = &p->val; if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } - if (Z_REFCOUNTED_P(zv)) { - ref = Z_COUNTED_P(zv); - GC_DELREF(ref); - if (!GC_REF_CHECK_COLOR(ref, GC_GREY)) { - GC_REF_SET_COLOR(ref, GC_GREY); - GC_STACK_PUSH(ref); - } - } - p++; - } - zv = &p->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); } ref = Z_COUNTED_P(zv); GC_DELREF(ref); @@ -991,7 +1041,6 @@ static void gc_mark_roots(gc_stack *stack) static void gc_scan(zend_refcounted *ref, gc_stack *stack) { - Bucket *p, *end; zval *zv; GC_STACK_DCL(stack); @@ -1052,36 +1101,61 @@ static void gc_scan(zend_refcounted *ref, gc_stack *stack) HashTable *ht = (HashTable *)ref; ZEND_ASSERT(ht != &EG(symbol_table)); if (!ht->nNumUsed) goto next; - p = ht->arData; - end = p + ht->nNumUsed; - while (1) { - end--; - zv = &end->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); + if (HT_IS_PACKED(ht)) { + zval *end; + + zv = ht->arPacked; + end = zv + ht->nNumUsed; + while (1) { + end--; + if (Z_REFCOUNTED_P(end)) { + break; + } + if (zv == end) goto next; } - if (Z_REFCOUNTED_P(zv)) { - break; + while (zv != end) { + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { + GC_REF_SET_COLOR(ref, GC_WHITE); + GC_STACK_PUSH(ref); + } + } + zv++; + } + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + while (1) { + end--; + zv = &end->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + break; + } + if (p == end) goto next; + } + while (p != end) { + zv = &p->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { + GC_REF_SET_COLOR(ref, GC_WHITE); + GC_STACK_PUSH(ref); + } + } + p++; } - if (p == end) goto next; - } - while (p != end) { zv = &p->val; if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } - if (Z_REFCOUNTED_P(zv)) { - ref = Z_COUNTED_P(zv); - if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { - GC_REF_SET_COLOR(ref, GC_WHITE); - GC_STACK_PUSH(ref); - } - } - p++; - } - zv = &p->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); } ref = Z_COUNTED_P(zv); if (GC_REF_CHECK_COLOR(ref, GC_GREY)) { @@ -1150,7 +1224,6 @@ static int gc_collect_white(zend_refcounted *ref, uint32_t *flags, gc_stack *sta { int count = 0; HashTable *ht = NULL; - Bucket *p, *end; zval *zv; GC_STACK_DCL(stack); @@ -1240,37 +1313,63 @@ static int gc_collect_white(zend_refcounted *ref, uint32_t *flags, gc_stack *sta handle_ht: if (!ht->nNumUsed) goto next; - p = ht->arData; - end = p + ht->nNumUsed; - while (1) { - end--; - zv = &end->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); + if (HT_IS_PACKED(ht)) { + zval *end; + + zv = ht->arPacked; + end = zv + ht->nNumUsed; + while (1) { + end--; + if (Z_REFCOUNTED_P(end)) { + break; + } + if (zv == end) goto next; } - if (Z_REFCOUNTED_P(zv)) { - break; + while (zv != end) { + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_ADDREF(ref); + if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { + GC_REF_SET_BLACK(ref); + GC_STACK_PUSH(ref); + } + } + zv++; + } + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + while (1) { + end--; + zv = &end->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + break; + } + if (p == end) goto next; + } + while (p != end) { + zv = &p->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_ADDREF(ref); + if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { + GC_REF_SET_BLACK(ref); + GC_STACK_PUSH(ref); + } + } + p++; } - if (p == end) goto next; - } - while (p != end) { zv = &p->val; if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } - if (Z_REFCOUNTED_P(zv)) { - ref = Z_COUNTED_P(zv); - GC_ADDREF(ref); - if (GC_REF_CHECK_COLOR(ref, GC_WHITE)) { - GC_REF_SET_BLACK(ref); - GC_STACK_PUSH(ref); - } - } - p++; - } - zv = &p->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); } ref = Z_COUNTED_P(zv); GC_ADDREF(ref); @@ -1329,7 +1428,6 @@ static int gc_collect_roots(uint32_t *flags, gc_stack *stack) static int gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffer *root, gc_stack *stack) { HashTable *ht = NULL; - Bucket *p, *end; zval *zv; int count = 0; GC_STACK_DCL(stack); @@ -1397,33 +1495,55 @@ static int gc_remove_nested_data_from_buffer(zend_refcounted *ref, gc_root_buffe } if (!ht->nNumUsed) goto next; - p = ht->arData; - end = p + ht->nNumUsed; - while (1) { - end--; - zv = &end->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); + if (HT_IS_PACKED(ht)) { + zval *end; + + zv = ht->arPacked; + end = zv + ht->nNumUsed; + while (1) { + end--; + if (Z_REFCOUNTED_P(end)) { + break; + } + if (zv == end) goto next; } - if (Z_REFCOUNTED_P(zv)) { - break; + while (zv != end) { + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_STACK_PUSH(ref); + } + zv++; + } + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + while (1) { + end--; + zv = &end->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + break; + } + if (p == end) goto next; + } + while (p != end) { + zv = &p->val; + if (Z_TYPE_P(zv) == IS_INDIRECT) { + zv = Z_INDIRECT_P(zv); + } + if (Z_REFCOUNTED_P(zv)) { + ref = Z_COUNTED_P(zv); + GC_STACK_PUSH(ref); + } + p++; } - if (p == end) goto next; - } - while (p != end) { zv = &p->val; if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } - if (Z_REFCOUNTED_P(zv)) { - ref = Z_COUNTED_P(zv); - GC_STACK_PUSH(ref); - } - p++; - } - zv = &p->val; - if (Z_TYPE_P(zv) == IS_INDIRECT) { - zv = Z_INDIRECT_P(zv); } ref = Z_COUNTED_P(zv); continue; diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index b7cc9aea8cdc5..965b9edb60b8f 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -608,28 +608,46 @@ static zend_result zend_generator_get_next_delegated_value(zend_generator *gener HashTable *ht = Z_ARR(generator->values); HashPosition pos = Z_FE_POS(generator->values); - Bucket *p; - do { - if (UNEXPECTED(pos >= ht->nNumUsed)) { - /* Reached end of array */ - goto failure; - } + if (HT_IS_PACKED(ht)) { + do { + if (UNEXPECTED(pos >= ht->nNumUsed)) { + /* Reached end of array */ + goto failure; + } - p = &ht->arData[pos]; - value = &p->val; - pos++; - } while (Z_ISUNDEF_P(value)); + value = &ht->arPacked[pos]; + pos++; + } while (Z_ISUNDEF_P(value)); - zval_ptr_dtor(&generator->value); - ZVAL_COPY(&generator->value, value); + zval_ptr_dtor(&generator->value); + ZVAL_COPY(&generator->value, value); - zval_ptr_dtor(&generator->key); - if (p->key) { - ZVAL_STR_COPY(&generator->key, p->key); + zval_ptr_dtor(&generator->key); + ZVAL_LONG(&generator->key, pos - 1); } else { - ZVAL_LONG(&generator->key, p->h); - } + Bucket *p; + do { + if (UNEXPECTED(pos >= ht->nNumUsed)) { + /* Reached end of array */ + goto failure; + } + + p = &ht->arData[pos]; + value = &p->val; + pos++; + } while (Z_ISUNDEF_P(value)); + + zval_ptr_dtor(&generator->value); + ZVAL_COPY(&generator->value, value); + + zval_ptr_dtor(&generator->key); + if (p->key) { + ZVAL_STR_COPY(&generator->key, p->key); + } else { + ZVAL_LONG(&generator->key, p->h); + } + } Z_FE_POS(generator->values) = pos; } else { zend_object_iterator *iter = (zend_object_iterator *) Z_OBJ(generator->values); diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 8ee292106a6b3..07c8506ce093f 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -148,12 +148,12 @@ static zend_always_inline void zend_hash_real_init_packed_ex(HashTable *ht) void *data; if (UNEXPECTED(GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)) { - data = pemalloc(HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK), 1); + data = pemalloc(HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), 1); } else if (EXPECTED(ht->nTableSize == HT_MIN_SIZE)) { /* Use specialized API with constant allocation amount for a particularly common case. */ - data = emalloc(HT_SIZE_EX(HT_MIN_SIZE, HT_MIN_MASK)); + data = emalloc(HT_PACKED_SIZE_EX(HT_MIN_SIZE, HT_MIN_MASK)); } else { - data = emalloc(HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK)); + data = emalloc(HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK)); } HT_SET_DATA_ADDR(ht, data); /* Don't overwrite iterator count. */ @@ -283,21 +283,16 @@ ZEND_API HashTable* ZEND_FASTCALL _zend_new_array(uint32_t nSize) ZEND_API HashTable* ZEND_FASTCALL zend_new_pair(zval *val1, zval *val2) { - Bucket *p; + zval *zv; HashTable *ht = emalloc(sizeof(HashTable)); _zend_hash_init_int(ht, HT_MIN_SIZE, ZVAL_PTR_DTOR, 0); ht->nNumUsed = ht->nNumOfElements = ht->nNextFreeElement = 2; zend_hash_real_init_packed_ex(ht); - p = ht->arData; - ZVAL_COPY_VALUE(&p->val, val1); - p->h = 0; - p->key = NULL; - - p++; - ZVAL_COPY_VALUE(&p->val, val2); - p->h = 1; - p->key = NULL; + zv = ht->arPacked; + ZVAL_COPY_VALUE(zv, val1); + zv++; + ZVAL_COPY_VALUE(zv, val2); return ht; } @@ -308,7 +303,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_packed_grow(HashTable *ht) zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%u * %zu + %zu)", ht->nTableSize * 2, sizeof(Bucket), sizeof(Bucket)); } ht->nTableSize += ht->nTableSize; - HT_SET_DATA_ADDR(ht, perealloc2(HT_GET_DATA_ADDR(ht), HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK), HT_USED_SIZE(ht), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); + HT_SET_DATA_ADDR(ht, perealloc2(HT_GET_DATA_ADDR(ht), HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), HT_PACKED_USED_SIZE(ht), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); } ZEND_API void ZEND_FASTCALL zend_hash_real_init(HashTable *ht, bool packed) @@ -338,7 +333,9 @@ ZEND_API void ZEND_FASTCALL zend_hash_real_init_mixed(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht) { void *new_data, *old_data = HT_GET_DATA_ADDR(ht); - Bucket *old_buckets = ht->arData; + zval *src = ht->arPacked; + Bucket *dst; + uint32_t i; uint32_t nSize = ht->nTableSize; HT_ASSERT_RC1(ht); @@ -346,7 +343,14 @@ ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht) new_data = pemalloc(HT_SIZE_EX(nSize, HT_SIZE_TO_MASK(nSize)), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); ht->nTableMask = HT_SIZE_TO_MASK(ht->nTableSize); HT_SET_DATA_ADDR(ht, new_data); - memcpy(ht->arData, old_buckets, sizeof(Bucket) * ht->nNumUsed); + dst = ht->arData; + for (i = 0; i < ht->nNumUsed; i++) { + ZVAL_COPY_VALUE(&dst->val, src); + dst->h = i; + dst->key = NULL; + dst++; + src++; + } pefree(old_data, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); zend_hash_rehash(ht); } @@ -354,15 +358,22 @@ ZEND_API void ZEND_FASTCALL zend_hash_packed_to_hash(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_to_packed(HashTable *ht) { void *new_data, *old_data = HT_GET_DATA_ADDR(ht); - Bucket *old_buckets = ht->arData; + Bucket *src = ht->arData; + zval *dst; + uint32_t i; HT_ASSERT_RC1(ht); - new_data = pemalloc(HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); + new_data = pemalloc(HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); HT_FLAGS(ht) |= HASH_FLAG_PACKED | HASH_FLAG_STATIC_KEYS; ht->nTableMask = HT_MIN_MASK; HT_SET_DATA_ADDR(ht, new_data); HT_HASH_RESET_PACKED(ht); - memcpy(ht->arData, old_buckets, sizeof(Bucket) * ht->nNumUsed); + dst = ht->arPacked; + for (i = 0; i < ht->nNumUsed; i++) { + ZVAL_COPY_VALUE(dst, &src->val); + dst++; + src++; + } pefree(old_data, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); } @@ -377,13 +388,13 @@ ZEND_API void ZEND_FASTCALL zend_hash_extend(HashTable *ht, uint32_t nSize, bool zend_hash_real_init(ht, packed); } else { if (packed) { - ZEND_ASSERT(HT_FLAGS(ht) & HASH_FLAG_PACKED); + ZEND_ASSERT(HT_IS_PACKED(ht)); if (nSize > ht->nTableSize) { ht->nTableSize = zend_hash_check_size(nSize); - HT_SET_DATA_ADDR(ht, perealloc2(HT_GET_DATA_ADDR(ht), HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK), HT_USED_SIZE(ht), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); + HT_SET_DATA_ADDR(ht, perealloc2(HT_GET_DATA_ADDR(ht), HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), HT_PACKED_USED_SIZE(ht), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); } } else { - ZEND_ASSERT(!(HT_FLAGS(ht) & HASH_FLAG_PACKED)); + ZEND_ASSERT(!HT_IS_PACKED(ht)); if (nSize > ht->nTableSize) { void *new_data, *old_data = HT_GET_DATA_ADDR(ht); Bucket *old_buckets = ht->arData; @@ -405,6 +416,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_discard(HashTable *ht, uint32_t nNumUsed) Bucket *p, *end, *arData; uint32_t nIndex; + ZEND_ASSERT(!HT_IS_PACKED(ht)); arData = ht->arData; p = arData + ht->nNumUsed; end = arData + nNumUsed; @@ -459,8 +471,14 @@ ZEND_API uint32_t zend_array_count(HashTable *ht) static zend_always_inline HashPosition _zend_hash_get_valid_pos(const HashTable *ht, HashPosition pos) { - while (pos < ht->nNumUsed && Z_ISUNDEF(ht->arData[pos].val)) { - pos++; + if (HT_IS_PACKED(ht)) { + while (pos < ht->nNumUsed && Z_ISUNDEF(ht->arPacked[pos])) { + pos++; + } + } else { + while (pos < ht->nNumUsed && Z_ISUNDEF(ht->arData[pos].val)) { + pos++; + } } return pos; } @@ -990,6 +1008,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, uint32_t nIndex; uint32_t idx; Bucket *p; + zval *zv; IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); @@ -998,41 +1017,48 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, h = 0; } - if (HT_FLAGS(ht) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(ht)) { if ((flag & (HASH_ADD_NEW|HASH_ADD_NEXT)) != (HASH_ADD_NEW|HASH_ADD_NEXT) && h < ht->nNumUsed) { - p = ht->arData + h; - if (Z_TYPE(p->val) != IS_UNDEF) { + zv = ht->arPacked + h; + if (Z_TYPE_P(zv) != IS_UNDEF) { if (flag & HASH_LOOKUP) { - return &p->val; + return zv; } replace: if (flag & HASH_ADD) { return NULL; } if (ht->pDestructor) { - ht->pDestructor(&p->val); + ht->pDestructor(zv); } - ZVAL_COPY_VALUE(&p->val, pData); - return &p->val; + ZVAL_COPY_VALUE(zv, pData); + return zv; } else { /* we have to keep the order :( */ goto convert_to_hash; } } else if (EXPECTED(h < ht->nTableSize)) { add_to_packed: - p = ht->arData + h; + zv = ht->arPacked + h; /* incremental initialization of empty Buckets */ if ((flag & (HASH_ADD_NEW|HASH_ADD_NEXT)) != (HASH_ADD_NEW|HASH_ADD_NEXT)) { if (h > ht->nNumUsed) { - Bucket *q = ht->arData + ht->nNumUsed; - while (q != p) { - ZVAL_UNDEF(&q->val); + zval *q = ht->arPacked + ht->nNumUsed; + while (q != zv) { + ZVAL_UNDEF(q); q++; } } } ht->nNextFreeElement = ht->nNumUsed = h + 1; - goto add; + ht->nNumOfElements++; + if (flag & HASH_LOOKUP) { + ZVAL_NULL(zv); + } else { + ZVAL_COPY_VALUE(zv, pData); + } + + return zv; } else if ((h >> 1) < ht->nTableSize && (ht->nTableSize >> 1) < ht->nNumOfElements) { zend_hash_packed_grow(ht); @@ -1058,6 +1084,7 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, return &p->val; } ZEND_ASSERT((flag & HASH_ADD_NEW) == 0); + zv = &p->val; goto replace; } } @@ -1072,7 +1099,6 @@ static zend_always_inline zval *_zend_hash_index_add_or_update_i(HashTable *ht, if ((zend_long)h >= ht->nNextFreeElement) { ht->nNextFreeElement = (zend_long)h < ZEND_LONG_MAX ? h + 1 : ZEND_LONG_MAX; } -add: ht->nNumOfElements++; p->h = h; p->key = NULL; @@ -1141,7 +1167,7 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_set_bucket_key(HashTable *ht, Bucket *b, IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); - ZEND_ASSERT(!(HT_FLAGS(ht) & HASH_FLAG_PACKED)); + ZEND_ASSERT(!HT_IS_PACKED(ht)); p = zend_hash_find_bucket(ht, key, 0); if (UNEXPECTED(p)) { @@ -1199,6 +1225,7 @@ static void ZEND_FASTCALL zend_hash_do_resize(HashTable *ht) IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); + ZEND_ASSERT(!HT_IS_PACKED(ht)); if (ht->nNumUsed > ht->nNumOfElements + (ht->nNumOfElements >> 5)) { /* additional term is there to amortize the cost of compaction */ zend_hash_rehash(ht); } else if (ht->nTableSize < HT_MAX_SIZE) { /* Let's double the table size */ @@ -1310,14 +1337,53 @@ ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht) } } -static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, Bucket *p, Bucket *prev) +static zend_always_inline void _zend_hash_packed_del_val(HashTable *ht, uint32_t idx, zval *zv) { - if (!(HT_FLAGS(ht) & HASH_FLAG_PACKED)) { - if (prev) { - Z_NEXT(prev->val) = Z_NEXT(p->val); - } else { - HT_HASH(ht, p->h | ht->nTableMask) = Z_NEXT(p->val); + ZEND_ASSERT(HT_IS_PACKED(ht)); + + idx = HT_HASH_TO_IDX(idx); + ht->nNumOfElements--; + if (ht->nInternalPointer == idx || UNEXPECTED(HT_HAS_ITERATORS(ht))) { + uint32_t new_idx; + + new_idx = idx; + while (1) { + new_idx++; + if (new_idx >= ht->nNumUsed) { + break; + } else if (Z_TYPE(ht->arPacked[new_idx]) != IS_UNDEF) { + break; + } + } + if (ht->nInternalPointer == idx) { + ht->nInternalPointer = new_idx; } + zend_hash_iterators_update(ht, idx, new_idx); + } + if (ht->nNumUsed - 1 == idx) { + do { + ht->nNumUsed--; + } while (ht->nNumUsed > 0 && (UNEXPECTED(Z_TYPE(ht->arPacked[ht->nNumUsed-1]) == IS_UNDEF))); + ht->nInternalPointer = MIN(ht->nInternalPointer, ht->nNumUsed); + } + if (ht->pDestructor) { + zval tmp; + ZVAL_COPY_VALUE(&tmp, zv); + ZVAL_UNDEF(zv); + ht->pDestructor(&tmp); + } else { + ZVAL_UNDEF(zv); + } +} + +static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, Bucket *p, Bucket *prev) +{ + ZEND_ASSERT(!HT_IS_PACKED(ht)); + + if (prev) { + Z_NEXT(prev->val) = Z_NEXT(p->val); + } else { + HT_HASH(ht, p->h | ht->nTableMask) = Z_NEXT(p->val); } idx = HT_HASH_TO_IDX(idx); ht->nNumOfElements--; @@ -1360,27 +1426,39 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, static zend_always_inline void _zend_hash_del_el(HashTable *ht, uint32_t idx, Bucket *p) { Bucket *prev = NULL; + uint32_t nIndex; + uint32_t i; + + ZEND_ASSERT(!HT_IS_PACKED(ht)); - if (!(HT_FLAGS(ht) & HASH_FLAG_PACKED)) { - uint32_t nIndex = p->h | ht->nTableMask; - uint32_t i = HT_HASH(ht, nIndex); + nIndex = p->h | ht->nTableMask; + i = HT_HASH(ht, nIndex); - if (i != idx) { + if (i != idx) { + prev = HT_HASH_TO_BUCKET(ht, i); + while (Z_NEXT(prev->val) != idx) { + i = Z_NEXT(prev->val); prev = HT_HASH_TO_BUCKET(ht, i); - while (Z_NEXT(prev->val) != idx) { - i = Z_NEXT(prev->val); - prev = HT_HASH_TO_BUCKET(ht, i); - } - } + } } _zend_hash_del_el_ex(ht, idx, p, prev); } +ZEND_API void ZEND_FASTCALL zend_hash_packed_del_val(HashTable *ht, zval *zv) +{ + IS_CONSISTENT(ht); + HT_ASSERT_RC1(ht); + ZEND_ASSERT(HT_IS_PACKED(ht)); + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(zv - ht->arPacked), zv); +} + + ZEND_API void ZEND_FASTCALL zend_hash_del_bucket(HashTable *ht, Bucket *p) { IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); + ZEND_ASSERT(!HT_IS_PACKED(ht)); _zend_hash_del_el(ht, HT_IDX_TO_HASH(p - ht->arData), p); } @@ -1546,11 +1624,11 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_index_del(HashTable *ht, zend_ulong IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); - if (HT_FLAGS(ht) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(ht)) { if (h < ht->nNumUsed) { - p = ht->arData + h; - if (Z_TYPE(p->val) != IS_UNDEF) { - _zend_hash_del_el_ex(ht, HT_IDX_TO_HASH(h), p, NULL); + zval *zv = ht->arPacked + h; + if (Z_TYPE_P(zv) != IS_UNDEF) { + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(h), zv); return SUCCESS; } } @@ -1573,60 +1651,81 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_index_del(HashTable *ht, zend_ulong ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht) { - Bucket *p, *end; - IS_CONSISTENT(ht); HT_ASSERT(ht, GC_REFCOUNT(ht) <= 1); if (ht->nNumUsed) { - p = ht->arData; - end = p + ht->nNumUsed; - if (ht->pDestructor) { - SET_INCONSISTENT(HT_IS_DESTROYING); + if (HT_IS_PACKED(ht)) { + if (ht->pDestructor) { + zval *zv = ht->arPacked; + zval *end = zv + ht->nNumUsed; - if (HT_HAS_STATIC_KEYS_ONLY(ht)) { + SET_INCONSISTENT(HT_IS_DESTROYING); if (HT_IS_WITHOUT_HOLES(ht)) { do { - ht->pDestructor(&p->val); - } while (++p != end); + ht->pDestructor(zv); + } while (++zv != end); } else { do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { - ht->pDestructor(&p->val); + if (EXPECTED(Z_TYPE_P(zv) != IS_UNDEF)) { + ht->pDestructor(zv); } - } while (++p != end); + } while (++zv != end); } - } else if (HT_IS_WITHOUT_HOLES(ht)) { - do { - ht->pDestructor(&p->val); - if (EXPECTED(p->key)) { - zend_string_release(p->key); + SET_INCONSISTENT(HT_DESTROYED); + } + zend_hash_iterators_remove(ht); + } else { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + if (ht->pDestructor) { + SET_INCONSISTENT(HT_IS_DESTROYING); + + if (HT_HAS_STATIC_KEYS_ONLY(ht)) { + if (HT_IS_WITHOUT_HOLES(ht)) { + do { + ht->pDestructor(&p->val); + } while (++p != end); + } else { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + ht->pDestructor(&p->val); + } + } while (++p != end); } - } while (++p != end); - } else { - do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + } else if (HT_IS_WITHOUT_HOLES(ht)) { + do { ht->pDestructor(&p->val); if (EXPECTED(p->key)) { zend_string_release(p->key); } - } - } while (++p != end); - } - - SET_INCONSISTENT(HT_DESTROYED); - } else { - if (!HT_HAS_STATIC_KEYS_ONLY(ht)) { - do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { - if (EXPECTED(p->key)) { + } while (++p != end); + } else { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + ht->pDestructor(&p->val); + if (EXPECTED(p->key)) { zend_string_release(p->key); + } } - } - } while (++p != end); + } while (++p != end); + } + + SET_INCONSISTENT(HT_DESTROYED); + } else { + if (!HT_HAS_STATIC_KEYS_ONLY(ht)) { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + if (EXPECTED(p->key)) { + zend_string_release(p->key); + } + } + } while (++p != end); + } } + zend_hash_iterators_remove(ht); } - zend_hash_iterators_remove(ht); } else if (EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) { return; } @@ -1635,8 +1734,6 @@ ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht) { - Bucket *p, *end; - IS_CONSISTENT(ht); HT_ASSERT(ht, GC_REFCOUNT(ht) <= 1); @@ -1651,30 +1748,40 @@ ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht) goto free_ht; } - p = ht->arData; - end = p + ht->nNumUsed; SET_INCONSISTENT(HT_IS_DESTROYING); - if (HT_HAS_STATIC_KEYS_ONLY(ht)) { - do { - i_zval_ptr_dtor(&p->val); - } while (++p != end); - } else if (HT_IS_WITHOUT_HOLES(ht)) { + if (HT_IS_PACKED(ht)) { + zval *zv = ht->arPacked; + zval *end = zv + ht->nNumUsed; + do { - i_zval_ptr_dtor(&p->val); - if (EXPECTED(p->key)) { - zend_string_release_ex(p->key, 0); - } - } while (++p != end); + i_zval_ptr_dtor(zv); + } while (++zv != end); } else { - do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + if (HT_HAS_STATIC_KEYS_ONLY(ht)) { + do { + i_zval_ptr_dtor(&p->val); + } while (++p != end); + } else if (HT_IS_WITHOUT_HOLES(ht)) { + do { i_zval_ptr_dtor(&p->val); if (EXPECTED(p->key)) { zend_string_release_ex(p->key, 0); } - } - } while (++p != end); + } while (++p != end); + } else { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + i_zval_ptr_dtor(&p->val); + if (EXPECTED(p->key)) { + zend_string_release_ex(p->key, 0); + } + } + } while (++p != end); + } } } else if (EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) { goto free_ht; @@ -1688,48 +1795,49 @@ ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht) { - Bucket *p, *end; - IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); if (ht->nNumUsed) { - p = ht->arData; - end = p + ht->nNumUsed; - if (ht->pDestructor) { - if (HT_HAS_STATIC_KEYS_ONLY(ht)) { - if (HT_IS_WITHOUT_HOLES(ht)) { - do { - ht->pDestructor(&p->val); - } while (++p != end); - } else { - do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { - ht->pDestructor(&p->val); - } - } while (++p != end); - } - } else if (HT_IS_WITHOUT_HOLES(ht)) { - do { - ht->pDestructor(&p->val); - if (EXPECTED(p->key)) { - zend_string_release(p->key); - } - } while (++p != end); - } else { - do { - if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { - ht->pDestructor(&p->val); - if (EXPECTED(p->key)) { - zend_string_release(p->key); - } + if (HT_IS_PACKED(ht)) { + zval *zv = ht->arPacked; + zval *end = zv + ht->nNumUsed; + + if (ht->pDestructor) { + if (HT_HAS_STATIC_KEYS_ONLY(ht)) { + if (HT_IS_WITHOUT_HOLES(ht)) { + do { + ht->pDestructor(zv); + } while (++zv != end); + } else { + do { + if (EXPECTED(Z_TYPE_P(zv) != IS_UNDEF)) { + ht->pDestructor(zv); + } + } while (++zv != end); } - } while (++p != end); + } } } else { - if (!HT_HAS_STATIC_KEYS_ONLY(ht)) { - if (HT_IS_WITHOUT_HOLES(ht)) { + Bucket *p = ht->arData; + Bucket *end = p + ht->nNumUsed; + + if (ht->pDestructor) { + if (HT_HAS_STATIC_KEYS_ONLY(ht)) { + if (HT_IS_WITHOUT_HOLES(ht)) { + do { + ht->pDestructor(&p->val); + } while (++p != end); + } else { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + ht->pDestructor(&p->val); + } + } while (++p != end); + } + } else if (HT_IS_WITHOUT_HOLES(ht)) { do { + ht->pDestructor(&p->val); if (EXPECTED(p->key)) { zend_string_release(p->key); } @@ -1737,15 +1845,32 @@ ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht) } else { do { if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + ht->pDestructor(&p->val); if (EXPECTED(p->key)) { zend_string_release(p->key); } } } while (++p != end); } + } else { + if (!HT_HAS_STATIC_KEYS_ONLY(ht)) { + if (HT_IS_WITHOUT_HOLES(ht)) { + do { + if (EXPECTED(p->key)) { + zend_string_release(p->key); + } + } while (++p != end); + } else { + do { + if (EXPECTED(Z_TYPE(p->val) != IS_UNDEF)) { + if (EXPECTED(p->key)) { + zend_string_release(p->key); + } + } + } while (++p != end); + } + } } - } - if (!(HT_FLAGS(ht) & HASH_FLAG_PACKED)) { HT_HASH_RESET(ht); } } @@ -1763,6 +1888,7 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht) HT_ASSERT_RC1(ht); if (ht->nNumUsed) { + ZEND_ASSERT(!HT_IS_PACKED(ht)); p = ht->arData; end = p + ht->nNumUsed; if (HT_HAS_STATIC_KEYS_ONLY(ht)) { @@ -1797,15 +1923,24 @@ ZEND_API void ZEND_FASTCALL zend_symtable_clean(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_graceful_destroy(HashTable *ht) { uint32_t idx; - Bucket *p; IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); - p = ht->arData; - for (idx = 0; idx < ht->nNumUsed; idx++, p++) { - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + if (HT_IS_PACKED(ht)) { + zval *zv = ht->arPacked; + + for (idx = 0; idx < ht->nNumUsed; idx++, zv++) { + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + } else { + Bucket *p = ht->arData; + + for (idx = 0; idx < ht->nNumUsed; idx++, p++) { + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } } if (!(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) { pefree(HT_GET_DATA_ADDR(ht), GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); @@ -1817,18 +1952,29 @@ ZEND_API void ZEND_FASTCALL zend_hash_graceful_destroy(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_graceful_reverse_destroy(HashTable *ht) { uint32_t idx; - Bucket *p; IS_CONSISTENT(ht); HT_ASSERT_RC1(ht); idx = ht->nNumUsed; - p = ht->arData + ht->nNumUsed; - while (idx > 0) { - idx--; - p--; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + if (HT_IS_PACKED(ht)) { + zval *zv = ht->arPacked + ht->nNumUsed; + + while (idx > 0) { + idx--; + zv--; + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + } else { + Bucket *p = ht->arData + ht->nNumUsed; + + while (idx > 0) { + idx--; + p--; + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } } if (!(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) { @@ -1850,22 +1996,38 @@ ZEND_API void ZEND_FASTCALL zend_hash_graceful_reverse_destroy(HashTable *ht) ZEND_API void ZEND_FASTCALL zend_hash_apply(HashTable *ht, apply_func_t apply_func) { uint32_t idx; - Bucket *p; int result; IS_CONSISTENT(ht); + if (HT_IS_PACKED(ht)) { + for (idx = 0; idx < ht->nNumUsed; idx++) { + zval *zv = ht->arPacked + idx; - for (idx = 0; idx < ht->nNumUsed; idx++) { - p = ht->arData + idx; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - result = apply_func(&p->val); + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + result = apply_func(zv); - if (result & ZEND_HASH_APPLY_REMOVE) { - HT_ASSERT_RC1(ht); - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } - if (result & ZEND_HASH_APPLY_STOP) { - break; + } else { + for (idx = 0; idx < ht->nNumUsed; idx++) { + Bucket *p = ht->arData + idx; + + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + result = apply_func(&p->val); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } } } @@ -1874,22 +2036,36 @@ ZEND_API void ZEND_FASTCALL zend_hash_apply(HashTable *ht, apply_func_t apply_fu ZEND_API void ZEND_FASTCALL zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *argument) { uint32_t idx; - Bucket *p; int result; IS_CONSISTENT(ht); - - for (idx = 0; idx < ht->nNumUsed; idx++) { - p = ht->arData + idx; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - result = apply_func(&p->val, argument); - - if (result & ZEND_HASH_APPLY_REMOVE) { - HT_ASSERT_RC1(ht); - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + if (HT_IS_PACKED(ht)) { + for (idx = 0; idx < ht->nNumUsed; idx++) { + zval *zv = ht->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + result = apply_func(zv, argument); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } - if (result & ZEND_HASH_APPLY_STOP) { - break; + } else { + for (idx = 0; idx < ht->nNumUsed; idx++) { + Bucket *p = ht->arData + idx; + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + result = apply_func(&p->val, argument); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } } } @@ -1898,31 +2074,54 @@ ZEND_API void ZEND_FASTCALL zend_hash_apply_with_argument(HashTable *ht, apply_f ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t apply_func, int num_args, ...) { uint32_t idx; - Bucket *p; va_list args; zend_hash_key hash_key; int result; IS_CONSISTENT(ht); - for (idx = 0; idx < ht->nNumUsed; idx++) { - p = ht->arData + idx; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - va_start(args, num_args); - hash_key.h = p->h; - hash_key.key = p->key; + if (HT_IS_PACKED(ht)) { + for (idx = 0; idx < ht->nNumUsed; idx++) { + zval *zv = ht->arPacked + idx; - result = apply_func(&p->val, num_args, args, &hash_key); + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + va_start(args, num_args); + hash_key.h = idx; + hash_key.key = NULL; - if (result & ZEND_HASH_APPLY_REMOVE) { - HT_ASSERT_RC1(ht); - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + result = apply_func(zv, num_args, args, &hash_key); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + if (result & ZEND_HASH_APPLY_STOP) { + va_end(args); + break; + } + va_end(args); } - if (result & ZEND_HASH_APPLY_STOP) { + } else { + for (idx = 0; idx < ht->nNumUsed; idx++) { + Bucket *p = ht->arData + idx; + + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + va_start(args, num_args); + hash_key.h = p->h; + hash_key.key = p->key; + + result = apply_func(&p->val, num_args, args, &hash_key); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } + if (result & ZEND_HASH_APPLY_STOP) { + va_end(args); + break; + } va_end(args); - break; } - va_end(args); } } @@ -1930,25 +2129,46 @@ ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t ap ZEND_API void ZEND_FASTCALL zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func) { uint32_t idx; - Bucket *p; int result; IS_CONSISTENT(ht); idx = ht->nNumUsed; - while (idx > 0) { - idx--; - p = ht->arData + idx; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + if (HT_IS_PACKED(ht)) { + zval *zv; - result = apply_func(&p->val); + while (idx > 0) { + idx--; + zv = ht->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; - if (result & ZEND_HASH_APPLY_REMOVE) { - HT_ASSERT_RC1(ht); - _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + result = apply_func(zv); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_packed_del_val(ht, HT_IDX_TO_HASH(idx), zv); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } - if (result & ZEND_HASH_APPLY_STOP) { - break; + } else { + Bucket *p; + + while (idx > 0) { + idx--; + p = ht->arData + idx; + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + + result = apply_func(&p->val); + + if (result & ZEND_HASH_APPLY_REMOVE) { + HT_ASSERT_RC1(ht); + _zend_hash_del_el(ht, HT_IDX_TO_HASH(idx), p); + } + if (result & ZEND_HASH_APPLY_STOP) { + break; + } } } } @@ -1957,15 +2177,36 @@ ZEND_API void ZEND_FASTCALL zend_hash_reverse_apply(HashTable *ht, apply_func_t ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor) { uint32_t idx; - Bucket *p; zval *new_entry, *data; IS_CONSISTENT(source); IS_CONSISTENT(target); HT_ASSERT_RC1(target); + if (HT_IS_PACKED(source)) { + for (idx = 0; idx < source->nNumUsed; idx++) { + zval *zv = source->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; + + /* INDIRECT element may point to UNDEF-ined slots */ + data = zv; + if (Z_TYPE_P(data) == IS_INDIRECT) { + data = Z_INDIRECT_P(data); + if (UNEXPECTED(Z_TYPE_P(data) == IS_UNDEF)) { + continue; + } + } + new_entry = zend_hash_index_update(target, idx, data); + if (pCopyConstructor) { + pCopyConstructor(new_entry); + } + } + return; + } + for (idx = 0; idx < source->nNumUsed; idx++) { - p = source->arData + idx; + Bucket *p = source->arData + idx; + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; /* INDIRECT element may point to UNDEF-ined slots */ @@ -1988,10 +2229,8 @@ ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, } -static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTable *target, uint32_t idx, Bucket *p, Bucket *q, bool packed, bool static_keys, bool with_holes) +static zend_always_inline bool zend_array_dup_value(HashTable *source, HashTable *target, zval *data, zval *dest, bool packed, bool with_holes) { - zval *data = &p->val; - if (with_holes) { if (!packed && Z_TYPE_INFO_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); @@ -2022,14 +2261,21 @@ static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTab Z_ADDREF_P(data); } } while (0); - ZVAL_COPY_VALUE(&q->val, data); + ZVAL_COPY_VALUE(dest, data); - q->h = p->h; - if (packed) { - q->key = NULL; - } else { + return 1; +} + +static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTable *target, uint32_t idx, Bucket *p, Bucket *q, bool packed, bool static_keys, bool with_holes) +{ + if (!zend_array_dup_value(source, target, &p->val, &q->val, packed, with_holes)) { + return 0; + } + + if (!packed) { uint32_t nIndex; + q->h = p->h; q->key = p->key; if (!static_keys && q->key) { zend_string_addref(q->key); @@ -2044,14 +2290,14 @@ static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTab static zend_always_inline void zend_array_dup_packed_elements(HashTable *source, HashTable *target, bool with_holes) { - Bucket *p = source->arData; - Bucket *q = target->arData; - Bucket *end = p + source->nNumUsed; + zval *p = source->arPacked; + zval *q = target->arPacked; + zval *end = p + source->nNumUsed; do { - if (!zend_array_dup_element(source, target, 0, p, q, 1, 1, with_holes)) { + if (!zend_array_dup_value(source, target, p, q, 1, with_holes)) { if (with_holes) { - ZVAL_UNDEF(&q->val); + ZVAL_UNDEF(q); } } p++; q++; @@ -2115,17 +2361,23 @@ ZEND_API HashTable* ZEND_FASTCALL zend_array_dup(HashTable *source) target->nNumOfElements = source->nNumOfElements; target->nNextFreeElement = source->nNextFreeElement; target->nTableSize = source->nTableSize; - HT_SET_DATA_ADDR(target, emalloc(HT_SIZE(target))); - target->nInternalPointer = source->nInternalPointer; - memcpy(HT_GET_DATA_ADDR(target), HT_GET_DATA_ADDR(source), HT_USED_SIZE(source)); - } else if (HT_FLAGS(source) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(source)) { + HT_SET_DATA_ADDR(target, emalloc(HT_PACKED_SIZE(target))); + target->nInternalPointer = source->nInternalPointer; + memcpy(HT_GET_DATA_ADDR(target), HT_GET_DATA_ADDR(source), HT_PACKED_USED_SIZE(source)); + } else { + HT_SET_DATA_ADDR(target, emalloc(HT_SIZE(target))); + target->nInternalPointer = source->nInternalPointer; + memcpy(HT_GET_DATA_ADDR(target), HT_GET_DATA_ADDR(source), HT_USED_SIZE(source)); + } + } else if (HT_IS_PACKED(source)) { HT_FLAGS(target) = HT_FLAGS(source) & HASH_FLAG_MASK; target->nTableMask = HT_MIN_MASK; target->nNumUsed = source->nNumUsed; target->nNumOfElements = source->nNumOfElements; target->nNextFreeElement = source->nNextFreeElement; target->nTableSize = source->nTableSize; - HT_SET_DATA_ADDR(target, emalloc(HT_SIZE_EX(target->nTableSize, HT_MIN_MASK))); + HT_SET_DATA_ADDR(target, emalloc(HT_PACKED_SIZE_EX(target->nTableSize, HT_MIN_MASK))); target->nInternalPointer = (source->nInternalPointer < source->nNumUsed) ? source->nInternalPointer : 0; @@ -2180,6 +2432,20 @@ ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, HashTable *source HT_ASSERT_RC1(target); if (overwrite) { + if (HT_IS_PACKED(source)) { + for (idx = 0; idx < source->nNumUsed; idx++) { + s = source->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(s) == IS_UNDEF)) { + continue; + } + t = zend_hash_index_update(target, idx, s); + if (pCopyConstructor) { + pCopyConstructor(t); + } + } + return; + } + for (idx = 0; idx < source->nNumUsed; idx++) { p = source->arData + idx; s = &p->val; @@ -2202,6 +2468,20 @@ ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, HashTable *source } } } else { + if (HT_IS_PACKED(source)) { + for (idx = 0; idx < source->nNumUsed; idx++) { + s = source->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(s) == IS_UNDEF)) { + continue; + } + t = zend_hash_index_add(target, idx, s); + if (t && pCopyConstructor) { + pCopyConstructor(t); + } + } + return; + } + for (idx = 0; idx < source->nNumUsed; idx++) { p = source->arData + idx; s = &p->val; @@ -2227,12 +2507,12 @@ ZEND_API void ZEND_FASTCALL zend_hash_merge(HashTable *target, HashTable *source } -static bool ZEND_FASTCALL zend_hash_replace_checker_wrapper(HashTable *target, zval *source_data, Bucket *p, void *pParam, merge_checker_func_t merge_checker_func) +static bool ZEND_FASTCALL zend_hash_replace_checker_wrapper(HashTable *target, zval *source_data, zend_ulong h, zend_string *key, void *pParam, merge_checker_func_t merge_checker_func) { zend_hash_key hash_key; - hash_key.h = p->h; - hash_key.key = p->key; + hash_key.h = h; + hash_key.key = key; return merge_checker_func(target, source_data, &hash_key, pParam); } @@ -2247,10 +2527,11 @@ ZEND_API void ZEND_FASTCALL zend_hash_merge_ex(HashTable *target, HashTable *sou IS_CONSISTENT(target); HT_ASSERT_RC1(target); + ZEND_ASSERT(!HT_IS_PACKED(source)); for (idx = 0; idx < source->nNumUsed; idx++) { p = source->arData + idx; if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; - if (zend_hash_replace_checker_wrapper(target, &p->val, p, pParam, pMergeSource)) { + if (zend_hash_replace_checker_wrapper(target, &p->val, p->h, p->key, pParam, pMergeSource)) { t = zend_hash_update(target, p->key, &p->val); if (pCopyConstructor) { pCopyConstructor(t); @@ -2299,11 +2580,12 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_index_find(const HashTable *ht, zend_ulon IS_CONSISTENT(ht); - if (HT_FLAGS(ht) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(ht)) { if (h < ht->nNumUsed) { - p = ht->arData + h; - if (Z_TYPE(p->val) != IS_UNDEF) { - return &p->val; + zval *zv = ht->arPacked + h; + + if (Z_TYPE_P(zv) != IS_UNDEF) { + return zv; } } return NULL; @@ -2342,11 +2624,21 @@ ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, Has HT_ASSERT(ht, &ht->nInternalPointer != pos || GC_REFCOUNT(ht) == 1); idx = ht->nNumUsed; - while (idx > 0) { - idx--; - if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { - *pos = idx; - return; + if (HT_IS_PACKED(ht)) { + while (idx > 0) { + idx--; + if (Z_TYPE(ht->arPacked[idx]) != IS_UNDEF) { + *pos = idx; + return; + } + } + } else { + while (idx > 0) { + idx--; + if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { + *pos = idx; + return; + } } } *pos = ht->nNumUsed; @@ -2362,15 +2654,29 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_move_forward_ex(HashTable *ht, Hash idx = _zend_hash_get_valid_pos(ht, *pos); if (idx < ht->nNumUsed) { - while (1) { - idx++; - if (idx >= ht->nNumUsed) { - *pos = ht->nNumUsed; - return SUCCESS; + if (HT_IS_PACKED(ht)) { + while (1) { + idx++; + if (idx >= ht->nNumUsed) { + *pos = ht->nNumUsed; + return SUCCESS; + } + if (Z_TYPE(ht->arPacked[idx]) != IS_UNDEF) { + *pos = idx; + return SUCCESS; + } } - if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { - *pos = idx; - return SUCCESS; + } else { + while (1) { + idx++; + if (idx >= ht->nNumUsed) { + *pos = ht->nNumUsed; + return SUCCESS; + } + if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { + *pos = idx; + return SUCCESS; + } } } } else { @@ -2386,11 +2692,21 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, Ha HT_ASSERT(ht, &ht->nInternalPointer != pos || GC_REFCOUNT(ht) == 1); if (idx < ht->nNumUsed) { - while (idx > 0) { - idx--; - if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { - *pos = idx; - return SUCCESS; + if (HT_IS_PACKED(ht)) { + while (idx > 0) { + idx--; + if (Z_TYPE(ht->arPacked[idx]) != IS_UNDEF) { + *pos = idx; + return SUCCESS; + } + } + } else { + while (idx > 0) { + idx--; + if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) { + *pos = idx; + return SUCCESS; + } } } *pos = ht->nNumUsed; @@ -2410,6 +2726,10 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zen IS_CONSISTENT(ht); idx = _zend_hash_get_valid_pos(ht, *pos); if (idx < ht->nNumUsed) { + if (HT_IS_PACKED(ht)) { + *num_index = idx; + return HASH_KEY_IS_LONG; + } p = ht->arData + idx; if (p->key) { *str_index = p->key; @@ -2432,6 +2752,10 @@ ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *h if (idx >= ht->nNumUsed) { ZVAL_NULL(key); } else { + if (HT_IS_PACKED(ht)) { + ZVAL_LONG(key, idx); + return; + } p = ht->arData + idx; if (p->key) { ZVAL_STR_COPY(key, p->key); @@ -2449,6 +2773,9 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, Hash IS_CONSISTENT(ht); idx = _zend_hash_get_valid_pos(ht, *pos); if (idx < ht->nNumUsed) { + if (HT_IS_PACKED(ht)) { + return HASH_KEY_IS_LONG; + } p = ht->arData + idx; if (p->key) { return HASH_KEY_IS_STRING; @@ -2468,6 +2795,9 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_data_ex(HashTable *ht, HashPo IS_CONSISTENT(ht); idx = _zend_hash_get_valid_pos(ht, *pos); if (idx < ht->nNumUsed) { + if (HT_IS_PACKED(ht)) { + return &ht->arPacked[idx]; + } p = ht->arData + idx; return &p->val; } else { @@ -2531,6 +2861,10 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b return; } + if (HT_IS_PACKED(ht)) { + zend_hash_packed_to_hash(ht); // TODO: ??? + } + if (HT_IS_WITHOUT_HOLES(ht)) { /* Store original order of elements in extra space to allow stable sorting. */ for (i = 0; i < ht->nNumUsed; i++) { @@ -2552,7 +2886,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b sort((void *)ht->arData, ht->nNumUsed, sizeof(Bucket), (compare_func_t) compar, (swap_func_t)(renumber? zend_hash_bucket_renum_swap : - ((HT_FLAGS(ht) & HASH_FLAG_PACKED) ? zend_hash_bucket_packed_swap : zend_hash_bucket_swap))); + (HT_IS_PACKED(ht) ? zend_hash_bucket_packed_swap : zend_hash_bucket_swap))); ht->nInternalPointer = 0; @@ -2568,7 +2902,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b ht->nNextFreeElement = i; } - if (HT_FLAGS(ht) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(ht)) { if (!renumber) { zend_hash_packed_to_hash(ht); } @@ -2576,12 +2910,19 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b if (renumber) { void *new_data, *old_data = HT_GET_DATA_ADDR(ht); Bucket *old_buckets = ht->arData; + zval *zv; - new_data = pemalloc(HT_SIZE_EX(ht->nTableSize, HT_MIN_MASK), (GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); + new_data = pemalloc(HT_PACKED_SIZE_EX(ht->nTableSize, HT_MIN_MASK), (GC_FLAGS(ht) & IS_ARRAY_PERSISTENT)); HT_FLAGS(ht) |= HASH_FLAG_PACKED | HASH_FLAG_STATIC_KEYS; ht->nTableMask = HT_MIN_MASK; HT_SET_DATA_ADDR(ht, new_data); - memcpy(ht->arData, old_buckets, sizeof(Bucket) * ht->nNumUsed); + p = old_buckets; + zv = ht->arPacked; + for (i = 0; i < ht->nTableSize; i++) { + ZVAL_COPY_VALUE(zv, &p->val); + zv++; + p++; + } pefree(old_data, GC_FLAGS(ht) & IS_ARRAY_PERSISTENT); HT_HASH_RESET_PACKED(ht); } else { @@ -2592,58 +2933,82 @@ ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort, b static zend_always_inline int zend_hash_compare_impl(HashTable *ht1, HashTable *ht2, compare_func_t compar, bool ordered) { uint32_t idx1, idx2; + zend_string *key1, *key2; + zend_ulong h1, h2; + zval *pData1, *pData2;; + int result; if (ht1->nNumOfElements != ht2->nNumOfElements) { return ht1->nNumOfElements > ht2->nNumOfElements ? 1 : -1; } for (idx1 = 0, idx2 = 0; idx1 < ht1->nNumUsed; idx1++) { - Bucket *p1 = ht1->arData + idx1, *p2; - zval *pData1, *pData2; - int result; + if (HT_IS_PACKED(ht1)) { + pData1 = ht1->arPacked + idx1; + h1 = idx1; + key1 = NULL; + } else { + Bucket *p = ht1->arData + idx1; + pData1 = &p->val; + h1 = p->h; + key1 = p->key; + } - if (Z_TYPE(p1->val) == IS_UNDEF) continue; + if (Z_TYPE_P(pData1) == IS_UNDEF) continue; if (ordered) { - while (1) { - ZEND_ASSERT(idx2 != ht2->nNumUsed); - p2 = ht2->arData + idx2; - if (Z_TYPE(p2->val) != IS_UNDEF) break; - idx2++; - } - if (p1->key == NULL && p2->key == NULL) { /* numeric indices */ - if (p1->h != p2->h) { - return p1->h > p2->h ? 1 : -1; + if (HT_IS_PACKED(ht2)) { + while (1) { + ZEND_ASSERT(idx2 != ht2->nNumUsed); + pData2 = ht2->arPacked + idx2; + h2 = idx2; + key2 = NULL; + if (Z_TYPE_P(pData2) != IS_UNDEF) break; + idx2++; + } + } else { + while (1) { + Bucket *p; + ZEND_ASSERT(idx2 != ht2->nNumUsed); + p = ht2->arData + idx2; + pData2 = &p->val; + h2 = p->h; + key2 = p->key; + if (Z_TYPE_P(pData2) != IS_UNDEF) break; + idx2++; + } + } + if (key1 == NULL && key2 == NULL) { /* numeric indices */ + if (h1 != h2) { + return h1 > h2 ? 1 : -1; } - } else if (p1->key != NULL && p2->key != NULL) { /* string indices */ - if (ZSTR_LEN(p1->key) != ZSTR_LEN(p2->key)) { - return ZSTR_LEN(p1->key) > ZSTR_LEN(p2->key) ? 1 : -1; + } else if (key1 != NULL && key2 != NULL) { /* string indices */ + if (ZSTR_LEN(key1) != ZSTR_LEN(key2)) { + return ZSTR_LEN(key1) > ZSTR_LEN(key2) ? 1 : -1; } - result = memcmp(ZSTR_VAL(p1->key), ZSTR_VAL(p2->key), ZSTR_LEN(p1->key)); + result = memcmp(ZSTR_VAL(key1), ZSTR_VAL(key2), ZSTR_LEN(key1)); if (result != 0) { return result; } } else { /* Mixed key types: A string key is considered as larger */ - return p1->key != NULL ? 1 : -1; + return key1 != NULL ? 1 : -1; } - pData2 = &p2->val; idx2++; } else { - if (p1->key == NULL) { /* numeric index */ - pData2 = zend_hash_index_find(ht2, p1->h); + if (key1 == NULL) { /* numeric index */ + pData2 = zend_hash_index_find(ht2, h1); if (pData2 == NULL) { return 1; } } else { /* string index */ - pData2 = zend_hash_find(ht2, p1->key); + pData2 = zend_hash_find(ht2, key1); if (pData2 == NULL) { return 1; } } } - pData1 = &p1->val; if (Z_TYPE_P(pData1) == IS_INDIRECT) { pData1 = Z_INDIRECT_P(pData1); } @@ -2694,10 +3059,10 @@ ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t co } -ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, bucket_compare_func_t compar, uint32_t flag) +ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag) { uint32_t idx; - Bucket *p, *res; + zval *res; IS_CONSISTENT(ht); @@ -2705,30 +3070,60 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, bucket_compar return NULL; } - idx = 0; - while (1) { - if (idx == ht->nNumUsed) { - return NULL; + if (HT_IS_PACKED(ht)) { + zval *zv; + + idx = 0; + while (1) { + if (idx == ht->nNumUsed) { + return NULL; + } + if (Z_TYPE(ht->arPacked[idx]) != IS_UNDEF) break; + idx++; } - if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) break; - idx++; - } - res = ht->arData + idx; - for (; idx < ht->nNumUsed; idx++) { - p = ht->arData + idx; - if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + res = ht->arPacked + idx; + for (; idx < ht->nNumUsed; idx++) { + zv = ht->arPacked + idx; + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; - if (flag) { - if (compar(res, p) < 0) { /* max */ - res = p; + if (flag) { + if (compar(res, zv) < 0) { /* max */ + res = zv; + } + } else { + if (compar(res, zv) > 0) { /* min */ + res = zv; + } } - } else { - if (compar(res, p) > 0) { /* min */ - res = p; + } + } else { + Bucket *p; + + idx = 0; + while (1) { + if (idx == ht->nNumUsed) { + return NULL; + } + if (Z_TYPE(ht->arData[idx].val) != IS_UNDEF) break; + idx++; + } + res = &ht->arData[idx].val; + for (; idx < ht->nNumUsed; idx++) { + p = ht->arData + idx; + if (UNEXPECTED(Z_TYPE(p->val) == IS_UNDEF)) continue; + + if (flag) { + if (compar(res, &p->val) < 0) { /* max */ + res = &p->val; + } + } else { + if (compar(res, &p->val) > 0) { /* min */ + res = &p->val; + } } } } - return &res->val; + return res; } ZEND_API bool ZEND_FASTCALL _zend_handle_numeric_str_ex(const char *key, size_t length, zend_ulong *idx) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 092682d67713a..bab6c98d27563 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -170,6 +170,7 @@ ZEND_API zend_result ZEND_FASTCALL zend_hash_str_del(HashTable *ht, const char * ZEND_API zend_result ZEND_FASTCALL zend_hash_str_del_ind(HashTable *ht, const char *key, size_t len); ZEND_API zend_result ZEND_FASTCALL zend_hash_index_del(HashTable *ht, zend_ulong h); ZEND_API void ZEND_FASTCALL zend_hash_del_bucket(HashTable *ht, Bucket *p); +ZEND_API void ZEND_FASTCALL zend_hash_packed_del_val(HashTable *ht, zval *zv); /* Data retrieval */ ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); @@ -192,7 +193,7 @@ static zend_always_inline zval *zend_hash_find_ex(const HashTable *ht, zend_stri #define ZEND_HASH_INDEX_FIND(_ht, _h, _ret, _not_found) do { \ if (EXPECTED(HT_FLAGS(_ht) & HASH_FLAG_PACKED)) { \ if (EXPECTED((zend_ulong)(_h) < (zend_ulong)(_ht)->nNumUsed)) { \ - _ret = &_ht->arData[_h].val; \ + _ret = &_ht->arPacked[_h]; \ if (UNEXPECTED(Z_TYPE_P(_ret) == IS_UNDEF)) { \ goto _not_found; \ } \ @@ -215,7 +216,7 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_index_lookup(HashTable *ht, zend_ulong h) #define ZEND_HASH_INDEX_LOOKUP(_ht, _h, _ret) do { \ if (EXPECTED(HT_FLAGS(_ht) & HASH_FLAG_PACKED)) { \ if (EXPECTED((zend_ulong)(_h) < (zend_ulong)(_ht)->nNumUsed)) { \ - _ret = &_ht->arData[_h].val; \ + _ret = &_ht->arPacked[_h]; \ if (EXPECTED(Z_TYPE_P(_ret) != IS_UNDEF)) { \ break; \ } \ @@ -284,7 +285,7 @@ ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q); typedef int (*bucket_compare_func_t)(Bucket *a, Bucket *b); ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, bool ordered); ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, bucket_compare_func_t compare_func, bool renumber); -ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, bucket_compare_func_t compar, uint32_t flag); +ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag); #define zend_hash_sort(ht, compare_func, renumber) \ zend_hash_sort_ex(ht, zend_sort, compare_func, renumber) @@ -959,9 +960,44 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer) #define ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) do { \ + HashTable *__ht = (_ht); \ + bool _is_packed = HT_IS_PACKED(__ht); \ + zval *__z; \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + Bucket *_p = NULL; \ + uint32_t _idx = _from; \ + zval *_end; \ + if (_is_packed) { \ + __z = __ht->arPacked + _from; \ + _end = __ht->arPacked + __ht->nNumUsed; \ + } else { \ + __z = &__ht->arData[_from].val; \ + _end = &__ht->arData[__ht->nNumUsed].val; \ + } \ + while (__z != _end) { \ + zval *_z = __z; \ + if (_is_packed) { \ + __z++; \ + __h = _idx; \ + _idx++; \ + } else { \ + _p = (Bucket*)__z; \ + __z = &(_p + 1)->val; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ + } \ + (void) __h; (void) __key; (void) _p; (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_HASH_FOREACH_FROM_OLD(_ht, indirect, _from) do { \ HashTable *__ht = (_ht); \ Bucket *_p = __ht->arData + (_from); \ Bucket *_end = __ht->arData + __ht->nNumUsed; \ + ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ for (; _p != _end; _p++) { \ zval *_z = &_p->val; \ if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ @@ -972,10 +1008,42 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_FOREACH(_ht, indirect) ZEND_HASH_FOREACH_FROM(_ht, indirect, 0) #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \ + HashTable *__ht = (_ht); \ + uint32_t _idx = __ht->nNumUsed; \ + Bucket *_p = NULL; \ + zval *_z; \ + zval *__z = NULL; \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + bool _is_packed = HT_IS_PACKED(__ht); \ + if (_is_packed) { \ + __z = __ht->arPacked + _idx; \ + } else { \ + _p = __ht->arData + _idx; \ + } \ + for (;_idx > 0; _idx--) { \ + if (_is_packed) { \ + __z--; \ + _z = __z; \ + __h = _idx - 1; \ + } else { \ + _p--; \ + _z = &_p->val; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ + } \ + (void) __h; (void) __key; (void) _p; (void) __z; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_HASH_REVERSE_FOREACH_OLD(_ht, indirect) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ Bucket *_p = __ht->arData + _idx; \ zval *_z; \ + ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ for (_idx = __ht->nNumUsed; _idx > 0; _idx--) { \ _p--; \ _z = &_p->val; \ @@ -1051,119 +1119,119 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; + _h = __h; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; + _h = __h; #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; + _key = __key; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; + _key = __key; #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; + _h = __h; \ + _key = __key; #define ZEND_HASH_REVERSE_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; + _h = __h; \ + _key = __key; #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ ZEND_HASH_FOREACH_FROM(ht, 0, _from); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _ptr = Z_PTR_P(_z); /* The following macros are useful to insert a sequence of new elements @@ -1173,7 +1241,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, */ #define ZEND_HASH_FILL_PACKED(ht) do { \ HashTable *__fill_ht = (ht); \ - Bucket *__fill_bkt = __fill_ht->arData + __fill_ht->nNumUsed; \ + zval *__fill_val = __fill_ht->arPacked + __fill_ht->nNumUsed; \ uint32_t __fill_idx = __fill_ht->nNumUsed; \ ZEND_ASSERT(HT_FLAGS(__fill_ht) & HASH_FLAG_PACKED); @@ -1183,35 +1251,33 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, __fill_ht->nNumOfElements = __fill_idx; \ __fill_ht->nNextFreeElement = __fill_idx; \ zend_hash_packed_grow(__fill_ht); \ - __fill_bkt = __fill_ht->arData + __fill_idx; \ + __fill_val = __fill_ht->arPacked + __fill_idx; \ } \ } while (0); #define ZEND_HASH_FILL_SET(_val) \ - ZVAL_COPY_VALUE(&__fill_bkt->val, _val) + ZVAL_COPY_VALUE(__fill_val, _val) #define ZEND_HASH_FILL_SET_NULL() \ - ZVAL_NULL(&__fill_bkt->val) + ZVAL_NULL(__fill_val) #define ZEND_HASH_FILL_SET_LONG(_val) \ - ZVAL_LONG(&__fill_bkt->val, _val) + ZVAL_LONG(__fill_val, _val) #define ZEND_HASH_FILL_SET_DOUBLE(_val) \ - ZVAL_DOUBLE(&__fill_bkt->val, _val) + ZVAL_DOUBLE(__fill_val, _val) #define ZEND_HASH_FILL_SET_STR(_val) \ - ZVAL_STR(&__fill_bkt->val, _val) + ZVAL_STR(__fill_val, _val) #define ZEND_HASH_FILL_SET_STR_COPY(_val) \ - ZVAL_STR_COPY(&__fill_bkt->val, _val) + ZVAL_STR_COPY(__fill_val, _val) #define ZEND_HASH_FILL_SET_INTERNED_STR(_val) \ - ZVAL_INTERNED_STR(&__fill_bkt->val, _val) + ZVAL_INTERNED_STR(__fill_val, _val) #define ZEND_HASH_FILL_NEXT() do {\ - __fill_bkt->h = (__fill_idx); \ - __fill_bkt->key = NULL; \ - __fill_bkt++; \ + __fill_val++; \ __fill_idx++; \ } while (0) diff --git a/Zend/zend_list.c b/Zend/zend_list.c index b3409e33ce845..d667a21c80a9d 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -216,10 +216,11 @@ void zend_close_rsrc_list(HashTable *ht) { /* Reload ht->arData on each iteration, as it may be reallocated. */ uint32_t i = ht->nNumUsed; + while (i-- > 0) { - Bucket *p = &ht->arData[i]; - if (Z_TYPE(p->val) != IS_UNDEF) { - zend_resource *res = Z_PTR(p->val); + zval *p = HT_IS_PACKED(ht) ? &ht->arPacked[i] : &ht->arData[i].val; + if (Z_TYPE_P(p) != IS_UNDEF) { + zend_resource *res = Z_PTR_P(p); if (res->type >= 0) { zend_resource_dtor(res); } diff --git a/Zend/zend_types.h b/Zend/zend_types.h index fe551c38820cd..0110494c65c52 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -368,7 +368,11 @@ struct _zend_array { uint32_t flags; } u; uint32_t nTableMask; - Bucket *arData; + union { + uint32_t *arHash; /* hash table (allocated above this pointer) */ + Bucket *arData; /* array of hash buckets */ + zval *arPacked; /* packed array of zvals */ + }; uint32_t nNumUsed; uint32_t nNumOfElements; uint32_t nTableSize; @@ -382,14 +386,14 @@ struct _zend_array { * ===================== * * +=============================+ - * | HT_HASH(ht, ht->nTableMask) | - * | ... | - * | HT_HASH(ht, -1) | - * +-----------------------------+ - * ht->arData ---> | Bucket[0] | - * | ... | - * | Bucket[ht->nTableSize-1] | - * +=============================+ + * | HT_HASH(ht, ht->nTableMask) | +=============================+ + * | ... | | HT_INVALID_IDX | + * | HT_HASH(ht, -1) | | HT_INVALID_IDX | + * +-----------------------------+ +-----------------------------+ + * ht->arData ---> | Bucket[0] | ht->arPacked ---> | ZVAL[0] | + * | ... | | ... | + * | Bucket[ht->nTableSize-1] | | ZVAL[ht->nTableSize-1] | + * +=============================+ +=============================+ */ #define HT_INVALID_IDX ((uint32_t) -1) @@ -420,7 +424,7 @@ struct _zend_array { #define HT_HASH_EX(data, idx) \ ((uint32_t*)(data))[(int32_t)(idx)] #define HT_HASH(ht, idx) \ - HT_HASH_EX((ht)->arData, idx) + HT_HASH_EX((ht)->arHash, idx) #define HT_SIZE_TO_MASK(nTableSize) \ ((uint32_t)(-((nTableSize) + (nTableSize)))) @@ -434,6 +438,14 @@ struct _zend_array { HT_SIZE_EX((ht)->nTableSize, (ht)->nTableMask) #define HT_USED_SIZE(ht) \ (HT_HASH_SIZE((ht)->nTableMask) + ((size_t)(ht)->nNumUsed * sizeof(Bucket))) +#define HT_PACKED_DATA_SIZE(nTableSize) \ + ((size_t)(nTableSize) * sizeof(zval)) +#define HT_PACKED_SIZE_EX(nTableSize, nTableMask) \ + (HT_PACKED_DATA_SIZE((nTableSize)) + HT_HASH_SIZE((nTableMask))) +#define HT_PACKED_SIZE(ht) \ + HT_PACKED_SIZE_EX((ht)->nTableSize, (ht)->nTableMask) +#define HT_PACKED_USED_SIZE(ht) \ + (HT_HASH_SIZE((ht)->nTableMask) + ((size_t)(ht)->nNumUsed * sizeof(zval))) #ifdef __SSE2__ # define HT_HASH_RESET(ht) do { \ char *p = (char*)&HT_HASH(ht, (ht)->nTableMask); \ diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 6a55dd9d87a5c..a57cafe127001 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6830,7 +6830,6 @@ ZEND_VM_HOT_HANDLER(78, ZEND_FE_FETCH_R, VAR, ANY, JMP_ADDR) uint32_t value_type; HashTable *fe_ht; HashPosition pos; - Bucket *p; array = EX_VAR(opline->op1.var); if (UNEXPECTED(Z_TYPE_P(array) != IS_ARRAY)) { @@ -6838,31 +6837,54 @@ ZEND_VM_HOT_HANDLER(78, ZEND_FE_FETCH_R, VAR, ANY, JMP_ADDR) } fe_ht = Z_ARRVAL_P(array); pos = Z_FE_POS_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - ZEND_VM_CONTINUE(); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + Z_FE_POS_P(array) = pos + 1; + if (RETURN_VALUE_USED(opline)) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - Z_FE_POS_P(array) = pos; - if (RETURN_VALUE_USED(opline)) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + Bucket *p; + + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + Z_FE_POS_P(array) = pos; + if (RETURN_VALUE_USED(opline)) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } - if (EXPECTED(OP2_TYPE == IS_CV)) { zval *variable_ptr = EX_VAR(opline->op2.var); SAVE_OPLINE(); @@ -6897,27 +6919,48 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR) if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { pos = zend_hash_iterator_pos_ex(Z_FE_ITER_P(EX_VAR(opline->op1.var)), array); fe_ht = Z_ARRVAL_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_C_GOTO(fe_fetch_w_exit); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_C_GOTO(fe_fetch_w_exit); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos + 1; + if (RETURN_VALUE_USED(opline)) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; - if (RETURN_VALUE_USED(opline)) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_C_GOTO(fe_fetch_w_exit); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; + if (RETURN_VALUE_USED(opline)) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { @@ -9746,34 +9789,57 @@ ZEND_VM_HOT_TYPE_SPEC_HANDLER(ZEND_FE_FETCH_R, op->op2_type == IS_CV && (op1_inf uint32_t value_type; HashTable *fe_ht; HashPosition pos; - Bucket *p; array = EX_VAR(opline->op1.var); SAVE_OPLINE(); fe_ht = Z_ARRVAL_P(array); pos = Z_FE_POS_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - ZEND_VM_CONTINUE(); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + Z_FE_POS_P(array) = pos + 1; + if (RETURN_VALUE_USED(opline)) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - Z_FE_POS_P(array) = pos; - if (RETURN_VALUE_USED(opline)) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + Bucket *p; + + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + Z_FE_POS_P(array) = pos; + if (RETURN_VALUE_USED(opline)) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index f2eb205d53c29..ad441d46f61cf 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -21900,7 +21900,6 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_R_SPEC_VA uint32_t value_type; HashTable *fe_ht; HashPosition pos; - Bucket *p; array = EX_VAR(opline->op1.var); if (UNEXPECTED(Z_TYPE_P(array) != IS_ARRAY)) { @@ -21908,31 +21907,54 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_R_SPEC_VA } fe_ht = Z_ARRVAL_P(array); pos = Z_FE_POS_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - ZEND_VM_CONTINUE(); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + Z_FE_POS_P(array) = pos + 1; + if (RETURN_VALUE_USED(opline)) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - Z_FE_POS_P(array) = pos; - if (RETURN_VALUE_USED(opline)) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + Bucket *p; + + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + Z_FE_POS_P(array) = pos; + if (RETURN_VALUE_USED(opline)) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } - if (EXPECTED(opline->op2_type == IS_CV)) { zval *variable_ptr = EX_VAR(opline->op2.var); SAVE_OPLINE(); @@ -21967,27 +21989,48 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER(Z if (EXPECTED(Z_TYPE_P(array) == IS_ARRAY)) { pos = zend_hash_iterator_pos_ex(Z_FE_ITER_P(EX_VAR(opline->op1.var)), array); fe_ht = Z_ARRVAL_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - goto fe_fetch_w_exit; + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + goto fe_fetch_w_exit; + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos + 1; + if (RETURN_VALUE_USED(opline)) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; - if (RETURN_VALUE_USED(opline)) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + goto fe_fetch_w_exit; + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + EG(ht_iterators)[Z_FE_ITER_P(EX_VAR(opline->op1.var))].pos = pos; + if (RETURN_VALUE_USED(opline)) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } } else if (EXPECTED(Z_TYPE_P(array) == IS_OBJECT)) { @@ -30960,34 +31003,57 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_R_SIMPLE_ uint32_t value_type; HashTable *fe_ht; HashPosition pos; - Bucket *p; array = EX_VAR(opline->op1.var); SAVE_OPLINE(); fe_ht = Z_ARRVAL_P(array); pos = Z_FE_POS_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - ZEND_VM_CONTINUE(); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + Z_FE_POS_P(array) = pos + 1; + if (0) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - Z_FE_POS_P(array) = pos; - if (0) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + Bucket *p; + + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + Z_FE_POS_P(array) = pos; + if (0) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } @@ -31005,34 +31071,57 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_R_SIMPLE_ uint32_t value_type; HashTable *fe_ht; HashPosition pos; - Bucket *p; array = EX_VAR(opline->op1.var); SAVE_OPLINE(); fe_ht = Z_ARRVAL_P(array); pos = Z_FE_POS_P(array); - p = fe_ht->arData + pos; - while (1) { - if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - /* reached end of iteration */ - ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - ZEND_VM_CONTINUE(); + if (HT_IS_PACKED(fe_ht)) { + value = fe_ht->arPacked + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + pos++; + value++; } - pos++; - value = &p->val; - value_type = Z_TYPE_INFO_P(value); - ZEND_ASSERT(value_type != IS_INDIRECT); - if (EXPECTED(value_type != IS_UNDEF)) { - break; + Z_FE_POS_P(array) = pos + 1; + if (1) { + ZVAL_LONG(EX_VAR(opline->result.var), pos); } - p++; - } - Z_FE_POS_P(array) = pos; - if (1) { - if (!p->key) { - ZVAL_LONG(EX_VAR(opline->result.var), p->h); - } else { - ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } else { + Bucket *p; + + p = fe_ht->arData + pos; + while (1) { + if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + /* reached end of iteration */ + ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + ZEND_VM_CONTINUE(); + } + pos++; + value = &p->val; + value_type = Z_TYPE_INFO_P(value); + ZEND_ASSERT(value_type != IS_INDIRECT); + if (EXPECTED(value_type != IS_UNDEF)) { + break; + } + p++; + } + Z_FE_POS_P(array) = pos; + if (1) { + if (!p->key) { + ZVAL_LONG(EX_VAR(opline->result.var), p->h); + } else { + ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + } } } diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 963df0671a0a7..47419f0b21905 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -2969,6 +2969,7 @@ static int zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ * zend_string *key; Bucket *b = type->record.fields.arData; + ZEND_ASSERT(!HT_IS_PACKED(&type->record.fields)); ZEND_HASH_FOREACH_STR_KEY_PTR(&old->record.fields, key, old_field) { while (Z_TYPE(b->val) == IS_UNDEF) { b++; @@ -3001,17 +3002,32 @@ static int zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ * return 0; } else if (old->func.args) { zend_ffi_type *arg_type; - Bucket *b = type->func.args->arData; - ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { - while (Z_TYPE(b->val) == IS_UNDEF) { + if (HT_IS_PACKED(type->func.args)) { + zval *zv = type->func.args->arPacked; + + ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { + while (Z_TYPE_P(zv) == IS_UNDEF) { + zv++; + } + if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR_P(zv)))) { + return 0; + } + zv++; + } ZEND_HASH_FOREACH_END(); + } else { + Bucket *b = type->func.args->arData; + + ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { + while (Z_TYPE(b->val) == IS_UNDEF) { + b++; + } + if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR(b->val)))) { + return 0; + } b++; - } - if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR(b->val)))) { - return 0; - } - b++; - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } } break; default: diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index 2f82cfe3b9ab9..d00ef1ad8829a 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -101,28 +101,54 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) } idx = 0; - while (idx < ht->nNumUsed) { - z = &ht->arData[idx].val; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; + if (HT_IS_PACKED(ht)) { + while (idx < ht->nNumUsed) { + z = &ht->arPacked[idx]; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; } - idx++; - } - if (idx >= ht->nNumUsed || !valid_format(z)) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_format_object: bad format; the date format (first " - "element of the array) is not valid", 0); - RETURN_FALSE; - } - dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); + if (idx >= ht->nNumUsed || !valid_format(z)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "datefmt_format_object: bad format; the date format (first " + "element of the array) is not valid", 0); + RETURN_FALSE; + } + dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); - idx++; - while (idx < ht->nNumUsed) { - z = &ht->arData[idx].val; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; + idx++; + while (idx < ht->nNumUsed) { + z = &ht->arPacked[idx]; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; + } + } else { + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; } + if (idx >= ht->nNumUsed || !valid_format(z)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "datefmt_format_object: bad format; the date format (first " + "element of the array) is not valid", 0); + RETURN_FALSE; + } + dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); + idx++; + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; + } } if (idx >= ht->nNumUsed || !valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/opcache/jit/zend_jit_arm64.dasc b/ext/opcache/jit/zend_jit_arm64.dasc index 8e08214286851..a9bcfd70234c6 100644 --- a/ext/opcache/jit/zend_jit_arm64.dasc +++ b/ext/opcache/jit/zend_jit_arm64.dasc @@ -4985,15 +4985,15 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o } else { | bls >2 // NOT_FOUND } - | // _ret = &_ht->arData[_h].val; + | // _ret = &_ht->arPacked[_h].val; if (val >= 0) { - | ldr REG0, [FCARG1x, #offsetof(zend_array, arData)] + | ldr REG0, [FCARG1x, #offsetof(zend_array, arPacked)] if (val != 0) { - | ADD_SUB_64_WITH_CONST add, REG0, REG0, (val * sizeof(Bucket)), TMP1 + | ADD_SUB_64_WITH_CONST add, REG0, REG0, (val * sizeof(zval)), TMP1 } } else { - | ldr TMP1, [FCARG1x, #offsetof(zend_array, arData)] - | add REG0, TMP1, FCARG2x, lsl #5 + | ldr TMP1, [FCARG1x, #offsetof(zend_array, arPacked)] + | add REG0, TMP1, FCARG2x, lsl #4 } } } @@ -13412,7 +13412,11 @@ static int zend_jit_hash_jmp(dasm_State **Dst, const zend_op *opline, const zend | LOAD_ADDR FCARG1x, jumptable | ldr TMP1, [FCARG1x, #offsetof(HashTable, arData)] | sub REG0, REG0, TMP1 - | mov FCARG1x, #(sizeof(Bucket) / sizeof(void*)) + if (HT_IS_PACKED(jumptable)) { + | mov FCARG1x, #(sizeof(zval) / sizeof(void*)) + } else { + | mov FCARG1x, #(sizeof(Bucket) / sizeof(void*)) + } | sdiv REG0, REG0, FCARG1x | adr FCARG1x, >4 | ldr TMP1, [FCARG1x, REG0] @@ -13449,7 +13453,11 @@ static int zend_jit_hash_jmp(dasm_State **Dst, const zend_op *opline, const zend | .addr &exit_addr } } - p++; + if (HT_IS_PACKED(jumptable)) { + p = (Bucket*)(((zval*)p)+1); + } else { + p++; + } count--; } while (count); |.code @@ -13568,7 +13576,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o } if (HT_IS_PACKED(jumptable)) { uint32_t count = jumptable->nNumUsed; - Bucket *p = jumptable->arData; + zval *zv = jumptable->arPacked; | CMP_64_WITH_CONST_32 FCARG2x, jumptable->nNumUsed, TMP1 if (default_label) { @@ -13588,9 +13596,8 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o if (trace_info) { trace_info->jmp_table_size += count; } - p = jumptable->arData; do { - if (Z_TYPE(p->val) == IS_UNDEF) { + if (Z_TYPE_P(zv) == IS_UNDEF) { if (default_label) { | .addr &default_label } else if (next_opline) { @@ -13599,7 +13606,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o | .addr =>default_b } } else { - target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL(p->val)); + target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); if (!next_opline) { b = ssa->cfg.map[target - op_array->opcodes]; | .addr =>b @@ -13611,7 +13618,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o | .addr &exit_addr } } - p++; + zv++; count--; } while (count); |.code @@ -13914,84 +13921,166 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, uint32_t o | // array = EX_VAR(opline->op1.var); | // fe_ht = Z_ARRVAL_P(array); | GET_ZVAL_PTR FCARG1x, op1_addr, TMP1 + + if (op1_info & MAY_BE_PACKED_GUARD) { + int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_PACKED_GUARD); + const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); + + if (!exit_addr) { + return 0; + } + if (op1_info & MAY_BE_ARRAY_PACKED) { + | ldr TMP1w, [FCARG1x, #offsetof(zend_array, u.flags)] + | TST_32_WITH_CONST TMP1w, HASH_FLAG_PACKED, TMP2w + | beq &exit_addr + } else { + | ldr TMP1w, [FCARG1x, #offsetof(zend_array, u.flags)] + | TST_32_WITH_CONST TMP1w, HASH_FLAG_PACKED, TMP2w + | bne &exit_addr + } + } + | // pos = Z_FE_POS_P(array); | MEM_ACCESS_32_WITH_UOFFSET ldr, REG0w, FP, (opline->op1.var + offsetof(zval, u2.fe_pos)), TMP1 - | // p = fe_ht->arData + pos; - || ZEND_ASSERT(sizeof(Bucket) == 32); - | mov FCARG2w, REG0w - | ldr TMP1, [FCARG1x, #offsetof(zend_array, arData)] - | add FCARG2x, TMP1, FCARG2x, lsl #5 - |1: - | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - | ldr TMP1w, [FCARG1x, #offsetof(zend_array, nNumUsed)] - | cmp TMP1w, REG0w - | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - | // ZEND_VM_CONTINUE(); - if (exit_addr) { - if (exit_opcode == ZEND_JMP) { - | bls &exit_addr + + if (MAY_BE_HASH(op1_info)) { + if (MAY_BE_PACKED(op1_info)) { + | ldr TMP1w, [FCARG1x, #offsetof(zend_array, u.flags)] + | TST_32_WITH_CONST TMP1w, HASH_FLAG_PACKED, TMP2w + | bne >2 + } + | // p = fe_ht->arData + pos; + || ZEND_ASSERT(sizeof(Bucket) == 32); + | mov FCARG2w, REG0w + | ldr TMP1, [FCARG1x, #offsetof(zend_array, arData)] + | add FCARG2x, TMP1, FCARG2x, lsl #5 + |1: + | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + | ldr TMP1w, [FCARG1x, #offsetof(zend_array, nNumUsed)] + | cmp TMP1w, REG0w + | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + | // ZEND_VM_CONTINUE(); + if (exit_addr) { + if (exit_opcode == ZEND_JMP) { + | bls &exit_addr + } else { + | bls >3 + } } else { - | bls >3 + | bls =>target_label + } + | // pos++; + | add REG0w, REG0w, #1 + | // value_type = Z_TYPE_INFO_P(value); + | // if (EXPECTED(value_type != IS_UNDEF)) { + if (!exit_addr || exit_opcode == ZEND_JMP) { + | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, >3, TMP1w + } else { + | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, &exit_addr, TMP1w + } + | // p++; + | add FCARG2x, FCARG2x, #sizeof(Bucket) + | b <1 + if (MAY_BE_PACKED(op1_info)) { + |2: } - } else { - | bls =>target_label } - | // pos++; - | add REG0w, REG0w, #1 - | // value_type = Z_TYPE_INFO_P(value); - | // if (EXPECTED(value_type != IS_UNDEF)) { - if (!exit_addr || exit_opcode == ZEND_JMP) { - | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, >3, TMP1w - } else { - | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, &exit_addr, TMP1w + if (MAY_BE_PACKED(op1_info)) { + | // p = fe_ht->arPacked + pos; + || ZEND_ASSERT(sizeof(zval) == 16); + | mov FCARG2w, REG0w + | ldr TMP1, [FCARG1x, #offsetof(zend_array, arPacked)] + | add FCARG2x, TMP1, FCARG2x, lsl #4 + |1: + | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + | ldr TMP1w, [FCARG1x, #offsetof(zend_array, nNumUsed)] + | cmp TMP1w, REG0w + | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + | // ZEND_VM_CONTINUE(); + if (exit_addr) { + if (exit_opcode == ZEND_JMP) { + | bls &exit_addr + } else { + | bls >4 + } + } else { + | bls =>target_label + } + | // pos++; + | add REG0w, REG0w, #1 + | // value_type = Z_TYPE_INFO_P(value); + | // if (EXPECTED(value_type != IS_UNDEF)) { + if (!exit_addr || exit_opcode == ZEND_JMP) { + | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, >4, TMP1w + } else { + | IF_NOT_Z_TYPE FCARG2x, IS_UNDEF, &exit_addr, TMP1w + } + | // p++; + | add FCARG2x, FCARG2x, #sizeof(zval) + | b <1 } - | // p++; - | add FCARG2x, FCARG2x, #sizeof(Bucket) - | b <1 - |3: if (!exit_addr || exit_opcode == ZEND_JMP) { zend_jit_addr val_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG2, 0); zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); uint32_t val_info; - | // Z_FE_POS_P(array) = pos + 1; - | MEM_ACCESS_32_WITH_UOFFSET str, REG0w, FP, (opline->op1.var + offsetof(zval, u2.fe_pos)), TMP1 - if (RETURN_VALUE_USED(opline)) { zend_jit_addr res_addr = RES_ADDR(); - if ((op1_info & MAY_BE_ARRAY_KEY_LONG) - && (op1_info & MAY_BE_ARRAY_KEY_STRING)) { - | // if (!p->key) { - | ldr REG0, [FCARG2x, #offsetof(Bucket, key)] - | cbz REG0, >2 - } - if (op1_info & MAY_BE_ARRAY_KEY_STRING) { - | // ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); - | ldr REG0, [FCARG2x, #offsetof(Bucket, key)] - | SET_ZVAL_PTR res_addr, REG0, TMP1 - | ldr TMP1w, [REG0, #offsetof(zend_refcounted, gc.u.type_info)] - | TST_32_WITH_CONST TMP1w, IS_STR_INTERNED, TMP2w - | beq >1 - | SET_ZVAL_TYPE_INFO res_addr, IS_STRING, TMP1w, TMP2 - | b >3 - |1: - | GC_ADDREF REG0, TMP1w - | SET_ZVAL_TYPE_INFO res_addr, IS_STRING_EX, TMP1w, TMP2 + if (MAY_BE_HASH(op1_info)) { + |3: + | // Z_FE_POS_P(array) = pos + 1; + | MEM_ACCESS_32_WITH_UOFFSET str, REG0w, FP, (opline->op1.var + offsetof(zval, u2.fe_pos)), TMP1 + + if ((op1_info & MAY_BE_ARRAY_KEY_LONG) + && (op1_info & MAY_BE_ARRAY_KEY_STRING)) { + | // if (!p->key) { + | ldr REG0, [FCARG2x, #offsetof(Bucket, key)] + | cbz REG0, >2 + } + if (op1_info & MAY_BE_ARRAY_KEY_STRING) { + | // ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + | ldr REG0, [FCARG2x, #offsetof(Bucket, key)] + | SET_ZVAL_PTR res_addr, REG0, TMP1 + | ldr TMP1w, [REG0, #offsetof(zend_refcounted, gc.u.type_info)] + | TST_32_WITH_CONST TMP1w, IS_STR_INTERNED, TMP2w + | beq >1 + | SET_ZVAL_TYPE_INFO res_addr, IS_STRING, TMP1w, TMP2 + | b >3 + |1: + | GC_ADDREF REG0, TMP1w + | SET_ZVAL_TYPE_INFO res_addr, IS_STRING_EX, TMP1w, TMP2 + if ((op1_info & MAY_BE_ARRAY_KEY_LONG) && MAY_BE_PACKED(op1_info)) { + | b >3 + |2: + } + } if (op1_info & MAY_BE_ARRAY_KEY_LONG) { - | b >3 - |2: + | // ZVAL_LONG(EX_VAR(opline->result.var), p->h); + | ldr REG0, [FCARG2x, #offsetof(Bucket, h)] + | SET_ZVAL_LVAL_FROM_REG res_addr, REG0, TMP1 + | SET_ZVAL_TYPE_INFO res_addr, IS_LONG, TMP1w, TMP2 + if (MAY_BE_PACKED(op1_info)) { + | b >3 + } } } - if (op1_info & MAY_BE_ARRAY_KEY_LONG) { - | // ZVAL_LONG(EX_VAR(opline->result.var), p->h); - | ldr REG0, [FCARG2x, #offsetof(Bucket, h)] + if (MAY_BE_PACKED(op1_info)) { + |4: + | // Z_FE_POS_P(array) = pos + 1; + | MEM_ACCESS_32_WITH_UOFFSET str, REG0w, FP, (opline->op1.var + offsetof(zval, u2.fe_pos)), TMP1 + | sub REG0w, REG0w, #1 | SET_ZVAL_LVAL_FROM_REG res_addr, REG0, TMP1 | SET_ZVAL_TYPE_INFO res_addr, IS_LONG, TMP1w, TMP2 } |3: + } else { + |3: + |4: + | // Z_FE_POS_P(array) = pos + 1; + | MEM_ACCESS_32_WITH_UOFFSET str, REG0w, FP, (opline->op1.var + offsetof(zval, u2.fe_pos)), TMP1 } val_info = ((op1_info & MAY_BE_ARRAY_OF_ANY) >> MAY_BE_ARRAY_SHIFT); @@ -14015,6 +14104,9 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, uint32_t o | ZVAL_COPY_VALUE var_addr, -1, val_addr, val_info, ZREG_REG0, ZREG_FCARG1, ZREG_TMP1, ZREG_TMP2, ZREG_FPR0 | TRY_ADDREF val_info, REG0w, FCARG1x, TMP1w } + } else { + |3: + |4: } return 1; diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c index a8fa723264d4f..c998ea468a32f 100644 --- a/ext/opcache/jit/zend_jit_trace.c +++ b/ext/opcache/jit/zend_jit_trace.c @@ -1716,8 +1716,23 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin case ZEND_COUNT: case ZEND_QM_ASSIGN: case ZEND_FE_RESET_R: + ADD_OP1_TRACE_GUARD(); + break; case ZEND_FE_FETCH_R: ADD_OP1_TRACE_GUARD(); + if (op1_type == IS_ARRAY && (orig_op1_type & ~IS_TRACE_PACKED) == IS_ARRAY) { + + zend_ssa_var_info *info = &tssa->var_info[tssa->ops[idx].op1_use]; + + if (MAY_BE_PACKED(info->type) && MAY_BE_HASH(info->type)) { + info->type |= MAY_BE_PACKED_GUARD; + if (orig_op1_type & IS_TRACE_PACKED) { + info->type &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH); + } else { + info->type &= ~MAY_BE_ARRAY_PACKED; + } + } + } break; case ZEND_VERIFY_RETURN_TYPE: if (opline->op1_type == IS_UNUSED) { diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 81a0489c3cbf7..e1e12a88a96a4 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -5447,20 +5447,20 @@ static int zend_jit_fetch_dimension_address_inner(dasm_State **Dst, const zend_o } else { | jbe >2 // NOT_FOUND } - | // _ret = &_ht->arData[_h].val; + | // _ret = &_ht->arPacked[h]; if (val >= 0) { - | mov r0, aword [FCARG1a + offsetof(zend_array, arData)] + | mov r0, aword [FCARG1a + offsetof(zend_array, arPacked)] if (val != 0) { - | add r0, val * sizeof(Bucket) + | add r0, val * sizeof(zval) } } else { |.if X64 | mov r0, FCARG2a - | shl r0, 5 + | shl r0, 4 |.else - | imul r0, FCARG2a, sizeof(Bucket) + | imul r0, FCARG2a, sizeof(zval) |.endif - | add r0, aword [FCARG1a + offsetof(zend_array, arData)] + | add r0, aword [FCARG1a + offsetof(zend_array, arPacked)] } } } @@ -14233,7 +14233,11 @@ static int zend_jit_hash_jmp(dasm_State **Dst, const zend_op *opline, const zend } | LOAD_ADDR FCARG1a, jumptable | sub r0, aword [FCARG1a + offsetof(HashTable, arData)] - | mov FCARG1a, (sizeof(Bucket) / sizeof(void*)) + if (HT_IS_PACKED(jumptable)) { + | mov FCARG1a, (sizeof(zval) / sizeof(void*)) + } else { + | mov FCARG1a, (sizeof(Bucket) / sizeof(void*)) + } |.if X64 | cqo |.else @@ -14281,7 +14285,11 @@ static int zend_jit_hash_jmp(dasm_State **Dst, const zend_op *opline, const zend | .aword &exit_addr } } - p++; + if (HT_IS_PACKED(jumptable)) { + p = (Bucket*)(((zval*)p)+1); + } else { + p++; + } count--; } while (count); |.code @@ -14398,7 +14406,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o } if (HT_IS_PACKED(jumptable)) { uint32_t count = jumptable->nNumUsed; - Bucket *p = jumptable->arData; + zval *zv = jumptable->arPacked; | cmp FCARG2a, jumptable->nNumUsed if (default_label) { @@ -14424,9 +14432,8 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o if (trace_info) { trace_info->jmp_table_size += count; } - p = jumptable->arData; do { - if (Z_TYPE(p->val) == IS_UNDEF) { + if (Z_TYPE_P(zv) == IS_UNDEF) { if (default_label) { | .aword &default_label } else if (next_opline) { @@ -14435,7 +14442,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o | .aword =>default_b } } else { - target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL(p->val)); + target = ZEND_OFFSET_TO_OPLINE(opline, Z_LVAL_P(zv)); if (!next_opline) { b = ssa->cfg.map[target - op_array->opcodes]; | .aword =>b @@ -14447,7 +14454,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o | .aword &exit_addr } } - p++; + zv++; count--; } while (count); |.code @@ -14754,86 +14761,166 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, uint32_t o | // array = EX_VAR(opline->op1.var); | // fe_ht = Z_ARRVAL_P(array); | GET_ZVAL_PTR FCARG1a, op1_addr + + if (op1_info & MAY_BE_PACKED_GUARD) { + int32_t exit_point = zend_jit_trace_get_exit_point(opline, ZEND_JIT_EXIT_PACKED_GUARD); + const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point); + + if (!exit_addr) { + return 0; + } + if (op1_info & MAY_BE_ARRAY_PACKED) { + | test dword [FCARG1a + offsetof(zend_array, u.flags)], HASH_FLAG_PACKED + | jz &exit_addr + } else { + | test dword [FCARG1a + offsetof(zend_array, u.flags)], HASH_FLAG_PACKED + | jnz &exit_addr + } + } + | // pos = Z_FE_POS_P(array); | mov eax, dword [FP + opline->op1.var + offsetof(zval, u2.fe_pos)] - | // p = fe_ht->arData + pos; - |.if X64 - || ZEND_ASSERT(sizeof(Bucket) == 32); - | mov FCARG2d, eax - | shl FCARG2a, 5 - |.else - | imul FCARG2a, r0, sizeof(Bucket) - |.endif - | add FCARG2a, aword [FCARG1a + offsetof(zend_array, arData)] - |1: - | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { - | cmp dword [FCARG1a + offsetof(zend_array, nNumUsed)], eax - | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); - | // ZEND_VM_CONTINUE(); - if (exit_addr) { - if (exit_opcode == ZEND_JMP) { - | jbe &exit_addr + + if (MAY_BE_HASH(op1_info)) { + if (MAY_BE_PACKED(op1_info)) { + | test dword [FCARG1a + offsetof(zend_array, u.flags)], HASH_FLAG_PACKED + | jnz >2 + } + + | // p = fe_ht->arData + pos; + |.if X64 + || ZEND_ASSERT(sizeof(Bucket) == 32); + | mov FCARG2d, eax + | shl FCARG2a, 5 + |.else + | imul FCARG2a, r0, sizeof(Bucket) + |.endif + | add FCARG2a, aword [FCARG1a + offsetof(zend_array, arData)] + |1: + | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + | cmp dword [FCARG1a + offsetof(zend_array, nNumUsed)], eax + | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + | // ZEND_VM_CONTINUE(); + if (exit_addr) { + if (exit_opcode == ZEND_JMP) { + | jbe &exit_addr + } else { + | jbe >3 + } } else { - | jbe >3 + | jbe =>target_label + } + | // pos++; + | add eax, 1 + | // value_type = Z_TYPE_INFO_P(value); + | // if (EXPECTED(value_type != IS_UNDEF)) { + if (!exit_addr || exit_opcode == ZEND_JMP) { + | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, >3 + } else { + | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, &exit_addr + } + | // p++; + | add FCARG2a, sizeof(Bucket) + | jmp <1 + if (MAY_BE_PACKED(op1_info)) { + |2: } - } else { - | jbe =>target_label } - | // pos++; - | add eax, 1 - | // value_type = Z_TYPE_INFO_P(value); - | // if (EXPECTED(value_type != IS_UNDEF)) { - if (!exit_addr || exit_opcode == ZEND_JMP) { - | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, >3 - } else { - | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, &exit_addr + if (MAY_BE_PACKED(op1_info)) { + | // p = fe_ht->arPacked + pos; + || ZEND_ASSERT(sizeof(zval) == 16); + | mov FCARG2d, eax + | shl FCARG2a, 4 + | add FCARG2a, aword [FCARG1a + offsetof(zend_array, arPacked)] + |1: + | // if (UNEXPECTED(pos >= fe_ht->nNumUsed)) { + | cmp dword [FCARG1a + offsetof(zend_array, nNumUsed)], eax + | // ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); + | // ZEND_VM_CONTINUE(); + if (exit_addr) { + if (exit_opcode == ZEND_JMP) { + | jbe &exit_addr + } else { + | jbe >4 + } + } else { + | jbe =>target_label + } + | // pos++; + | add eax, 1 + | // value_type = Z_TYPE_INFO_P(value); + | // if (EXPECTED(value_type != IS_UNDEF)) { + if (!exit_addr || exit_opcode == ZEND_JMP) { + | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, >4 + } else { + | IF_NOT_Z_TYPE FCARG2a, IS_UNDEF, &exit_addr + } + | // p++; + | add FCARG2a, sizeof(zval) + | jmp <1 } - | // p++; - | add FCARG2a, sizeof(Bucket) - | jmp <1 - |3: + if (!exit_addr || exit_opcode == ZEND_JMP) { zend_jit_addr val_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FCARG2, 0); zend_jit_addr var_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->op2.var); uint32_t val_info; - | // Z_FE_POS_P(array) = pos + 1; - | mov dword [FP + opline->op1.var + offsetof(zval, u2.fe_pos)], eax - if (RETURN_VALUE_USED(opline)) { zend_jit_addr res_addr = RES_ADDR(); - if ((op1_info & MAY_BE_ARRAY_KEY_LONG) - && (op1_info & MAY_BE_ARRAY_KEY_STRING)) { - | // if (!p->key) { - | cmp aword [FCARG2a + offsetof(Bucket, key)], 0 - | jz >2 - } - if (op1_info & MAY_BE_ARRAY_KEY_STRING) { - | // ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); - | mov r0, aword [FCARG2a + offsetof(Bucket, key)] - | SET_ZVAL_PTR res_addr, r0 - | test dword [r0 + offsetof(zend_refcounted, gc.u.type_info)], IS_STR_INTERNED - | jz >1 - | SET_ZVAL_TYPE_INFO res_addr, IS_STRING - | jmp >3 - |1: - | GC_ADDREF r0 - | SET_ZVAL_TYPE_INFO res_addr, IS_STRING_EX + if (MAY_BE_HASH(op1_info)) { + |3: + | // Z_FE_POS_P(array) = pos + 1; + | mov dword [FP + opline->op1.var + offsetof(zval, u2.fe_pos)], eax + + if ((op1_info & MAY_BE_ARRAY_KEY_LONG) + && (op1_info & MAY_BE_ARRAY_KEY_STRING)) { + | // if (!p->key) { + | cmp aword [FCARG2a + offsetof(Bucket, key)], 0 + | jz >2 + } + if (op1_info & MAY_BE_ARRAY_KEY_STRING) { + | // ZVAL_STR_COPY(EX_VAR(opline->result.var), p->key); + | mov r0, aword [FCARG2a + offsetof(Bucket, key)] + | SET_ZVAL_PTR res_addr, r0 + | test dword [r0 + offsetof(zend_refcounted, gc.u.type_info)], IS_STR_INTERNED + | jz >1 + | SET_ZVAL_TYPE_INFO res_addr, IS_STRING + | jmp >3 + |1: + | GC_ADDREF r0 + | SET_ZVAL_TYPE_INFO res_addr, IS_STRING_EX + if ((op1_info & MAY_BE_ARRAY_KEY_LONG) || MAY_BE_PACKED(op1_info)) { + | jmp >3 + |2: + } + } if (op1_info & MAY_BE_ARRAY_KEY_LONG) { - | jmp >3 - |2: + | // ZVAL_LONG(EX_VAR(opline->result.var), p->h); + | mov r0, aword [FCARG2a + offsetof(Bucket, h)] + | SET_ZVAL_LVAL res_addr, r0 + | SET_ZVAL_TYPE_INFO res_addr, IS_LONG + if (MAY_BE_PACKED(op1_info)) { + | jmp >3 + } } } - if (op1_info & MAY_BE_ARRAY_KEY_LONG) { - | // ZVAL_LONG(EX_VAR(opline->result.var), p->h); - | mov r0, aword [FCARG2a + offsetof(Bucket, h)] + if (MAY_BE_PACKED(op1_info)) { + |4: + | // Z_FE_POS_P(array) = pos + 1; + | mov dword [FP + opline->op1.var + offsetof(zval, u2.fe_pos)], eax + | sub r0, 1 | SET_ZVAL_LVAL res_addr, r0 | SET_ZVAL_TYPE_INFO res_addr, IS_LONG } |3: + } else { + |3: + |4: + | // Z_FE_POS_P(array) = pos + 1; + | mov dword [FP + opline->op1.var + offsetof(zval, u2.fe_pos)], eax } val_info = ((op1_info & MAY_BE_ARRAY_OF_ANY) >> MAY_BE_ARRAY_SHIFT); @@ -14857,6 +14944,9 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, uint32_t o | ZVAL_COPY_VALUE var_addr, -1, val_addr, val_info, ZREG_R0, ZREG_FCARG1 | TRY_ADDREF val_info, ah, FCARG1a } + } else { + |3: + |4: } return 1; diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 22ccc4d84305d..22389d36515f3 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -299,8 +299,6 @@ static void zend_file_cache_serialize_hash(HashTable *ht, void *buf, serialize_callback_t func) { - Bucket *p, *end; - if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) { ht->arData = NULL; return; @@ -308,16 +306,33 @@ static void zend_file_cache_serialize_hash(HashTable *ht, if (IS_SERIALIZED(ht->arData)) { return; } - SERIALIZE_PTR(ht->arData); - p = ht->arData; - UNSERIALIZE_PTR(p); - end = p + ht->nNumUsed; - while (p < end) { - if (Z_TYPE(p->val) != IS_UNDEF) { - SERIALIZE_STR(p->key); - func(&p->val, script, info, buf); + if (HT_IS_PACKED(ht)) { + zval *p, *end; + + SERIALIZE_PTR(ht->arPacked); + p = ht->arPacked; + UNSERIALIZE_PTR(p); + end = p + ht->nNumUsed; + while (p < end) { + if (Z_TYPE_P(p) != IS_UNDEF) { + func(p, script, info, buf); + } + p++; + } + } else { + Bucket *p, *end; + + SERIALIZE_PTR(ht->arData); + p = ht->arData; + UNSERIALIZE_PTR(p); + end = p + ht->nNumUsed; + while (p < end) { + if (Z_TYPE(p->val) != IS_UNDEF) { + SERIALIZE_STR(p->key); + func(&p->val, script, info, buf); + } + p++; } - p++; } } @@ -1091,8 +1106,6 @@ static void zend_file_cache_unserialize_hash(HashTable *ht, unserialize_callback_t func, dtor_func_t dtor) { - Bucket *p, *end; - ht->pDestructor = dtor; if (HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED) { if (EXPECTED(!file_cache_only)) { @@ -1106,14 +1119,29 @@ static void zend_file_cache_unserialize_hash(HashTable *ht, return; } UNSERIALIZE_PTR(ht->arData); - p = ht->arData; - end = p + ht->nNumUsed; - while (p < end) { - if (Z_TYPE(p->val) != IS_UNDEF) { - UNSERIALIZE_STR(p->key); - func(&p->val, script, buf); + if (HT_IS_PACKED(ht)) { + zval *p, *end; + + p = ht->arPacked; + end = p + ht->nNumUsed; + while (p < end) { + if (Z_TYPE_P(p) != IS_UNDEF) { + func(p, script, buf); + } + p++; + } + } else { + Bucket *p, *end; + + p = ht->arData; + end = p + ht->nNumUsed; + while (p < end) { + if (Z_TYPE(p->val) != IS_UNDEF) { + UNSERIALIZE_STR(p->key); + func(&p->val, script, buf); + } + p++; } - p++; } } diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index d2b62c30eb9b4..eff537901632b 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -115,12 +115,12 @@ static void zend_hash_persist(HashTable *ht) HT_FLAGS(ht) |= HASH_FLAG_UNINITIALIZED; return; } - if (HT_FLAGS(ht) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(ht)) { void *data = HT_GET_DATA_ADDR(ht); if (GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) { - data = zend_shared_memdup(data, HT_USED_SIZE(ht)); + data = zend_shared_memdup(data, HT_PACKED_USED_SIZE(ht)); } else { - data = zend_shared_memdup_free(data, HT_USED_SIZE(ht)); + data = zend_shared_memdup_free(data, HT_PACKED_USED_SIZE(ht)); } HT_SET_DATA_ADDR(ht, data); } else if (ht->nNumUsed > HT_MIN_SIZE && ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 4) { @@ -215,21 +215,32 @@ static void zend_persist_zval(zval *z) && zend_accel_in_shm(Z_ARR_P(z))) { /* pass */ } else { - Bucket *p; + HashTable *ht; if (!Z_REFCOUNTED_P(z)) { - Z_ARR_P(z) = zend_shared_memdup_put(Z_ARR_P(z), sizeof(zend_array)); + ht = zend_shared_memdup_put(Z_ARR_P(z), sizeof(zend_array)); } else { GC_REMOVE_FROM_BUFFER(Z_ARR_P(z)); - Z_ARR_P(z) = zend_shared_memdup_put_free(Z_ARR_P(z), sizeof(zend_array)); + ht = zend_shared_memdup_put_free(Z_ARR_P(z), sizeof(zend_array)); + } + Z_ARR_P(z) = ht; + zend_hash_persist(ht); + if (HT_IS_PACKED(ht)) { + zval *zv; + + ZEND_HASH_FOREACH_VAL(ht, zv) { + zend_persist_zval(zv); + } ZEND_HASH_FOREACH_END(); + } else { + Bucket *p; + + ZEND_HASH_FOREACH_BUCKET(ht, p) { + if (p->key) { + zend_accel_store_interned_string(p->key); + } + zend_persist_zval(&p->val); + } ZEND_HASH_FOREACH_END(); } - zend_hash_persist(Z_ARRVAL_P(z)); - ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(z), p) { - if (p->key) { - zend_accel_store_interned_string(p->key); - } - zend_persist_zval(&p->val); - } ZEND_HASH_FOREACH_END(); /* make immutable array */ Z_TYPE_FLAGS_P(z) = 0; GC_SET_REFCOUNT(Z_COUNTED_P(z), 2); @@ -328,15 +339,24 @@ uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name) static HashTable *zend_persist_backed_enum_table(HashTable *backed_enum_table) { HashTable *ptr; - Bucket *p; zend_hash_persist(backed_enum_table); - ZEND_HASH_FOREACH_BUCKET(backed_enum_table, p) { - if (p->key != NULL) { - zend_accel_store_interned_string(p->key); - } - zend_persist_zval(&p->val); - } ZEND_HASH_FOREACH_END(); + if (HT_IS_PACKED(backed_enum_table)) { + zval *zv; + + ZEND_HASH_FOREACH_VAL(backed_enum_table, zv) { + zend_persist_zval(zv); + } ZEND_HASH_FOREACH_END(); + } else { + Bucket *p; + + ZEND_HASH_FOREACH_BUCKET(backed_enum_table, p) { + if (p->key != NULL) { + zend_accel_store_interned_string(p->key); + } + zend_persist_zval(&p->val); + } ZEND_HASH_FOREACH_END(); + } ptr = zend_shared_memdup_free(backed_enum_table, sizeof(HashTable)); GC_SET_REFCOUNT(ptr, 2); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index 3f79290841a0c..deb33c570b194 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -54,7 +54,9 @@ static void zend_hash_persist_calc(HashTable *ht) return; } - if (!(HT_FLAGS(ht) & HASH_FLAG_PACKED) && ht->nNumUsed > HT_MIN_SIZE && ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 4) { + if (HT_IS_PACKED(ht)) { + ADD_SIZE(HT_PACKED_USED_SIZE(ht)); + } else if (ht->nNumUsed > HT_MIN_SIZE && ht->nNumUsed < (uint32_t)(-(int32_t)ht->nTableMask) / 4) { /* compact table */ uint32_t hash_size; @@ -112,16 +114,26 @@ static void zend_persist_zval_calc(zval *z) } size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array)); if (size) { - Bucket *p; + HashTable *ht = Z_ARRVAL_P(z); ADD_SIZE(size); - zend_hash_persist_calc(Z_ARRVAL_P(z)); - ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(z), p) { - if (p->key) { - ADD_INTERNED_STRING(p->key); - } - zend_persist_zval_calc(&p->val); - } ZEND_HASH_FOREACH_END(); + zend_hash_persist_calc(ht); + if (HT_IS_PACKED(ht)) { + zval *zv; + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(z), zv) { + zend_persist_zval_calc(zv); + } ZEND_HASH_FOREACH_END(); + } else { + Bucket *p; + + ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(z), p) { + if (p->key) { + ADD_INTERNED_STRING(p->key); + } + zend_persist_zval_calc(&p->val); + } ZEND_HASH_FOREACH_END(); + } } break; case IS_CONSTANT_AST: @@ -534,15 +546,24 @@ void zend_persist_class_entry_calc(zend_class_entry *ce) } if (ce->backed_enum_table) { - Bucket *p; ADD_SIZE(sizeof(HashTable)); zend_hash_persist_calc(ce->backed_enum_table); - ZEND_HASH_FOREACH_BUCKET(ce->backed_enum_table, p) { - if (p->key != NULL) { - ADD_INTERNED_STRING(p->key); - } - zend_persist_zval_calc(&p->val); - } ZEND_HASH_FOREACH_END(); + if (HT_IS_PACKED(ce->backed_enum_table)) { + zval *zv; + + ZEND_HASH_FOREACH_VAL(ce->backed_enum_table, zv) { + zend_persist_zval_calc(zv); + } ZEND_HASH_FOREACH_END(); + } else { + Bucket *p; + + ZEND_HASH_FOREACH_BUCKET(ce->backed_enum_table, p) { + if (p->key != NULL) { + ADD_INTERNED_STRING(p->key); + } + zend_persist_zval_calc(&p->val); + } ZEND_HASH_FOREACH_END(); + } } } } diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 20a9984c2df00..c589d75ec4904 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2106,7 +2106,9 @@ static zend_string *php_pcre_replace_array(HashTable *regex, tmp_replace_entry_str = NULL; break; } - zv = &replace_ht->arData[replace_idx].val; + zv = HT_IS_PACKED(replace_ht) ? + &replace_ht->arPacked[replace_idx] : + &replace_ht->arData[replace_idx].val; replace_idx++; if (Z_TYPE_P(zv) != IS_UNDEF) { replace_entry_str = zval_get_tmp_string(zv, &tmp_replace_entry_str); diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index f0917501751f5..5eecc94bb3d91 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -703,12 +703,22 @@ static bool php_snmp_parse_oid( pptr = ZSTR_VAL(type_str); objid_query->vars[objid_query->count].type = *pptr; } else if (type_ht) { - while (idx_type < type_ht->nNumUsed) { - tmp_type = &type_ht->arData[idx_type].val; - if (Z_TYPE_P(tmp_type) != IS_UNDEF) { - break; + if (HT_IS_PACKED(type_ht)) { + while (idx_type < type_ht->nNumUsed) { + tmp_type = &type_ht->arPacked[idx_type]; + if (Z_TYPE_P(tmp_type) != IS_UNDEF) { + break; + } + idx_type++; + } + } else { + while (idx_type < type_ht->nNumUsed) { + tmp_type = &type_ht->arData[idx_type].val; + if (Z_TYPE_P(tmp_type) != IS_UNDEF) { + break; + } + idx_type++; } - idx_type++; } if (idx_type < type_ht->nNumUsed) { convert_to_string(tmp_type); @@ -730,12 +740,22 @@ static bool php_snmp_parse_oid( if (value_str) { objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str); } else if (value_ht) { - while (idx_value < value_ht->nNumUsed) { - tmp_value = &value_ht->arData[idx_value].val; - if (Z_TYPE_P(tmp_value) != IS_UNDEF) { - break; + if (HT_IS_PACKED(value_ht)) { + while (idx_value < value_ht->nNumUsed) { + tmp_value = &value_ht->arPacked[idx_value]; + if (Z_TYPE_P(tmp_value) != IS_UNDEF) { + break; + } + idx_value++; + } + } else { + while (idx_value < value_ht->nNumUsed) { + tmp_value = &value_ht->arData[idx_value].val; + if (Z_TYPE_P(tmp_value) != IS_UNDEF) { + break; + } + idx_value++; } - idx_value++; } if (idx_value < value_ht->nNumUsed) { convert_to_string(tmp_value); diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index c6b7e02a00ce7..31774235f767f 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -464,6 +464,7 @@ PHP_FUNCTION(spl_autoload_call) } /* }}} */ #define HT_MOVE_TAIL_TO_HEAD(ht) \ + ZEND_ASSERT(!HT_IS_PACKED(ht)); \ do { \ Bucket tmp = (ht)->arData[(ht)->nNumUsed-1]; \ memmove((ht)->arData + 1, (ht)->arData, \ diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 72e6d00c43c8d..0a8815af6dff8 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1990,10 +1990,17 @@ static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern) /* { uint32_t idx = 0; zval *first; - while (Z_ISUNDEF(Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val)) { - idx++; + if (HT_IS_PACKED(Z_ARRVAL(intern->u.file.current_zval))) { + while (Z_ISUNDEF(Z_ARRVAL(intern->u.file.current_zval)->arPacked[idx])) { + idx++; + } + first = &Z_ARRVAL(intern->u.file.current_zval)->arPacked[idx]; + } else { + while (Z_ISUNDEF(Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val)) { + idx++; + } + first = &Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val; } - first = &Z_ARRVAL(intern->u.file.current_zval)->arData[idx].val; return Z_TYPE_P(first) == IS_STRING && Z_STRLEN_P(first) == 0; } return zend_hash_num_elements(Z_ARRVAL(intern->u.file.current_zval)) == 0; diff --git a/ext/standard/array.c b/ext/standard/array.c index 6345dd4ebbadf..d26a110eada34 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1205,6 +1205,12 @@ PHP_FUNCTION(key) } /* }}} */ +static int php_data_compare(const void *f, const void *s) /* {{{ */ +{ + return zend_compare((zval*)f, (zval*)s); +} +/* }}} */ + /* {{{ * proto mixed min(array values) * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) @@ -1224,7 +1230,7 @@ PHP_FUNCTION(min) zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0])); RETURN_THROWS(); } else { - zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 0); + zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_data_compare, 0); if (result) { RETURN_COPY_DEREF(result); } else { @@ -1270,7 +1276,7 @@ PHP_FUNCTION(max) zend_argument_type_error(1, "must be of type array, %s given", zend_zval_type_name(&args[0])); RETURN_THROWS(); } else { - zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare_unstable, 1); + zval *result = zend_hash_minmax(Z_ARRVAL(args[0]), php_data_compare, 1); if (result) { RETURN_COPY_DEREF(result); } else { @@ -2566,8 +2572,7 @@ PHP_FUNCTION(array_fill) RETURN_THROWS(); } else if (EXPECTED(start_key >= 0) && EXPECTED(start_key < num)) { /* create packed array */ - Bucket *p; - zend_long n; + zval *zv; array_init_size(return_value, (uint32_t)(start_key + num)); zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); @@ -2579,18 +2584,15 @@ PHP_FUNCTION(array_fill) GC_ADDREF_EX(Z_COUNTED_P(val), (uint32_t)num); } - p = Z_ARRVAL_P(return_value)->arData; - n = start_key; + zv = Z_ARRVAL_P(return_value)->arPacked; while (start_key--) { - ZVAL_UNDEF(&p->val); - p++; + ZVAL_UNDEF(zv); + zv++; } while (num--) { - ZVAL_COPY_VALUE(&p->val, val); - p->h = n++; - p->key = NULL; - p++; + ZVAL_COPY_VALUE(zv, val); + zv++; } } else { /* create hash */ @@ -2859,7 +2861,7 @@ PHP_FUNCTION(range) static void php_array_data_shuffle(zval *array) /* {{{ */ { uint32_t idx, j, n_elems; - Bucket *p, temp; + zval *zv, temp; HashTable *hash; zend_long rnd_idx; uint32_t n_left; @@ -2873,13 +2875,17 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ hash = Z_ARRVAL_P(array); n_left = n_elems; + if (!HT_IS_PACKED(hash)) { + zend_hash_to_packed(hash); + } + if (EXPECTED(!HT_HAS_ITERATORS(hash))) { if (hash->nNumUsed != hash->nNumOfElements) { for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) { - p = hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; + zv = hash->arPacked + idx; + if (Z_TYPE_P(zv) == IS_UNDEF) continue; if (j != idx) { - hash->arData[j] = *p; + ZVAL_COPY_VALUE(&hash->arPacked[j], zv); } j++; } @@ -2887,9 +2893,9 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ while (--n_left) { rnd_idx = php_mt_rand_range(0, n_left); if (rnd_idx != n_left) { - temp = hash->arData[n_left]; - hash->arData[n_left] = hash->arData[rnd_idx]; - hash->arData[rnd_idx] = temp; + ZVAL_COPY_VALUE(&temp, &hash->arPacked[n_left]); + ZVAL_COPY_VALUE(&hash->arPacked[n_left], &hash->arPacked[rnd_idx]); + ZVAL_COPY_VALUE(&hash->arPacked[rnd_idx], &temp); } } } else { @@ -2897,10 +2903,10 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ if (hash->nNumUsed != hash->nNumOfElements) { for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) { - p = hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; + zv = hash->arPacked + idx; + if (Z_TYPE_P(zv) == IS_UNDEF) continue; if (j != idx) { - hash->arData[j] = *p; + ZVAL_COPY_VALUE(&hash->arPacked[j], zv); if (idx == iter_pos) { zend_hash_iterators_update(hash, idx, j); iter_pos = zend_hash_iterators_lower_pos(hash, iter_pos + 1); @@ -2912,28 +2918,16 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ while (--n_left) { rnd_idx = php_mt_rand_range(0, n_left); if (rnd_idx != n_left) { - temp = hash->arData[n_left]; - hash->arData[n_left] = hash->arData[rnd_idx]; - hash->arData[rnd_idx] = temp; + ZVAL_COPY_VALUE(&temp, &hash->arPacked[n_left]); + ZVAL_COPY_VALUE(&hash->arPacked[n_left], &hash->arPacked[rnd_idx]); + ZVAL_COPY_VALUE(&hash->arPacked[rnd_idx], &temp); zend_hash_iterators_update(hash, (uint32_t)rnd_idx, n_left); } } } hash->nNumUsed = n_elems; hash->nInternalPointer = 0; - - for (j = 0; j < n_elems; j++) { - p = hash->arData + j; - if (p->key) { - zend_string_release_ex(p->key, 0); - } - p->h = j; - p->key = NULL; - } hash->nNextFreeElement = n_elems; - if (!(HT_FLAGS(hash) & HASH_FLAG_PACKED)) { - zend_hash_to_packed(hash); - } } /* }}} */ @@ -2958,7 +2952,6 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H zend_long num_in; /* Number of entries in the input hashtable */ zend_long pos; /* Current position in the hashtable */ uint32_t idx; - Bucket *p; /* Pointer to hash bucket */ zval *entry; /* Hash entry */ uint32_t iter_pos = zend_hash_iterators_lower_pos(in_hash, 0); @@ -2982,80 +2975,138 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H /* Create and initialize output hash */ zend_hash_init(&out_hash, (length > 0 ? num_in - length : 0) + (replace ? zend_hash_num_elements(replace) : 0), NULL, ZVAL_PTR_DTOR, 0); - /* Start at the beginning of the input hash and copy entries to output hash until offset is reached */ - for (pos = 0, idx = 0; pos < offset && idx < in_hash->nNumUsed; idx++) { - p = in_hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - entry = &p->val; + if (HT_IS_PACKED(in_hash)) { + /* Start at the beginning of the input hash and copy entries to output hash until offset is reached */ + entry = in_hash->arPacked; + for (pos = 0, idx = 0; pos < offset && idx < in_hash->nNumUsed; idx++, entry++) { + if (Z_TYPE_P(entry) == IS_UNDEF) continue; - /* Update output hash depending on key type */ - if (p->key == NULL) { zend_hash_next_index_insert_new(&out_hash, entry); - } else { - zend_hash_add_new(&out_hash, p->key, entry); + if (idx == iter_pos) { + if ((zend_long)idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } + pos++; } - if (idx == iter_pos) { - if ((zend_long)idx != pos) { - zend_hash_iterators_update(in_hash, idx, pos); + + /* If hash for removed entries exists, go until offset+length and copy the entries to it */ + if (removed != NULL) { + for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++, entry++) { + if (Z_TYPE_P(entry) == IS_UNDEF) continue; + pos++; + Z_TRY_ADDREF_P(entry); + zend_hash_next_index_insert_new(removed, entry); + zend_hash_packed_del_val(in_hash, entry); + } + } else { /* otherwise just skip those entries */ + int pos2 = pos; + + for ( ; pos2 < offset + length && idx < in_hash->nNumUsed; idx++, entry++) { + if (Z_TYPE_P(entry) == IS_UNDEF) continue; + pos2++; + zend_hash_packed_del_val(in_hash, entry); } - iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); } - pos++; - } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos); - /* If hash for removed entries exists, go until offset+length and copy the entries to it */ - if (removed != NULL) { - for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++) { - p = in_hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; + /* If there are entries to insert.. */ + if (replace) { + ZEND_HASH_FOREACH_VAL(replace, entry) { + Z_TRY_ADDREF_P(entry); + zend_hash_next_index_insert_new(&out_hash, entry); + pos++; + } ZEND_HASH_FOREACH_END(); + } + + /* Copy the remaining input hash entries to the output hash */ + entry = in_hash->arPacked + idx; + for ( ; idx < in_hash->nNumUsed ; idx++, entry++) { + if (Z_TYPE_P(entry) == IS_UNDEF) continue; + zend_hash_next_index_insert_new(&out_hash, entry); + if (idx == iter_pos) { + if ((zend_long)idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } pos++; + } + } else { + Bucket *p = in_hash->arData; + + /* Start at the beginning of the input hash and copy entries to output hash until offset is reached */ + for (pos = 0, idx = 0; pos < offset && idx < in_hash->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; entry = &p->val; - Z_TRY_ADDREF_P(entry); + + /* Update output hash depending on key type */ if (p->key == NULL) { - zend_hash_next_index_insert_new(removed, entry); + zend_hash_next_index_insert_new(&out_hash, entry); } else { - zend_hash_add_new(removed, p->key, entry); + zend_hash_add_new(&out_hash, p->key, entry); } - zend_hash_del_bucket(in_hash, p); + if (idx == iter_pos) { + if ((zend_long)idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } + pos++; } - } else { /* otherwise just skip those entries */ - int pos2 = pos; - for ( ; pos2 < offset + length && idx < in_hash->nNumUsed; idx++) { - p = in_hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - pos2++; - zend_hash_del_bucket(in_hash, p); - } - } - iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos); + /* If hash for removed entries exists, go until offset+length and copy the entries to it */ + if (removed != NULL) { + for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + pos++; + entry = &p->val; + Z_TRY_ADDREF_P(entry); + if (p->key == NULL) { + zend_hash_next_index_insert_new(removed, entry); + } else { + zend_hash_add_new(removed, p->key, entry); + } + zend_hash_del_bucket(in_hash, p); + } + } else { /* otherwise just skip those entries */ + int pos2 = pos; - /* If there are entries to insert.. */ - if (replace) { - ZEND_HASH_FOREACH_VAL(replace, entry) { - Z_TRY_ADDREF_P(entry); - zend_hash_next_index_insert_new(&out_hash, entry); - pos++; - } ZEND_HASH_FOREACH_END(); - } + for ( ; pos2 < offset + length && idx < in_hash->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + pos2++; + zend_hash_del_bucket(in_hash, p); + } + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos); - /* Copy the remaining input hash entries to the output hash */ - for ( ; idx < in_hash->nNumUsed ; idx++) { - p = in_hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - entry = &p->val; - if (p->key == NULL) { - zend_hash_next_index_insert_new(&out_hash, entry); - } else { - zend_hash_add_new(&out_hash, p->key, entry); + /* If there are entries to insert.. */ + if (replace) { + ZEND_HASH_FOREACH_VAL(replace, entry) { + Z_TRY_ADDREF_P(entry); + zend_hash_next_index_insert_new(&out_hash, entry); + pos++; + } ZEND_HASH_FOREACH_END(); } - if (idx == iter_pos) { - if ((zend_long)idx != pos) { - zend_hash_iterators_update(in_hash, idx, pos); + + /* Copy the remaining input hash entries to the output hash */ + for ( ; idx < in_hash->nNumUsed ; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + entry = &p->val; + if (p->key == NULL) { + zend_hash_next_index_insert_new(&out_hash, entry); + } else { + zend_hash_add_new(&out_hash, p->key, entry); } - iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + if (idx == iter_pos) { + if ((zend_long)idx != pos) { + zend_hash_iterators_update(in_hash, idx, pos); + } + iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1); + } + pos++; } - pos++; } /* replace HashTable data */ @@ -3114,7 +3165,6 @@ PHP_FUNCTION(array_pop) zval *stack, /* Input stack */ *val; /* Value to be popped */ uint32_t idx; - Bucket *p; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ARRAY_EX(stack, 0, 1) @@ -3124,27 +3174,52 @@ PHP_FUNCTION(array_pop) return; } - /* Get the last value and copy it into the return value */ - idx = Z_ARRVAL_P(stack)->nNumUsed; - while (1) { - if (idx == 0) { - return; + if (HT_IS_PACKED(Z_ARRVAL_P(stack))) { + /* Get the last value and copy it into the return value */ + idx = Z_ARRVAL_P(stack)->nNumUsed; + while (1) { + if (idx == 0) { + return; + } + idx--; + val = Z_ARRVAL_P(stack)->arPacked + idx; + if (Z_TYPE_P(val) != IS_UNDEF) { + break; + } } - idx--; - p = Z_ARRVAL_P(stack)->arData + idx; - val = &p->val; - if (Z_TYPE_P(val) != IS_UNDEF) { - break; + RETVAL_COPY_DEREF(val); + + if (idx == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) { + Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1; } - } - RETVAL_COPY_DEREF(val); - if (!p->key && (zend_long)p->h == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) { - Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1; - } + /* Delete the last value */ + zend_hash_packed_del_val(Z_ARRVAL_P(stack), val); + } else { + Bucket *p; + + /* Get the last value and copy it into the return value */ + idx = Z_ARRVAL_P(stack)->nNumUsed; + while (1) { + if (idx == 0) { + return; + } + idx--; + p = Z_ARRVAL_P(stack)->arData + idx; + val = &p->val; + if (Z_TYPE_P(val) != IS_UNDEF) { + break; + } + } + RETVAL_COPY_DEREF(val); + + if (!p->key && (zend_long)p->h == (Z_ARRVAL_P(stack)->nNextFreeElement - 1)) { + Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1; + } - /* Delete the last value */ - zend_hash_del_bucket(Z_ARRVAL_P(stack), p); + /* Delete the last value */ + zend_hash_del_bucket(Z_ARRVAL_P(stack), p); + } zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack)); } /* }}} */ @@ -3155,7 +3230,6 @@ PHP_FUNCTION(array_shift) zval *stack, /* Input stack */ *val; /* Value to be popped */ uint32_t idx; - Bucket *p; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ARRAY_EX(stack, 0, 1) @@ -3165,38 +3239,35 @@ PHP_FUNCTION(array_shift) return; } - /* Get the first value and copy it into the return value */ - idx = 0; - while (1) { - if (idx == Z_ARRVAL_P(stack)->nNumUsed) { - return; - } - p = Z_ARRVAL_P(stack)->arData + idx; - val = &p->val; - if (Z_TYPE_P(val) != IS_UNDEF) { - break; - } - idx++; - } - RETVAL_COPY_DEREF(val); - - /* Delete the first value */ - zend_hash_del_bucket(Z_ARRVAL_P(stack), p); - /* re-index like it did before */ - if (HT_FLAGS(Z_ARRVAL_P(stack)) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(Z_ARRVAL_P(stack))) { uint32_t k = 0; + /* Get the first value and copy it into the return value */ + idx = 0; + while (1) { + if (idx == Z_ARRVAL_P(stack)->nNumUsed) { + return; + } + val = Z_ARRVAL_P(stack)->arPacked + idx; + if (Z_TYPE_P(val) != IS_UNDEF) { + break; + } + idx++; + } + RETVAL_COPY_DEREF(val); + + /* Delete the first value */ + zend_hash_packed_del_val(Z_ARRVAL_P(stack), val); + if (EXPECTED(!HT_HAS_ITERATORS(Z_ARRVAL_P(stack)))) { for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { - p = Z_ARRVAL_P(stack)->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; + val = Z_ARRVAL_P(stack)->arPacked + idx; + if (Z_TYPE_P(val) == IS_UNDEF) continue; if (idx != k) { - Bucket *q = Z_ARRVAL_P(stack)->arData + k; - q->h = k; - q->key = NULL; - ZVAL_COPY_VALUE(&q->val, &p->val); - ZVAL_UNDEF(&p->val); + zval *q = Z_ARRVAL_P(stack)->arPacked + k; + ZVAL_COPY_VALUE(q, val); + ZVAL_UNDEF(val); } k++; } @@ -3204,14 +3275,12 @@ PHP_FUNCTION(array_shift) uint32_t iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), 0); for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { - p = Z_ARRVAL_P(stack)->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; + val = Z_ARRVAL_P(stack)->arPacked + idx; + if (Z_TYPE_P(val) == IS_UNDEF) continue; if (idx != k) { - Bucket *q = Z_ARRVAL_P(stack)->arData + k; - q->h = k; - q->key = NULL; - ZVAL_COPY_VALUE(&q->val, &p->val); - ZVAL_UNDEF(&p->val); + zval *q = Z_ARRVAL_P(stack)->arPacked + k; + ZVAL_COPY_VALUE(q, val); + ZVAL_UNDEF(val); if (idx == iter_pos) { zend_hash_iterators_update(Z_ARRVAL_P(stack), idx, k); iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), iter_pos + 1); @@ -3225,6 +3294,25 @@ PHP_FUNCTION(array_shift) } else { uint32_t k = 0; int should_rehash = 0; + Bucket *p; + + /* Get the first value and copy it into the return value */ + idx = 0; + while (1) { + if (idx == Z_ARRVAL_P(stack)->nNumUsed) { + return; + } + p = Z_ARRVAL_P(stack)->arData + idx; + val = &p->val; + if (Z_TYPE_P(val) != IS_UNDEF) { + break; + } + idx++; + } + RETVAL_COPY_DEREF(val); + + /* Delete the first value */ + zend_hash_del_bucket(Z_ARRVAL_P(stack), p); for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) { p = Z_ARRVAL_P(stack)->arData + idx; @@ -3393,6 +3481,33 @@ static inline Bucket* find_bucket_at_offset(HashTable* ht, zend_long offset) } /* }}} */ +/* {{{ find_bucket_at_offset(HashTable* ht, zend_long offset) + Finds the bucket at the given valid offset */ +static inline zval* find_packed_val_at_offset(HashTable* ht, zend_long offset) +{ + zend_long pos; + zval *zv; + ZEND_ASSERT(offset >= 0 && offset <= ht->nNumOfElements); + if (HT_IS_WITHOUT_HOLES(ht)) { + /* There's no need to iterate over the array to filter out holes if there are no holes */ + /* This properly handles both packed and unpacked arrays. */ + return ht->arPacked + offset; + } + /* Otherwise, this code has to iterate over the HashTable and skip holes in the array. */ + pos = 0; + ZEND_HASH_FOREACH_VAL(ht, zv) { + if (pos >= offset) { + /* This is the bucket of the array element at the requested offset */ + return zv; + } + ++pos; + } ZEND_HASH_FOREACH_END(); + + /* Return a pointer to the end of the bucket array. */ + return ht->arPacked + ht->nNumUsed; +} +/* }}} */ + /* {{{ Returns elements specified by offset and length */ PHP_FUNCTION(array_slice) { @@ -3446,34 +3561,57 @@ PHP_FUNCTION(array_slice) // Contains modified variants of ZEND_HASH_FOREACH_VAL { HashTable *ht = Z_ARRVAL_P(input); - Bucket *p = find_bucket_at_offset(ht, offset); - Bucket *end = ht->arData + ht->nNumUsed; /* Start at the beginning and go until we hit offset */ - if (HT_IS_PACKED(Z_ARRVAL_P(input)) && - (!preserve_keys || - (offset == 0 && HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(input))))) { - - zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); - ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - for (; p != end; p++) { - if (__fill_idx >= length) { - break; + if (HT_IS_PACKED(ht)) { + zval *zv = find_packed_val_at_offset(ht, offset); + zval *end = ht->arPacked + ht->nNumUsed; + + if (!preserve_keys + || (offset == 0 && HT_IS_WITHOUT_HOLES(ht))) { + zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); + ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { + for (; zv != end; zv++) { + if (__fill_idx >= length) { + break; + } + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) { + continue; + } + entry = zv; + if (UNEXPECTED(Z_ISREF_P(entry)) && + UNEXPECTED(Z_REFCOUNT_P(entry) == 1)) { + entry = Z_REFVAL_P(entry); + } + Z_TRY_ADDREF_P(entry); + ZEND_HASH_FILL_ADD(entry); } - entry = &p->val; - if (UNEXPECTED(Z_TYPE_P(entry) == IS_UNDEF)) { + } ZEND_HASH_FILL_END(); + } else { + zend_long n = 0; /* Current number of elements */ + zend_long idx = zv - ht->arPacked; + + for (; zv != end; zv++, idx++) { + if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) { continue; } - if (UNEXPECTED(Z_ISREF_P(entry)) && - UNEXPECTED(Z_REFCOUNT_P(entry) == 1)) { - entry = Z_REFVAL_P(entry); + if (n >= length) { + break; } - Z_TRY_ADDREF_P(entry); - ZEND_HASH_FILL_ADD(entry); + n++; + if (preserve_keys) { + entry = zend_hash_index_add_new(Z_ARRVAL_P(return_value), idx, zv); + } else { + entry = zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), zv); + } + zval_add_ref(entry); } - } ZEND_HASH_FILL_END(); + } } else { zend_long n = 0; /* Current number of elements */ + Bucket *p = find_bucket_at_offset(ht, offset); + Bucket *end = ht->arData + ht->nNumUsed; + for (; p != end; p++) { entry = &p->val; if (UNEXPECTED(Z_TYPE_P(entry) == IS_UNDEF)) { @@ -3574,7 +3712,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ zval *src_entry; zend_string *string_key; - if ((HT_FLAGS(dest) & HASH_FLAG_PACKED) && (HT_FLAGS(src) & HASH_FLAG_PACKED)) { + if (HT_IS_PACKED(dest) && HT_IS_PACKED(src)) { zend_hash_extend(dest, zend_hash_num_elements(dest) + zend_hash_num_elements(src), 1); ZEND_HASH_FILL_PACKED(dest) { ZEND_HASH_FOREACH_VAL(src, src_entry) { @@ -3749,7 +3887,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET ret = &args[0]; } if (ret) { - if (HT_FLAGS(Z_ARRVAL_P(ret)) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(Z_ARRVAL_P(ret))) { if (HT_IS_WITHOUT_HOLES(Z_ARRVAL_P(ret))) { ZVAL_COPY(return_value, ret); return; @@ -3777,7 +3915,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET /* copy first array */ array_init_size(return_value, count); dest = Z_ARRVAL_P(return_value); - if (HT_FLAGS(src) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(src)) { zend_hash_real_init_packed(dest); ZEND_HASH_FILL_PACKED(dest) { ZEND_HASH_FOREACH_VAL(src, src_entry) { @@ -4170,7 +4308,7 @@ PHP_FUNCTION(array_reverse) /* Initialize return array */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input))); - if ((HT_FLAGS(Z_ARRVAL_P(input)) & HASH_FLAG_PACKED) && !preserve_keys) { + if (HT_IS_PACKED(Z_ARRVAL_P(input)) && !preserve_keys) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { @@ -4238,7 +4376,7 @@ PHP_FUNCTION(array_pad) } array_init_size(return_value, pad_size_abs); - if (HT_FLAGS(Z_ARRVAL_P(input)) & HASH_FLAG_PACKED) { + if (HT_IS_PACKED(Z_ARRVAL_P(input))) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); if (pad_size < 0) { @@ -4440,12 +4578,24 @@ PHP_FUNCTION(array_unique) /* create and sort array with pointers to the target_hash buckets */ arTmp = pemalloc((Z_ARRVAL_P(array)->nNumOfElements + 1) * sizeof(struct bucketindex), GC_FLAGS(Z_ARRVAL_P(array)) & IS_ARRAY_PERSISTENT); - for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++) { - p = Z_ARRVAL_P(array)->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - arTmp[i].b = *p; - arTmp[i].i = i; - i++; + if (HT_IS_PACKED(Z_ARRVAL_P(array))) { + zval *zv = Z_ARRVAL_P(array)->arPacked; + for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++, zv++) { + if (Z_TYPE_P(zv) == IS_UNDEF) continue; + ZVAL_COPY_VALUE(&arTmp[i].b.val, zv); + arTmp[i].b.h = idx; + arTmp[i].b.key = NULL; + arTmp[i].i = i; + i++; + } + } else { + p = Z_ARRVAL_P(array)->arData; + for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + arTmp[i].b = *p; + arTmp[i].i = i; + i++; + } } ZVAL_UNDEF(&arTmp[i].b.val); zend_sort((void *) arTmp, i, sizeof(struct bucketindex), @@ -4690,10 +4840,21 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT); lists[i] = list; ptrs[i] = list; - for (idx = 0; idx < hash->nNumUsed; idx++) { - p = hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - *list++ = *p; + if (HT_IS_PACKED(hash)) { + zval *zv = hash->arPacked; + for (idx = 0; idx < hash->nNumUsed; idx++, zv++) { + if (Z_TYPE_P(zv) == IS_UNDEF) continue; + ZVAL_COPY_VALUE(&list->val, zv); + list->h = idx; + list->key = NULL; + list++; + } + } else { + p = hash->arData; + for (idx = 0; idx < hash->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + *list++ = *p; + } } ZVAL_UNDEF(&list->val); if (hash->nNumOfElements > 1) { @@ -5064,10 +5225,21 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), GC_FLAGS(hash) & IS_ARRAY_PERSISTENT); lists[i] = list; ptrs[i] = list; - for (idx = 0; idx < hash->nNumUsed; idx++) { - p = hash->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - *list++ = *p; + if (HT_IS_PACKED(hash)) { + zval *zv = hash->arPacked; + for (idx = 0; idx < hash->nNumUsed; idx++, zv++) { + if (Z_TYPE_P(zv) == IS_UNDEF) continue; + ZVAL_COPY_VALUE(&list->val, zv); + list->h = idx; + list->key = NULL; + list++; + } + } else { + p = hash->arData; + for (idx = 0; idx < hash->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + *list++ = *p; + } } ZVAL_UNDEF(&list->val); if (hash->nNumOfElements > 1) { @@ -5416,7 +5588,6 @@ PHP_FUNCTION(array_multisort) zval** arrays; Bucket** indirect; uint32_t idx; - Bucket* p; HashTable* hash; int argc; int array_size; @@ -5533,11 +5704,22 @@ PHP_FUNCTION(array_multisort) } for (i = 0; i < num_arrays; i++) { k = 0; - for (idx = 0; idx < Z_ARRVAL_P(arrays[i])->nNumUsed; idx++) { - p = Z_ARRVAL_P(arrays[i])->arData + idx; - if (Z_TYPE(p->val) == IS_UNDEF) continue; - indirect[k][i] = *p; - k++; + if (HT_IS_PACKED(Z_ARRVAL_P(arrays[i]))) { + zval *zv = Z_ARRVAL_P(arrays[i])->arPacked; + for (idx = 0; idx < Z_ARRVAL_P(arrays[i])->nNumUsed; idx++, zv++) { + if (Z_TYPE_P(zv) == IS_UNDEF) continue; + ZVAL_COPY_VALUE(&indirect[k][i].val, zv); + indirect[k][i].h = idx; + indirect[k][i].key = NULL; + k++; + } + } else { + Bucket *p = Z_ARRVAL_P(arrays[i])->arData; + for (idx = 0; idx < Z_ARRVAL_P(arrays[i])->nNumUsed; idx++, p++) { + if (Z_TYPE(p->val) == IS_UNDEF) continue; + indirect[k][i] = *p; + k++; + } } } for (k = 0; k < array_size; k++) { @@ -5550,26 +5732,28 @@ PHP_FUNCTION(array_multisort) /* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */ for (i = 0; i < num_arrays; i++) { - int repack; - hash = Z_ARRVAL_P(arrays[i]); hash->nNumUsed = array_size; + hash->nNextFreeElement = array_size; hash->nInternalPointer = 0; - repack = !(HT_FLAGS(hash) & HASH_FLAG_PACKED); + if (HT_IS_PACKED(hash)) { + for (k = 0; k < array_size; k++) { + ZVAL_COPY_VALUE(&hash->arPacked[k], &indirect[k][i].val); + } + } else { + int repack = 1; - for (n = 0, k = 0; k < array_size; k++) { - hash->arData[k] = indirect[k][i]; - if (hash->arData[k].key == NULL) { - hash->arData[k].h = n++; - } else { - repack = 0; + for (n = 0, k = 0; k < array_size; k++) { + hash->arData[k] = indirect[k][i]; + if (hash->arData[k].key == NULL) { + hash->arData[k].h = n++; + } else { + repack = 0; + } + } + if (repack) { + zend_hash_to_packed(hash); } - } - hash->nNextFreeElement = array_size; - if (repack) { - zend_hash_to_packed(hash); - } else if (!(HT_FLAGS(hash) & HASH_FLAG_PACKED)) { - zend_hash_rehash(hash); } } @@ -5634,17 +5818,27 @@ PHP_FUNCTION(array_rand) * The worst case probability of hitting an empty element is 1-1/2. The worst case * probability of hitting N empty elements in a row is (1-1/2)**N. * For N=10 this becomes smaller than 0.1%. */ - do { - zend_long randval = php_mt_rand_range(0, ht->nNumUsed - 1); - Bucket *bucket = &ht->arData[randval]; - if (!Z_ISUNDEF(bucket->val)) { - if (bucket->key) { - RETURN_STR_COPY(bucket->key); - } else { - RETURN_LONG(bucket->h); + if (HT_IS_PACKED(ht)) { + do { + zend_long randval = php_mt_rand_range(0, ht->nNumUsed - 1); + zval *zv = &ht->arPacked[randval]; + if (!Z_ISUNDEF_P(zv)) { + RETURN_LONG(randval); } - } - } while (1); + } while (1); + } else { + do { + zend_long randval = php_mt_rand_range(0, ht->nNumUsed - 1); + Bucket *bucket = &ht->arData[randval]; + if (!Z_ISUNDEF(bucket->val)) { + if (bucket->key) { + RETURN_STR_COPY(bucket->key); + } else { + RETURN_LONG(bucket->h); + } + } + } while (1); + } } if (num_req <= 0 || num_req > num_avail) { @@ -5938,7 +6132,7 @@ PHP_FUNCTION(array_map) } array_init_size(return_value, maxlen); - zend_hash_real_init(Z_ARRVAL_P(return_value), HT_FLAGS(Z_ARRVAL(arrays[0])) & HASH_FLAG_PACKED); + zend_hash_real_init(Z_ARRVAL_P(return_value), HT_IS_PACKED(Z_ARRVAL(arrays[0]))); ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { fci.retval = &result; @@ -5988,18 +6182,31 @@ PHP_FUNCTION(array_map) /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ uint32_t pos = array_pos[i]; - while (1) { - if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { - ZVAL_NULL(&zv); - break; - } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arData[pos].val) != IS_UNDEF) { - ZVAL_COPY(&zv, &Z_ARRVAL(arrays[i])->arData[pos].val); - array_pos[i] = pos + 1; - break; + if (HT_IS_PACKED(Z_ARRVAL(arrays[i]))) { + while (1) { + if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { + ZVAL_NULL(&zv); + break; + } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arPacked[pos]) != IS_UNDEF) { + ZVAL_COPY(&zv, &Z_ARRVAL(arrays[i])->arPacked[pos]); + array_pos[i] = pos + 1; + break; + } + pos++; + } + } else { + while (1) { + if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { + ZVAL_NULL(&zv); + break; + } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arData[pos].val) != IS_UNDEF) { + ZVAL_COPY(&zv, &Z_ARRVAL(arrays[i])->arData[pos].val); + array_pos[i] = pos + 1; + break; + } + pos++; } - pos++; } - zend_hash_next_index_insert_new(Z_ARRVAL(result), &zv); } @@ -6014,16 +6221,30 @@ PHP_FUNCTION(array_map) /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ uint32_t pos = array_pos[i]; - while (1) { - if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { - ZVAL_NULL(¶ms[i]); - break; - } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arData[pos].val) != IS_UNDEF) { - ZVAL_COPY(¶ms[i], &Z_ARRVAL(arrays[i])->arData[pos].val); - array_pos[i] = pos + 1; - break; + if (HT_IS_PACKED(Z_ARRVAL(arrays[i]))) { + while (1) { + if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { + ZVAL_NULL(¶ms[i]); + break; + } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arPacked[pos]) != IS_UNDEF) { + ZVAL_COPY(¶ms[i], &Z_ARRVAL(arrays[i])->arPacked[pos]); + array_pos[i] = pos + 1; + break; + } + pos++; + } + } else { + while (1) { + if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { + ZVAL_NULL(¶ms[i]); + break; + } else if (Z_TYPE(Z_ARRVAL(arrays[i])->arData[pos].val) != IS_UNDEF) { + ZVAL_COPY(¶ms[i], &Z_ARRVAL(arrays[i])->arData[pos].val); + array_pos[i] = pos + 1; + break; + } + pos++; } - pos++; } } @@ -6198,8 +6419,13 @@ PHP_FUNCTION(array_combine) while (1) { if (pos_values >= values->nNumUsed) { break; - } else if (Z_TYPE(values->arData[pos_values].val) != IS_UNDEF) { + } + if (HT_IS_PACKED(values)) { + entry_values = &values->arPacked[pos_values]; + } else { entry_values = &values->arData[pos_values].val; + } + if (Z_TYPE_P(entry_values) != IS_UNDEF) { if (Z_TYPE_P(entry_keys) == IS_LONG) { entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry_keys), entry_values); diff --git a/ext/standard/string.c b/ext/standard/string.c index 8a223b72f4e33..9059cfec7d891 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2353,12 +2353,22 @@ PHP_FUNCTION(substr_replace) zend_string *tmp_repl_str = NULL; if (repl_ht) { repl_idx = 0; - while (repl_idx < repl_ht->nNumUsed) { - tmp_repl = &repl_ht->arData[repl_idx].val; - if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { - break; + if (HT_IS_PACKED(repl_ht)) { + while (repl_idx < repl_ht->nNumUsed) { + tmp_repl = &repl_ht->arPacked[repl_idx]; + if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { + break; + } + repl_idx++; + } + } else { + while (repl_idx < repl_ht->nNumUsed) { + tmp_repl = &repl_ht->arData[repl_idx].val; + if (Z_TYPE_P(tmp_repl) != IS_UNDEF) { + break; + } + repl_idx++; } - repl_idx++; } if (repl_idx < repl_ht->nNumUsed) { repl_str = zval_get_tmp_string(tmp_repl, &tmp_repl_str); @@ -2400,12 +2410,22 @@ PHP_FUNCTION(substr_replace) zend_string *orig_str = zval_get_tmp_string(tmp_str, &tmp_orig_str); if (from_ht) { - while (from_idx < from_ht->nNumUsed) { - tmp_from = &from_ht->arData[from_idx].val; - if (Z_TYPE_P(tmp_from) != IS_UNDEF) { - break; + while (from_idx < from_ht->nNumUsed) { + tmp_from = &from_ht->arPacked[from_idx]; + if (Z_TYPE_P(tmp_from) != IS_UNDEF) { + break; + } + from_idx++; + } + if (HT_IS_PACKED(from_ht)) { + } else { + while (from_idx < from_ht->nNumUsed) { + tmp_from = &from_ht->arData[from_idx].val; + if (Z_TYPE_P(tmp_from) != IS_UNDEF) { + break; + } + from_idx++; } - from_idx++; } if (from_idx < from_ht->nNumUsed) { f = zval_get_long(tmp_from); @@ -2435,12 +2455,22 @@ PHP_FUNCTION(substr_replace) } if (len_ht) { - while (len_idx < len_ht->nNumUsed) { - tmp_len = &len_ht->arData[len_idx].val; - if (Z_TYPE_P(tmp_len) != IS_UNDEF) { - break; + if (HT_IS_PACKED(len_ht)) { + while (len_idx < len_ht->nNumUsed) { + tmp_len = &len_ht->arPacked[len_idx]; + if (Z_TYPE_P(tmp_len) != IS_UNDEF) { + break; + } + len_idx++; + } + } else { + while (len_idx < len_ht->nNumUsed) { + tmp_len = &len_ht->arData[len_idx].val; + if (Z_TYPE_P(tmp_len) != IS_UNDEF) { + break; + } + len_idx++; } - len_idx++; } if (len_idx < len_ht->nNumUsed) { l = zval_get_long(tmp_len); @@ -2470,12 +2500,22 @@ PHP_FUNCTION(substr_replace) result_len = ZSTR_LEN(orig_str) - l; if (repl_ht) { - while (repl_idx < repl_ht->nNumUsed) { - tmp_repl = &repl_ht->arData[repl_idx].val; - if (repl_ht != IS_UNDEF) { - break; + if (HT_IS_PACKED(repl_ht)) { + while (repl_idx < repl_ht->nNumUsed) { + tmp_repl = &repl_ht->arPacked[repl_idx]; + if (repl_ht != IS_UNDEF) { + break; + } + repl_idx++; + } + } else { + while (repl_idx < repl_ht->nNumUsed) { + tmp_repl = &repl_ht->arData[repl_idx].val; + if (repl_ht != IS_UNDEF) { + break; + } + repl_idx++; } - repl_idx++; } if (repl_idx < repl_ht->nNumUsed) { zend_string *tmp_repl_str; @@ -4158,12 +4198,22 @@ static zend_long php_str_replace_in_subject( if (replace_ht) { /* Get current entry */ zval *replace_entry = NULL; - while (replace_idx < replace_ht->nNumUsed) { - replace_entry = &replace_ht->arData[replace_idx].val; - if (Z_TYPE_P(replace_entry) != IS_UNDEF) { - break; + if (HT_IS_PACKED(replace_ht)) { + while (replace_idx < replace_ht->nNumUsed) { + replace_entry = &replace_ht->arPacked[replace_idx]; + if (Z_TYPE_P(replace_entry) != IS_UNDEF) { + break; + } + replace_idx++; + } + } else { + while (replace_idx < replace_ht->nNumUsed) { + replace_entry = &replace_ht->arData[replace_idx].val; + if (Z_TYPE_P(replace_entry) != IS_UNDEF) { + break; + } + replace_idx++; } - replace_idx++; } if (replace_idx < replace_ht->nNumUsed) { /* Make sure we're dealing with strings. */ From 63f76a67ef642c81a4411774a9e4041c64335951 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 14 Sep 2021 13:34:26 +0300 Subject: [PATCH 02/21] Fixed memory leaks in ext/standard/tests/array/shuffle_basic2.phpt without opcache. --- ext/standard/array.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/standard/array.c b/ext/standard/array.c index d26a110eada34..5e425bc61a46e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2876,6 +2876,18 @@ static void php_array_data_shuffle(zval *array) /* {{{ */ n_left = n_elems; if (!HT_IS_PACKED(hash)) { + if (!HT_HAS_STATIC_KEYS_ONLY(hash)) { + Bucket *p = hash->arData; + uint32_t i = hash->nNumUsed; + + for (; i > 0; p++, i--) { + if (Z_ISUNDEF(p->val)) continue; + if (p->key) { + zend_string_release(p->key); + p->key = NULL; + } + } + } zend_hash_to_packed(hash); } From ebda1e89fa3051778132258495f07526565140d9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 20 Sep 2021 23:22:52 +0300 Subject: [PATCH 03/21] Move condition --- ext/standard/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 9059cfec7d891..f3a3e70663aab 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2410,6 +2410,7 @@ PHP_FUNCTION(substr_replace) zend_string *orig_str = zval_get_tmp_string(tmp_str, &tmp_orig_str); if (from_ht) { + if (HT_IS_PACKED(from_ht)) { while (from_idx < from_ht->nNumUsed) { tmp_from = &from_ht->arPacked[from_idx]; if (Z_TYPE_P(tmp_from) != IS_UNDEF) { @@ -2417,7 +2418,6 @@ PHP_FUNCTION(substr_replace) } from_idx++; } - if (HT_IS_PACKED(from_ht)) { } else { while (from_idx < from_ht->nNumUsed) { tmp_from = &from_ht->arData[from_idx].val; From 6b1e401ba0f20aa6f569659c1626b50db89210fd Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 26 Oct 2021 13:51:29 +0300 Subject: [PATCH 04/21] Revert packed array related changes --- .../dateformat/dateformat_format_object.cpp | 62 ++++++------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index d00ef1ad8829a..2f82cfe3b9ab9 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -101,54 +101,28 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) } idx = 0; - if (HT_IS_PACKED(ht)) { - while (idx < ht->nNumUsed) { - z = &ht->arPacked[idx]; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; - } - idx++; + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; } - if (idx >= ht->nNumUsed || !valid_format(z)) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_format_object: bad format; the date format (first " - "element of the array) is not valid", 0); - RETURN_FALSE; - } - dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); - idx++; - while (idx < ht->nNumUsed) { - z = &ht->arPacked[idx]; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; - } - idx++; - } - } else { - while (idx < ht->nNumUsed) { - z = &ht->arData[idx].val; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; - } - idx++; - } - if (idx >= ht->nNumUsed || !valid_format(z)) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_format_object: bad format; the date format (first " - "element of the array) is not valid", 0); - RETURN_FALSE; - } - dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); + } + if (idx >= ht->nNumUsed || !valid_format(z)) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "datefmt_format_object: bad format; the date format (first " + "element of the array) is not valid", 0); + RETURN_FALSE; + } + dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); - idx++; - while (idx < ht->nNumUsed) { - z = &ht->arData[idx].val; - if (Z_TYPE_P(z) != IS_UNDEF) { - break; - } - idx++; + idx++; + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; } + idx++; } if (idx >= ht->nNumUsed || !valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, From ebbde9196b74cb2a2a3f1d325fe130c313b5868e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 26 Oct 2021 13:53:49 +0300 Subject: [PATCH 05/21] ws --- Zend/zend_hash.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index bab6c98d27563..d1acad4625e09 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -982,8 +982,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, __h = _idx; \ _idx++; \ } else { \ - _p = (Bucket*)__z; \ - __z = &(_p + 1)->val; \ + _p = (Bucket*)__z; \ + __z = &(_p + 1)->val; \ __h = _p->h; \ __key = _p->key; \ if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ From ea245bd950c9faee66decf58dd71a7a89db2ab1c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 26 Oct 2021 14:11:53 +0300 Subject: [PATCH 06/21] Packed arrays can't contain IS_INDIRECT elements --- Zend/zend_hash.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 07c8506ce093f..0e9e0fd0cabb4 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -2188,15 +2188,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, zval *zv = source->arPacked + idx; if (UNEXPECTED(Z_TYPE_P(zv) == IS_UNDEF)) continue; - /* INDIRECT element may point to UNDEF-ined slots */ - data = zv; - if (Z_TYPE_P(data) == IS_INDIRECT) { - data = Z_INDIRECT_P(data); - if (UNEXPECTED(Z_TYPE_P(data) == IS_UNDEF)) { - continue; - } - } - new_entry = zend_hash_index_update(target, idx, data); + new_entry = zend_hash_index_update(target, idx, zv); if (pCopyConstructor) { pCopyConstructor(new_entry); } From 1b30fd958532db67479e40dda1fdd057ca77f94d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 27 Oct 2021 11:17:52 +0300 Subject: [PATCH 07/21] Use specific array/hash/packed iterators where possible --- Zend/Optimizer/block_pass.c | 4 +- Zend/Optimizer/dfa_pass.c | 12 +- Zend/Optimizer/sccp.c | 8 +- Zend/Optimizer/zend_cfg.c | 8 +- Zend/Optimizer/zend_dump.c | 8 +- Zend/Optimizer/zend_inference.c | 4 +- Zend/Optimizer/zend_optimizer.c | 8 +- Zend/zend.c | 8 +- Zend/zend_API.c | 4 +- Zend/zend_alloc.c | 4 +- Zend/zend_ast.c | 8 +- Zend/zend_attributes.c | 12 +- Zend/zend_builtin_functions.c | 20 +- Zend/zend_compile.c | 24 +- Zend/zend_exceptions.c | 8 +- Zend/zend_execute.c | 4 +- Zend/zend_execute_API.c | 4 +- Zend/zend_generators.c | 4 +- Zend/zend_hash.c | 26 +- Zend/zend_hash.h | 467 ++++++++++++++---- Zend/zend_inheritance.c | 4 +- Zend/zend_list.c | 4 +- Zend/zend_opcode.c | 4 +- Zend/zend_vm_def.h | 20 +- Zend/zend_vm_execute.h | 20 +- ext/curl/interface.c | 12 +- ext/dom/node.c | 6 +- ext/dom/xpath.c | 4 +- ext/ffi/ffi.c | 48 +- ext/filter/filter.c | 8 +- ext/gd/gd.c | 28 +- ext/imap/php_imap.c | 16 +- ext/intl/collator/collator_convert.c | 8 +- ext/intl/collator/collator_sort.c | 4 +- ext/intl/converter/converter.c | 8 +- .../dateformat/dateformat_format_object.cpp | 4 +- ext/intl/locale/locale_methods.c | 8 +- ext/intl/msgformat/msgformat_helpers.cpp | 4 +- ext/json/json_encoder.c | 4 +- ext/ldap/ldap.c | 4 +- ext/libxml/libxml.c | 4 +- ext/mbstring/mbstring.c | 24 +- ext/mysqli/mysqli.c | 4 +- ext/mysqli/mysqli_api.c | 4 +- ext/mysqli/mysqli_nonapi.c | 12 +- ext/odbc/php_odbc.c | 24 +- ext/opcache/zend_persist.c | 12 +- ext/opcache/zend_persist_calc.c | 12 +- ext/openssl/openssl.c | 44 +- ext/openssl/xp_ssl.c | 12 +- ext/pcntl/pcntl.c | 16 +- ext/pcre/php_pcre.c | 28 +- ext/pdo/pdo_dbh.c | 4 +- ext/pdo/pdo_stmt.c | 20 +- ext/pdo_pgsql/pgsql_driver.c | 4 +- ext/pgsql/pgsql.c | 36 +- ext/phar/phar_object.c | 8 +- ext/reflection/php_reflection.c | 12 +- ext/session/php_session.h | 4 +- ext/session/session.c | 9 +- ext/snmp/snmp.c | 4 +- ext/soap/php_encoding.c | 60 +-- ext/soap/php_http.c | 2 +- ext/soap/php_packet_soap.c | 4 +- ext/soap/php_schema.c | 20 +- ext/soap/php_sdl.c | 28 +- ext/soap/soap.c | 96 ++-- ext/sockets/conversions.c | 8 +- ext/sockets/sockets.c | 10 +- ext/sodium/libsodium.c | 4 +- ext/spl/php_spl.c | 8 +- ext/spl/spl_array.c | 4 +- ext/spl/spl_dllist.c | 4 +- ext/spl/spl_fixedarray.c | 16 +- ext/spl/spl_observer.c | 24 +- ext/sqlite3/sqlite3.c | 4 +- ext/standard/array.c | 230 +++++---- ext/standard/basic_functions.c | 12 +- ext/standard/browscap.c | 4 +- ext/standard/file.c | 8 +- ext/standard/formatted_print.c | 4 +- ext/standard/head.c | 4 +- ext/standard/http.c | 4 +- ext/standard/http_fopen_wrapper.c | 8 +- ext/standard/info.c | 32 +- ext/standard/mail.c | 8 +- ext/standard/proc_open.c | 20 +- ext/standard/streamsfuncs.c | 28 +- ext/standard/string.c | 40 +- ext/standard/url.c | 4 +- ext/standard/user_filters.c | 2 +- ext/standard/var.c | 40 +- ext/tidy/tidy.c | 15 +- ext/tokenizer/tokenizer.c | 8 +- ext/xml/xml.c | 4 +- ext/xsl/xsltprocessor.c | 8 +- ext/zend_test/test.c | 4 +- ext/zlib/zlib.c | 4 +- main/output.c | 4 +- main/php_variables.c | 4 +- main/streams/streams.c | 8 +- sapi/fpm/fpm/fpm_php.c | 4 +- sapi/phpdbg/phpdbg.c | 4 +- sapi/phpdbg/phpdbg_bp.c | 24 +- sapi/phpdbg/phpdbg_frame.c | 4 +- sapi/phpdbg/phpdbg_info.c | 8 +- sapi/phpdbg/phpdbg_utils.c | 4 +- sapi/phpdbg/phpdbg_watch.c | 8 +- 108 files changed, 1158 insertions(+), 857 deletions(-) diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c index eac6d6b37aa73..92460ffa4b354 100644 --- a/Zend/Optimizer/block_pass.c +++ b/Zend/Optimizer/block_pass.c @@ -1058,9 +1058,9 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op uint32_t s = 0; ZEND_ASSERT(b->successors_count == (opline->opcode == ZEND_MATCH ? 1 : 2) + zend_hash_num_elements(jumptable)); - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_TO_OFFSET(opline, new_opcodes + blocks[b->successors[s++]].start); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); opline->extended_value = ZEND_OPLINE_TO_OFFSET(opline, new_opcodes + blocks[b->successors[s++]].start); break; } diff --git a/Zend/Optimizer/dfa_pass.c b/Zend/Optimizer/dfa_pass.c index 166580742b034..b28e45abbd446 100644 --- a/Zend/Optimizer/dfa_pass.c +++ b/Zend/Optimizer/dfa_pass.c @@ -415,7 +415,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa) ZVAL_TRUE(&tmp); dst = zend_new_array(zend_hash_num_elements(src)); if (strict) { - ZEND_HASH_FOREACH_VAL(src, val) { + ZEND_ARRAY_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) == IS_STRING) { zend_hash_add(dst, Z_STR_P(val), &tmp); } else if (Z_TYPE_P(val) == IS_LONG) { @@ -425,16 +425,16 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa) ok = 0; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { - ZEND_HASH_FOREACH_VAL(src, val) { + ZEND_ARRAY_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) != IS_STRING || ZEND_HANDLE_NUMERIC(Z_STR_P(val), idx)) { zend_array_destroy(dst); ok = 0; break; } zend_hash_add(dst, Z_STR_P(val), &tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (ok) { @@ -660,11 +660,11 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)) == old->start) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) == old->start) { opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start); } diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c index 381220a11468b..dae98d35534b5 100644 --- a/Zend/Optimizer/sccp.c +++ b/Zend/Optimizer/sccp.c @@ -587,7 +587,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) { } SEPARATE_ARRAY(result); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) { if (key) { value = zend_hash_update(Z_ARR_P(result), key, value); } else { @@ -597,7 +597,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) { return FAILURE; } Z_TRY_ADDREF_P(value); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } @@ -2009,7 +2009,7 @@ static void join_hash_tables(HashTable *ret, HashTable *ht1, HashTable *ht2) zend_string *key; zval *val1, *val2; - ZEND_HASH_FOREACH_KEY_VAL(ht1, index, key, val1) { + ZEND_ARRAY_FOREACH_KEY_VAL(ht1, index, key, val1) { if (key) { val2 = zend_hash_find(ht2, key); } else { @@ -2023,7 +2023,7 @@ static void join_hash_tables(HashTable *ret, HashTable *ht1, HashTable *ht2) } Z_TRY_ADDREF_P(val1); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } static zend_result join_partial_arrays(zval *a, zval *b) diff --git a/Zend/Optimizer/zend_cfg.c b/Zend/Optimizer/zend_cfg.c index 380286cc0bf56..9b63c83e21e5b 100644 --- a/Zend/Optimizer/zend_cfg.c +++ b/Zend/Optimizer/zend_cfg.c @@ -401,9 +401,9 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, { HashTable *jumptable = Z_ARRVAL_P(CRT_CONSTANT(opline->op2)); zval *zv; - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { BB_START(ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); BB_START(ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)); BB_START(i + 1); break; @@ -574,9 +574,9 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, block->successors_count = (opline->opcode == ZEND_MATCH ? 1 : 2) + zend_hash_num_elements(jumptable); block->successors = zend_arena_calloc(arena, block->successors_count, sizeof(int)); - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { block->successors[s++] = block_map[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))]; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); block->successors[s++] = block_map[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)]; if (opline->opcode != ZEND_MATCH) { diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c index 41146bdad97ec..c4f596768b9ef 100644 --- a/Zend/Optimizer/zend_dump.c +++ b/Zend/Optimizer/zend_dump.c @@ -31,7 +31,7 @@ void zend_dump_ht(HashTable *ht) zval *val; bool first = 1; - ZEND_HASH_FOREACH_KEY_VAL(ht, index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(ht, index, key, val) { if (first) { first = 0; } else { @@ -44,7 +44,7 @@ void zend_dump_ht(HashTable *ht) } fprintf(stderr, " =>"); zend_dump_const(val); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } void zend_dump_const(const zval *zv) @@ -643,7 +643,7 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block zend_string *key; zend_ulong num_key; zval *zv; - ZEND_HASH_FOREACH_KEY_VAL(jumptable, num_key, key, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL(jumptable, num_key, key, zv) { if (key) { fprintf(stderr, " \"%s\":", ZSTR_VAL(key)); } else { @@ -654,7 +654,7 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block } else { fprintf(stderr, " %04u,", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); fprintf(stderr, " default:"); } else { zend_dump_const(op); diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index 7a3ec1a27b409..05393823567a3 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -2031,14 +2031,14 @@ ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv) tmp |= MAY_BE_RCN; } - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, str, val) { if (str) { tmp |= MAY_BE_ARRAY_KEY_STRING; } else { tmp |= MAY_BE_ARRAY_KEY_LONG; } tmp |= 1 << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (HT_IS_PACKED(ht)) { tmp &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH); } diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c index 83671106c8add..2c8de44aa47b8 100644 --- a/Zend/Optimizer/zend_optimizer.c +++ b/Zend/Optimizer/zend_optimizer.c @@ -676,9 +676,9 @@ void zend_optimizer_migrate_jump(zend_op_array *op_array, zend_op *new_opline, z { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, new_opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); new_opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, new_opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)); break; } @@ -722,9 +722,9 @@ void zend_optimizer_shift_jump(zend_op_array *op_array, zend_op *opline, uint32_ { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)) - shiftlist[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))]); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) - shiftlist[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)]); break; } diff --git a/Zend/zend.c b/Zend/zend.c index 52295761245f1..e2122292f24f7 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -315,7 +315,7 @@ static void print_hash(smart_str *buf, HashTable *ht, int indent, bool is_object } smart_str_appends(buf, "(\n"); indent += PRINT_ZVAL_INDENT; - ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { for (i = 0; i < indent; i++) { smart_str_appendc(buf, ' '); } @@ -345,7 +345,7 @@ static void print_hash(smart_str *buf, HashTable *ht, int indent, bool is_object smart_str_appends(buf, "] => "); zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT); smart_str_appends(buf, "\n"); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); indent -= PRINT_ZVAL_INDENT; for (i = 0; i < indent; i++) { smart_str_appendc(buf, ' '); @@ -361,7 +361,7 @@ static void print_flat_hash(smart_str *buf, HashTable *ht) /* {{{ */ zend_ulong num_key; int i = 0; - ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { if (i++ > 0) { smart_str_appendc(buf, ','); } @@ -373,7 +373,7 @@ static void print_flat_hash(smart_str *buf, HashTable *ht) /* {{{ */ } smart_str_appends(buf, "] => "); zend_print_flat_zval_r_to_buf(buf, tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 245967d678883..90f4d0bbf2087 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3919,7 +3919,7 @@ ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args)); fci->params = params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval)); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), arg) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), arg) { if (func && !Z_ISREF_P(arg) && ARG_SHOULD_BE_SENT_BY_REF(func, n)) { ZVAL_NEW_REF(params, arg); Z_TRY_ADDREF_P(arg); @@ -3928,7 +3928,7 @@ ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function } params++; n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index aa0fe9fad5908..5e02856d45f52 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2798,10 +2798,10 @@ static void *tracked_realloc(void *ptr, size_t new_size) { static void tracked_free_all() { HashTable *tracked_allocs = AG(mm_heap)->tracked_allocs; zend_ulong h; - ZEND_HASH_FOREACH_NUM_KEY(tracked_allocs, h) { + ZEND_ARRAY_FOREACH_NUM_KEY(tracked_allocs, h) { void *ptr = (void *) (uintptr_t) (h << ZEND_MM_ALIGNMENT_LOG2); free(ptr); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } #endif diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index a064927f93a87..34bd2dfc6d889 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -460,7 +460,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) { zval *val; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { if (key) { zend_hash_update(Z_ARRVAL_P(result), key, val); } else { @@ -471,7 +471,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) { } } Z_TRY_ADDREF_P(val); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } @@ -1418,7 +1418,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit zval *val; bool first = true; smart_str_appendc(str, '['); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zv), idx, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(zv), idx, key, val) { if (first) { first = false; } else { @@ -1433,7 +1433,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit smart_str_appends(str, " => "); } zend_ast_export_zval(str, val, 0, indent); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendc(str, ']'); break; } diff --git a/Zend/zend_attributes.c b/Zend/zend_attributes.c index a9bf3811b3710..a4c71c738b1cc 100644 --- a/Zend/zend_attributes.c +++ b/Zend/zend_attributes.c @@ -78,11 +78,11 @@ static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, if (attributes) { zend_attribute *attr; - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, lcname)) { return attr; } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } return NULL; @@ -93,13 +93,13 @@ static zend_attribute *get_attribute_str(HashTable *attributes, const char *str, if (attributes) { zend_attribute *attr; - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && ZSTR_LEN(attr->lcname) == len) { if (0 == memcmp(ZSTR_VAL(attr->lcname), str, len)) { return attr; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } return NULL; @@ -173,13 +173,13 @@ ZEND_API bool zend_is_attribute_repeated(HashTable *attributes, zend_attribute * { zend_attribute *other; - ZEND_HASH_FOREACH_PTR(attributes, other) { + ZEND_PACKED_FOREACH_PTR(attributes, other) { if (other != attr && other->offset == attr->offset) { if (zend_string_equals(other->lcname, attr->lcname)) { return 1; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); return 0; } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 7e58639508d55..53e861383a660 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -418,7 +418,7 @@ static bool validate_constant_array_argument(HashTable *ht, int argument_number) zval *val; GC_PROTECT_RECURSION(ht); - ZEND_HASH_FOREACH_VAL(ht, val) { + ZEND_ARRAY_FOREACH_VAL(ht, val) { ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_ARRAY && Z_REFCOUNTED_P(val)) { if (Z_IS_RECURSIVE_P(val)) { @@ -430,7 +430,7 @@ static bool validate_constant_array_argument(HashTable *ht, int argument_number) break; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_UNPROTECT_RECURSION(ht); return ret; } @@ -443,7 +443,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */ zval *new_val, *val; array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(src), idx, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(src), idx, key, val) { /* constant arrays can't contain references */ ZVAL_DEREF(val); if (key) { @@ -458,7 +458,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */ } else { Z_TRY_ADDREF_P(val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -1399,20 +1399,20 @@ ZEND_FUNCTION(get_resources) if (!type) { array_init(return_value); - ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (zend_string_equals_literal(type, "Unknown")) { array_init(return_value); - ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) <= 0) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { int id = zend_fetch_list_dtor_id(ZSTR_VAL(type)); @@ -1422,12 +1422,12 @@ ZEND_FUNCTION(get_resources) } array_init(return_value); - ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) == id) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } /* }}} */ diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 640dbe55de5d8..9c7535a99c553 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4079,7 +4079,7 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args ZVAL_TRUE(&tmp); if (strict) { - ZEND_HASH_FOREACH_VAL(src, val) { + ZEND_ARRAY_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) == IS_STRING) { zend_hash_add(dst, Z_STR_P(val), &tmp); } else if (Z_TYPE_P(val) == IS_LONG) { @@ -4089,9 +4089,9 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args ok = 0; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { - ZEND_HASH_FOREACH_VAL(src, val) { + ZEND_ARRAY_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) != IS_STRING || is_numeric_string(Z_STRVAL_P(val), Z_STRLEN_P(val), NULL, NULL, 0)) { zend_array_destroy(dst); @@ -4099,7 +4099,7 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args break; } zend_hash_add(dst, Z_STR_P(val), &tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } zend_array_destroy(src); @@ -6437,7 +6437,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3 } /* Validate attributes in a secondary loop (needed to detect repeated attributes). */ - ZEND_HASH_FOREACH_PTR(*attributes, attr) { + ZEND_PACKED_FOREACH_PTR(*attributes, attr) { if (attr->offset != offset || NULL == (config = zend_internal_attribute_get(attr->lcname))) { continue; } @@ -6460,7 +6460,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3 if (config->validator != NULL) { config->validator(attr, target, CG(active_class_entry)); } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } /* }}} */ @@ -8402,7 +8402,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ zval *val; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { if (key) { zend_hash_update(Z_ARRVAL_P(result), key, val); } else if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), val)) { @@ -8410,7 +8410,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ return 0; } Z_TRY_ADDREF_P(val); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); continue; } else { @@ -8954,22 +8954,22 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */ opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &assign_node, NULL); SET_NODE(opline->result, result); - ZEND_HASH_FOREACH_PTR(CG(memoized_exprs), node) { + ZEND_ARRAY_FOREACH_PTR(CG(memoized_exprs), node) { if (node->op_type == IS_TMP_VAR || node->op_type == IS_VAR) { need_frees = 1; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Free DUPed expressions if there are any */ if (need_frees) { uint32_t jump_opnum = zend_emit_jump(0); zend_update_jump_target_to_next(coalesce_opnum); - ZEND_HASH_FOREACH_PTR(CG(memoized_exprs), node) { + ZEND_ARRAY_FOREACH_PTR(CG(memoized_exprs), node) { if (node->op_type == IS_TMP_VAR || node->op_type == IS_VAR) { zend_emit_op(NULL, ZEND_FREE, node, NULL); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_update_jump_target_to_next(jump_opnum); } else { zend_update_jump_target_to_next(coalesce_opnum); diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index da4b664981f19..d7c98d0f925d6 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -566,13 +566,13 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* zend_string *name; zval *arg; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { if (name) { smart_str_append(str, name); smart_str_appends(str, ": "); } _build_trace_args(arg, str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (last_len != ZSTR_LEN(str->s)) { ZSTR_LEN(str->s) -= 2; /* remove last ', ' */ @@ -591,14 +591,14 @@ ZEND_API zend_string *zend_trace_to_string(HashTable *trace, bool include_main) uint32_t num = 0; smart_str str = {0}; - ZEND_HASH_FOREACH_NUM_KEY_VAL(trace, index, frame) { + ZEND_ARRAY_FOREACH_NUM_KEY_VAL(trace, index, frame) { if (Z_TYPE_P(frame) != IS_ARRAY) { zend_error(E_WARNING, "Expected array for frame " ZEND_ULONG_FMT, index); continue; } _build_trace_string(&str, Z_ARRVAL_P(frame), num++); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (include_main) { smart_str_appendc(&str, '#'); diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index dce0f32e835ff..31ca08a2ce932 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1224,7 +1224,7 @@ static void zend_verify_internal_func_info(zend_function *fn, zval *retval) { uint32_t num_checked = 0; zend_string *str; zval *val; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, str, val) { if (str) { if (!(type_mask & MAY_BE_ARRAY_KEY_STRING)) { zend_error_noreturn(E_CORE_ERROR, @@ -1248,7 +1248,7 @@ static void zend_verify_internal_func_info(zend_function *fn, zval *retval) { if (++num_checked > 16) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } #endif } diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 7b9f8b849dc18..996673a36b8c0 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -816,7 +816,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_ zval *arg; uint32_t arg_num = ZEND_CALL_NUM_ARGS(call) + 1; bool have_named_params = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL(fci->named_params, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(fci->named_params, name, arg) { bool must_wrap = 0; zval *target; if (name) { @@ -867,7 +867,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_ ZEND_CALL_NUM_ARGS(call)++; arg_num++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_MAY_HAVE_UNDEF)) { diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 965b9edb60b8f..fa64f8c3560fa 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -171,10 +171,10 @@ static void zend_generator_remove_child(zend_generator_node *node, zend_generato zend_hash_index_del(ht, (zend_ulong) child); if (node->children == 2) { zend_generator *other_child; - ZEND_HASH_FOREACH_PTR(ht, other_child) { + ZEND_ARRAY_FOREACH_PTR(ht, other_child) { node->child.single = other_child; break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_destroy(ht); efree(ht); } diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 0e9e0fd0cabb4..74409e574e28b 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -3187,7 +3187,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht) { HashTable *new_ht = zend_new_array(zend_hash_num_elements(ht)); - ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL(ht, num_key, str_key, zv) { if (!str_key) { str_key = zend_long_to_str(num_key); zend_string_delref(str_key); @@ -3204,7 +3204,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht) } } while (0); zend_hash_update(new_ht, str_key, zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return new_ht; } @@ -3220,16 +3220,18 @@ ZEND_API HashTable* ZEND_FASTCALL zend_proptable_to_symtable(HashTable *ht, bool zend_string *str_key; zval *zv; - ZEND_HASH_FOREACH_STR_KEY(ht, str_key) { - /* The `str_key &&` here might seem redundant: property tables should - * only have string keys. Unfortunately, this isn't true, at the very - * least because of ArrayObject, which stores a symtable where the - * property table should be. - */ - if (str_key && ZEND_HANDLE_NUMERIC(str_key, num_key)) { - goto convert; - } - } ZEND_HASH_FOREACH_END(); + if (!HT_IS_PACKED(ht)) { + ZEND_HASH_FOREACH_STR_KEY(ht, str_key) { + /* The `str_key &&` here might seem redundant: property tables should + * only have string keys. Unfortunately, this isn't true, at the very + * least because of ArrayObject, which stores a symtable where the + * property table should be. + */ + if (str_key && ZEND_HANDLE_NUMERIC(str_key, num_key)) { + goto convert; + } + } ZEND_HASH_FOREACH_END(); + } if (always_duplicate) { return zend_array_dup(ht); diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index d1acad4625e09..b364ae3737f3d 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -959,41 +959,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define zend_hash_get_current_data_ptr(ht) \ zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer) +/* Hash array iterators */ #define ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) do { \ - HashTable *__ht = (_ht); \ - bool _is_packed = HT_IS_PACKED(__ht); \ - zval *__z; \ - zend_ulong __h; \ - zend_string *__key = NULL; \ - Bucket *_p = NULL; \ - uint32_t _idx = _from; \ - zval *_end; \ - if (_is_packed) { \ - __z = __ht->arPacked + _from; \ - _end = __ht->arPacked + __ht->nNumUsed; \ - } else { \ - __z = &__ht->arData[_from].val; \ - _end = &__ht->arData[__ht->nNumUsed].val; \ - } \ - while (__z != _end) { \ - zval *_z = __z; \ - if (_is_packed) { \ - __z++; \ - __h = _idx; \ - _idx++; \ - } else { \ - _p = (Bucket*)__z; \ - __z = &(_p + 1)->val; \ - __h = _p->h; \ - __key = _p->key; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ - } \ - } \ - (void) __h; (void) __key; (void) _p; (void) _idx; \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; - -#define ZEND_HASH_FOREACH_FROM_OLD(_ht, indirect, _from) do { \ HashTable *__ht = (_ht); \ Bucket *_p = __ht->arData + (_from); \ Bucket *_end = __ht->arData + __ht->nNumUsed; \ @@ -1008,37 +975,6 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_FOREACH(_ht, indirect) ZEND_HASH_FOREACH_FROM(_ht, indirect, 0) #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \ - HashTable *__ht = (_ht); \ - uint32_t _idx = __ht->nNumUsed; \ - Bucket *_p = NULL; \ - zval *_z; \ - zval *__z = NULL; \ - zend_ulong __h; \ - zend_string *__key = NULL; \ - bool _is_packed = HT_IS_PACKED(__ht); \ - if (_is_packed) { \ - __z = __ht->arPacked + _idx; \ - } else { \ - _p = __ht->arData + _idx; \ - } \ - for (;_idx > 0; _idx--) { \ - if (_is_packed) { \ - __z--; \ - _z = __z; \ - __h = _idx - 1; \ - } else { \ - _p--; \ - _z = &_p->val; \ - __h = _p->h; \ - __key = _p->key; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ - } \ - } \ - (void) __h; (void) __key; (void) _p; (void) __z; \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; - -#define ZEND_HASH_REVERSE_FOREACH_OLD(_ht, indirect) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ Bucket *_p = __ht->arData + _idx; \ @@ -1119,117 +1055,434 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; + _h = _p->h; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = __h; + _h = _p->h; #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = __key; + _key = _p->key; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = __key; + _key = _p->key; #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; + _h = _p->h; \ + _key = _p->key; #define ZEND_HASH_REVERSE_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; + _h = _p->h; \ + _key = _p->key; #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; \ + _h = _p->h; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ + _h = _p->h; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = __key; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ ZEND_HASH_FOREACH_FROM(ht, 0, _from); \ - _key = __key; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = __key; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ + _h = _p->h; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ + _h = _p->h; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _key = __key; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _key = __key; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _h = __h; \ - _key = __key; \ + _h = _p->h; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _h = __h; \ - _key = __key; \ + _h = _p->h; \ + _key = _p->key; \ _val = _z; #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; \ + _h = _p->h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ + _h = _p->h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = __key; \ + _key = _p->key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = __key; \ + _key = _p->key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ + _h = _p->h; \ + _key = _p->key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); + +/* Packed array iterators */ +#define ZEND_PACKED_FOREACH_FROM(_ht, _from) do { \ + HashTable *__ht = (_ht); \ + zend_ulong _idx = (_from); \ + zval *_z = __ht->arPacked + (_from); \ + zval *_end = __ht->arPacked + __ht->nNumUsed; \ + ZEND_ASSERT(HT_IS_PACKED(__ht)); \ + for (;_z != _end; _z++, _idx++) { \ + (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_PACKED_FOREACH(_ht) ZEND_PACKED_FOREACH_FROM(_ht, 0) + +#define ZEND_PACKED_REVERSE_FOREACH(_ht) do { \ + HashTable *__ht = (_ht); \ + zend_ulong _idx = __ht->nNumUsed; \ + zval *_z = __ht->arPacked + _idx; \ + ZEND_ASSERT(HT_IS_PACKED(__ht)); \ + while (_idx > 0) { \ + _z--; \ + _idx--; \ + (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_PACKED_FOREACH_END() \ + } \ + } while (0) + +#define ZEND_PACKED_FOREACH_VAL(ht, _val) \ + ZEND_PACKED_FOREACH(ht); \ + _val = _z; + +#define ZEND_PACKED_REVERSE_FOREACH_VAL(ht, _val) \ + ZEND_PACKED_REVERSE_FOREACH(ht); \ + _val = _z; + +#define ZEND_PACKED_FOREACH_PTR(ht, _ptr) \ + ZEND_PACKED_FOREACH(ht); \ + _ptr = Z_PTR_P(_z); + +#define ZEND_PACKED_REVERSE_FOREACH_PTR(ht, _ptr) \ + ZEND_PACKED_REVERSE_FOREACH(ht); \ + _ptr = Z_PTR_P(_z); + +#define ZEND_PACKED_FOREACH_KEY(ht, _h) \ + ZEND_PACKED_FOREACH(ht); \ + _h = _idx; + +#define ZEND_PACKED_REVERSE_FOREACH_KEY(ht, _h) \ + ZEND_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; + +#define ZEND_PACKED_FOREACH_KEY_VAL(ht, _h, _val) \ + ZEND_PACKED_FOREACH(ht); \ + _h = _idx; \ + _val = _z; + +#define ZEND_PACKED_REVERSE_FOREACH_KEY_VAL(ht, _h, _val) \ + ZEND_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; \ + _val = _z; + +#define ZEND_PACKED_FOREACH_KEY_PTR(ht, _h, _ptr) \ + ZEND_PACKED_FOREACH(ht); \ + _h = _idx; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_PACKED_REVERSE_FOREACH_KEY_PTR(ht, _h, _ptr) \ + ZEND_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; \ + _ptr = Z_PTR_P(_z); + +/* Common hash/packed array iterators */ +#define ZEND_ARRAY_FOREACH_FROM(_ht, indirect, _from) do { \ + HashTable *__ht = (_ht); \ + bool _is_packed = HT_IS_PACKED(__ht); \ + zval *__z; \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + Bucket *_p = NULL; \ + uint32_t _idx = _from; \ + zval *_end; \ + if (_is_packed) { \ + __z = __ht->arPacked + _from; \ + _end = __ht->arPacked + __ht->nNumUsed; \ + } else { \ + __z = &__ht->arData[_from].val; \ + _end = &__ht->arData[__ht->nNumUsed].val; \ + } \ + while (__z != _end) { \ + zval *_z = __z; \ + if (_is_packed) { \ + __z++; \ + __h = _idx; \ + _idx++; \ + } else { \ + _p = (Bucket*)__z; \ + __z = &(_p + 1)->val; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ + } \ + (void) __h; (void) __key; (void) _p; (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_ARRAY_FOREACH(_ht, indirect) ZEND_ARRAY_FOREACH_FROM(_ht, indirect, 0) + +#define ZEND_ARRAY_REVERSE_FOREACH(_ht, indirect) do { \ + HashTable *__ht = (_ht); \ + uint32_t _idx = __ht->nNumUsed; \ + Bucket *_p = NULL; \ + zval *_z; \ + zval *__z = NULL; \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + bool _is_packed = HT_IS_PACKED(__ht); \ + if (_is_packed) { \ + __z = __ht->arPacked + _idx; \ + } else { \ + _p = __ht->arData + _idx; \ + } \ + for (;_idx > 0; _idx--) { \ + if (_is_packed) { \ + __z--; \ + _z = __z; \ + __h = _idx - 1; \ + } else { \ + _p--; \ + _z = &_p->val; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ + } \ + (void) __h; (void) __key; (void) _p; (void) __z; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_ARRAY_FOREACH_END() \ + } \ + } while (0) + +#define _ZEND_ARRAY_FOREACH_VAL(_ht) do { \ + HashTable *__ht = (_ht); \ + zval *_z, *_end; \ + size_t _size; \ + if (HT_IS_PACKED(_ht)) { \ + _z = __ht->arPacked; \ + _end = __ht->arPacked + __ht->nNumUsed; \ + _size = sizeof(zval); \ + } else {\ + _z = &__ht->arData->val; \ + _end = &__ht->arData[__ht->nNumUsed].val; \ + _size = sizeof(Bucket); \ + } \ + for (; _z != _end; _z = (zval*)(((char*)_z) + _size)) { \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define _ZEND_ARRAY_REVERSE_FOREACH_VAL(_ht) do { \ + HashTable *__ht = (_ht); \ + uint32_t _idx = __ht->nNumUsed; \ + zval *_z; \ + size_t _size; \ + if (HT_IS_PACKED(__ht)) { \ + _z = __ht->arPacked + _idx; \ + _size = sizeof(zval); \ + } else { \ + _z = &__ht->arData[_idx].val; \ + _size = sizeof(Bucket); \ + } \ + for (;_idx > 0; _idx--) { \ + _z = (zval*)(((char*)_z) - _size); \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define ZEND_ARRAY_FOREACH_VAL(ht, _val) \ + _ZEND_ARRAY_FOREACH_VAL(ht); \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_VAL(ht, _val) \ + _ZEND_ARRAY_REVERSE_FOREACH_VAL(ht); \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_VAL_IND(ht, _val) \ + ZEND_ARRAY_FOREACH(ht, 1); \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_VAL_IND(ht, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_PTR(ht, _ptr) \ + _ZEND_ARRAY_FOREACH_VAL(ht); \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_REVERSE_FOREACH_PTR(ht, _ptr) \ + _ZEND_ARRAY_REVERSE_FOREACH_VAL(ht, 0); \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_FOREACH_NUM_KEY(ht, _h) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; + +#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY(ht, _h) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _h = __h; + +#define ZEND_ARRAY_FOREACH_STR_KEY(ht, _key) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _key = __key; + +#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY(ht, _key) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _key = __key; + +#define ZEND_ARRAY_FOREACH_KEY(ht, _h, _key) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; \ + _key = __key; + +#define ZEND_ARRAY_REVERSE_FOREACH_KEY(ht, _h, _key) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _h = __h; \ + _key = __key; + +#define ZEND_ARRAY_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _h = __h; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, _key, _val) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ + ZEND_ARRAY_FOREACH_FROM(ht, 0, _from); \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_KEY_VAL(ht, _h, _key, _val) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _h = __h; \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ + ZEND_ARRAY_FOREACH(ht, 1); \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ + ZEND_ARRAY_FOREACH(ht, 1); \ + _h = __h; \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ + _h = __h; \ + _key = __key; \ + _val = _z; + +#define ZEND_ARRAY_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _h = __h; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _key = __key; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ + _key = __key; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ + ZEND_ARRAY_FOREACH(ht, 0); \ + _h = __h; \ + _key = __key; \ + _ptr = Z_PTR_P(_z); + +#define ZEND_ARRAY_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ + ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ _h = __h; \ _key = __key; \ _ptr = Z_PTR_P(_z); @@ -1309,16 +1562,24 @@ static zend_always_inline bool zend_array_is_list(zend_array *array) } /* Packed arrays are lists */ - if (HT_IS_PACKED(array) && HT_IS_WITHOUT_HOLES(array)) { - return 1; - } - - /* Check if the list could theoretically be repacked */ - ZEND_HASH_FOREACH_KEY(array, num_idx, str_idx) { - if (str_idx != NULL || num_idx != expected_idx++) { - return 0; + if (HT_IS_PACKED(array)) { + if (HT_IS_WITHOUT_HOLES(array)) { + return 1; } - } ZEND_HASH_FOREACH_END(); + /* Check if the list could theoretically be repacked */ + ZEND_PACKED_FOREACH_KEY(array, num_idx) { + if (num_idx != expected_idx++) { + return 0; + } + } ZEND_PACKED_FOREACH_END(); + } else { + /* Check if the list could theoretically be repacked */ + ZEND_HASH_FOREACH_KEY(array, num_idx, str_idx) { + if (str_idx != NULL || num_idx != expected_idx++) { + return 0; + } + } ZEND_HASH_FOREACH_END(); + } return 1; } diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 0e8e1aa4627a7..d9295bab6832e 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -2530,7 +2530,7 @@ static void report_variance_errors(zend_class_entry *ce) { obligations = zend_hash_index_find_ptr(all_obligations, num_key); ZEND_ASSERT(obligations != NULL); - ZEND_HASH_FOREACH_PTR(obligations, obligation) { + ZEND_PACKED_FOREACH_PTR(obligations, obligation) { if (obligation->type == OBLIGATION_COMPATIBILITY) { /* Just used to populate the delayed_autoloads table, * which will be used when printing the "unresolved" error. */ @@ -2546,7 +2546,7 @@ static void report_variance_errors(zend_class_entry *ce) { } else { zend_error_noreturn(E_CORE_ERROR, "Bug #78647"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); /* Only warnings were thrown above -- that means that there are incompatibilities, but only * ones that we permit. Mark all classes with open obligations as fully linked. */ diff --git a/Zend/zend_list.c b/Zend/zend_list.c index d667a21c80a9d..a7b992b567090 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -285,11 +285,11 @@ ZEND_API int zend_fetch_list_dtor_id(const char *type_name) { zend_rsrc_list_dtors_entry *lde; - ZEND_HASH_FOREACH_PTR(&list_destructors, lde) { + ZEND_ARRAY_FOREACH_PTR(&list_destructors, lde) { if (lde->type_name && (strcmp(type_name, lde->type_name) == 0)) { return lde->resource_id; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return 0; } diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index ad41b9f699d01..aa77fb4798f81 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -1116,9 +1116,9 @@ ZEND_API void pass_two(zend_op_array *op_array) /* absolute indexes to relative offsets */ HashTable *jumptable = Z_ARRVAL_P(CT_CONSTANT(opline->op2)); zval *zv; - ZEND_HASH_FOREACH_VAL(jumptable, zv) { + ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, Z_LVAL_P(zv)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value); break; diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 405e649aa4b13..5be3d3a258b86 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5032,7 +5032,7 @@ ZEND_VM_C_LABEL(send_again): bool separate = 0; /* check if any of arguments are going to be passed by reference */ - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; tmp_arg_num = zend_get_arg_offset_by_name( @@ -5043,14 +5043,14 @@ ZEND_VM_C_LABEL(send_again): break; } tmp_arg_num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (separate) { SEPARATE_ARRAY(args); ht = Z_ARRVAL_P(args); } } - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -5088,7 +5088,7 @@ ZEND_VM_C_LABEL(send_again): } arg_num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(args) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(args); @@ -5277,7 +5277,7 @@ ZEND_VM_C_LABEL(send_array): zend_vm_stack_extend_call_frame(&EX(call), 0, len); arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); - ZEND_HASH_FOREACH_VAL(ht, arg) { + ZEND_ARRAY_FOREACH_VAL(ht, arg) { bool must_wrap = 0; if (skip > 0) { skip--; @@ -5309,7 +5309,7 @@ ZEND_VM_C_LABEL(send_array): ZEND_CALL_NUM_ARGS(EX(call))++; arg_num++; param++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } FREE_OP2(); } else { @@ -5319,7 +5319,7 @@ ZEND_VM_C_LABEL(send_array): arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); have_named_params = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (name) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -5364,7 +5364,7 @@ ZEND_VM_C_LABEL(send_array): arg_num++; param++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } FREE_OP1(); @@ -6008,7 +6008,7 @@ ZEND_VM_C_LABEL(add_unpack_again): zval *val; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -6022,7 +6022,7 @@ ZEND_VM_C_LABEL(add_unpack_again): break; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(op1) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(op1); zend_object_iterator *iter; diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index e26ba090db2dd..10dc9e43f19a2 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2134,7 +2134,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ bool separate = 0; /* check if any of arguments are going to be passed by reference */ - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; tmp_arg_num = zend_get_arg_offset_by_name( @@ -2145,14 +2145,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ break; } tmp_arg_num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (separate) { SEPARATE_ARRAY(args); ht = Z_ARRVAL_P(args); } } - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -2190,7 +2190,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ } arg_num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(args) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(args); @@ -2379,7 +2379,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O zend_vm_stack_extend_call_frame(&EX(call), 0, len); arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); - ZEND_HASH_FOREACH_VAL(ht, arg) { + ZEND_ARRAY_FOREACH_VAL(ht, arg) { bool must_wrap = 0; if (skip > 0) { skip--; @@ -2411,7 +2411,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O ZEND_CALL_NUM_ARGS(EX(call))++; arg_num++; param++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } FREE_OP(opline->op2_type, opline->op2.var); } else { @@ -2421,7 +2421,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); have_named_params = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { if (name) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -2466,7 +2466,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O arg_num++; param++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } FREE_OP(opline->op1_type, opline->op1.var); @@ -2543,7 +2543,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER( zval *val; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -2557,7 +2557,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER( break; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(op1) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(op1); zend_object_iterator *iter; diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 3292458d63554..eb5878960946e 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2017,7 +2017,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo } #endif - ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) { + ZEND_ARRAY_FOREACH_KEY_VAL(postfields, num_key, string_key, current) { zend_string *postval, *tmp_postval; /* Pretend we have a string_key here */ if (!string_key) { @@ -2212,7 +2212,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo #endif zend_tmp_string_release(tmp_postval); zend_string_release_ex(string_key, 0); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); SAVE_CURL_ERROR(ch, error); if (error != CURLE_OK) { @@ -2753,7 +2753,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue } ph = Z_ARRVAL_P(zvalue); - ZEND_HASH_FOREACH_VAL(ph, current) { + ZEND_ARRAY_FOREACH_VAL(ph, current) { ZVAL_DEREF(current); val = zval_get_tmp_string(current, &tmp_val); slist = curl_slist_append(slist, ZSTR_VAL(val)); @@ -2762,7 +2762,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue php_error_docref(NULL, E_WARNING, "Could not build curl_slist"); return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (slist) { if ((*ch->clone) == 1) { @@ -3015,7 +3015,7 @@ PHP_FUNCTION(curl_setopt_array) ch = Z_CURL_P(zid); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) { if (string_key) { zend_argument_value_error(2, "contains an invalid cURL option"); RETURN_THROWS(); @@ -3025,7 +3025,7 @@ PHP_FUNCTION(curl_setopt_array) if (_php_curl_setopt(ch, (zend_long) option, entry, 1) == FAILURE) { RETURN_FALSE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); RETURN_TRUE; } diff --git a/ext/dom/node.c b/ext/dom/node.c index 893670807bca4..e4421ddfefe1e 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -1592,7 +1592,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ ctxp->node = nodep; tmp = zend_hash_str_find(ht, "namespaces", sizeof("namespaces")-1); - if (tmp && Z_TYPE_P(tmp) == IS_ARRAY) { + if (tmp && Z_TYPE_P(tmp) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(tmp))) { zval *tmpns; zend_string *prefix; @@ -1626,11 +1626,11 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ inclusive_ns_prefixes = safe_emalloc(zend_hash_num_elements(Z_ARRVAL_P(ns_prefixes)) + 1, sizeof(xmlChar *), 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(ns_prefixes), tmpns) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(ns_prefixes), tmpns) { if (Z_TYPE_P(tmpns) == IS_STRING) { inclusive_ns_prefixes[nscount++] = (xmlChar *) Z_STRVAL_P(tmpns); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); inclusive_ns_prefixes[nscount] = NULL; } else { php_error_docref(NULL, E_NOTICE, diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index 876d8b00dae0e..8d30edabf2876 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -500,12 +500,12 @@ PHP_METHOD(DOMXPath, registerPhpFunctions) ZEND_PARSE_PARAMETERS_END(); if (ht) { - ZEND_HASH_FOREACH_VAL(ht, entry) { + ZEND_ARRAY_FOREACH_VAL(ht, entry) { zend_string *str = zval_get_string(entry); ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_string_release_ex(str, 0); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); intern->registerPhpFunctions = 2; } else if (name) { ZVAL_LONG(&new_string, 1); diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 5ab672622bec2..f70723ff59d68 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -811,9 +811,9 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */ zend_ffi_type *arg_type; size_t arg_size = 0; - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return arg_size; } /* }}} */ @@ -885,11 +885,11 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v int n = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(callback_data->type->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(callback_data->type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); zend_ffi_cdata_to_zval(NULL, args[n], arg_type, BP_VAR_R, &fci.params[n], (zend_ffi_flags)(arg_type->attr & ZEND_FFI_ATTR_CONST), 0, 0); n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ZVAL_UNDEF(&retval); @@ -959,7 +959,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ * int n = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); callback_data->arg_types[n] = zend_ffi_get_type(arg_type); if (!callback_data->arg_types[n]) { @@ -969,7 +969,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ * return NULL; } n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } callback_data->ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); if (!callback_data->ret_type) { @@ -2652,7 +2652,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2661,7 +2661,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ goto exit; } n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } for (; n < EX_NUM_ARGS(); n++) { arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); @@ -2697,7 +2697,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2706,7 +2706,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ goto exit; } n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); @@ -3004,7 +3004,7 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ if (HT_IS_PACKED(type->func.args)) { zval *zv = type->func.args->arPacked; - ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(old->func.args, arg_type) { while (Z_TYPE_P(zv) == IS_UNDEF) { zv++; } @@ -3012,11 +3012,11 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ return 0; } zv++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { Bucket *b = type->func.args->arData; - ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(old->func.args, arg_type) { while (Z_TYPE(b->val) == IS_UNDEF) { b++; } @@ -3024,7 +3024,7 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ return 0; } b++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } break; @@ -3084,11 +3084,11 @@ static bool zend_ffi_subst_old_type(zend_ffi_type **dcl, zend_ffi_type *old, zen if (dcl_type->func.args) { zval *zv; - ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_ARRAY_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_old_type((zend_ffi_type**)&Z_PTR_P(zv), old, type)) { return 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } break; case ZEND_FFI_TYPE_STRUCT: @@ -3588,11 +3588,11 @@ static bool zend_ffi_subst_type(zend_ffi_type **dcl, zend_ffi_type *type) /* {{{ if (dcl_type->func.args) { zval *zv; - ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_ARRAY_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_type((zend_ffi_type**)&Z_PTR_P(zv), type)) { return 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } break; case ZEND_FFI_TYPE_STRUCT: @@ -4091,7 +4091,7 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ } } - ZEND_HASH_REVERSE_FOREACH_VAL(dims, val) { + ZEND_ARRAY_REVERSE_FOREACH_VAL(dims, val) { zend_long n = zval_get_long(val); zend_ffi_type *new_type; @@ -4118,7 +4118,7 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ } type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ctype = (zend_ffi_ctype*)zend_ffi_ctype_new(zend_ffi_ctype_ce); ctype->type = type; @@ -6280,7 +6280,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n int no_args = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(args, arg_type) { + ZEND_ARRAY_FOREACH_PTR(args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); if (arg_type->kind == ZEND_FFI_TYPE_VOID) { if (zend_hash_num_elements(args) != 1) { @@ -6294,7 +6294,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n no_args = 1; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (no_args) { zend_hash_destroy(args); pefree(args, FFI_G(persistent)); @@ -6307,7 +6307,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ulong i; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_NUM_KEY_PTR(args, i, arg_type) { + ZEND_ARRAY_FOREACH_NUM_KEY_PTR(args, i, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); # ifdef _WIN64 if (i >= 4 && i <= 5 && (arg_type->kind == ZEND_FFI_TYPE_FLOAT || arg_type->kind == ZEND_FFI_TYPE_DOUBLE)) { @@ -6321,7 +6321,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ffi_parser_error("Type float/double is not allowed at position " ZEND_ULONG_FMT " with __vectorcall at line %d", i+1, FFI_G(line)); return; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } #endif diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 836ee8345affb..39ad1fd03e758 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -446,7 +446,7 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f } Z_PROTECT_RECURSION_P(value); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(value), element) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(value), element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) == IS_ARRAY) { SEPARATE_ARRAY(element); @@ -454,7 +454,7 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f } else { php_zval_filter(element, filter, flags, options, charset, copy); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); Z_UNPROTECT_RECURSION_P(value); } else { php_zval_filter(value, filter, flags, options, charset, copy); @@ -616,7 +616,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op } else { array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) { if (arg_key == NULL) { zend_argument_type_error(2, "must contain only string keys"); RETURN_THROWS(); @@ -640,7 +640,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op ); zend_hash_update(Z_ARRVAL_P(return_value), arg_key, &nval); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } /* }}} */ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 880d6dddc7d70..3623ce88cd09a 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -801,9 +801,9 @@ PHP_FUNCTION(imagesetstyle) /* copy the style values in the stylearr */ stylearr = safe_emalloc(sizeof(int), num_styles, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(styles), item) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(styles), item) { stylearr[index++] = zval_get_long(item); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); gdImageSetStyle(im, stylearr, index); @@ -3233,15 +3233,17 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode) zend_string *key; /* walk the assoc array */ - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(EXT), key, item) { - if (key == NULL) { - continue; - } - if (zend_string_equals_literal(key, "linespacing")) { - strex.flags |= gdFTEX_LINESPACE; - strex.linespacing = zval_get_double(item); - } - } ZEND_HASH_FOREACH_END(); + if (!HT_IS_PACKED(Z_ARRVAL_P(EXT))) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(EXT), key, item) { + if (key == NULL) { + continue; + } + if (zend_string_equals_literal(key, "linespacing")) { + strex.flags |= gdFTEX_LINESPACE; + strex.linespacing = zval_get_double(item); + } + } ZEND_HASH_FOREACH_END(); + } } #ifdef VIRTUAL_DIR @@ -3487,9 +3489,9 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS) colors = emalloc(num_colors * sizeof(int)); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) { *(colors + i++) = (int) zval_get_long(color); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); RETVAL_BOOL(gdImageScatterColor(im, (int)scatter_sub, (int)scatter_plus, colors, num_colors)); diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index a543c1d78a21b..62103ab1addd1 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -3139,7 +3139,7 @@ PHP_FUNCTION(imap_mail_compose) if (Z_TYPE_P(pvalue) == IS_ARRAY) { custom_headers_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pvalue), env_data) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pvalue), env_data) { custom_headers_param = mail_newbody_parameter(); convert_to_string(env_data); CHECK_HEADER_INJECTION(Z_STR_P(env_data), 0, "custom_headers"); @@ -3148,12 +3148,12 @@ PHP_FUNCTION(imap_mail_compose) memcpy(custom_headers_param->value, Z_STRVAL_P(env_data), Z_STRLEN_P(env_data) + 1); custom_headers_param->next = tmp_param; tmp_param = custom_headers_param; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } first = 1; - ZEND_HASH_FOREACH_VAL(body, data) { + ZEND_ARRAY_FOREACH_VAL(body, data) { if (first) { first = 0; @@ -3193,7 +3193,7 @@ PHP_FUNCTION(imap_mail_compose) bod->parameter = tmp_param; } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "type.parameters", sizeof("type.parameters") - 1)) != NULL) { - if(Z_TYPE_P(pvalue) == IS_ARRAY) { + if(Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { @@ -3233,7 +3233,7 @@ PHP_FUNCTION(imap_mail_compose) memcpy(bod->disposition.type, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "disposition", sizeof("disposition") - 1)) != NULL) { - if (Z_TYPE_P(pvalue) == IS_ARRAY) { + if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { @@ -3315,7 +3315,7 @@ PHP_FUNCTION(imap_mail_compose) bod->parameter = tmp_param; } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "type.parameters", sizeof("type.parameters") - 1)) != NULL) { - if (Z_TYPE_P(pvalue) == IS_ARRAY) { + if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { @@ -3355,7 +3355,7 @@ PHP_FUNCTION(imap_mail_compose) memcpy(bod->disposition.type, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "disposition", sizeof("disposition") - 1)) != NULL) { - if (Z_TYPE_P(pvalue) == IS_ARRAY) { + if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { @@ -3399,7 +3399,7 @@ PHP_FUNCTION(imap_mail_compose) bod->md5 = cpystr(Z_STRVAL_P(pvalue)); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (bod && bod->type == TYPEMULTIPART && (!bod->nested.part || !bod->nested.part->next)) { php_error_docref(NULL, E_WARNING, "Cannot generate multipart e-mail without components."); diff --git a/ext/intl/collator/collator_convert.c b/ext/intl/collator/collator_convert.c index 55f2995895b88..a74ed27871a62 100644 --- a/ext/intl/collator/collator_convert.c +++ b/ext/intl/collator/collator_convert.c @@ -118,13 +118,13 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* stat zval *hashData; zend_string *hashKey; - ZEND_HASH_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { + ZEND_ARRAY_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE. */ collator_convert_hash_item_from_utf8_to_utf16( hash, hashData, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) return; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -137,14 +137,14 @@ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* stat zend_string *hashKey; zval *hashData; - ZEND_HASH_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { + ZEND_ARRAY_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { /* Convert current hash item from UTF-16LE to UTF-8. */ collator_convert_hash_item_from_utf16_to_utf8( hash, hashData, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) { return; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index 0634e68fc7a36..2dcc572243c1f 100644 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -384,7 +384,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) utf16_buf = eumalloc( utf16_buf_size ); /* Iterate through input hash and create a sort key for each value. */ - ZEND_HASH_FOREACH_VAL(hash, hashData) { + ZEND_ARRAY_FOREACH_VAL(hash, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf. */ utf16_len = utf16_buf_size; @@ -457,7 +457,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) sortKeyBufOffset += sortKeyLen; ++sortKeyCount; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* update ptrs to point to valid keys. */ for( j = 0; j < sortKeyCount; j++ ) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index c3d54e8a84a4d..7557dea541fd7 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -190,9 +190,9 @@ static void php_converter_append_toUnicode_target(zval *val, UConverterToUnicode HashTable *ht = Z_ARRVAL_P(val); zval *tmpzval; - ZEND_HASH_FOREACH_VAL(ht, tmpzval) { + ZEND_ARRAY_FOREACH_VAL(ht, tmpzval) { php_converter_append_toUnicode_target(tmpzval, args, objval); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return; } default: @@ -274,9 +274,9 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni { HashTable *ht = Z_ARRVAL_P(val); zval *tmpzval; - ZEND_HASH_FOREACH_VAL(ht, tmpzval) { + ZEND_ARRAY_FOREACH_VAL(ht, tmpzval) { php_converter_append_fromUnicode_target(tmpzval, args, objval); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return; } default: diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index 6afc9e6dca503..34f7c7bd4db0c 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -99,7 +99,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) uint32_t idx = 0; zval *z; - ZEND_HASH_FOREACH_VAL(ht, z) { + ZEND_ARRAY_FOREACH_VAL(ht, z) { if (!valid_format(z)) { if (idx == 0) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -120,7 +120,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) timeStyle = (DateFormat::EStyle)Z_LVAL_P(z); } idx++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ZEND_ASSERT(idx == 2 && "We checked that there are two elements above"); } else if (Z_TYPE_P(format) == IS_LONG) { if (!valid_format(format)) { diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index 1782dd6ecb43f..49a6ee04b7b7b 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -774,7 +774,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, HashTable *arr = Z_ARRVAL_P(ele_value); zval *data; - ZEND_HASH_FOREACH_VAL(arr, data) { + ZEND_ARRAY_FOREACH_VAL(arr, data) { if(Z_TYPE_P(data) != IS_STRING) { return FAILURE; } @@ -783,7 +783,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, } smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); smart_str_appendl(loc_name, Z_STRVAL_P(data) , Z_STRLEN_P(data)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } else { return FAILURE; @@ -1342,7 +1342,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr, zend_string* return_value = NULL; char **cur_arr = ecalloc(zend_hash_num_elements(hash_arr)*2, sizeof(char *)); - ZEND_HASH_FOREACH_VAL(hash_arr, ele_value) { + ZEND_ARRAY_FOREACH_VAL(hash_arr, ele_value) { /* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */ if(Z_TYPE_P(ele_value)!= IS_STRING) { /* element value is not a string */ @@ -1357,7 +1357,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr, } cur_arr[cur_arr_len*2+1] = Z_STRVAL_P(ele_value); cur_arr_len++ ; - } ZEND_HASH_FOREACH_END(); /* end of for */ + } ZEND_ARRAY_FOREACH_END(); /* end of for */ /* Canonicalize array elements */ if(canonicalize) { diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index 5ca44b8ab346b..6ea5333849e52 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -391,7 +391,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, zend_string *str_index; zend_ulong num_index; - ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { + ZEND_ARRAY_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; UnicodeString& key = farg_names[argNum]; Formattable::Type argType = Formattable::kObject, //unknown @@ -586,7 +586,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, } } argNum++; - } ZEND_HASH_FOREACH_END(); // visiting each argument + } ZEND_ARRAY_FOREACH_END(); // visiting each argument if (U_FAILURE(err.code)) { return; diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index b0f703041b068..75429400f09ce 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -223,7 +223,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso zval *data; zend_ulong index; - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, data) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(myht, index, key, data) { if (r == PHP_JSON_OUTPUT_ARRAY) { if (need_comma) { smart_str_appendc(buf, ','); @@ -281,7 +281,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso zend_release_properties(prop_ht); return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } PHP_JSON_HASH_UNPROTECT_RECURSION(myht); diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 6e0f28f68080e..cc1536c12830f 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -757,7 +757,7 @@ static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array, uint32 ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0); *ctrls = NULL; ctrlp = ctrls; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) { if (Z_TYPE_P(ctrlarray) != IS_ARRAY) { zend_argument_type_error(arg_num, "must contain only arrays, where each array is a control"); error = 1; @@ -772,7 +772,7 @@ static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array, uint32 } *ctrlp = NULL; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (error) { ctrlp = ctrls; diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 0f63b90a947e1..39938a4be5a25 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -370,7 +370,7 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) if (Z_TYPE(s->wrapperdata) == IS_ARRAY) { zval *header; - ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL(s->wrapperdata), header) { + ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL(s->wrapperdata), header) { const char buf[] = "Content-Type:"; if (Z_TYPE_P(header) == IS_STRING && !zend_binary_strncasecmp(Z_STRVAL_P(header), Z_STRLEN_P(header), buf, sizeof(buf)-1, sizeof(buf)-1)) { @@ -407,7 +407,7 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) efree(needle); break; /* found content-type */ } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index a7dfcbe7d4c82..7cc2f1215166a 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -350,7 +350,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi bool included_auto = 0; size_t n = 0; zval *hash_entry; - ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) { + ZEND_ARRAY_FOREACH_VAL(target_hash, hash_entry) { zend_string *encoding_str = zval_try_get_string(hash_entry); if (UNEXPECTED(!encoding_str)) { efree(ZEND_VOIDP(list)); @@ -382,7 +382,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi } } zend_string_release(encoding_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *return_list = list; *return_size = n; return SUCCESS; @@ -2429,7 +2429,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons } GC_TRY_PROTECT_RECURSION(input); output = zend_new_array(zend_hash_num_elements(input)); - ZEND_HASH_FOREACH_KEY_VAL(input, idx, key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(input, idx, key, entry) { /* convert key */ if (key) { ckey = php_mb_convert_encoding( @@ -2482,7 +2482,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons } else { zend_hash_index_add(output, idx, &entry_tmp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(input); return output; @@ -3009,7 +3009,7 @@ static int mb_recursive_encoder_detector_feed(mbfl_encoding_detector *identd, zv ht = HASH_OF(var); if (ht != NULL) { - ZEND_HASH_FOREACH_VAL_IND(ht, entry) { + ZEND_ARRAY_FOREACH_VAL_IND(ht, entry) { if (mb_recursive_encoder_detector_feed(identd, entry, recursion_error)) { if (Z_REFCOUNTED_P(var)) { Z_UNPROTECT_RECURSION_P(var); @@ -3021,7 +3021,7 @@ static int mb_recursive_encoder_detector_feed(mbfl_encoding_detector *identd, zv } return 0; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (Z_REFCOUNTED_P(var)) { @@ -3062,14 +3062,14 @@ static int mb_recursive_convert_variable(mbfl_buffer_converter *convd, zval *var ht = HASH_OF(var); if (ht != NULL) { - ZEND_HASH_FOREACH_VAL_IND(ht, entry) { + ZEND_ARRAY_FOREACH_VAL_IND(ht, entry) { if (mb_recursive_convert_variable(convd, entry)) { if (Z_REFCOUNTED_P(var)) { Z_UNPROTECT_RECURSION_P(var); } return 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (Z_REFCOUNTED_P(var)) { @@ -3209,9 +3209,9 @@ static int *make_conversion_map(HashTable *target_hash, int *convmap_size) int *convmap = (int *)safe_emalloc(n_elems, sizeof(int), 0); int *mapelm = convmap; - ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) { + ZEND_ARRAY_FOREACH_VAL(target_hash, hash_entry) { *mapelm++ = zval_get_long(hash_entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *convmap_size = n_elems / 4; return convmap; @@ -3924,7 +3924,7 @@ static int php_mb_check_encoding_recursive(HashTable *vars, const mbfl_encoding return 0; } GC_TRY_PROTECT_RECURSION(vars); - ZEND_HASH_FOREACH_KEY_VAL(vars, idx, key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(vars, idx, key, entry) { ZVAL_DEREF(entry); if (key) { if (!php_mb_check_encoding(ZSTR_VAL(key), ZSTR_LEN(key), encoding)) { @@ -3956,7 +3956,7 @@ static int php_mb_check_encoding_recursive(HashTable *vars, const mbfl_encoding valid = 0; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(vars); return valid; } diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 3782820e77d62..0ed4d51fc02d0 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -398,7 +398,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp) retval = zend_new_array(zend_hash_num_elements(props) + 1); - ZEND_HASH_FOREACH_PTR(props, entry) { + ZEND_ARRAY_FOREACH_PTR(props, entry) { zval rv; zval *value; @@ -406,7 +406,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp) if (value != &EG(uninitialized_zval)) { zend_hash_add(retval, entry->name, value); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *is_temp = 1; return retval; diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 96dee255b2b96..c73059eeec7d0 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -846,11 +846,11 @@ PHP_FUNCTION(mysqli_stmt_execute) ZEND_ASSERT(params); index = 0; - ZEND_HASH_FOREACH_VAL(input_params, tmp) { + ZEND_ARRAY_FOREACH_VAL(input_params, tmp) { ZVAL_COPY_VALUE(¶ms[index].zv, tmp); params[index].type = MYSQL_TYPE_VAR_STRING; index++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (mysqlnd_stmt_bind_param(stmt->stmt, params)) { MYSQLI_REPORT_STMT_ERROR(stmt->stmt); diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index b4f80f6df38c6..961ac290cf5e8 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -772,7 +772,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar return SUCCESS; } *out_array = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(in_array)) + 1, sizeof(MYSQLND *)); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_array), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(in_array), elem) { i++; if (Z_TYPE_P(elem) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) { @@ -793,7 +793,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar } (*out_array)[current++] = mysql->mysql; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } /* }}} */ @@ -808,7 +808,7 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a array_init_size(&dest_array, zend_hash_num_elements(Z_ARRVAL_P(out_array))); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(out_array), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(out_array), elem) { if (Z_TYPE_P(elem) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) { continue; @@ -831,7 +831,7 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a p++; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* destroy old array and add new one */ zval_ptr_dtor(out_array); @@ -850,7 +850,7 @@ static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, z array_init(&proxy); if (in_array) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_zval_array), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(in_zval_array), elem) { MY_MYSQL *mysql; mysqli_object *intern = Z_MYSQLI_P(elem); mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)intern->ptr)->ptr; @@ -862,7 +862,7 @@ static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, z ret++; p++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* destroy old array and add new one */ diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index a99785985ffc2..810f8717e71d3 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -151,14 +151,14 @@ static void _close_odbc_conn(zend_resource *rsrc) odbc_connection *conn = (odbc_connection *)rsrc->ptr; - ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* If aborted via timer expiration, don't try to call any unixODBC function */ if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) { @@ -178,14 +178,14 @@ static void _close_odbc_pconn(zend_resource *rsrc) odbc_result *res; odbc_connection *conn = (odbc_connection *)rsrc->ptr; - ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* If aborted via timer expiration, don't try to call any unixODBC function */ if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) { @@ -822,14 +822,14 @@ PHP_FUNCTION(odbc_close_all) } /* Loop through list and close all statements */ - ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { zend_list_close(p); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Second loop through list, now close all connections */ - ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr) { if (p->type == le_conn){ zend_list_close(p); @@ -840,7 +840,7 @@ PHP_FUNCTION(odbc_close_all) (apply_func_arg_t) _close_pconn_with_res, (void *)p); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -1014,7 +1014,7 @@ PHP_FUNCTION(odbc_execute) } i = 1; - ZEND_HASH_FOREACH_VAL(pv_param_ht, tmp) { + ZEND_ARRAY_FOREACH_VAL(pv_param_ht, tmp) { unsigned char otype = Z_TYPE_P(tmp); zend_string *tmpstr = zval_try_get_string(tmp); if (!tmpstr) { @@ -1084,7 +1084,7 @@ PHP_FUNCTION(odbc_execute) RETURN_FALSE; } if (++i > result->numparams) break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* Close cursor, needed for doing multiple selects */ rc = SQLFreeStmt(result->stmt, SQL_CLOSE); @@ -2351,14 +2351,14 @@ PHP_FUNCTION(odbc_close) is_pconn = 1; } - ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_list_close(Z_RES_P(pv_conn)); diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index a5f69091b2abb..38fecae79b0dd 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -228,9 +228,9 @@ static void zend_persist_zval(zval *z) if (HT_IS_PACKED(ht)) { zval *zv; - ZEND_HASH_FOREACH_VAL(ht, zv) { + ZEND_PACKED_FOREACH_VAL(ht, zv) { zend_persist_zval(zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } else { Bucket *p; @@ -285,7 +285,7 @@ static HashTable *zend_persist_attributes(HashTable *attributes) zend_hash_persist(attributes); - ZEND_HASH_FOREACH_VAL(attributes, v) { + ZEND_PACKED_FOREACH_VAL(attributes, v) { zend_attribute *attr = Z_PTR_P(v); zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc)); @@ -300,7 +300,7 @@ static HashTable *zend_persist_attributes(HashTable *attributes) } ZVAL_PTR(v, copy); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable)); GC_SET_REFCOUNT(ptr, 2); @@ -344,9 +344,9 @@ static HashTable *zend_persist_backed_enum_table(HashTable *backed_enum_table) if (HT_IS_PACKED(backed_enum_table)) { zval *zv; - ZEND_HASH_FOREACH_VAL(backed_enum_table, zv) { + ZEND_PACKED_FOREACH_VAL(backed_enum_table, zv) { zend_persist_zval(zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } else { Bucket *p; diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index ced90fa2f6719..db010cef3ed14 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -121,9 +121,9 @@ static void zend_persist_zval_calc(zval *z) if (HT_IS_PACKED(ht)) { zval *zv; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(z), zv) { + ZEND_PACKED_FOREACH_VAL(Z_ARRVAL_P(z), zv) { zend_persist_zval_calc(zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } else { Bucket *p; @@ -164,7 +164,7 @@ static void zend_persist_attributes_calc(HashTable *attributes) ADD_SIZE(sizeof(HashTable)); zend_hash_persist_calc(attributes); - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_PACKED_FOREACH_PTR(attributes, attr) { ADD_SIZE(ZEND_ATTRIBUTE_SIZE(attr->argc)); ADD_INTERNED_STRING(attr->name); ADD_INTERNED_STRING(attr->lcname); @@ -175,7 +175,7 @@ static void zend_persist_attributes_calc(HashTable *attributes) } zend_persist_zval_calc(&attr->args[i].value); } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } } @@ -551,9 +551,9 @@ void zend_persist_class_entry_calc(zend_class_entry *ce) if (HT_IS_PACKED(ce->backed_enum_table)) { zval *zv; - ZEND_HASH_FOREACH_VAL(ce->backed_enum_table, zv) { + ZEND_PACKED_FOREACH_VAL(ce->backed_enum_table, zv) { zend_persist_zval_calc(zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } else { Bucket *p; diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 506074172a3b3..9f67744e80b9d 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -2374,7 +2374,7 @@ static X509_STORE *php_openssl_setup_verify(zval *calist) } if (calist && (Z_TYPE_P(calist) == IS_ARRAY)) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(calist), item) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(calist), item) { zend_string *str = zval_try_get_string(item); if (UNEXPECTED(!str)) { return NULL; @@ -2406,7 +2406,7 @@ static X509_STORE *php_openssl_setup_verify(zval *calist) dir_lookup = NULL; } zend_string_release(str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); @@ -2484,7 +2484,7 @@ static STACK_OF(X509) * php_array_to_X509_sk(zval * zcerts) /* {{{ */ /* get certs */ if (Z_TYPE_P(zcerts) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zcerts), zcertval) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zcerts), zcertval) { cert = php_openssl_x509_from_zval(zcertval, &free_cert); if (cert == NULL) { // TODO Add Warning? @@ -2501,7 +2501,7 @@ static STACK_OF(X509) * php_array_to_X509_sk(zval * zcerts) /* {{{ */ } sk_X509_push(sk, cert); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { /* a single certificate */ cert = php_openssl_x509_from_zval(zcerts, &free_cert); @@ -2859,7 +2859,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z subj = X509_REQ_get_subject_name(csr); /* apply values from the dn hash */ - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(dn), strindex, item) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(dn), strindex, item) { if (strindex) { int nid = OBJ_txt2nid(ZSTR_VAL(strindex)); if (nid != NID_undef) { @@ -2884,7 +2884,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z php_error_docref(NULL, E_WARNING, "dn: %s is not a recognized name", ZSTR_VAL(strindex)); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Finally apply defaults from config file */ for(i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { @@ -2936,7 +2936,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z } } if (attribs) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(attribs), strindex, item) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(attribs), strindex, item) { int nid; if (NULL == strindex) { @@ -2960,7 +2960,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z } else { php_error_docref(NULL, E_WARNING, "dn: %s is not a recognized name", ZSTR_VAL(strindex)); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ @@ -5346,7 +5346,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) /* get certs */ if (Z_TYPE_P(zrecipcerts) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { bool free_cert; cert = php_openssl_x509_from_zval(zcertval, &free_cert); @@ -5365,7 +5365,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) } } sk_X509_push(recipcerts, cert); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { /* a single certificate */ bool free_cert; @@ -5405,7 +5405,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) /* tack on extra headers */ if (zheaders) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { zend_string *str = zval_try_get_string(zcertval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -5416,7 +5416,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) BIO_printf(outfile, "%s\n", ZSTR_VAL(str)); } zend_string_release(str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } (void)BIO_reset(infile); @@ -5626,7 +5626,7 @@ PHP_FUNCTION(openssl_pkcs7_sign) if (zheaders) { int ret; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { zend_string *str = zval_try_get_string(hval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -5640,7 +5640,7 @@ PHP_FUNCTION(openssl_pkcs7_sign) if (ret < 0) { php_openssl_store_errors(); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* write the signed data */ if (!SMIME_write_PKCS7(outfile, p7, infile, (int)flags)) { @@ -5976,7 +5976,7 @@ PHP_FUNCTION(openssl_cms_encrypt) /* get certs */ if (Z_TYPE_P(zrecipcerts) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { bool free_cert; cert = php_openssl_x509_from_zval(zcertval, &free_cert); @@ -5994,7 +5994,7 @@ PHP_FUNCTION(openssl_cms_encrypt) } } sk_X509_push(recipcerts, cert); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { /* a single certificate */ bool free_cert; @@ -6037,7 +6037,7 @@ PHP_FUNCTION(openssl_cms_encrypt) /* tack on extra headers */ if (zheaders && encoding == ENCODING_SMIME) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { zend_string *str = zval_try_get_string(zcertval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -6048,7 +6048,7 @@ PHP_FUNCTION(openssl_cms_encrypt) BIO_printf(outfile, "%s\n", ZSTR_VAL(str)); } zend_string_release(str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } (void)BIO_reset(infile); @@ -6317,7 +6317,7 @@ PHP_FUNCTION(openssl_cms_sign) if (zheaders && encoding == ENCODING_SMIME) { int ret; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { zend_string *str = zval_try_get_string(hval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -6331,7 +6331,7 @@ PHP_FUNCTION(openssl_cms_sign) if (ret < 0) { php_openssl_store_errors(); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* writing the signed data depends on the encoding */ switch (encoding) { @@ -6885,7 +6885,7 @@ PHP_FUNCTION(openssl_seal) /* get the public keys we are using to seal this data */ i = 0; - ZEND_HASH_FOREACH_VAL(pubkeysht, pubkey) { + ZEND_ARRAY_FOREACH_VAL(pubkeysht, pubkey) { pkeys[i] = php_openssl_pkey_from_zval(pubkey, 1, NULL, 0); if (pkeys[i] == NULL) { if (!EG(exception)) { @@ -6896,7 +6896,7 @@ PHP_FUNCTION(openssl_seal) } eks[i] = emalloc(EVP_PKEY_size(pkeys[i]) + 1); i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ctx = EVP_CIPHER_CTX_new(); if (ctx == NULL || !EVP_EncryptInit(ctx,cipher,NULL,NULL)) { diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 5564bf6f08681..88e2329adc04c 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -184,13 +184,13 @@ static int php_openssl_is_http_stream_talking_to_iis(php_stream *stream) /* {{{ #define SERVER_MICROSOFT_IIS "Server: Microsoft-IIS" #define SERVER_GOOGLE "Server: GFE/" - ZEND_HASH_FOREACH_VAL(Z_ARRVAL(stream->wrapperdata), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(stream->wrapperdata), tmp) { if (zend_string_equals_literal_ci(Z_STR_P(tmp), SERVER_MICROSOFT_IIS)) { return 1; } else if (zend_string_equals_literal_ci(Z_STR_P(tmp), SERVER_GOOGLE)) { return 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return 0; } @@ -358,7 +358,7 @@ static bool php_openssl_x509_fingerprint_match(X509 *peer, zval *val) return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), key, current) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), key, current) { if (key == NULL || Z_TYPE_P(current) != IS_STRING) { php_error_docref(NULL, E_WARNING, "Invalid peer_fingerprint array; [algo => fingerprint] form required"); return 0; @@ -366,7 +366,7 @@ static bool php_openssl_x509_fingerprint_match(X509 *peer, zval *val) if (php_openssl_x509_fingerprint_cmp(peer, ZSTR_VAL(key), Z_STRVAL_P(current)) != 0) { return 0; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return 1; } else { @@ -1417,7 +1417,7 @@ static int php_openssl_enable_server_sni(php_stream *stream, php_openssl_netstre ); memset(sslsock->sni_certs, 0, sslsock->sni_cert_count * sizeof(php_openssl_sni_cert_t)); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val), key_index, key, current) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(val), key_index, key, current) { (void) key_index; if (!key) { @@ -1496,7 +1496,7 @@ static int php_openssl_enable_server_sni(php_stream *stream, php_openssl_netstre sslsock->sni_certs[i].ctx = ctx; ++i; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); SSL_CTX_set_tlsext_servername_callback(sslsock->ctx, php_openssl_server_sni_callback); diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 54ed5c4b90e91..3c8ff256d4c2d 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -837,7 +837,7 @@ PHP_FUNCTION(pcntl_exec) argv = safe_emalloc((argc + 2), sizeof(char *), 0); *argv = path; current_arg = argv+1; - ZEND_HASH_FOREACH_VAL(args_hash, element) { + ZEND_ARRAY_FOREACH_VAL(args_hash, element) { if (argi >= argc) break; if (!try_convert_to_string(element)) { efree(argv); @@ -847,7 +847,7 @@ PHP_FUNCTION(pcntl_exec) *current_arg = Z_STRVAL_P(element); argi++; current_arg++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *current_arg = NULL; } else { argv = emalloc(2 * sizeof(char *)); @@ -862,7 +862,7 @@ PHP_FUNCTION(pcntl_exec) envc = zend_hash_num_elements(envs_hash); pair = envp = safe_emalloc((envc + 1), sizeof(char *), 0); - ZEND_HASH_FOREACH_KEY_VAL(envs_hash, key_num, key, element) { + ZEND_ARRAY_FOREACH_KEY_VAL(envs_hash, key_num, key, element) { if (envi >= envc) break; if (!key) { key = zend_long_to_str(key_num); @@ -889,7 +889,7 @@ PHP_FUNCTION(pcntl_exec) zend_string_release_ex(key, 0); envi++; pair++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *(pair) = NULL; if (execve(path, argv, envp) == -1) { @@ -1048,14 +1048,14 @@ PHP_FUNCTION(pcntl_sigprocmask) RETURN_FALSE; } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { signo = zval_get_long(user_signo); if (sigaddset(&set, signo) != 0) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (sigprocmask(how, &set, &oldset) != 0) { PCNTL_G(last_error) = errno; @@ -1109,14 +1109,14 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{ RETURN_FALSE; } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { signo = zval_get_long(user_signo); if (sigaddset(&set, signo) != 0) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (timedwait) { timeout.tv_sec = (time_t) tv_sec; diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index bde53d589dbda..ea0c3b025b9c0 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2101,7 +2101,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, uint32_t replace_idx = 0; /* For each entry in the regex array, get the entry */ - ZEND_HASH_FOREACH_VAL(regex, regex_entry) { + ZEND_ARRAY_FOREACH_VAL(regex, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_str; zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str); @@ -2136,13 +2136,13 @@ static zend_string *php_pcre_replace_array(HashTable *regex, if (UNEXPECTED(result == NULL)) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { ZEND_ASSERT(replace_str != NULL); /* For each entry in the regex array, get the entry */ - ZEND_HASH_FOREACH_VAL(regex, regex_entry) { + ZEND_ARRAY_FOREACH_VAL(regex, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_str; zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str); @@ -2158,7 +2158,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, if (UNEXPECTED(result == NULL)) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return subject_str; @@ -2206,7 +2206,7 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl zend_string_addref(subject); /* For each entry in the regex array, get the entry */ - ZEND_HASH_FOREACH_VAL(regex_ht, regex_entry) { + ZEND_ARRAY_FOREACH_VAL(regex_ht, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_entry_str; zend_string *regex_entry_str = zval_get_tmp_string(regex_entry, &tmp_regex_entry_str); @@ -2221,7 +2221,7 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl if (UNEXPECTED(result == NULL)) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return subject; } @@ -2257,7 +2257,7 @@ static size_t preg_replace_func_impl(zval *return_value, /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { zend_string *tmp_subject_entry_str; zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str); @@ -2273,7 +2273,7 @@ static size_t preg_replace_func_impl(zval *return_value, } } zend_tmp_string_release(tmp_subject_entry_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return replace_count; @@ -2337,7 +2337,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, bool is_filter) /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { old_replace_count = replace_count; zend_string *tmp_subject_entry_str; zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str); @@ -2358,7 +2358,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, bool is_filter) } } zend_tmp_string_release(tmp_subject_entry_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (zcount) { @@ -2438,7 +2438,7 @@ PHP_FUNCTION(preg_replace_callback_array) GC_TRY_ADDREF(subject_str); } - ZEND_HASH_FOREACH_STR_KEY_VAL(pattern, str_idx_regex, replace) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(pattern, str_idx_regex, replace) { if (!str_idx_regex) { php_error_docref(NULL, E_WARNING, "Delimiter must not be alphanumeric or backslash"); RETVAL_NULL(); @@ -2474,7 +2474,7 @@ PHP_FUNCTION(preg_replace_callback_array) if (EG(exception)) { goto error; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (zcount) { ZEND_TRY_ASSIGN_REF_LONG(zcount, replace_count); @@ -2922,7 +2922,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return options = (pce->compile_options & PCRE2_UTF) ? 0 : PCRE2_NO_UTF_CHECK; /* Go through the input array */ - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { zend_string *tmp_subject_str; zend_string *subject_str = zval_get_tmp_string(entry, &tmp_subject_str); @@ -2970,7 +2970,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return } zend_tmp_string_release(tmp_subject_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (match_data != mdata) { pcre2_match_data_free(match_data); } diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index d53d2ca63c0d1..4edb9f3b5104f 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -403,7 +403,7 @@ PHP_METHOD(PDO, __construct) zend_ulong long_key; zend_string *str_key = NULL; - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), long_key, str_key, attr_value) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(options), long_key, str_key, attr_value) { if (str_key) { continue; } @@ -411,7 +411,7 @@ PHP_METHOD(PDO, __construct) /* TODO: Should the constructor fail when the attribute cannot be set? */ pdo_dbh_attribute_set(dbh, long_key, attr_value); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } zend_restore_error_handling(&zeh); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 5320d50cf9c9f..3ee74d962f107 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -68,7 +68,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p return 0; } - ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) { + ZEND_ARRAY_FOREACH_PTR(stmt->bound_param_map, name) { if (!zend_string_equals(name, param->name)) { position++; continue; @@ -80,7 +80,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p } param->paramno = position; return 1; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* TODO Error? */ pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); return 0; @@ -108,12 +108,12 @@ static bool dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_ty iterate: if (ht) { - ZEND_HASH_FOREACH_PTR(ht, param) { + ZEND_ARRAY_FOREACH_PTR(ht, param) { if (!stmt->methods->param_hook(stmt, param, event_type)) { ret = 0; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (ret && is_param) { ht = stmt->bound_columns; @@ -409,7 +409,7 @@ PHP_METHOD(PDOStatement, execute) stmt->bound_params = NULL; } - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input_params), num_index, key, tmp) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input_params), num_index, key, tmp) { memset(¶m, 0, sizeof(param)); if (key) { @@ -431,7 +431,7 @@ PHP_METHOD(PDOStatement, execute) } RETURN_FALSE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { @@ -592,7 +592,7 @@ static bool do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, ze /* update those bound column variables now */ struct pdo_bound_param_data *param; - ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { + ZEND_ARRAY_FOREACH_PTR(stmt->bound_columns, param) { if (param->paramno >= 0) { if (!Z_ISREF(param->parameter)) { continue; @@ -609,7 +609,7 @@ static bool do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, ze * it's better to use LAZY or BOUND fetches if you want to shave * off those cycles */ } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return 1; @@ -1981,7 +1981,7 @@ PHP_METHOD(PDOStatement, debugDumpParams) if (stmt->bound_params) { zend_ulong num; zend_string *key = NULL; - ZEND_HASH_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { + ZEND_ARRAY_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { if (key) { php_stream_printf(out, "Key: Name: [%zd] %.*s\n", ZSTR_LEN(key), (int) ZSTR_LEN(key), ZSTR_VAL(key)); @@ -1999,7 +1999,7 @@ PHP_METHOD(PDOStatement, debugDumpParams) param->is_param, param->param_type); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } php_stream_close(out); diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index be9e8c012252e..12c360f2c73fa 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -610,7 +610,7 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray) zval *tmp; PQclear(pgsql_result); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { size_t query_len; if (!try_convert_to_string(tmp)) { efree(query); @@ -633,7 +633,7 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray) PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (query) { efree(query); } diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 82c1af88aa16c..f4ad80d8f13e1 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1194,7 +1194,7 @@ PHP_FUNCTION(pg_query_params) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -1208,7 +1208,7 @@ PHP_FUNCTION(pg_query_params) zend_string_release(param_str); } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } pgsql_result = PQexecParams(pgsql, query, num_params, @@ -1380,7 +1380,7 @@ PHP_FUNCTION(pg_execute) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -1393,7 +1393,7 @@ PHP_FUNCTION(pg_execute) } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, @@ -3221,7 +3221,7 @@ PHP_FUNCTION(pg_copy_from) if (pgsql_result) { int command_failed = 0; PQclear(pgsql_result); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { zend_string *tmp = zval_try_get_string(value); if (UNEXPECTED(!tmp)) { return; @@ -3239,7 +3239,7 @@ PHP_FUNCTION(pg_copy_from) } efree(query); zend_string_release(tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (PQputCopyEnd(pgsql, NULL) != 1) { PHP_PQ_ERROR("putcopyend failed: %s", pgsql); @@ -3745,7 +3745,7 @@ PHP_FUNCTION(pg_send_query_params) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -3758,7 +3758,7 @@ PHP_FUNCTION(pg_send_query_params) } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (PQsendQueryParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0)) { @@ -3912,7 +3912,7 @@ PHP_FUNCTION(pg_send_execute) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -3927,7 +3927,7 @@ PHP_FUNCTION(pg_send_execute) } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (PQsendQueryPrepared(pgsql, stmtname, num_params, (const char * const *)params, NULL, NULL, 0)) { @@ -4582,7 +4582,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * return FAILURE; } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { skip_field = 0; ZVAL_NULL(&new_val); @@ -5193,7 +5193,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * PQfreemem(escaped); } } - } ZEND_HASH_FOREACH_END(); /* for */ + } ZEND_ARRAY_FOREACH_END(); /* for */ zval_ptr_dtor(&meta); @@ -5333,7 +5333,7 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t build_tablename(&querystr, pg_link, table); smart_str_appends(&querystr, " ("); - ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) { + ZEND_ARRAY_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) { if (fld == NULL) { zend_value_error("Array of values must be an associative array with string keys"); goto cleanup; @@ -5346,12 +5346,12 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t smart_str_append(&querystr, fld); } smart_str_appendc(&querystr, ','); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ZSTR_LEN(querystr.s)--; smart_str_appends(&querystr, ") VALUES ("); /* make values string */ - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(var_array), val) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(var_array), val) { /* we can avoid the key_type check here, because we tested it in the other loop */ switch (Z_TYPE_P(val)) { case IS_STRING: @@ -5382,7 +5382,7 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t goto cleanup; } smart_str_appendc(&querystr, ','); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Remove the trailing "," */ ZSTR_LEN(querystr.s)--; smart_str_appends(&querystr, ");"); @@ -5508,7 +5508,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr, zend_string *fld; zval *val; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, fld, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, fld, val) { if (fld == NULL) { zend_value_error("Array of values must be an associative array with string keys"); return -1; @@ -5556,7 +5556,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr, return -1; } smart_str_appendl(querystr, pad, pad_len); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (querystr->s) { ZSTR_LEN(querystr->s) -= pad_len; } diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 448d03b7cc75e..5fcfbac357c0c 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -878,7 +878,7 @@ PHP_METHOD(Phar, mungServer) phar_request_initialize(); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) { if (Z_TYPE_P(data) != IS_STRING) { zend_throw_exception_ex(phar_ce_PharException, 0, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); @@ -895,7 +895,7 @@ PHP_METHOD(Phar, mungServer) PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_FILENAME; } // TODO Warning for invalid value? - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -4357,7 +4357,7 @@ PHP_METHOD(Phar, extractTo) RETURN_FALSE; } - ZEND_HASH_FOREACH_VAL(files_ht, zval_file) { + ZEND_ARRAY_FOREACH_VAL(files_ht, zval_file) { ZVAL_DEREF(zval_file); if (IS_STRING != Z_TYPE_P(zval_file)) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, @@ -4376,7 +4376,7 @@ PHP_METHOD(Phar, extractTo) ZSTR_VAL(Z_STR_P(zval_file)), phar_obj->archive->fname); RETURN_THROWS(); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); RETURN_TRUE; } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 11024b9aee8cd..32bd596b61ebc 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -619,7 +619,7 @@ static int format_default_value(smart_str *str, zval *value) { bool is_list = zend_array_is_list(Z_ARRVAL_P(value)); bool first = true; smart_str_appendc(str, '['); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(value), num_key, str_key, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(value), num_key, str_key, zv) { if (!first) { smart_str_appends(str, ", "); } @@ -636,7 +636,7 @@ static int format_default_value(smart_str *str, zval *value) { smart_str_appends(str, " => "); } format_default_value(str, zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendc(str, ']'); } else { ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST); @@ -1125,18 +1125,18 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s // Name based filtering using lowercased key. zend_string *filter = zend_string_tolower(name); - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, filter)) { reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_string_release(filter); return SUCCESS; } - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(attributes, attr) { if (attr->offset != offset) { continue; } @@ -1161,7 +1161,7 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } diff --git a/ext/session/php_session.h b/ext/session/php_session.h index bc8c3548c7059..0c1eb0ca9c639 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -289,7 +289,7 @@ PHPAPI int php_session_reset_id(void); #define PS_ENCODE_LOOP(code) do { \ HashTable *_ht = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); \ - ZEND_HASH_FOREACH_KEY(_ht, num_key, key) { \ + ZEND_ARRAY_FOREACH_KEY(_ht, num_key, key) { \ if (key == NULL) { \ php_error_docref(NULL, E_WARNING, \ "Skipping numeric key " ZEND_LONG_FMT, num_key);\ @@ -298,7 +298,7 @@ PHPAPI int php_session_reset_id(void); if ((struc = php_get_session_var(key))) { \ code; \ } \ - } ZEND_HASH_FOREACH_END(); \ + } ZEND_ARRAY_FOREACH_END(); \ } while(0) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps) diff --git a/ext/session/session.c b/ext/session/session.c index 18444932ceb37..426a037872c83 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1727,8 +1727,7 @@ PHP_FUNCTION(session_set_cookie_params) zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array"); RETURN_THROWS(); } - - ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(options_ht, key, value) { if (key) { ZVAL_DEREF(value); if (zend_string_equals_literal_ci(key, "lifetime")) { @@ -1757,7 +1756,7 @@ PHP_FUNCTION(session_set_cookie_params) } else { php_error_docref(NULL, E_WARNING, "Argument #1 ($lifetime_or_options) cannot contain numeric keys"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (found == 0) { zend_argument_value_error(1, "must contain at least 1 valid key"); @@ -2492,7 +2491,7 @@ PHP_FUNCTION(session_start) /* set options */ if (options) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) { if (str_idx) { switch(Z_TYPE_P(value)) { case IS_STRING: @@ -2518,7 +2517,7 @@ PHP_FUNCTION(session_start) } } (void) num_idx; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } php_session_start(); diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 6e6f5a92903ef..d3f707b9e3642 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -695,7 +695,7 @@ static bool php_snmp_parse_oid( } objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0); objid_query->array_output = (st & SNMP_CMD_SET) == 0; - ZEND_HASH_FOREACH_VAL(oid_ht, tmp_oid) { + ZEND_ARRAY_FOREACH_VAL(oid_ht, tmp_oid) { convert_to_string(tmp_oid); objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid); if (st & SNMP_CMD_SET) { @@ -769,7 +769,7 @@ static bool php_snmp_parse_oid( } } objid_query->count++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* now parse all OIDs */ diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 3a4626aa5beee..c35cbbfd7d9cb 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -1346,13 +1346,13 @@ static void model_to_zval_object(zval *ret, sdlContentModelPtr model, xmlNodePtr sdlContentModelPtr tmp; sdlContentModelPtr any = NULL; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { if (tmp->kind == XSD_CONTENT_ANY) { any = tmp; } else { model_to_zval_object(ret, tmp, data, sdl); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (any) { model_to_zval_any(ret, data->children); } @@ -1607,7 +1607,7 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * HashTable *ht = Z_ARRVAL_P(data); zval *val; - ZEND_HASH_FOREACH_VAL(ht, val) { + ZEND_ARRAY_FOREACH_VAL(ht, val) { ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_NULL && model->u.element->nillable) { property = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -1627,7 +1627,7 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * xmlNsPtr nsp = encode_add_ns(property, model->u.element->namens); xmlSetNs(property, nsp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { if (Z_TYPE_P(data) == IS_NULL && model->u.element->nillable) { property = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -1686,9 +1686,9 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * HashTable *ht = Z_ARRVAL_P(data); zval *val; - ZEND_HASH_FOREACH_VAL(ht, val) { + ZEND_ARRAY_FOREACH_VAL(ht, val) { master_to_xml(enc, val, style, node); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { master_to_xml(enc, data, style, node); } @@ -1707,28 +1707,28 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * case XSD_CONTENT_ALL: { sdlContentModelPtr tmp; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { if (!model_to_xml_object(node, tmp, object, style, strict && (tmp->min_occurs > 0))) { if (!strict || tmp->min_occurs > 0) { return 0; } } strict = 1; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return 1; } case XSD_CONTENT_CHOICE: { sdlContentModelPtr tmp; int ret = 0; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { int tmp_ret = model_to_xml_object(node, tmp, object, style, 0); if (tmp_ret == 1) { return 1; } else if (tmp_ret != 0) { ret = 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return ret; } case XSD_CONTENT_GROUP: { @@ -1758,9 +1758,9 @@ static sdlTypePtr model_array_element(sdlContentModelPtr model) if (zend_hash_num_elements(model->u.content) != 1) { return NULL; } - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { return model_array_element(tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* TODO Check this is correct */ ZEND_FALLTHROUGH; @@ -1863,7 +1863,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo (array_el = model_array_element(sdlType->model)) != NULL) { zval *val; - ZEND_HASH_FOREACH_VAL(prop, val) { + ZEND_ARRAY_FOREACH_VAL(prop, val) { xmlNodePtr property; ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_NULL && array_el->nillable) { @@ -1880,7 +1880,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlNsPtr nsp = encode_add_ns(property, array_el->namens); xmlSetNs(property, nsp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (sdlType->model) { model_to_xml_object(xmlParam, sdlType->model, data, style, 1); } @@ -1934,7 +1934,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo zend_string *str_key; xmlNodePtr property; - ZEND_HASH_FOREACH_STR_KEY_VAL_IND(prop, str_key, zprop) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL_IND(prop, str_key, zprop) { ZVAL_DEREF(zprop); property = master_to_xml(get_conversion(Z_TYPE_P(zprop)), zprop, style, xmlParam); @@ -1952,7 +1952,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlNodeSetName(property, BAD_CAST(prop_name)); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (style == SOAP_ENCODED) { set_ns_and_type(xmlParam, type); @@ -2088,7 +2088,7 @@ static void add_xml_array_elements(xmlNodePtr xmlParam, xmlNodePtr xparam; if (data && Z_TYPE_P(data) == IS_ARRAY) { - ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(data), zdata) { + ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL_P(data), zdata) { if (j >= dims[0]) { break; } @@ -2112,7 +2112,7 @@ static void add_xml_array_elements(xmlNodePtr xmlParam, add_xml_array_elements(xmlParam, type, enc, ns, dimension-1, dims+1, zdata, style); } j++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (dimension == 1) { while (j < dims[0]) { @@ -2284,9 +2284,9 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod for (i = 1; i < dimension; i++) { if (el != NULL && Z_TYPE_P(el) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(el)) > 0) { - ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(el), el) { + ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL_P(el), el) { break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ZVAL_DEREF(el); if (Z_TYPE_P(el) == IS_ARRAY) { dims[i] = zend_hash_num_elements(Z_ARRVAL_P(el)); @@ -2646,7 +2646,7 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP FIND_ZVAL_NULL(data, xmlParam, style); if (Z_TYPE_P(data) == IS_ARRAY) { - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(data), int_val, key_val, temp_data) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(data), int_val, key_val, temp_data) { item = xmlNewNode(NULL, BAD_CAST("item")); xmlAddChild(xmlParam, item); key = xmlNewNode(NULL, BAD_CAST("key")); @@ -2672,7 +2672,7 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP ZVAL_DEREF(temp_data); xparam = master_to_xml(get_conversion(Z_TYPE_P(temp_data)), temp_data, style, item); xmlNodeSetName(xparam, BAD_CAST("value")); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (style == SOAP_ENCODED) { set_ns_and_type(xmlParam, type); @@ -2951,10 +2951,10 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP if (enc->sdl_type && enc->sdl_type->kind == XSD_TYPEKIND_LIST && enc->sdl_type->elements) { sdlTypePtr type; - ZEND_HASH_FOREACH_PTR(enc->sdl_type->elements, type) { + ZEND_ARRAY_FOREACH_PTR(enc->sdl_type->elements, type) { list_enc = type->encode; break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ret = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -2965,7 +2965,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP smart_str list = {0}; HashTable *ht = Z_ARRVAL_P(data); - ZEND_HASH_FOREACH_VAL(ht, tmp) { + ZEND_ARRAY_FOREACH_VAL(ht, tmp) { xmlNodePtr dummy = master_to_xml(list_enc, tmp, SOAP_LITERAL, ret); if (dummy && dummy->children && dummy->children->content) { if (list.s && ZSTR_LEN(list.s) != 0) { @@ -2977,7 +2977,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP } xmlUnlinkNode(dummy); xmlFreeNode(dummy); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_0(&list); if (list.s) { xmlNodeSetContentLen(ret, BAD_CAST(ZSTR_VAL(list.s)), ZSTR_LEN(list.s)); @@ -3459,12 +3459,12 @@ static int is_map(zval *array) return FALSE; } - ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(array), index, key) { + ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(array), index, key) { if (key || index != i) { return TRUE; } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return FALSE; } @@ -3485,7 +3485,7 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type) cur_type = prev_type = 0; ht = Z_ARRVAL_P(array); - ZEND_HASH_FOREACH_VAL_IND(ht, tmp) { + ZEND_ARRAY_FOREACH_VAL_IND(ht, tmp) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_OBJECT && Z_OBJCE_P(tmp) == soap_var_class_entry) { @@ -3534,7 +3534,7 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type) prev_stype = cur_stype; prev_ns = cur_ns; i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (different || i == 0) { smart_str_appendl(type, "xsd:anyType", sizeof("xsd:anyType")-1); diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index db3c97b647391..1cd73ed792876 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -823,7 +823,7 @@ int make_http_soap_request(zval *this_ptr, /* Send cookies along with request */ cookies = Z_CLIENT_COOKIES_P(this_ptr); ZEND_ASSERT(Z_TYPE_P(cookies) == IS_ARRAY); - if (zend_hash_num_elements(Z_ARRVAL_P(cookies)) != 0) { + if (zend_hash_num_elements(Z_ARRVAL_P(cookies)) != 0 && !HT_IS_PACKED(Z_ARRVAL_P(cookies))) { zval *data; zend_string *key; has_cookies = 1; diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index c93451506ee3b..d822f4e82bcc8 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -265,7 +265,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction if (fn->responseParameters) { res_count = zend_hash_num_elements(fn->responseParameters); - ZEND_HASH_FOREACH_PTR(fn->responseParameters, param) { + ZEND_ARRAY_FOREACH_PTR(fn->responseParameters, param) { if (fnb->style == SOAP_DOCUMENT) { if (param->element) { name = param->element->name; @@ -329,7 +329,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction add_assoc_zval(return_value, param->paramName, &tmp); param_count++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else { /* Function has no WSDL description */ diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index e93679a55ea39..2d423e9d9b831 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -2197,10 +2197,10 @@ static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model) if (model->max_occurs != 1) { sdlContentModelPtr tmp; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { tmp->min_occurs = 0; tmp->max_occurs = model->max_occurs; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); model->kind = XSD_CONTENT_ALL; model->min_occurs = 1; @@ -2212,9 +2212,9 @@ static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model) case XSD_CONTENT_ALL: { sdlContentModelPtr tmp; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { schema_content_model_fixup(ctx, tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); break; } default: @@ -2253,9 +2253,9 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type) type->ref = NULL; } if (type->elements) { - ZEND_HASH_FOREACH_PTR(type->elements, tmp) { + ZEND_ARRAY_FOREACH_PTR(type->elements, tmp) { schema_type_fixup(ctx, tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (type->model) { schema_content_model_fixup(ctx, type->model); @@ -2264,14 +2264,14 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type) zend_string *str_key; zend_ulong index; - ZEND_HASH_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) { + ZEND_ARRAY_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) { if (str_key) { schema_attribute_fixup(ctx, attr); } else { schema_attributegroup_fixup(ctx, attr, type->attributes); zend_hash_index_del(type->attributes, index); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } @@ -2302,9 +2302,9 @@ void schema_pass2(sdlCtx *ctx) } ZEND_HASH_FOREACH_END(); } if (sdl->types) { - ZEND_HASH_FOREACH_PTR(sdl->types, type) { + ZEND_ARRAY_FOREACH_PTR(sdl->types, type) { schema_type_fixup(ctx, type); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (ctx->attributes) { zend_hash_destroy(ctx->attributes); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 4b79090ee83ff..cb3cac6c75e36 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -593,7 +593,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap if (*parts == '\0') break; end = strchr(parts, ' '); if (end) *end = '\0'; - ZEND_HASH_FOREACH_PTR(params, param) { + ZEND_ARRAY_FOREACH_PTR(params, param) { if (param->paramName && strcmp(parts, param->paramName) == 0) { sdlParamPtr x_param; @@ -604,7 +604,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap found = 1; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (!found) { soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in ", parts); } @@ -1884,9 +1884,9 @@ static void sdl_serialize_model(sdlContentModelPtr model, HashTable *tmp_types, int i = zend_hash_num_elements(model->u.content); WSDL_CACHE_PUT_INT(i, out); - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { sdl_serialize_model(tmp, tmp_types, tmp_elements, out); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } break; case XSD_CONTENT_GROUP_REF: @@ -2508,7 +2508,7 @@ static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *p pparams = malloc(sizeof(HashTable)); zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(params, key, tmp) { pparam = malloc(sizeof(sdlParam)); memset(pparam, 0, sizeof(sdlParam)); *pparam = *tmp; @@ -2536,7 +2536,7 @@ static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *p } else { zend_hash_next_index_insert_ptr(pparams, pparam); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return pparams; } @@ -2668,10 +2668,10 @@ static sdlContentModelPtr make_persistent_sdl_model(sdlContentModelPtr model, Ha pmodel->u.content = malloc(sizeof(HashTable)); zend_hash_init(pmodel->u.content, zend_hash_num_elements(model->u.content), NULL, delete_model_persistent, 1); - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { pcontent = make_persistent_sdl_model(tmp, ptr_map, bp_types, bp_encoders); zend_hash_next_index_insert_ptr(pmodel->u.content, pcontent); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); break; case XSD_CONTENT_GROUP_REF: @@ -2783,7 +2783,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, ptype->elements = malloc(sizeof(HashTable)); zend_hash_init(ptype->elements, zend_hash_num_elements(type->elements), NULL, delete_type_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { pelem = make_persistent_sdl_type(tmp, ptr_map, bp_types, bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2792,7 +2792,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, zend_hash_next_index_insert_ptr(ptype->elements, pelem); } zend_hash_str_add_ptr(ptr_map, (char*)&tmp, sizeof(tmp), pelem); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (ptype->attributes) { @@ -2972,7 +2972,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->types = malloc(sizeof(HashTable)); zend_hash_init(psdl->types, zend_hash_num_elements(sdl->types), NULL, delete_type_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2981,7 +2981,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) zend_hash_next_index_insert_ptr(psdl->types, ptype); } zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (sdl->elements) { @@ -3036,12 +3036,12 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) if (zend_hash_num_elements(&bp_encoders)) { encodePtr *tmp, penc = NULL; - ZEND_HASH_FOREACH_PTR(&bp_encoders, tmp) { + ZEND_ARRAY_FOREACH_PTR(&bp_encoders, tmp) { if ((penc = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { assert(0); } *tmp = penc; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } diff --git a/ext/soap/soap.c b/ext/soap/soap.c index f33aacfff706a..7e135de967000 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -730,7 +730,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ HashTable *ht2; HashTable *typemap = NULL; - ZEND_HASH_FOREACH_VAL(ht, tmp) { + ZEND_ARRAY_FOREACH_VAL(ht, tmp) { char *type_name = NULL; char *type_ns = NULL; zval *to_xml = NULL; @@ -744,25 +744,27 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ } ht2 = Z_ARRVAL_P(tmp); - ZEND_HASH_FOREACH_STR_KEY_VAL(ht2, name, tmp) { - if (name) { - if (zend_string_equals_literal(name, "type_name")) { - if (Z_TYPE_P(tmp) == IS_STRING) { - type_name = Z_STRVAL_P(tmp); - } else if (Z_TYPE_P(tmp) != IS_NULL) { - } - } else if (zend_string_equals_literal(name, "type_ns")) { - if (Z_TYPE_P(tmp) == IS_STRING) { - type_ns = Z_STRVAL_P(tmp); - } else if (Z_TYPE_P(tmp) != IS_NULL) { + if (!HT_IS_PACKED(ht2)) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht2, name, tmp) { + if (name) { + if (zend_string_equals_literal(name, "type_name")) { + if (Z_TYPE_P(tmp) == IS_STRING) { + type_name = Z_STRVAL_P(tmp); + } else if (Z_TYPE_P(tmp) != IS_NULL) { + } + } else if (zend_string_equals_literal(name, "type_ns")) { + if (Z_TYPE_P(tmp) == IS_STRING) { + type_ns = Z_STRVAL_P(tmp); + } else if (Z_TYPE_P(tmp) != IS_NULL) { + } + } else if (zend_string_equals_literal(name, "to_xml")) { + to_xml = tmp; + } else if (zend_string_equals_literal(name, "from_xml")) { + to_zval = tmp; } - } else if (zend_string_equals_literal(name, "to_xml")) { - to_xml = tmp; - } else if (zend_string_equals_literal(name, "from_xml")) { - to_zval = tmp; } - } - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } if (type_name) { smart_str nscat = {0}; @@ -819,7 +821,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ zend_hash_update_ptr(typemap, nscat.s, new_enc); smart_str_free(&nscat); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return typemap; } /* }}} */ @@ -1107,7 +1109,7 @@ PHP_METHOD(SoapServer, addFunction) service->soap_functions.ft = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(function_name))); } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) { zend_string *key; zend_function *f; @@ -1127,7 +1129,7 @@ PHP_METHOD(SoapServer, addFunction) zend_hash_update(service->soap_functions.ft, key, &function_copy); zend_string_release_ex(key, 0); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else if (Z_TYPE_P(function_name) == IS_STRING) { zend_string *key; @@ -2417,12 +2419,12 @@ static void verify_soap_headers_array(HashTable *ht) /* {{{ */ { zval *tmp; - ZEND_HASH_FOREACH_VAL(ht, tmp) { + ZEND_ARRAY_FOREACH_VAL(ht, tmp) { if (Z_TYPE_P(tmp) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(tmp), soap_header_class_entry)) { php_error_docref(NULL, E_ERROR, "Invalid SOAP header"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -2499,12 +2501,12 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, bool is_soap_call) soap_headers = zend_array_dup(soap_headers); free_soap_headers = 1; } - ZEND_HASH_FOREACH_VAL(default_headers, tmp) { + ZEND_ARRAY_FOREACH_VAL(default_headers, tmp) { if(Z_TYPE_P(tmp) == IS_OBJECT) { Z_ADDREF_P(tmp); zend_hash_next_index_insert(soap_headers, tmp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { soap_headers = Z_ARRVAL_P(tmp); free_soap_headers = 0; @@ -2515,12 +2517,12 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, bool is_soap_call) if (arg_count > 0) { real_args = safe_emalloc(sizeof(zval), arg_count, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), param) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), param) { /*zval_add_ref(param);*/ ZVAL_DEREF(param); ZVAL_COPY_VALUE(&real_args[i], param); i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (output_headers) { output_headers = zend_try_array_init(output_headers); @@ -2595,11 +2597,11 @@ PHP_METHOD(SoapClient, __getTypes) array_init(return_value); if (sdl->types) { - ZEND_HASH_FOREACH_PTR(sdl->types, type) { + ZEND_ARRAY_FOREACH_PTR(sdl->types, type) { type_to_string(type, &buf, 0); add_next_index_stringl(return_value, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s)); smart_str_free(&buf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } } @@ -2879,14 +2881,14 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, i return; } num_of_params = zend_hash_num_elements(function->requestParameters); - ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { + ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { if (get_node(params, param->paramName) != NULL) { use_names = 1; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (use_names) { tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0); - ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { + ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { val = get_node(params, param->paramName); if (!val) { /* TODO: may be "nil" is not OK? */ @@ -2895,7 +2897,7 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, i master_to_zval(&tmp_parameters[cur_param], param->encode, val); } cur_param++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *parameters = tmp_parameters; *num_params = num_of_params; return; @@ -3889,7 +3891,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function if (head) { zval* header; - ZEND_HASH_FOREACH_VAL(soap_headers, header) { + ZEND_ARRAY_FOREACH_VAL(soap_headers, header) { if (Z_TYPE_P(header) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(header), soap_header_class_entry)) { continue; @@ -3933,7 +3935,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function xmlSetNs(h, nsptr); set_soap_header_attributes(h, header, version); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (use == SOAP_ENCODED) { @@ -4049,11 +4051,11 @@ static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int inde if ((tmp = zend_hash_str_find_ptr(ht, param_name, strlen(param_name))) != NULL) { return tmp; } else { - ZEND_HASH_FOREACH_PTR(ht, tmp) { + ZEND_ARRAY_FOREACH_PTR(ht, tmp) { if (tmp->paramName && strcmp(param_name, tmp->paramName) == 0) { return tmp; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else { if ((tmp = zend_hash_index_find_ptr(ht, index)) != NULL) { @@ -4105,7 +4107,7 @@ static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */ int ok = 1; xmlNodePtr node = params; - ZEND_HASH_FOREACH_PTR(tmp->requestParameters, param) { + ZEND_ARRAY_FOREACH_PTR(tmp->requestParameters, param) { if (param->element) { if (strcmp(param->element->name, (char*)node->name) != 0) { ok = 0; @@ -4125,7 +4127,7 @@ static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */ break; } node = node->next; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (ok /*&& node == NULL*/) { return tmp; } @@ -4181,7 +4183,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendc(buf, '('); if (function->requestParameters) { i = 0; - ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { + ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { if (i > 0) { smart_str_appendl(buf, ", ", 2); } @@ -4193,7 +4195,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, " $", 2); smart_str_appendl(buf, param->paramName, strlen(param->paramName)); i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } smart_str_appendc(buf, ')'); smart_str_0(buf); @@ -4220,9 +4222,9 @@ static void model_to_string(sdlContentModelPtr model, smart_str *buf, int level) case XSD_CONTENT_CHOICE: { sdlContentModelPtr tmp; - ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { + ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { model_to_string(tmp, buf, level); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); break; } case XSD_CONTENT_GROUP: @@ -4261,9 +4263,9 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ sdlTypePtr item_type; smart_str_appendl(buf, " {", 2); - ZEND_HASH_FOREACH_PTR(type->elements, item_type) { + ZEND_ARRAY_FOREACH_PTR(type->elements, item_type) { smart_str_appendl(buf, item_type->name, strlen(item_type->name)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendc(buf, '}'); } break; @@ -4275,13 +4277,13 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ int first = 0; smart_str_appendl(buf, " {", 2); - ZEND_HASH_FOREACH_PTR(type->elements, item_type) { + ZEND_ARRAY_FOREACH_PTR(type->elements, item_type) { if (!first) { smart_str_appendc(buf, ','); first = 0; } smart_str_appendl(buf, item_type->name, strlen(item_type->name)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendc(buf, '}'); } break; diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index ba5b1d8a5ad67..7a77026839761 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -213,7 +213,7 @@ static unsigned from_array_iterate(const zval *arr, /* Note i starts at 1, not 0! */ i = 1; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if ((size_t)snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } @@ -226,7 +226,7 @@ static unsigned from_array_iterate(const zval *arr, break; } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return i -1; } @@ -936,7 +936,7 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c control_len = (size_t)num_elems * CMSG_SPACE(20); cur_offset = 0; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if (ctx->err.has_error) { break; } @@ -949,7 +949,7 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c from_zval_write_control(elem, &control_buf, alloc, &control_len, &cur_offset, ctx); zend_llist_remove_tail(&ctx->keys); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); msg->msg_control = control_buf; msg->msg_controllen = cur_offset; /* not control_len, which may be larger */ diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index a82300114c214..f6f8e04343c1c 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -656,7 +656,7 @@ static int php_sock_array_to_fd_set(uint32_t arg_num, zval *sock_array, fd_set * if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(sock_array), element) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(sock_array), element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) != IS_OBJECT || Z_OBJCE_P(element) != socket_ce) { @@ -675,7 +675,7 @@ static int php_sock_array_to_fd_set(uint32_t arg_num, zval *sock_array, fd_set * *max_fd = php_sock->bsd_socket; } num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return num ? 1 : 0; } @@ -694,7 +694,7 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ ZEND_ASSERT(Z_TYPE_P(sock_array) == IS_ARRAY); array_init(&new_hash); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) { ZVAL_DEREF(element); php_sock = Z_SOCKET_P(element); @@ -713,7 +713,7 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ } } num++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Destroy old array, add new one */ zval_ptr_dtor(sock_array); @@ -2353,7 +2353,7 @@ PHP_FUNCTION(socket_addrinfo_lookup) memset(&hints, 0, sizeof(hints)); - if (zhints) { + if (zhints && !HT_IS_PACKED(Z_ARRVAL_P(zhints))) { ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) { if (key) { if (zend_string_equals_literal(key, "ai_flags")) { diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 53d7f116652de..8e187fe966b22 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -113,7 +113,7 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { zval *trace = zend_read_property(zend_get_exception_base(obj), obj, "trace", sizeof("trace")-1, 0, &rv); if (trace && Z_TYPE_P(trace) == IS_ARRAY) { zval *frame; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { if (Z_TYPE_P(frame) == IS_ARRAY) { zval *args = zend_hash_str_find(Z_ARRVAL_P(frame), "args", sizeof("args")-1); if (args) { @@ -121,7 +121,7 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { ZVAL_EMPTY_ARRAY(args); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 31774235f767f..3ac5430a44a15 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -676,9 +676,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Interfaces", strg + 2); efree(strg); @@ -686,9 +686,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Classes", strg + 2); efree(strg); diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 8a429fdf3f8bc..cbedb7de59820 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1259,13 +1259,13 @@ static zend_long spl_array_object_count_elements_helper(spl_array_object *intern zend_string *key; zval *val; /* Count public/dynamic properties */ - ZEND_HASH_FOREACH_STR_KEY_VAL(aht, key, val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(aht, key, val) { if (Z_TYPE_P(val) == IS_INDIRECT) { if (Z_TYPE_P(Z_INDIRECT_P(val)) == IS_UNDEF) continue; if (key && ZSTR_VAL(key)[0] == '\0') continue; } count++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return count; } else { return zend_hash_num_elements(aht); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index 893f81325baf1..b55ad85db2fa6 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -1156,9 +1156,9 @@ PHP_METHOD(SplDoublyLinkedList, __unserialize) { intern->flags = (int) Z_LVAL_P(flags_zv); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) { spl_ptr_llist_push(intern->llist, elem); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); object_properties_load(&intern->std, Z_ARRVAL_P(members_zv)); } /* }}} */ diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 9503baeaba87b..d1195c5eec3a1 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -579,10 +579,10 @@ PHP_METHOD(SplFixedArray, __wakeup) spl_fixedarray_init(&intern->array, size); - ZEND_HASH_FOREACH_VAL(intern_ht, data) { + ZEND_ARRAY_FOREACH_VAL(intern_ht, data) { ZVAL_COPY(&intern->array.elements[index], data); index++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Remove the unserialised properties, since we now have the elements * within the spl_fixedarray_object structure. */ @@ -644,7 +644,7 @@ PHP_METHOD(SplFixedArray, fromArray) zend_ulong num_index, max_index = 0; zend_long tmp; - ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { + ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { if (str_index != NULL || (zend_long)num_index < 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys"); RETURN_THROWS(); @@ -653,7 +653,7 @@ PHP_METHOD(SplFixedArray, fromArray) if (num_index > max_index) { max_index = num_index; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); tmp = max_index + 1; if (tmp <= 0) { @@ -662,9 +662,9 @@ PHP_METHOD(SplFixedArray, fromArray) } spl_fixedarray_init(&array, tmp); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_index, str_index, element) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_index, str_index, element) { ZVAL_COPY_DEREF(&array.elements[num_index], element); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (num > 0 && !save_indexes) { zval *element; @@ -672,10 +672,10 @@ PHP_METHOD(SplFixedArray, fromArray) spl_fixedarray_init(&array, num); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), element) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(data), element) { ZVAL_COPY_DEREF(&array.elements[i], element); i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { spl_fixedarray_init(&array, 0); } diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index be826b2f06d4d..7b4e5f897c533 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -182,9 +182,9 @@ static int spl_object_storage_detach(spl_SplObjectStorage *intern, zend_object * void spl_object_storage_addall(spl_SplObjectStorage *intern, spl_SplObjectStorage *other) { /* {{{ */ spl_SplObjectStorageElement *element; - ZEND_HASH_FOREACH_PTR(&other->storage, element) { + ZEND_ARRAY_FOREACH_PTR(&other->storage, element) { spl_object_storage_attach(intern, element->obj, &element->inf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); intern->index = 0; } /* }}} */ @@ -257,7 +257,7 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{ array_init(&storage); - ZEND_HASH_FOREACH_PTR(&intern->storage, element) { + ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { array_init(&tmp); /* Incrementing the refcount of obj and inf would confuse the garbage collector. * Prefer to null the destructor */ @@ -267,7 +267,7 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{ add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj); add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf); zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zname = spl_gen_private_prop_name(spl_ce_SplObjectStorage, "storage", sizeof("storage")-1); zend_symtable_update(debug_info, zname, &storage); @@ -284,10 +284,10 @@ static HashTable *spl_object_storage_get_gc(zend_object *obj, zval **table, int spl_SplObjectStorageElement *element; zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create(); - ZEND_HASH_FOREACH_PTR(&intern->storage, element) { + ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { zend_get_gc_buffer_add_obj(gc_buffer, element->obj); zend_get_gc_buffer_add_zval(gc_buffer, &element->inf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_get_gc_buffer_use(gc_buffer, table, n); return zend_std_get_properties(obj); @@ -474,11 +474,11 @@ PHP_METHOD(SplObjectStorage, removeAllExcept) other = Z_SPLOBJSTORAGE_P(obj); - ZEND_HASH_FOREACH_PTR(&intern->storage, element) { + ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { if (!spl_object_storage_contains(other, element->obj)) { spl_object_storage_detach(intern, element->obj); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); intern->index = 0; @@ -803,13 +803,13 @@ PHP_METHOD(SplObjectStorage, __serialize) /* storage */ array_init_size(&tmp, 2 * zend_hash_num_elements(&intern->storage)); - ZEND_HASH_FOREACH_PTR(&intern->storage, elem) { + ZEND_ARRAY_FOREACH_PTR(&intern->storage, elem) { zval obj; ZVAL_OBJ_COPY(&obj, elem->obj); zend_hash_next_index_insert(Z_ARRVAL(tmp), &obj); Z_TRY_ADDREF(elem->inf); zend_hash_next_index_insert(Z_ARRVAL(tmp), &elem->inf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &tmp); /* members */ @@ -844,7 +844,7 @@ PHP_METHOD(SplObjectStorage, __unserialize) } key = NULL; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), val) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(storage_zv), val) { if (key) { if (Z_TYPE_P(key) != IS_OBJECT) { zend_throw_exception(spl_ce_UnexpectedValueException, "Non-object key", 0); @@ -856,7 +856,7 @@ PHP_METHOD(SplObjectStorage, __unserialize) } else { key = val; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); object_properties_load(&intern->std, Z_ARRVAL_P(members_zv)); } diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 55ebf911e94d4..91ebc6f798edc 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1493,7 +1493,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ int return_code; if (stmt_obj->bound_params) { - ZEND_HASH_FOREACH_PTR(stmt_obj->bound_params, param) { + ZEND_ARRAY_FOREACH_PTR(stmt_obj->bound_params, param) { zval *parameter; /* parameter must be a reference? */ if (Z_ISREF(param->parameter)) { @@ -1586,7 +1586,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ php_sqlite3_error(stmt_obj->db_obj, "Unknown parameter type: %pd for parameter %pd", param->type, param->param_number); return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return SUCCESS; diff --git a/ext/standard/array.c b/ext/standard/array.c index 5e425bc61a46e..911aa8e192b3b 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -660,12 +660,12 @@ PHPAPI zend_long php_count_recursive(HashTable *ht) /* {{{ */ } cnt = zend_hash_num_elements(ht); - ZEND_HASH_FOREACH_VAL(ht, element) { + ZEND_ARRAY_FOREACH_VAL(ht, element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) == IS_ARRAY) { cnt += php_count_recursive(Z_ARRVAL_P(element)); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(ht); return cnt; @@ -1501,7 +1501,7 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) if (strict) { if (Z_TYPE_P(value) == IS_LONG) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG && Z_LVAL_P(entry) == Z_LVAL_P(value)) { if (behavior == 0) { @@ -1514,9 +1514,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (fast_is_identical_function(value, entry)) { if (behavior == 0) { @@ -1529,11 +1529,11 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else { if (Z_TYPE_P(value) == IS_LONG) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_long(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1545,9 +1545,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (Z_TYPE_P(value) == IS_STRING) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_string(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1559,9 +1559,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_function(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1573,7 +1573,7 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } @@ -1673,6 +1673,9 @@ static zend_long php_extract_ref_if_exists(zend_array *arr, zend_array *symbol_t zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1716,6 +1719,9 @@ static zend_long php_extract_if_exists(zend_array *arr, zend_array *symbol_table zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1757,6 +1763,9 @@ static zend_long php_extract_ref_overwrite(zend_array *arr, zend_array *symbol_t zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1804,6 +1813,9 @@ static zend_long php_extract_overwrite(zend_array *arr, zend_array *symbol_table zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1846,6 +1858,9 @@ static zend_long php_extract_ref_prefix_if_exists(zend_array *arr, zend_array *s zend_string *var_name; zval *entry, *orig_var, final_name; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1902,6 +1917,9 @@ static zend_long php_extract_prefix_if_exists(zend_array *arr, zend_array *symbo zend_string *var_name; zval *entry, *orig_var, final_name; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -1953,6 +1971,9 @@ static zend_long php_extract_ref_prefix_same(zend_array *arr, zend_array *symbol zend_string *var_name; zval *entry, *orig_var, final_name; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -2027,6 +2048,9 @@ static zend_long php_extract_prefix_same(zend_array *arr, zend_array *symbol_tab zend_string *var_name; zval *entry, *orig_var, final_name; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -2094,7 +2118,7 @@ static zend_long php_extract_ref_prefix_all(zend_array *arr, zend_array *symbol_ zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (ZSTR_LEN(var_name) == 0) { continue; @@ -2128,7 +2152,7 @@ static zend_long php_extract_ref_prefix_all(zend_array *arr, zend_array *symbol_ } } zval_ptr_dtor_str(&final_name); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return count; } @@ -2141,7 +2165,7 @@ static zend_long php_extract_prefix_all(zend_array *arr, zend_array *symbol_tabl zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (ZSTR_LEN(var_name) == 0) { continue; @@ -2175,7 +2199,7 @@ static zend_long php_extract_prefix_all(zend_array *arr, zend_array *symbol_tabl } } zval_ptr_dtor_str(&final_name); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return count; } @@ -2188,7 +2212,7 @@ static zend_long php_extract_ref_prefix_invalid(zend_array *arr, zend_array *sym zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (!php_valid_var_name(ZSTR_VAL(var_name), ZSTR_LEN(var_name)) || zend_string_equals_literal(var_name, "this")) { @@ -2230,7 +2254,7 @@ static zend_long php_extract_ref_prefix_invalid(zend_array *arr, zend_array *sym count++; } zval_ptr_dtor_str(&final_name); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return count; } @@ -2243,7 +2267,7 @@ static zend_long php_extract_prefix_invalid(zend_array *arr, zend_array *symbol_ zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (!php_valid_var_name(ZSTR_VAL(var_name), ZSTR_LEN(var_name)) || zend_string_equals_literal(var_name, "this")) { @@ -2285,7 +2309,7 @@ static zend_long php_extract_prefix_invalid(zend_array *arr, zend_array *symbol_ count++; } zval_ptr_dtor_str(&final_name); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return count; } @@ -2297,6 +2321,9 @@ static zend_long php_extract_ref_skip(zend_array *arr, zend_array *symbol_table) zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -2342,6 +2369,9 @@ static zend_long php_extract_skip(zend_array *arr, zend_array *symbol_table) /* zend_string *var_name; zval *entry, *orig_var; + if (HT_IS_PACKED(arr)) { + return 0; + } ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; @@ -2505,9 +2535,9 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu } Z_PROTECT_RECURSION_P(entry); } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(entry), value_ptr) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(entry), value_ptr) { php_compact_var(eg_active_symbol_table, return_value, value_ptr, pos); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (Z_REFCOUNTED_P(entry)) { Z_UNPROTECT_RECURSION_P(entry); } @@ -2629,7 +2659,7 @@ PHP_FUNCTION(array_fill_keys) /* Initialize return array */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(keys))); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { ZVAL_DEREF(entry); Z_TRY_ADDREF_P(val); if (Z_TYPE_P(entry) == IS_LONG) { @@ -2640,7 +2670,7 @@ PHP_FUNCTION(array_fill_keys) zend_symtable_update(Z_ARRVAL_P(return_value), key, val); zend_tmp_string_release(tmp_key); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -3025,11 +3055,11 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H /* If there are entries to insert.. */ if (replace) { - ZEND_HASH_FOREACH_VAL(replace, entry) { + ZEND_ARRAY_FOREACH_VAL(replace, entry) { Z_TRY_ADDREF_P(entry); zend_hash_next_index_insert_new(&out_hash, entry); pos++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* Copy the remaining input hash entries to the output hash */ @@ -3095,11 +3125,11 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H /* If there are entries to insert.. */ if (replace) { - ZEND_HASH_FOREACH_VAL(replace, entry) { + ZEND_ARRAY_FOREACH_VAL(replace, entry) { Z_TRY_ADDREF_P(entry); zend_hash_next_index_insert_new(&out_hash, entry); pos++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* Copy the remaining input hash entries to the output hash */ @@ -3370,13 +3400,13 @@ PHP_FUNCTION(array_unshift) zend_hash_next_index_insert_new(&new_hash, &args[i]); } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { if (key) { zend_hash_add_new(&new_hash, key, value); } else { zend_hash_next_index_insert_new(&new_hash, value); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (UNEXPECTED(HT_HAS_ITERATORS(Z_ARRVAL_P(stack)))) { zend_hash_iterators_advance(Z_ARRVAL_P(stack), argc); @@ -3507,13 +3537,13 @@ static inline zval* find_packed_val_at_offset(HashTable* ht, zend_long offset) } /* Otherwise, this code has to iterate over the HashTable and skip holes in the array. */ pos = 0; - ZEND_HASH_FOREACH_VAL(ht, zv) { + ZEND_PACKED_FOREACH_VAL(ht, zv) { if (pos >= offset) { /* This is the bucket of the array element at the requested offset */ return zv; } ++pos; - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); /* Return a pointer to the end of the bucket array. */ return ht->arPacked + ht->nNumUsed; @@ -3657,7 +3687,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *src_entry, *dest_entry; zend_string *string_key; - ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { if (string_key) { if ((dest_entry = zend_hash_find_known_hash(dest, string_key)) != NULL) { zval *src_zval = src_entry; @@ -3714,7 +3744,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *zv = zend_hash_next_index_insert(dest, src_entry); zval_add_ref(zv); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return 1; } /* }}} */ @@ -3727,17 +3757,17 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ if (HT_IS_PACKED(dest) && HT_IS_PACKED(src)) { zend_hash_extend(dest, zend_hash_num_elements(dest) + zend_hash_num_elements(src), 1); ZEND_HASH_FILL_PACKED(dest) { - ZEND_HASH_FOREACH_VAL(src, src_entry) { + ZEND_PACKED_FOREACH_VAL(src, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry)) && UNEXPECTED(Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); } Z_TRY_ADDREF_P(src_entry); ZEND_HASH_FILL_ADD(src_entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); @@ -3748,7 +3778,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ } else { zend_hash_next_index_insert_new(dest, src_entry); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return 1; } @@ -3761,7 +3791,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * zend_ulong num_key; int ret; - ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { src_zval = src_entry; ZVAL_DEREF(src_zval); if (string_key) { @@ -3818,7 +3848,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * if (!ret) { return 0; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return 1; } @@ -3908,12 +3938,12 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET bool copy = 1; zend_string *string_key; - ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(ret), string_key) { + ZEND_ARRAY_FOREACH_STR_KEY(Z_ARRVAL_P(ret), string_key) { if (!string_key) { copy = 0; break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (copy) { ZVAL_COPY(return_value, ret); return; @@ -3930,14 +3960,14 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET if (HT_IS_PACKED(src)) { zend_hash_real_init_packed(dest); ZEND_HASH_FILL_PACKED(dest) { - ZEND_HASH_FOREACH_VAL(src, src_entry) { + ZEND_PACKED_FOREACH_VAL(src, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); } Z_TRY_ADDREF_P(src_entry); ZEND_HASH_FILL_ADD(src_entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { zend_string *string_key; @@ -4029,7 +4059,7 @@ PHP_FUNCTION(array_keys) array_init(return_value); if (strict) { - ZEND_HASH_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (fast_is_identical_function(search_value, entry)) { if (str_idx) { @@ -4039,9 +4069,9 @@ PHP_FUNCTION(array_keys) } zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &new_val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { - ZEND_HASH_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { if (fast_equal_check_function(search_value, entry)) { if (str_idx) { ZVAL_STR_COPY(&new_val, str_idx); @@ -4050,7 +4080,7 @@ PHP_FUNCTION(array_keys) } zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &new_val); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else { array_init_size(return_value, elem_count); @@ -4066,14 +4096,14 @@ PHP_FUNCTION(array_keys) } } else { /* Go through input array and add keys to the return array */ - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_idx, str_idx, entry) { if (str_idx) { ZEND_HASH_FILL_SET_STR_COPY(str_idx); } else { ZEND_HASH_FILL_SET_LONG(num_idx); } ZEND_HASH_FILL_NEXT(); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } ZEND_HASH_FILL_END(); } @@ -4143,13 +4173,13 @@ PHP_FUNCTION(array_values) /* Go through input array and add values to the return array */ ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_HASH_FOREACH_VAL(arrval, entry) { + ZEND_ARRAY_FOREACH_VAL(arrval, entry) { if (UNEXPECTED(Z_ISREF_P(entry) && Z_REFCOUNT_P(entry) == 1)) { entry = Z_REFVAL_P(entry); } Z_TRY_ADDREF_P(entry); ZEND_HASH_FILL_ADD(entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ZEND_HASH_FILL_END(); } /* }}} */ @@ -4171,7 +4201,7 @@ PHP_FUNCTION(array_count_values) /* Go through input array and add values to the return array */ myht = Z_ARRVAL_P(input); - ZEND_HASH_FOREACH_VAL(myht, entry) { + ZEND_ARRAY_FOREACH_VAL(myht, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) { @@ -4192,7 +4222,7 @@ PHP_FUNCTION(array_count_values) } else { php_error_docref(NULL, E_WARNING, "Can only count string and integer values, entry skipped"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -4267,7 +4297,7 @@ PHP_FUNCTION(array_column) if (index_is_null) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_HASH_FOREACH_VAL(input, data) { + ZEND_ARRAY_FOREACH_VAL(input, data) { ZVAL_DEREF(data); if (column_is_null) { Z_TRY_ADDREF_P(data); @@ -4276,10 +4306,10 @@ PHP_FUNCTION(array_column) continue; } ZEND_HASH_FILL_ADD(colval); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_HASH_FOREACH_VAL(input, data) { + ZEND_ARRAY_FOREACH_VAL(input, data) { ZVAL_DEREF(data); if (column_is_null) { @@ -4298,7 +4328,7 @@ PHP_FUNCTION(array_column) } else { zend_hash_next_index_insert(Z_ARRVAL_P(return_value), colval); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } /* }}} */ @@ -4323,17 +4353,17 @@ PHP_FUNCTION(array_reverse) if (HT_IS_PACKED(Z_ARRVAL_P(input)) && !preserve_keys) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_PACKED_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (UNEXPECTED(Z_ISREF_P(entry) && Z_REFCOUNT_P(entry) == 1)) { entry = Z_REFVAL_P(entry); } Z_TRY_ADDREF_P(entry); ZEND_HASH_FILL_ADD(entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_HASH_REVERSE_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { + ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { if (string_key) { entry = zend_hash_add_new(Z_ARRVAL_P(return_value), string_key, entry); } else { @@ -4344,7 +4374,7 @@ PHP_FUNCTION(array_reverse) } } zval_add_ref(entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } /* }}} */ @@ -4400,10 +4430,10 @@ PHP_FUNCTION(array_pad) } ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), value) { + ZEND_PACKED_FOREACH_VAL(Z_ARRVAL_P(input), value) { Z_TRY_ADDREF_P(value); ZEND_HASH_FILL_ADD(value); - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); } ZEND_HASH_FILL_END(); if (pad_size > 0) { @@ -4451,7 +4481,7 @@ PHP_FUNCTION(array_flip) array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if (str_idx) { @@ -4470,7 +4500,7 @@ PHP_FUNCTION(array_flip) } else { php_error_docref(NULL, E_WARNING, "Can only flip string and integer values, entry skipped"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -4491,7 +4521,7 @@ PHP_FUNCTION(array_change_key_case) array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) { if (!string_key) { entry = zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry); } else { @@ -4505,7 +4535,7 @@ PHP_FUNCTION(array_change_key_case) } zval_add_ref(entry); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -4554,7 +4584,7 @@ PHP_FUNCTION(array_unique) zend_hash_init(&seen, zend_hash_num_elements(Z_ARRVAL_P(array)), NULL, NULL, 0); array_init(return_value); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, str_key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, str_key, val) { zval *retval; if (Z_TYPE_P(val) == IS_STRING) { retval = zend_hash_add_empty_element(&seen, Z_STR_P(val)); @@ -4578,7 +4608,7 @@ PHP_FUNCTION(array_unique) zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, val); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_destroy(&seen); return; @@ -4704,7 +4734,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa array_init(return_value); /* Iterate over keys of the first array, to compute keys that are in all of the other arrays. */ - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -4739,7 +4769,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa zend_hash_add_new(Z_ARRVAL_P(return_value), key, val); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -5089,7 +5119,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty array_init(return_value); /* Iterate over keys of the first array, to compute keys that aren't in the other arrays. */ - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -5124,7 +5154,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty zend_hash_add_new(Z_ARRVAL_P(return_value), key, val); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -5429,9 +5459,9 @@ PHP_FUNCTION(array_diff) zend_string *search_str, *tmp_search_str; value = NULL; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[0]), value) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[0]), value) { break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (!value) { for (i = 1; i < argc; i++) { @@ -5451,7 +5481,7 @@ PHP_FUNCTION(array_diff) RETURN_THROWS(); } if (!found) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), value) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), value) { str = zval_get_tmp_string(value, &tmp_str); if (zend_string_equals(search_str, str)) { zend_tmp_string_release(tmp_str); @@ -5459,7 +5489,7 @@ PHP_FUNCTION(array_diff) break; } zend_tmp_string_release(tmp_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } @@ -5492,16 +5522,16 @@ PHP_FUNCTION(array_diff) /* create exclude map */ zend_hash_init(&exclude, num, NULL, NULL, 0); for (i = 1; i < argc; i++) { - ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), value) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), value) { str = zval_get_tmp_string(value, &tmp_str); zend_hash_add(&exclude, str, &dummy); zend_tmp_string_release(tmp_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* copy all elements of first array that are not in exclude set */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0]))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), idx, key, value) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), idx, key, value) { str = zval_get_tmp_string(value, &tmp_str); if (!zend_hash_exists(&exclude, str)) { if (key) { @@ -5512,7 +5542,7 @@ PHP_FUNCTION(array_diff) zval_add_ref(value); } zend_tmp_string_release(tmp_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_destroy(&exclude); } @@ -5814,7 +5844,7 @@ PHP_FUNCTION(array_rand) /* If less than 1/2 of elements are used, don't sample. Instead search for a * specific offset using linear scan. */ zend_long i = 0, randval = php_mt_rand_range(0, num_avail - 1); - ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { + ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { if (i == randval) { if (string_key) { RETURN_STR_COPY(string_key); @@ -5823,7 +5853,7 @@ PHP_FUNCTION(array_rand) } } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* Sample random buckets until we hit one that is not empty. @@ -5883,7 +5913,7 @@ PHP_FUNCTION(array_rand) ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { /* We can't use zend_hash_index_find() * because the array may have string keys or gaps. */ - ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { + ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { if (zend_bitset_in(bitset, i) ^ negative_bitset) { if (string_key) { ZEND_HASH_FILL_SET_STR_COPY(string_key); @@ -5893,7 +5923,7 @@ PHP_FUNCTION(array_rand) ZEND_HASH_FILL_NEXT(); } i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ZEND_HASH_FILL_END(); free_alloca(bitset, use_heap); @@ -5913,14 +5943,14 @@ PHP_FUNCTION(array_sum) ZVAL_LONG(return_value, 0); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) { continue; } ZVAL_COPY(&entry_n, entry); convert_scalar_to_number(&entry_n); fast_add_function(return_value, return_value, &entry_n); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -5941,7 +5971,7 @@ PHP_FUNCTION(array_product) return; } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) { continue; } @@ -5958,7 +5988,7 @@ PHP_FUNCTION(array_product) convert_to_double(return_value); convert_to_double(&entry_n); Z_DVAL_P(return_value) *= Z_DVAL(entry_n); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -6000,7 +6030,7 @@ PHP_FUNCTION(array_reduce) fci.retval = &retval; fci.param_count = 2; - ZEND_HASH_FOREACH_VAL(htbl, operand) { + ZEND_ARRAY_FOREACH_VAL(htbl, operand) { ZVAL_COPY_VALUE(&args[0], return_value); ZVAL_COPY(&args[1], operand); fci.params = args; @@ -6017,7 +6047,7 @@ PHP_FUNCTION(array_reduce) zval_ptr_dtor(&args[0]); RETURN_NULL(); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -6061,7 +6091,7 @@ PHP_FUNCTION(array_filter) } } - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) { if (have_callback) { if (use_type) { /* Set up the key */ @@ -6105,7 +6135,7 @@ PHP_FUNCTION(array_filter) operand = zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, operand); } zval_add_ref(operand); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ @@ -6146,7 +6176,7 @@ PHP_FUNCTION(array_map) array_init_size(return_value, maxlen); zend_hash_real_init(Z_ARRVAL_P(return_value), HT_IS_PACKED(Z_ARRVAL(arrays[0]))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { fci.retval = &result; fci.param_count = 1; fci.params = &arg; @@ -6163,7 +6193,7 @@ PHP_FUNCTION(array_map) } else { zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, &result); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { uint32_t *array_pos = (HashPosition *)ecalloc(n_arrays, sizeof(HashPosition)); @@ -6368,7 +6398,7 @@ PHP_FUNCTION(array_chunk) ZVAL_UNDEF(&chunk); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) { /* If new chunk, create and initialize it. */ if (Z_TYPE(chunk) == IS_UNDEF) { array_init_size(&chunk, (uint32_t)size); @@ -6392,7 +6422,7 @@ PHP_FUNCTION(array_chunk) add_next_index_zval(return_value, &chunk); ZVAL_UNDEF(&chunk); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Add the final chunk if there is one. */ if (Z_TYPE(chunk) != IS_UNDEF) { @@ -6427,7 +6457,7 @@ PHP_FUNCTION(array_combine) } array_init_size(return_value, num_keys); - ZEND_HASH_FOREACH_VAL(keys, entry_keys) { + ZEND_ARRAY_FOREACH_VAL(keys, entry_keys) { while (1) { if (pos_values >= values->nNumUsed) { break; @@ -6454,6 +6484,6 @@ PHP_FUNCTION(array_combine) } pos_values++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 73d92fd447f19..06b869e374ac0 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1069,14 +1069,14 @@ PHP_FUNCTION(getopt) argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0); /* Iterate over the hash to construct the argv array. */ - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), entry) { zend_string *tmp_arg_str; zend_string *arg_str = zval_get_tmp_string(entry, &tmp_arg_str); argv[pos++] = estrdup(ZSTR_VAL(arg_str)); zend_tmp_string_release(tmp_arg_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* The C Standard requires argv[argc] to be NULL - this might * keep some getopt implementations happy. */ @@ -1103,7 +1103,7 @@ PHP_FUNCTION(getopt) memset(opts, 0, count * sizeof(opt_struct)); /* Iterate over the hash to construct the argv array. */ - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(p_longopts), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(p_longopts), entry) { zend_string *tmp_arg_str; zend_string *arg_str = zval_get_tmp_string(entry, &tmp_arg_str); @@ -1122,7 +1122,7 @@ PHP_FUNCTION(getopt) opts++; zend_tmp_string_release(tmp_arg_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1)); orig_opts = opts; @@ -1383,9 +1383,9 @@ static void add_config_entries(HashTable *hash, zval *return_value) /* {{{ */ zend_string *key; zval *zv; - ZEND_HASH_FOREACH_KEY_VAL(hash, h, key, zv) + ZEND_ARRAY_FOREACH_KEY_VAL(hash, h, key, zv) add_config_entry(h, key, zv, return_value); - ZEND_HASH_FOREACH_END(); + ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index ab2ae983d76e2..f2e0125f1dcec 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -727,11 +727,11 @@ PHP_FUNCTION(get_browser) if (found_entry == NULL) { browscap_entry *entry; - ZEND_HASH_FOREACH_PTR(bdata->htab, entry) { + ZEND_ARRAY_FOREACH_PTR(bdata->htab, entry) { if (browser_reg_compare(entry, lookup_browser_name, &found_entry)) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (found_entry == NULL) { found_entry = zend_hash_str_find_ptr(bdata->htab, diff --git a/ext/standard/file.c b/ext/standard/file.c index 4c31ee0eae661..916ceaab1f4fb 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -675,7 +675,7 @@ PHP_FUNCTION(file_put_contents) ssize_t bytes_written; zval *tmp; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(data), tmp) { zend_string *t; zend_string *str = zval_get_tmp_string(tmp, &t); if (ZSTR_LEN(str)) { @@ -689,7 +689,7 @@ PHP_FUNCTION(file_put_contents) } } zend_tmp_string_release(t); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } break; @@ -1902,7 +1902,7 @@ PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, cha ZEND_ASSERT((escape_char >= 0 && escape_char <= UCHAR_MAX) || escape_char == PHP_CSV_NO_ESCAPE); count = zend_hash_num_elements(Z_ARRVAL_P(fields)); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) { zend_string *tmp_field_str; zend_string *field_str = zval_get_tmp_string(field_tmp, &tmp_field_str); @@ -1940,7 +1940,7 @@ PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, cha smart_str_appendl(&csvline, &delimiter, 1); } zend_tmp_string_release(tmp_field_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (eol_str) { smart_str_append(&csvline, eol_str); diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index b988422df21ca..98434fb3a114a 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -744,10 +744,10 @@ static zval *php_formatted_print_get_array(zend_array *array, int *argc) n = zend_hash_num_elements(array); args = (zval *)safe_emalloc(n, sizeof(zval), 0); n = 0; - ZEND_HASH_FOREACH_VAL(array, zv) { + ZEND_ARRAY_FOREACH_VAL(array, zv) { ZVAL_COPY_VALUE(&args[n], zv); n++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); *argc = n; return args; diff --git a/ext/standard/head.c b/ext/standard/head.c index ab64fecf381aa..2c822262ba7f6 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -198,7 +198,7 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_ zend_string *key; zval *value; - ZEND_HASH_FOREACH_STR_KEY_VAL(options, key, value) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(options, key, value) { if (!key) { zend_value_error("%s(): option array cannot have numeric keys", get_active_function_name()); return FAILURE; @@ -219,7 +219,7 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_ zend_value_error("%s(): option \"%s\" is invalid", get_active_function_name(), ZSTR_VAL(key)); return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } diff --git a/ext/standard/http.c b/ext/standard/http.c index e0e95d8d6d529..8f4b8ef452013 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -48,7 +48,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } arg_sep_len = strlen(arg_sep); - ZEND_HASH_FOREACH_KEY_VAL(ht, idx, key, zdata) { + ZEND_ARRAY_FOREACH_KEY_VAL(ht, idx, key, zdata) { bool is_dynamic = 1; if (Z_TYPE_P(zdata) == IS_INDIRECT) { zdata = Z_INDIRECT_P(zdata); @@ -215,7 +215,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index b5132d9e005a3..0821886ae7e56 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -256,7 +256,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, if (Z_TYPE_P(tmpzval) == IS_ARRAY) { zval *tmpheader = NULL; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { if (Z_TYPE_P(tmpheader) == IS_STRING) { s = Z_STRVAL_P(tmpheader); do { @@ -280,7 +280,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, while (*s == '\r' || *s == '\n') s++; } while (*s != 0); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else if (Z_TYPE_P(tmpzval) == IS_STRING && Z_STRLEN_P(tmpzval)) { s = Z_STRVAL_P(tmpzval); do { @@ -425,12 +425,12 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, zval *tmpheader = NULL; smart_str tmpstr = {0}; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { if (Z_TYPE_P(tmpheader) == IS_STRING) { smart_str_append(&tmpstr, Z_STR_P(tmpheader)); smart_str_appendl(&tmpstr, "\r\n", sizeof("\r\n") - 1); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_0(&tmpstr); /* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */ if (tmpstr.s) { diff --git a/ext/standard/info.c b/ext/standard/info.c index 395110d25f218..cf301a6d3536f 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -99,20 +99,22 @@ static ZEND_COLD void php_info_print_stream_hash(const char *name, HashTable *ht php_info_printf("\nRegistered %s => ", name); } - ZEND_HASH_FOREACH_STR_KEY(ht, key) { - if (key) { - if (first) { - first = 0; - } else { - php_info_print(", "); - } - if (!sapi_module.phpinfo_as_text) { - php_info_print_html_esc(ZSTR_VAL(key), ZSTR_LEN(key)); - } else { - php_info_print(ZSTR_VAL(key)); + if (!HT_IS_PACKED(ht)) { + ZEND_HASH_FOREACH_STR_KEY(ht, key) { + if (key) { + if (first) { + first = 0; + } else { + php_info_print(", "); + } + if (!sapi_module.phpinfo_as_text) { + php_info_print_html_esc(ZSTR_VAL(key), ZSTR_LEN(key)); + } else { + php_info_print(ZSTR_VAL(key)); + } } - } - } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } if (!sapi_module.phpinfo_as_text) { php_info_print("\n"); @@ -173,7 +175,7 @@ static ZEND_COLD void php_print_gpcse_array(char *name, uint32_t name_length) zend_is_auto_global(key); if ((data = zend_hash_find_deref(&EG(symbol_table), key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) { - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) { if (!sapi_module.phpinfo_as_text) { php_info_print(""); php_info_print(""); @@ -230,7 +232,7 @@ static ZEND_COLD void php_print_gpcse_array(char *name, uint32_t name_length) } else { php_info_print("\n"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } zend_string_efree(key); } diff --git a/ext/standard/mail.c b/ext/standard/mail.c index bc5a06bec9cc3..8e17065bee8fb 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -131,7 +131,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v zend_string *tmp_key; zval *tmp_val; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), tmp_key, tmp_val) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), tmp_key, tmp_val) { if (tmp_key) { zend_type_error("Header \"%s\" must only contain numeric keys, \"%s\" found", ZSTR_VAL(key), ZSTR_VAL(tmp_key)); break; @@ -141,7 +141,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v break; } php_mail_build_headers_elem(s, key, tmp_val); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } @@ -152,7 +152,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers) zval *val; smart_str s = {0}; - ZEND_HASH_FOREACH_KEY_VAL(headers, idx, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(headers, idx, key, val) { if (!key) { zend_type_error("Header name cannot be numeric, " ZEND_LONG_FMT " given", idx); break; @@ -188,7 +188,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers) smart_str_free(&s); return NULL; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Remove the last \r\n */ if (s.s) s.s->len -= 2; diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index a57e66bd97954..f9f4af2f010cd 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -161,7 +161,7 @@ static php_process_env _php_array_to_envp(zval *environment) zend_hash_init(env_hash, cnt, NULL, NULL, 0); /* first, we have to get the size of all the elements in the hash */ - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(environment), key, element) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(environment), key, element) { str = zval_get_string(element); if (ZSTR_LEN(str) == 0) { @@ -177,14 +177,14 @@ static php_process_env _php_array_to_envp(zval *environment) } else { zend_hash_next_index_insert_ptr(env_hash, str); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); #ifndef PHP_WIN32 ep = env.envarray = (char **) ecalloc(cnt + 1, sizeof(char *)); #endif p = env.envp = (char *) ecalloc(sizeenv + 4, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(env_hash, key, str) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(env_hash, key, str) { #ifndef PHP_WIN32 *ep = p; ++ep; @@ -200,7 +200,7 @@ static php_process_env _php_array_to_envp(zval *environment) p += ZSTR_LEN(str); *p++ = '\0'; zend_string_release_ex(str, 0); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); assert((uint32_t)(p - env.envp) <= sizeenv); @@ -524,7 +524,7 @@ static zend_string *create_win_command_from_args(HashTable *args) bool is_prog_name = 1; int elem_num = 0; - ZEND_HASH_FOREACH_VAL(args, arg_zv) { + ZEND_ARRAY_FOREACH_VAL(args, arg_zv) { zend_string *arg_str = get_valid_arg_string(arg_zv, ++elem_num); if (!arg_str) { smart_str_free(&str); @@ -539,7 +539,7 @@ static zend_string *create_win_command_from_args(HashTable *args) is_prog_name = 0; zend_string_release(arg_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_0(&str); return str.s; } @@ -620,7 +620,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n *argv = safe_emalloc(sizeof(char *), num_elems + 1, 0); - ZEND_HASH_FOREACH_VAL(array, arg_zv) { + ZEND_ARRAY_FOREACH_VAL(array, arg_zv) { zend_string *arg_str = get_valid_arg_string(arg_zv, i + 1); if (!arg_str) { /* Terminate with NULL so exit_fail code knows how many entries to free */ @@ -637,7 +637,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n (*argv)[i++] = estrdup(ZSTR_VAL(arg_str)); zend_string_release(arg_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); (*argv)[i] = NULL; return command; @@ -1088,7 +1088,7 @@ PHP_FUNCTION(proc_open) descriptors = alloc_descriptor_array(descriptorspec); /* Walk the descriptor spec and set up files/pipes */ - ZEND_HASH_FOREACH_KEY_VAL(descriptorspec, nindex, str_index, descitem) { + ZEND_ARRAY_FOREACH_KEY_VAL(descriptorspec, nindex, str_index, descitem) { if (str_index) { zend_argument_value_error(2, "must be an integer indexed array"); goto exit_fail; @@ -1110,7 +1110,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } ndesc++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); #ifdef PHP_WIN32 if (cwd == NULL) { diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index b68daace373c9..b0ee8d531f994 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -607,7 +607,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t return 0; } - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { /* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast() would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave the higher bits of a SOCKET variable uninitialized on systems with little endian. */ @@ -632,7 +632,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t } cnt++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return cnt ? 1 : 0; } @@ -650,7 +650,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds) } ht = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(stream_array))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { php_socket_t this_fd; ZVAL_DEREF(elem); @@ -676,7 +676,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds) continue; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* destroy old array and add new one */ zval_ptr_dtor(stream_array); @@ -699,7 +699,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) } ht = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(stream_array))); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { ZVAL_DEREF(elem); php_stream_from_zval_no_verify(stream, elem); if (stream == NULL) { @@ -721,7 +721,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) ret++; continue; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (ret > 0) { /* destroy old array and add new one */ @@ -891,19 +891,21 @@ static int parse_context_options(php_stream_context *context, HashTable *options zend_string *wkey, *okey; int ret = SUCCESS; - ZEND_HASH_FOREACH_STR_KEY_VAL(options, wkey, wval) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(options, wkey, wval) { ZVAL_DEREF(wval); if (wkey && Z_TYPE_P(wval) == IS_ARRAY) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) { - if (okey) { - php_stream_context_set_option(context, ZSTR_VAL(wkey), ZSTR_VAL(okey), oval); - } - } ZEND_HASH_FOREACH_END(); + if (!HT_IS_PACKED(Z_ARRVAL_P(wval))) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) { + if (okey) { + php_stream_context_set_option(context, ZSTR_VAL(wkey), ZSTR_VAL(okey), oval); + } + } ZEND_HASH_FOREACH_END(); + } } else { zend_value_error("Options should have the form [\"wrappername\"][\"optionname\"] = $value"); return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return ret; } diff --git a/ext/standard/string.c b/ext/standard/string.c index 0f29cbb038a73..a8463bc6bf025 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1156,14 +1156,14 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return RETURN_EMPTY_STRING(); } else if (numelems == 1) { /* loop to search the first not undefined element... */ - ZEND_HASH_FOREACH_VAL(pieces, tmp) { + ZEND_ARRAY_FOREACH_VAL(pieces, tmp) { RETURN_STR(zval_get_string(tmp)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } ptr = strings = do_alloca((sizeof(*strings)) * numelems, use_heap); - ZEND_HASH_FOREACH_VAL(pieces, tmp) { + ZEND_ARRAY_FOREACH_VAL(pieces, tmp) { if (EXPECTED(Z_TYPE_P(tmp) == IS_STRING)) { ptr->str = Z_STR_P(tmp); len += ZSTR_LEN(ptr->str); @@ -1188,7 +1188,7 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return ptr->lval = 1; ptr++; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* numelems cannot be 0, we checked above */ str = zend_string_safe_alloc(numelems - 1, ZSTR_LEN(glue), len, 0); @@ -2404,7 +2404,7 @@ PHP_FUNCTION(substr_replace) from_idx = len_idx = repl_idx = 0; - ZEND_HASH_FOREACH_KEY_VAL(str_ht, num_index, str_index, tmp_str) { + ZEND_ARRAY_FOREACH_KEY_VAL(str_ht, num_index, str_index, tmp_str) { zend_string *tmp_orig_str; zend_string *orig_str = zval_get_tmp_string(tmp_str, &tmp_orig_str); @@ -2556,7 +2556,7 @@ PHP_FUNCTION(substr_replace) } zend_tmp_string_release(tmp_orig_str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* if */ } /* }}} */ @@ -2846,7 +2846,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p memset(bitset, 0, sizeof(bitset)); /* check if original array has numeric keys */ - ZEND_HASH_FOREACH_STR_KEY(pats, str_key) { + ZEND_ARRAY_FOREACH_STR_KEY(pats, str_key) { if (UNEXPECTED(!str_key)) { num_keys = 1; } else { @@ -2868,13 +2868,13 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p num_bitset[len / sizeof(zend_ulong)] |= Z_UL(1) << (len % sizeof(zend_ulong)); bitset[((unsigned char)ZSTR_VAL(str_key)[0]) / sizeof(zend_ulong)] |= Z_UL(1) << (((unsigned char)ZSTR_VAL(str_key)[0]) % sizeof(zend_ulong)); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (UNEXPECTED(num_keys)) { zend_string *key_used; /* we have to rebuild HashTable with numeric keys */ zend_hash_init(&str_hash, zend_hash_num_elements(pats), NULL, NULL, 0); - ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { if (UNEXPECTED(!str_key)) { key_used = zend_long_to_str(num_key); len = ZSTR_LEN(key_used); @@ -2904,7 +2904,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p if (UNEXPECTED(!str_key)) { zend_string_release_ex(key_used, 0); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); pats = &str_hash; } @@ -3307,7 +3307,7 @@ PHP_FUNCTION(strtr) zend_string *str_key, *tmp_str, *replace, *tmp_replace; zval *entry; - ZEND_HASH_FOREACH_KEY_VAL(from_ht, num_key, str_key, entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(from_ht, num_key, str_key, entry) { tmp_str = NULL; if (UNEXPECTED(!str_key)) { str_key = tmp_str = zend_long_to_str(num_key); @@ -3332,7 +3332,7 @@ PHP_FUNCTION(strtr) zend_tmp_string_release(tmp_str); zend_tmp_string_release(tmp_replace); return; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { php_strtr_array(return_value, str, from_ht); } @@ -4187,7 +4187,7 @@ static zend_long php_str_replace_in_subject( } /* For each entry in the search array, get the entry */ - ZEND_HASH_FOREACH_VAL(search_ht, search_entry) { + ZEND_ARRAY_FOREACH_VAL(search_ht, search_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_search_str; zend_string *search_str = zval_get_tmp_string(search_entry, &tmp_search_str); @@ -4284,7 +4284,7 @@ static zend_long php_str_replace_in_subject( return replace_count; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ZVAL_STR(result, subject_str); if (lc_subject_str) { zend_string_release_ex(lc_subject_str, 0); @@ -4355,7 +4355,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { zend_string *tmp_subject_str; ZVAL_DEREF(subject_entry); subject_str = zval_get_tmp_string(subject_entry, &tmp_subject_str); @@ -4368,7 +4368,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit } else { zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, &result); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { /* if subject is not an array */ count = php_str_replace_in_subject(search_str, search_ht, replace_str, replace_ht, subject_str, return_value, case_sensitivity); } @@ -4660,13 +4660,13 @@ PHP_FUNCTION(strip_tags) zval *tmp; zend_string *tag; - ZEND_HASH_FOREACH_VAL(allow_ht, tmp) { + ZEND_ARRAY_FOREACH_VAL(allow_ht, tmp) { tag = zval_get_string(tmp); smart_str_appendc(&tags_ss, '<'); smart_str_append(&tags_ss, tag); smart_str_appendc(&tags_ss, '>'); zend_string_release(tag); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (tags_ss.s) { smart_str_0(&tags_ss); allowed_tags = ZSTR_VAL(tags_ss.s); @@ -4776,7 +4776,7 @@ PHP_FUNCTION(setlocale) for (uint32_t i = 0; i < num_args; i++) { if (Z_TYPE(args[i]) == IS_ARRAY) { zval *elem; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), elem) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), elem) { zend_string *result = try_setlocale_zval(cat, elem); if (EG(exception)) { RETURN_THROWS(); @@ -4784,7 +4784,7 @@ PHP_FUNCTION(setlocale) if (result) { RETURN_STR(result); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { zend_string *result = try_setlocale_zval(cat, &args[i]); if (EG(exception)) { diff --git a/ext/standard/url.c b/ext/standard/url.c index e3d95768fb019..c61c60eabcc22 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -707,7 +707,7 @@ PHP_FUNCTION(get_headers) array_init(return_value); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&stream->wrapperdata), hdr) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&stream->wrapperdata), hdr) { if (Z_TYPE_P(hdr) != IS_STRING) { continue; } @@ -738,7 +738,7 @@ PHP_FUNCTION(get_headers) goto no_name_header; } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); php_stream_close(stream); } diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 9bfd85c6518e5..f98e9067f409c 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -497,7 +497,7 @@ PHP_FUNCTION(stream_get_filters) filters_hash = php_get_stream_filters_hash(); - if (filters_hash) { + if (filters_hash && !HT_IS_PACKED(filters_hash)) { ZEND_HASH_FOREACH_STR_KEY(filters_hash, filter_name) { if (filter_name) { add_next_index_str(return_value, zend_string_copy(filter_name)); diff --git a/ext/standard/var.c b/ext/standard/var.c index ef4b019fb6e76..655196065aed4 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -134,9 +134,9 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ } count = zend_hash_num_elements(myht); php_printf("%sarray(%d) {\n", COMMON, count); - ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(myht, num, key, val) { php_array_element_dump(val, num, key, level); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -170,7 +170,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ zend_string *key; zval *val; - ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(myht, num, key, val) { zend_property_info *prop_info = NULL; if (Z_TYPE_P(val) == IS_INDIRECT) { @@ -183,7 +183,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ if (!Z_ISUNDEF_P(val) || prop_info) { php_object_property_dump(prop_info, val, num, key, level); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_release_properties(myht); } if (level > 1) { @@ -330,9 +330,9 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ } else { php_printf("array(%d) interned {\n", count); } - ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { zval_array_element_dump(val, index, key, level); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -356,7 +356,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ php_printf("object(%s)#%d (%d) refcount(%u){\n", ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0, Z_REFCOUNT_P(struc)); zend_string_release_ex(class_name, 0); if (myht) { - ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { zend_property_info *prop_info = NULL; if (Z_TYPE_P(val) == IS_INDIRECT) { @@ -369,7 +369,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ if (!Z_ISUNDEF_P(val) || prop_info) { zval_object_property_dump(prop_info, val, index, key, level); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_UNPROTECT_RECURSION(myht); zend_release_properties(myht); } @@ -537,9 +537,9 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */ buffer_append_spaces(buf, level - 1); } smart_str_appendl(buf, "array (\n", 8); - ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { php_array_element_export(val, index, key, level, buf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -588,9 +588,9 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */ if (myht) { if (!is_enum) { - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(myht, index, key, val) { php_object_element_export(val, index, key, level, buf); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } GC_TRY_UNPROTECT_RECURSION(myht); zend_release_properties(myht); @@ -856,7 +856,7 @@ static int php_var_serialize_get_sleep_props( zend_hash_init(ht, zend_hash_num_elements(sleep_retval), NULL, ZVAL_PTR_DTOR, 0); /* TODO: Rewrite this by fetching the property info instead of trying out different * name manglings? */ - ZEND_HASH_FOREACH_VAL_IND(sleep_retval, name_val) { + ZEND_ARRAY_FOREACH_VAL_IND(sleep_retval, name_val) { zend_string *name, *tmp_name, *priv_name, *prot_name; ZVAL_DEREF(name_val); @@ -912,7 +912,7 @@ static int php_var_serialize_get_sleep_props( php_error_docref(NULL, E_WARNING, "\"%s\" returned as member variable from __sleep() but does not exist", ZSTR_VAL(name)); zend_tmp_string_release(tmp_name); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_release_properties(props); return retval; @@ -928,7 +928,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable zval *data; zend_ulong index; - ZEND_HASH_FOREACH_KEY_VAL_IND(ht, index, key, data) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, index, key, data) { if (incomplete_class && zend_string_equals_literal(key, MAGIC_MEMBER)) { incomplete_class = 0; continue; @@ -963,7 +963,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable } else { php_var_serialize_intern(buf, data, var_hash); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } smart_str_appendc(buf, '}'); } @@ -1090,7 +1090,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ php_var_serialize_class_name(buf, &obj); smart_str_append_unsigned(buf, zend_hash_num_elements(Z_ARRVAL(retval))); smart_str_appendl(buf, ":{", 2); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(retval), index, key, data) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(retval), index, key, data) { if (!key) { php_var_serialize_long(buf, index); } else { @@ -1101,7 +1101,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ data = Z_REFVAL_P(data); } php_var_serialize_intern(buf, data, var_hash); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendc(buf, '}'); zval_ptr_dtor(&obj); @@ -1357,12 +1357,12 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co zval *entry; zend_string *lcname; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(classes), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(classes), entry) { convert_to_string(entry); lcname = zend_string_tolower(Z_STR_P(entry)); zend_hash_add_empty_element(class_hash, lcname); zend_string_release_ex(lcname, 0); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); /* Exception during string conversion. */ if (EG(exception)) { diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index acf73b8a7c68b..4de56b13d2923 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -774,13 +774,14 @@ static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options) zval *opt_val; zend_string *opt_name; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht_options, opt_name, opt_val) { - if (opt_name == NULL) { - continue; - } - _php_tidy_set_tidy_opt(doc, ZSTR_VAL(opt_name), opt_val); - } ZEND_HASH_FOREACH_END(); - + if (!HT_IS_PACKED(ht_options)) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht_options, opt_name, opt_val) { + if (opt_name == NULL) { + continue; + } + _php_tidy_set_tidy_opt(doc, ZSTR_VAL(opt_name), opt_val); + } ZEND_HASH_FOREACH_END(); + } return SUCCESS; } diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index f3af90cdd0e84..aa762e07b6871 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -168,7 +168,7 @@ PHP_METHOD(PhpToken, is) } else if (Z_TYPE_P(kind) == IS_ARRAY) { zval *id_zval = NULL, *entry; zend_string *text = NULL; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(kind), entry) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(kind), entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if (!id_zval) { @@ -194,7 +194,7 @@ PHP_METHOD(PhpToken, is) zend_argument_type_error(1, "must only have elements of type string|int, %s given", zend_zval_type_name(entry)); RETURN_THROWS(); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); RETURN_FALSE; } else { zend_argument_type_error(1, "must be of type string|int|array, %s given", zend_zval_type_name(kind)); @@ -435,12 +435,12 @@ void on_event( case ON_FEEDBACK: { HashTable *tokens_ht = Z_ARRVAL_P(ctx->tokens); zval *token_zv, *id_zv = NULL; - ZEND_HASH_REVERSE_FOREACH_VAL(tokens_ht, token_zv) { + ZEND_ARRAY_REVERSE_FOREACH_VAL(tokens_ht, token_zv) { id_zv = extract_token_id_to_replace(token_zv, text, length); if (id_zv) { break; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); ZEND_ASSERT(id_zv); ZVAL_LONG(id_zv, token); break; diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 5c73837c385a1..62c1d7ba7a63a 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -814,7 +814,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) zval tag; zval *curtag, *mytype, *myval; - ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) { + ZEND_ARRAY_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) { if ((mytype = zend_hash_str_find(Z_ARRVAL_P(curtag),"type", sizeof("type") - 1))) { if (zend_string_equals_literal(Z_STR_P(mytype), "cdata")) { if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) { @@ -828,7 +828,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) } } break; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (parser->level <= XML_MAXLEVEL && parser->level > 0 && (doprint || (! parser->skipwhite))) { array_init(&tag); diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index bb52f75ac2c2d..acc1724e36b9a 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -681,7 +681,7 @@ PHP_METHOD(XSLTProcessor, setParameter) RETURN_THROWS(); } - ZEND_HASH_FOREACH_STR_KEY_VAL(array_value, string_key, entry) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(array_value, string_key, entry) { zval tmp; zend_string *str; @@ -695,7 +695,7 @@ PHP_METHOD(XSLTProcessor, setParameter) } ZVAL_STR(&tmp, str); zend_hash_update(intern->parameter, string_key, &tmp); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); RETURN_TRUE; } else { if (!value) { @@ -771,7 +771,7 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) intern = Z_XSL_P(id); if (restrict_ht) { - ZEND_HASH_FOREACH_VAL(restrict_ht, entry) { + ZEND_ARRAY_FOREACH_VAL(restrict_ht, entry) { zend_string *str = zval_try_get_string(entry); if (UNEXPECTED(!str)) { return; @@ -779,7 +779,7 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_string_release(str); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); intern->registerPhpFunctions = 2; } else if (restrict_str) { diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index d0de996d99777..3ebb795604e57 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -510,9 +510,9 @@ PHP_RINIT_FUNCTION(zend_test) PHP_RSHUTDOWN_FUNCTION(zend_test) { zend_ulong objptr; - ZEND_HASH_FOREACH_NUM_KEY(&ZT_G(global_weakmap), objptr) { + ZEND_ARRAY_FOREACH_NUM_KEY(&ZT_G(global_weakmap), objptr) { zend_weakrefs_hash_del(&ZT_G(global_weakmap), (zend_object *)(uintptr_t)objptr); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_destroy(&ZT_G(global_weakmap)); return SUCCESS; } diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 81a23c48c8444..81445e85cbddc 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -810,7 +810,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_ zend_string **strings = emalloc(sizeof(zend_string *) * zend_hash_num_elements(dictionary)); zend_string **end, **ptr = strings - 1; - ZEND_HASH_FOREACH_VAL(dictionary, cur) { + ZEND_ARRAY_FOREACH_VAL(dictionary, cur) { size_t i; *++ptr = zval_get_string(cur); @@ -839,7 +839,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_ } *dictlen += ZSTR_LEN(*ptr) + 1; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); dictptr = *dict = emalloc(*dictlen); ptr = strings; diff --git a/main/output.c b/main/output.c index 3efc0294f85b8..0044750873e8d 100644 --- a/main/output.c +++ b/main/output.c @@ -560,11 +560,11 @@ PHPAPI int php_output_handler_start(php_output_handler *handler) } } if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { - ZEND_HASH_FOREACH_PTR(rconflicts, conflict) { + ZEND_ARRAY_FOREACH_PTR(rconflicts, conflict) { if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) { return FAILURE; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* zend_stack_push returns stack level */ handler->level = zend_stack_push(&OG(handlers), &handler); diff --git a/main/php_variables.c b/main/php_variables.c index 127196779f221..82b28d9e05379 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -691,7 +691,7 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) zend_ulong num_key; int globals_check = (dest == (&EG(symbol_table))); - ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { + ZEND_ARRAY_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { if (Z_TYPE_P(src_entry) != IS_ARRAY || (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL) || (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL) @@ -711,7 +711,7 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) SEPARATE_ARRAY(dest_entry); php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry)); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ diff --git a/main/streams/streams.c b/main/streams/streams.c index 883a31c5a6fa6..c06f1b7ed1a13 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -91,9 +91,9 @@ PHP_RSHUTDOWN_FUNCTION(streams) { zval *el; - ZEND_HASH_FOREACH_VAL(&EG(persistent_list), el) { + ZEND_ARRAY_FOREACH_VAL(&EG(persistent_list), el) { forget_persistent_resource_id_numbers(el); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return SUCCESS; } @@ -119,13 +119,13 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * * regular list; allowing the same resource in several entries in the * regular list causes trouble (see bug #54623) */ *stream = (php_stream*)le->ptr; - ZEND_HASH_FOREACH_PTR(&EG(regular_list), regentry) { + ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), regentry) { if (regentry->ptr == le->ptr) { GC_ADDREF(regentry); (*stream)->res = regentry; return PHP_STREAM_PERSISTENT_SUCCESS; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); GC_ADDREF(le); (*stream)->res = zend_register_resource(*stream, le_pstream); } diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index 96648f44372db..fbe3873e04189 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -278,11 +278,11 @@ char* fpm_php_get_string_from_table(zend_string *table, char *key) /* {{{ */ return NULL; } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) { if (str && !strncmp(ZSTR_VAL(str), key, ZSTR_LEN(str))) { return Z_STRVAL_P(tmp); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return NULL; } diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index e9a5884b728f2..2cd1cae554a0e 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -526,9 +526,9 @@ PHP_FUNCTION(phpdbg_get_executable) files = &files_tmp; zend_hash_init(files, 0, NULL, NULL, 0); - ZEND_HASH_FOREACH_VAL(Z_ARR_P(option_buffer), filename) { + ZEND_ARRAY_FOREACH_VAL(Z_ARR_P(option_buffer), filename) { zend_hash_add_empty_element(files, zval_get_string(filename)); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } else { GC_ADDREF(files); } diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c index 3780c89033553..098b0ce65ab6d 100644 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@ -97,13 +97,13 @@ PHPDBG_API void phpdbg_reset_breakpoints(void) /* {{{ */ { HashTable *table; - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) { + ZEND_ARRAY_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) { phpdbg_breakbase_t *brake; - ZEND_HASH_FOREACH_PTR(table, brake) { + ZEND_ARRAY_FOREACH_PTR(table, brake) { brake->hits = 0; - } ZEND_HASH_FOREACH_END(); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* }}} */ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle) /* {{{ */ @@ -125,10 +125,10 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ phpdbg_notice("Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); /* this only looks like magic, it isn't */ - ZEND_HASH_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) { + ZEND_ARRAY_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) { phpdbg_breakbase_t *brake; - ZEND_HASH_FOREACH_PTR(table, brake) { + ZEND_ARRAY_FOREACH_PTR(table, brake) { if (brake->id == id) { char *new_str = NULL; @@ -244,8 +244,8 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ } *str = new_str; } - } ZEND_HASH_FOREACH_END(); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if ((*str) && !(*str)[0]) { @@ -362,7 +362,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin master = zend_hash_str_add_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable)); } - ZEND_HASH_FOREACH_PTR(fileht, brake) { + ZEND_ARRAY_FOREACH_PTR(fileht, brake) { new_brake = *brake; new_brake.filename = estrndup(file, filelen); PHPDBG_BREAK_UNMAPPING(brake->id); @@ -370,7 +370,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin if (zend_hash_index_add_mem(master, brake->line, &new_brake, sizeof(phpdbg_breakfile_t))) { PHPDBG_BREAK_MAPPING(brake->id, master); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur); @@ -1431,11 +1431,11 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable if ((*table = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id))) { phpdbg_breakbase_t *brake; - ZEND_HASH_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) { + ZEND_ARRAY_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) { if (brake->id == id) { return brake; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return NULL; diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index 644668d8d14e5..f5a2cd2220631 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -205,7 +205,7 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ m = func ? func->common.num_args : 0; - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) { + ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) { if (j) { phpdbg_out(", "); } @@ -234,7 +234,7 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ php_printf("%s", arg_print); efree(arg_print); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); if (is_variadic) { phpdbg_out("]"); diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index e63ec89e557dc..c526d0e68e305 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -399,7 +399,7 @@ PHPDBG_INFO(classes) /* {{{ */ phpdbg_notice("User Classes (%d)", zend_hash_num_elements(&classes)); /* once added, assume that classes are stable... until shutdown. */ - ZEND_HASH_FOREACH_PTR(&classes, ce) { + ZEND_PACKED_FOREACH_PTR(&classes, ce) { phpdbg_print_class_name(ce); if (ce->parent) { @@ -416,7 +416,7 @@ PHPDBG_INFO(classes) /* {{{ */ } else { phpdbg_writeln("|---- no source code"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); zend_hash_destroy(&classes); @@ -442,7 +442,7 @@ PHPDBG_INFO(funcs) /* {{{ */ phpdbg_notice("User Functions (%d)", zend_hash_num_elements(&functions)); - ZEND_HASH_FOREACH_PTR(&functions, zf) { + ZEND_PACKED_FOREACH_PTR(&functions, zf) { zend_op_array *op_array = &zf->op_array; phpdbg_write("|-------- %s", op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}"); @@ -452,7 +452,7 @@ PHPDBG_INFO(funcs) /* {{{ */ } else { phpdbg_writeln(" (no source code)"); } - } ZEND_HASH_FOREACH_END(); + } ZEND_PACKED_FOREACH_END(); zend_hash_destroy(&functions); diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c index 344b9c73e476d..4304a5cc4d671 100644 --- a/sapi/phpdbg/phpdbg_utils.c +++ b/sapi/phpdbg/phpdbg_utils.c @@ -487,7 +487,7 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable if (new_index && index_len == 0) { zend_ulong numkey; zend_string *strkey; - ZEND_HASH_FOREACH_KEY_VAL_IND(parent, numkey, strkey, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL_IND(parent, numkey, strkey, zv) { if (i == len || (i == len - 1 && input[len - 1] == ']')) { char *key, *propkey; size_t namelen, keylen; @@ -538,7 +538,7 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable } else { /* Ignore silently */ } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); return ret; } else if (new_index) { char last_chr = last_index[index_len]; diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index 05155bdd069ee..bb2e94aaf47ad 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -628,9 +628,9 @@ void phpdbg_recurse_watch_element(phpdbg_watch_element *element) { zend_long idx; ZEND_ASSERT(element->watch->type == WATCH_ON_HASHTABLE); - ZEND_HASH_FOREACH_KEY_VAL(HT_WATCH_HT(element->watch), idx, str, zv) { + ZEND_ARRAY_FOREACH_KEY_VAL(HT_WATCH_HT(element->watch), idx, str, zv) { phpdbg_add_recursive_watch_from_ht(element, idx, str, zv); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } @@ -1017,7 +1017,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { phpdbg_btree_result *res = phpdbg_btree_find(&PHPDBG_G(watch_HashTables), (zend_ulong) HT_WATCH_HT(watch)); phpdbg_watch_ht_info *hti = res ? res->ptr : NULL; - ZEND_HASH_REVERSE_FOREACH_KEY_VAL(HT_WATCH_HT(watch), idx, str, zv) { + ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(HT_WATCH_HT(watch), idx, str, zv) { if (!str) { str = zend_long_to_str(idx); // TODO: hack, use proper int handling for name in parent } else { @@ -1035,7 +1035,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { phpdbg_notice("Element %.*s has been added to watchpoint", (int) ZSTR_LEN(str), ZSTR_VAL(str)); zend_string_release(str); PHPDBG_G(watchpoint_hit) = 1; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); break; } From 319383decae57cdd0ac02254f8fea9c456cdd4e2 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 27 Oct 2021 13:10:11 +0300 Subject: [PATCH 08/21] Use general hash/packed iterators --- ext/soap/php_encoding.c | 12 ++++++------ ext/soap/php_schema.c | 4 ++-- ext/soap/php_sdl.c | 40 ++++++++++++++++++++-------------------- ext/soap/soap.c | 12 ++++++------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index c35cbbfd7d9cb..ab14938480284 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -270,11 +270,11 @@ static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type) if (sdl && sdl->encoders) { encodePtr enc; - ZEND_HASH_FOREACH_PTR(sdl->encoders, enc) { + ZEND_ARRAY_FOREACH_PTR(sdl->encoders, enc) { if (strcmp(enc->details.type_str, type) == 0) { return enc; } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } return NULL; } @@ -1490,7 +1490,7 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z if (sdlType->attributes) { sdlAttributePtr attr; - ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(sdlType->attributes, attr) { if (attr->name) { xmlAttrPtr val = get_attribute(data->properties, attr->name); char *str_val = NULL; @@ -1524,7 +1524,7 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z set_zval_property(ret, attr->name, &data); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } else { ZVAL_NULL(ret); @@ -1888,7 +1888,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo sdlAttributePtr attr; zval *zattr, rv; - ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(sdlType->attributes, attr) { if (attr->name) { zattr = get_zval_property(data, attr->name, &rv); if (zattr) { @@ -1916,7 +1916,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlFreeNode(dummy); } } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } if (style == SOAP_ENCODED) { diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index 2d423e9d9b831..b2e3a8f507bba 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -2282,9 +2282,9 @@ void schema_pass2(sdlCtx *ctx) sdlTypePtr type; if (ctx->attributes) { - ZEND_HASH_FOREACH_PTR(ctx->attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(ctx->attributes, attr) { schema_attribute_fixup(ctx, attr); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (ctx->attributeGroups) { ZEND_HASH_FOREACH_PTR(ctx->attributeGroups, type) { diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index cb3cac6c75e36..e41296fcaec89 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -1982,13 +1982,13 @@ static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTab tmp_elements = emalloc(sizeof(HashTable)); zend_hash_init(tmp_elements, i, NULL, NULL, 0); - ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, tmp_encoders, tmp_types, out); ZVAL_LONG(&zv, i); zend_hash_str_add(tmp_elements, (char*)&tmp, sizeof(tmp), &zv); i--; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (type->attributes) { @@ -2001,10 +2001,10 @@ static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTab sdlAttributePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_attribute(tmp, tmp_encoders, out); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (type->model) { WSDL_CACHE_PUT_1(1, out); @@ -2040,13 +2040,13 @@ static void sdl_serialize_parameters(HashTable *ht, HashTable *tmp_encoders, Has sdlParamPtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(ht, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(ht, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_string(tmp->paramName, out); WSDL_CACHE_PUT_INT(tmp->order, out); sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out); sdl_serialize_type_ref(tmp->element, tmp_types, out); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } } @@ -2164,11 +2164,11 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zval zv; - ZEND_HASH_FOREACH_PTR(sdl->types, tmp) { + ZEND_ARRAY_FOREACH_PTR(sdl->types, tmp) { ZVAL_LONG(&zv, type_num); zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); ++type_num; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (sdl->elements) { @@ -2198,11 +2198,11 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s encodePtr tmp; zval zv; - ZEND_HASH_FOREACH_PTR(sdl->encoders, tmp) { + ZEND_ARRAY_FOREACH_PTR(sdl->encoders, tmp) { ZVAL_LONG(&zv, encoder_num); zend_hash_str_add(&tmp_encoders, (char*)&tmp, sizeof(tmp), &zv); ++encoder_num; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } enc = defaultEncoding; while (enc->details.type != END_KNOWN_TYPES) { @@ -2228,10 +2228,10 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (sdl->elements) { @@ -2248,10 +2248,10 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s encodePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_encoder(tmp, &tmp_types, out); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* serialize bindings */ @@ -2801,7 +2801,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, ptype->attributes = malloc(sizeof(HashTable)); zend_hash_init(ptype->attributes, zend_hash_num_elements(type->attributes), NULL, delete_attribute_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { pattr = make_persistent_sdl_attribute(tmp, ptr_map, bp_types, bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2809,7 +2809,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, } else { zend_hash_next_index_insert_ptr(ptype->attributes, pattr); } - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (type->model) { @@ -3010,7 +3010,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->encoders = malloc(sizeof(HashTable)); zend_hash_init(psdl->encoders, zend_hash_num_elements(sdl->encoders), NULL, delete_encoder_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { penc = make_persistent_sdl_encoder(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -3019,19 +3019,19 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) zend_hash_next_index_insert_ptr(psdl->encoders, penc); } zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), penc); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } /* do backpatching here */ if (zend_hash_num_elements(&bp_types)) { sdlTypePtr *tmp, ptype = NULL; - ZEND_HASH_FOREACH_PTR(&bp_types, tmp) { + ZEND_ARRAY_FOREACH_PTR(&bp_types, tmp) { if ((ptype = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { assert(0); } *tmp = ptype; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (zend_hash_num_elements(&bp_encoders)) { encodePtr *tmp, penc = NULL; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 7e135de967000..24a42344f08fc 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -3361,7 +3361,7 @@ static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, ch zend_string *param_name; zend_ulong param_index = i; - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) { + ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) { parameter = get_param(function, ZSTR_VAL(param_name), param_index, TRUE); if (style == SOAP_RPC) { param = serialize_parameter(parameter, data, i, ZSTR_VAL(param_name), use, method); @@ -3378,7 +3378,7 @@ static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, ch i++; param_index = i; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (use == SOAP_ENCODED && version == SOAP_1_2 && method != NULL) { xmlSetNsProp(method, body->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE)); @@ -4159,7 +4159,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * } else { i = 0; smart_str_appendl(buf, "list(", 5); - ZEND_HASH_FOREACH_PTR(function->responseParameters, param) { + ZEND_ARRAY_FOREACH_PTR(function->responseParameters, param) { if (i > 0) { smart_str_appendl(buf, ", ", 2); } @@ -4171,7 +4171,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, " $", 2); smart_str_appendl(buf, param->paramName, strlen(param->paramName)); i++; - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); smart_str_appendl(buf, ") ", 2); } } else { @@ -4380,7 +4380,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ if (type->attributes) { sdlAttributePtr attr; - ZEND_HASH_FOREACH_PTR(type->attributes, attr) { + ZEND_ARRAY_FOREACH_PTR(type->attributes, attr) { if (spaces.s) { smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s)); } @@ -4393,7 +4393,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ } smart_str_appends(buf, attr->name); smart_str_appendl(buf, ";\n", 2); - } ZEND_HASH_FOREACH_END(); + } ZEND_ARRAY_FOREACH_END(); } if (spaces.s) { smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s)); From 6092d79eded909ffc6282aae8718602f0d9f81de Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 28 Oct 2021 23:43:39 +0300 Subject: [PATCH 09/21] Micro-optimization of genral hash/packed array iteration macros ZEND_ARRAY_FOREACH... --- Zend/zend_hash.h | 74 ++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index b364ae3737f3d..0691b5b5f5d6c 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -1243,30 +1243,22 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _ptr = Z_PTR_P(_z); /* Common hash/packed array iterators */ -#define ZEND_ARRAY_FOREACH_FROM(_ht, indirect, _from) do { \ +#define ZEND_ARRAY_FOREACH(_ht, indirect) do { \ HashTable *__ht = (_ht); \ bool _is_packed = HT_IS_PACKED(__ht); \ - zval *__z; \ + zval *__z = __ht->arPacked; \ zend_ulong __h; \ zend_string *__key = NULL; \ - Bucket *_p = NULL; \ - uint32_t _idx = _from; \ - zval *_end; \ - if (_is_packed) { \ - __z = __ht->arPacked + _from; \ - _end = __ht->arPacked + __ht->nNumUsed; \ - } else { \ - __z = &__ht->arData[_from].val; \ - _end = &__ht->arData[__ht->nNumUsed].val; \ - } \ - while (__z != _end) { \ + uint32_t _idx = 0; \ + uint32_t _count = __ht->nNumUsed; \ + for (;_count > 0; _count--) { \ zval *_z = __z; \ if (_is_packed) { \ __z++; \ __h = _idx; \ _idx++; \ } else { \ - _p = (Bucket*)__z; \ + Bucket *_p = (Bucket*)__z; \ __z = &(_p + 1)->val; \ __h = _p->h; \ __key = _p->key; \ @@ -1274,40 +1266,36 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _z = Z_INDIRECT_P(_z); \ } \ } \ - (void) __h; (void) __key; (void) _p; (void) _idx; \ + (void) __h; (void) __key; (void) _idx; \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; -#define ZEND_ARRAY_FOREACH(_ht, indirect) ZEND_ARRAY_FOREACH_FROM(_ht, indirect, 0) - #define ZEND_ARRAY_REVERSE_FOREACH(_ht, indirect) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ - Bucket *_p = NULL; \ zval *_z; \ - zval *__z = NULL; \ zend_ulong __h; \ zend_string *__key = NULL; \ bool _is_packed = HT_IS_PACKED(__ht); \ - if (_is_packed) { \ - __z = __ht->arPacked + _idx; \ - } else { \ - _p = __ht->arData + _idx; \ - } \ + size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ + sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ + zval *__z = (zval*)(((char*)__ht->arPacked) + (_idx * _size)); \ for (;_idx > 0; _idx--) { \ if (_is_packed) { \ __z--; \ _z = __z; \ __h = _idx - 1; \ } else { \ + Bucket *_p = (Bucket*)__z; \ _p--; \ - _z = &_p->val; \ + __z = &_p->val; \ + _z = __z; \ __h = _p->h; \ __key = _p->key; \ if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ _z = Z_INDIRECT_P(_z); \ } \ } \ - (void) __h; (void) __key; (void) _p; (void) __z; \ + (void) __h; (void) __key; (void) __z; \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define ZEND_ARRAY_FOREACH_END() \ @@ -1316,32 +1304,19 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define _ZEND_ARRAY_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ - zval *_z, *_end; \ - size_t _size; \ - if (HT_IS_PACKED(_ht)) { \ - _z = __ht->arPacked; \ - _end = __ht->arPacked + __ht->nNumUsed; \ - _size = sizeof(zval); \ - } else {\ - _z = &__ht->arData->val; \ - _end = &__ht->arData[__ht->nNumUsed].val; \ - _size = sizeof(Bucket); \ - } \ - for (; _z != _end; _z = (zval*)(((char*)_z) + _size)) { \ + uint32_t _count = __ht->nNumUsed; \ + size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ + sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ + zval *_z = __ht->arPacked; \ + for (; _count > 0; _z = (zval*)(((char*)_z) + _size), _count--) { \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define _ZEND_ARRAY_REVERSE_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ - zval *_z; \ - size_t _size; \ - if (HT_IS_PACKED(__ht)) { \ - _z = __ht->arPacked + _idx; \ - _size = sizeof(zval); \ - } else { \ - _z = &__ht->arData[_idx].val; \ - _size = sizeof(Bucket); \ - } \ + size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ + sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ + zval *_z = (zval*)(((char*)__ht->arPacked) + (_idx * _size)); \ for (;_idx > 0; _idx--) { \ _z = (zval*)(((char*)_z) - _size); \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; @@ -1411,11 +1386,6 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _key = __key; \ _val = _z; -#define ZEND_ARRAY_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ - ZEND_ARRAY_FOREACH_FROM(ht, 0, _from); \ - _key = __key; \ - _val = _z; - #define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ _key = __key; \ From 718042a8691f51edcc6ade99159244ffe0140f3b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 29 Oct 2021 01:58:46 +0300 Subject: [PATCH 10/21] Fixed ARM64 JIT --- ext/opcache/jit/zend_jit_arm64.dasc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/jit/zend_jit_arm64.dasc b/ext/opcache/jit/zend_jit_arm64.dasc index 0d8224cf5acce..e8e778e8a0096 100644 --- a/ext/opcache/jit/zend_jit_arm64.dasc +++ b/ext/opcache/jit/zend_jit_arm64.dasc @@ -14436,7 +14436,7 @@ static int zend_jit_fe_fetch(dasm_State **Dst, const zend_op *opline, uint32_t o | GC_ADDREF REG0, TMP1w | SET_ZVAL_TYPE_INFO res_addr, IS_STRING_EX, TMP1w, TMP2 - if ((op1_info & MAY_BE_ARRAY_KEY_LONG) && MAY_BE_PACKED(op1_info)) { + if ((op1_info & MAY_BE_ARRAY_KEY_LONG) || MAY_BE_PACKED(op1_info)) { | b >3 |2: } From 8e33bf865964e0b85012fc4442c1e994f4d5f811 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 29 Oct 2021 15:05:10 +0300 Subject: [PATCH 11/21] Sparate ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT macros --- Zend/zend_hash.h | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 0691b5b5f5d6c..094542a3750de 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -1243,6 +1243,24 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _ptr = Z_PTR_P(_z); /* Common hash/packed array iterators */ + +#if 0 +# define ZEND_ARRAY_ELEMET_SIZE(__ht) \ + (HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket)) +#else /* optimized version */ +# define ZEND_ARRAY_ELEMET_SIZE(__ht) \ + (sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED)) +#endif + +#define ZEND_ARRAY_ELEMET(__ht, _idx, _size) \ + ((zval*)(((char*)(__ht)->arPacked) + ((_idx) * (_size)))) + +#define ZEND_ARRAY_NEXT_ELEMENT(_el, _size) \ + ((zval*)(((char*)(_el)) + (_size))) + +#define ZEND_ARRAY_PREV_ELEMENT(_el, _size) \ + ((zval*)(((char*)(_el)) - (_size))) + #define ZEND_ARRAY_FOREACH(_ht, indirect) do { \ HashTable *__ht = (_ht); \ bool _is_packed = HT_IS_PACKED(__ht); \ @@ -1276,9 +1294,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zend_ulong __h; \ zend_string *__key = NULL; \ bool _is_packed = HT_IS_PACKED(__ht); \ - size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ - sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ - zval *__z = (zval*)(((char*)__ht->arPacked) + (_idx * _size)); \ + size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ + zval *__z = ZEND_ARRAY_ELEMET(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ if (_is_packed) { \ __z--; \ @@ -1305,20 +1322,18 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define _ZEND_ARRAY_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ uint32_t _count = __ht->nNumUsed; \ - size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ - sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ + size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ zval *_z = __ht->arPacked; \ - for (; _count > 0; _z = (zval*)(((char*)_z) + _size), _count--) { \ + for (; _count > 0; _z = ZEND_ARRAY_NEXT_ELEMENT(_z, _size), _count--) { \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define _ZEND_ARRAY_REVERSE_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ - size_t _size = /*HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket);*/ \ - sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED); \ - zval *_z = (zval*)(((char*)__ht->arPacked) + (_idx * _size)); \ + size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ + zval *_z = ZEND_ARRAY_ELEMET(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ - _z = (zval*)(((char*)_z) - _size); \ + _z = ZEND_ARRAY_PREV_ELEMENT(_z, _size); \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define ZEND_ARRAY_FOREACH_VAL(ht, _val) \ From 7c6f54e895fa3a8c315826e3080711da3a6c9f01 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 1 Nov 2021 15:45:06 +0300 Subject: [PATCH 12/21] Rename ZEND_HASH_*_FOREACH_* iteration macros --- Zend/Optimizer/block_pass.c | 4 +- Zend/Optimizer/dfa_pass.c | 12 +- Zend/Optimizer/sccp.c | 10 +- Zend/Optimizer/zend_cfg.c | 8 +- Zend/Optimizer/zend_dump.c | 8 +- Zend/Optimizer/zend_inference.c | 4 +- Zend/Optimizer/zend_optimizer.c | 18 +- Zend/zend.c | 8 +- Zend/zend_API.c | 36 +- Zend/zend_alloc.c | 4 +- Zend/zend_ast.c | 8 +- Zend/zend_attributes.c | 12 +- Zend/zend_builtin_functions.c | 44 +- Zend/zend_closures.c | 2 +- Zend/zend_compile.c | 32 +- Zend/zend_enum.c | 4 +- Zend/zend_exceptions.c | 8 +- Zend/zend_execute.c | 4 +- Zend/zend_execute_API.c | 24 +- Zend/zend_generators.c | 4 +- Zend/zend_hash.c | 12 +- Zend/zend_hash.h | 638 +++++++++--------- Zend/zend_inheritance.c | 42 +- Zend/zend_ini.c | 4 +- Zend/zend_list.c | 4 +- Zend/zend_objects.c | 2 +- Zend/zend_opcode.c | 18 +- Zend/zend_vm_def.h | 26 +- Zend/zend_vm_execute.h | 32 +- Zend/zend_vm_trace_handlers.h | 2 +- Zend/zend_vm_trace_map.h | 2 +- Zend/zend_weakrefs.c | 12 +- ext/curl/interface.c | 12 +- ext/dom/node.c | 6 +- ext/dom/php_dom.c | 2 +- ext/dom/xpath.c | 4 +- ext/ffi/ffi.c | 86 +-- ext/filter/filter.c | 8 +- ext/gd/gd.c | 10 +- ext/hash/hash.c | 6 +- ext/imap/php_imap.c | 16 +- ext/intl/collator/collator_convert.c | 8 +- ext/intl/collator/collator_sort.c | 4 +- ext/intl/converter/converter.c | 8 +- .../dateformat/dateformat_format_object.cpp | 4 +- ext/intl/locale/locale_methods.c | 8 +- ext/intl/msgformat/msgformat_helpers.cpp | 4 +- ext/json/json_encoder.c | 4 +- ext/ldap/ldap.c | 4 +- ext/libxml/libxml.c | 4 +- ext/mbstring/mbstring.c | 24 +- ext/mysqli/mysqli.c | 4 +- ext/mysqli/mysqli_api.c | 4 +- ext/mysqli/mysqli_nonapi.c | 12 +- ext/mysqlnd/mysqlnd_debug.c | 2 +- ext/mysqlnd/mysqlnd_plugin.c | 2 +- ext/mysqlnd/mysqlnd_reverse_api.c | 2 +- ext/mysqlnd/mysqlnd_wireprotocol.c | 4 +- ext/mysqlnd/php_mysqlnd.c | 4 +- ext/odbc/php_odbc.c | 24 +- ext/opcache/ZendAccelerator.c | 88 +-- ext/opcache/jit/zend_jit.c | 14 +- ext/opcache/jit/zend_jit_disasm.c | 2 +- ext/opcache/zend_accelerator_module.c | 4 +- ext/opcache/zend_persist.c | 38 +- ext/opcache/zend_persist_calc.c | 28 +- ext/openssl/openssl.c | 44 +- ext/openssl/xp_ssl.c | 12 +- ext/pcntl/pcntl.c | 16 +- ext/pcre/php_pcre.c | 28 +- ext/pdo/pdo.c | 4 +- ext/pdo/pdo_dbh.c | 6 +- ext/pdo/pdo_stmt.c | 20 +- ext/pdo_pgsql/pgsql_driver.c | 4 +- ext/pgsql/pgsql.c | 36 +- ext/phar/phar.c | 14 +- ext/phar/phar_object.c | 14 +- ext/phar/stream.c | 8 +- ext/phar/util.c | 4 +- ext/reflection/php_reflection.c | 68 +- ext/session/php_session.h | 4 +- ext/session/session.c | 14 +- ext/snmp/snmp.c | 6 +- ext/soap/php_encoding.c | 76 +-- ext/soap/php_http.c | 2 +- ext/soap/php_packet_soap.c | 4 +- ext/soap/php_schema.c | 30 +- ext/soap/php_sdl.c | 114 ++-- ext/soap/soap.c | 82 +-- ext/sockets/conversions.c | 8 +- ext/sockets/sockets.c | 10 +- ext/sodium/libsodium.c | 4 +- ext/spl/php_spl.c | 14 +- ext/spl/spl_array.c | 4 +- ext/spl/spl_dllist.c | 4 +- ext/spl/spl_fixedarray.c | 16 +- ext/spl/spl_observer.c | 24 +- ext/sqlite3/sqlite3.c | 4 +- ext/standard/array.c | 228 +++---- ext/standard/basic_functions.c | 14 +- ext/standard/browscap.c | 4 +- ext/standard/file.c | 8 +- ext/standard/formatted_print.c | 4 +- ext/standard/head.c | 4 +- ext/standard/http.c | 4 +- ext/standard/http_fopen_wrapper.c | 8 +- ext/standard/info.c | 10 +- ext/standard/mail.c | 8 +- ext/standard/password.c | 2 +- ext/standard/proc_open.c | 20 +- ext/standard/streamsfuncs.c | 22 +- ext/standard/string.c | 40 +- ext/standard/url.c | 4 +- ext/standard/user_filters.c | 2 +- ext/standard/var.c | 40 +- ext/tidy/tidy.c | 2 +- ext/tokenizer/tokenizer.c | 8 +- ext/xml/xml.c | 4 +- ext/xsl/xsltprocessor.c | 10 +- ext/zend_test/test.c | 4 +- ext/zip/php_zip.c | 2 +- ext/zlib/zlib.c | 4 +- main/output.c | 4 +- main/php_ini.c | 4 +- main/php_variables.c | 4 +- main/rfc1867.c | 2 +- main/streams/streams.c | 8 +- sapi/apache2handler/apache_config.c | 4 +- sapi/apache2handler/sapi_apache2.c | 2 +- sapi/cgi/cgi_main.c | 2 +- sapi/cli/php_cli.c | 2 +- sapi/cli/php_cli_server.c | 2 +- sapi/fpm/fpm/fpm_main.c | 2 +- sapi/fpm/fpm/fpm_php.c | 4 +- sapi/phpdbg/phpdbg.c | 12 +- sapi/phpdbg/phpdbg_bp.c | 66 +- sapi/phpdbg/phpdbg_frame.c | 4 +- sapi/phpdbg/phpdbg_info.c | 22 +- sapi/phpdbg/phpdbg_print.c | 10 +- sapi/phpdbg/phpdbg_utils.c | 4 +- sapi/phpdbg/phpdbg_watch.c | 40 +- win32/registry.c | 4 +- 142 files changed, 1436 insertions(+), 1422 deletions(-) diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c index 92460ffa4b354..eac6d6b37aa73 100644 --- a/Zend/Optimizer/block_pass.c +++ b/Zend/Optimizer/block_pass.c @@ -1058,9 +1058,9 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array, zend_op uint32_t s = 0; ZEND_ASSERT(b->successors_count == (opline->opcode == ZEND_MATCH ? 1 : 2) + zend_hash_num_elements(jumptable)); - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_TO_OFFSET(opline, new_opcodes + blocks[b->successors[s++]].start); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); opline->extended_value = ZEND_OPLINE_TO_OFFSET(opline, new_opcodes + blocks[b->successors[s++]].start); break; } diff --git a/Zend/Optimizer/dfa_pass.c b/Zend/Optimizer/dfa_pass.c index b28e45abbd446..166580742b034 100644 --- a/Zend/Optimizer/dfa_pass.c +++ b/Zend/Optimizer/dfa_pass.c @@ -415,7 +415,7 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa) ZVAL_TRUE(&tmp); dst = zend_new_array(zend_hash_num_elements(src)); if (strict) { - ZEND_ARRAY_FOREACH_VAL(src, val) { + ZEND_HASH_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) == IS_STRING) { zend_hash_add(dst, Z_STR_P(val), &tmp); } else if (Z_TYPE_P(val) == IS_LONG) { @@ -425,16 +425,16 @@ int zend_dfa_optimize_calls(zend_op_array *op_array, zend_ssa *ssa) ok = 0; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { - ZEND_ARRAY_FOREACH_VAL(src, val) { + ZEND_HASH_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) != IS_STRING || ZEND_HANDLE_NUMERIC(Z_STR_P(val), idx)) { zend_array_destroy(dst); ok = 0; break; } zend_hash_add(dst, Z_STR_P(val), &tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (ok) { @@ -660,11 +660,11 @@ static void zend_ssa_replace_control_link(zend_op_array *op_array, zend_ssa *ssa { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)) == old->start) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) == old->start) { opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, dst->start); } diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c index dae98d35534b5..71aefe04a821a 100644 --- a/Zend/Optimizer/sccp.c +++ b/Zend/Optimizer/sccp.c @@ -587,7 +587,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) { } SEPARATE_ARRAY(result); - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(array), key, value) { if (key) { value = zend_hash_update(Z_ARR_P(result), key, value); } else { @@ -597,7 +597,7 @@ static inline zend_result ct_eval_add_array_unpack(zval *result, zval *array) { return FAILURE; } Z_TRY_ADDREF_P(value); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } @@ -767,7 +767,7 @@ static inline zend_result ct_eval_in_array(zval *result, uint32_t extended_value zval key_tmp; res = 0; - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { res = 1; @@ -2009,7 +2009,7 @@ static void join_hash_tables(HashTable *ret, HashTable *ht1, HashTable *ht2) zend_string *key; zval *val1, *val2; - ZEND_ARRAY_FOREACH_KEY_VAL(ht1, index, key, val1) { + ZEND_HASH_FOREACH_KEY_VAL(ht1, index, key, val1) { if (key) { val2 = zend_hash_find(ht2, key); } else { @@ -2023,7 +2023,7 @@ static void join_hash_tables(HashTable *ret, HashTable *ht1, HashTable *ht2) } Z_TRY_ADDREF_P(val1); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } static zend_result join_partial_arrays(zval *a, zval *b) diff --git a/Zend/Optimizer/zend_cfg.c b/Zend/Optimizer/zend_cfg.c index 9b63c83e21e5b..380286cc0bf56 100644 --- a/Zend/Optimizer/zend_cfg.c +++ b/Zend/Optimizer/zend_cfg.c @@ -401,9 +401,9 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, { HashTable *jumptable = Z_ARRVAL_P(CRT_CONSTANT(opline->op2)); zval *zv; - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { BB_START(ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); BB_START(ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)); BB_START(i + 1); break; @@ -574,9 +574,9 @@ ZEND_API void zend_build_cfg(zend_arena **arena, const zend_op_array *op_array, block->successors_count = (opline->opcode == ZEND_MATCH ? 1 : 2) + zend_hash_num_elements(jumptable); block->successors = zend_arena_calloc(arena, block->successors_count, sizeof(int)); - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { block->successors[s++] = block_map[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))]; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); block->successors[s++] = block_map[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)]; if (opline->opcode != ZEND_MATCH) { diff --git a/Zend/Optimizer/zend_dump.c b/Zend/Optimizer/zend_dump.c index c4f596768b9ef..41146bdad97ec 100644 --- a/Zend/Optimizer/zend_dump.c +++ b/Zend/Optimizer/zend_dump.c @@ -31,7 +31,7 @@ void zend_dump_ht(HashTable *ht) zval *val; bool first = 1; - ZEND_ARRAY_FOREACH_KEY_VAL(ht, index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(ht, index, key, val) { if (first) { first = 0; } else { @@ -44,7 +44,7 @@ void zend_dump_ht(HashTable *ht) } fprintf(stderr, " =>"); zend_dump_const(val); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } void zend_dump_const(const zval *zv) @@ -643,7 +643,7 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block zend_string *key; zend_ulong num_key; zval *zv; - ZEND_ARRAY_FOREACH_KEY_VAL(jumptable, num_key, key, zv) { + ZEND_HASH_FOREACH_KEY_VAL(jumptable, num_key, key, zv) { if (key) { fprintf(stderr, " \"%s\":", ZSTR_VAL(key)); } else { @@ -654,7 +654,7 @@ ZEND_API void zend_dump_op(const zend_op_array *op_array, const zend_basic_block } else { fprintf(stderr, " %04u,", (uint32_t)ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); fprintf(stderr, " default:"); } else { zend_dump_const(op); diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index 05393823567a3..7a3ec1a27b409 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -2031,14 +2031,14 @@ ZEND_API uint32_t ZEND_FASTCALL zend_array_type_info(const zval *zv) tmp |= MAY_BE_RCN; } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, str, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { if (str) { tmp |= MAY_BE_ARRAY_KEY_STRING; } else { tmp |= MAY_BE_ARRAY_KEY_LONG; } tmp |= 1 << (Z_TYPE_P(val) + MAY_BE_ARRAY_SHIFT); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (HT_IS_PACKED(ht)) { tmp &= ~(MAY_BE_ARRAY_NUMERIC_HASH|MAY_BE_ARRAY_STRING_HASH); } diff --git a/Zend/Optimizer/zend_optimizer.c b/Zend/Optimizer/zend_optimizer.c index 2c8de44aa47b8..caab99c98b5f7 100644 --- a/Zend/Optimizer/zend_optimizer.c +++ b/Zend/Optimizer/zend_optimizer.c @@ -676,9 +676,9 @@ void zend_optimizer_migrate_jump(zend_op_array *op_array, zend_op *new_opline, z { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, new_opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); new_opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, new_opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)); break; } @@ -722,9 +722,9 @@ void zend_optimizer_shift_jump(zend_op_array *op_array, zend_op *opline, uint32_ { HashTable *jumptable = Z_ARRVAL(ZEND_OP2_LITERAL(opline)); zval *zv; - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv)) - shiftlist[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, Z_LVAL_P(zv))]); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value) - shiftlist[ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, opline->extended_value)]); break; } @@ -1360,15 +1360,15 @@ void zend_foreach_op_array(zend_script *script, zend_op_array_func_t func, void zend_foreach_op_array_helper(&script->main_op_array, func, context); - ZEND_HASH_FOREACH_PTR(&script->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&script->function_table, op_array) { zend_foreach_op_array_helper(op_array, func, context); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY_PTR(&script->class_table, key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&script->class_table, key, ce) { if (ce->refcount > 1 && !zend_string_equals_ci(key, ce->name)) { continue; } - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->scope == ce && op_array->type == ZEND_USER_FUNCTION && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) { @@ -1516,11 +1516,11 @@ ZEND_API void zend_optimize_script(zend_script *script, zend_long optimization_l } } - ZEND_HASH_FOREACH_STR_KEY_PTR(&script->class_table, key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&script->class_table, key, ce) { if (ce->refcount > 1 && !zend_string_equals_ci(key, ce->name)) { continue; } - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, name, op_array) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->function_table, name, op_array) { if (op_array->scope != ce && op_array->type == ZEND_USER_FUNCTION) { zend_op_array *orig_op_array = zend_hash_find_ptr(&op_array->scope->function_table, name); diff --git a/Zend/zend.c b/Zend/zend.c index e2122292f24f7..52295761245f1 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -315,7 +315,7 @@ static void print_hash(smart_str *buf, HashTable *ht, int indent, bool is_object } smart_str_appends(buf, "(\n"); indent += PRINT_ZVAL_INDENT; - ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { + ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { for (i = 0; i < indent; i++) { smart_str_appendc(buf, ' '); } @@ -345,7 +345,7 @@ static void print_hash(smart_str *buf, HashTable *ht, int indent, bool is_object smart_str_appends(buf, "] => "); zend_print_zval_r_to_buf(buf, tmp, indent+PRINT_ZVAL_INDENT); smart_str_appends(buf, "\n"); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); indent -= PRINT_ZVAL_INDENT; for (i = 0; i < indent; i++) { smart_str_appendc(buf, ' '); @@ -361,7 +361,7 @@ static void print_flat_hash(smart_str *buf, HashTable *ht) /* {{{ */ zend_ulong num_key; int i = 0; - ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { + ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { if (i++ > 0) { smart_str_appendc(buf, ','); } @@ -373,7 +373,7 @@ static void print_flat_hash(smart_str *buf, HashTable *ht) /* {{{ */ } smart_str_appends(buf, "] => "); zend_print_flat_zval_r_to_buf(buf, tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 90f4d0bbf2087..cf643402722c5 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1285,7 +1285,7 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */ zval *value; EG(fake_scope) = Z_OBJCE_P(obj); - ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, value) { if (key) { write_property(zobj, key, value, NULL); } @@ -1321,7 +1321,7 @@ ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_ zend_hash_init(constants_table, zend_hash_num_elements(&class_type->constants_table), NULL, NULL, 0); zend_hash_extend(constants_table, zend_hash_num_elements(&class_type->constants_table), 0); - ZEND_HASH_FOREACH_STR_KEY_PTR(&class_type->constants_table, key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&class_type->constants_table, key, c) { if (Z_TYPE(c->value) == IS_CONSTANT_AST) { new_c = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant)); memcpy(new_c, c, sizeof(zend_class_constant)); @@ -1409,7 +1409,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) / } else { constants_table = &class_type->constants_table; } - ZEND_HASH_FOREACH_PTR(constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) { if (Z_TYPE(c->value) == IS_CONSTANT_AST) { val = &c->value; if (UNEXPECTED(zval_update_constant_ex(val, c->ce) != SUCCESS)) { @@ -1461,7 +1461,7 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) / } if (class_type->default_static_members_count) { - ZEND_HASH_FOREACH_PTR(&class_type->properties_info, prop_info) { + ZEND_HASH_MAP_FOREACH_PTR(&class_type->properties_info, prop_info) { if (prop_info->flags & ZEND_ACC_STATIC) { val = static_members_table + prop_info->offset; if (Z_TYPE_P(val) == IS_CONSTANT_AST @@ -1526,7 +1526,7 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti zend_string *key; zend_property_info *property_info; - ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, prop) { property_info = zend_get_property_info(object->ce, key, 1); if (property_info != ZEND_WRONG_PROPERTY_INFO && property_info && @@ -1558,7 +1558,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) zend_long h; zend_property_info *property_info; - ZEND_HASH_FOREACH_KEY_VAL(properties, h, key, prop) { + ZEND_HASH_MAP_FOREACH_KEY_VAL(properties, h, key, prop) { if (key) { if (ZSTR_VAL(key)[0] == '\0') { const char *class_name, *prop_name; @@ -2243,7 +2243,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ int class_count = 0; /* Collect extensions with request startup/shutdown handlers */ - ZEND_HASH_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { if (module->request_startup_func) { startup_count++; } @@ -2266,7 +2266,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ module_post_deactivate_handlers[post_deactivate_count] = NULL; startup_count = 0; - ZEND_HASH_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { if (module->request_startup_func) { module_request_startup_handlers[startup_count++] = module; } @@ -2279,7 +2279,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ } ZEND_HASH_FOREACH_END(); /* Collect internal classes with static members */ - ZEND_HASH_FOREACH_PTR(CG(class_table), ce) { + ZEND_HASH_MAP_FOREACH_PTR(CG(class_table), ce) { if (ce->type == ZEND_INTERNAL_CLASS && ce->default_static_members_count > 0) { class_count++; @@ -2292,7 +2292,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */ class_cleanup_handlers[class_count] = NULL; if (class_count) { - ZEND_HASH_FOREACH_PTR(CG(class_table), ce) { + ZEND_HASH_MAP_FOREACH_PTR(CG(class_table), ce) { if (ce->type == ZEND_INTERNAL_CLASS && ce->default_static_members_count > 0) { class_cleanup_handlers[--class_count] = ce; @@ -2981,7 +2981,7 @@ ZEND_API void zend_deactivate_modules(void) /* {{{ */ if (EG(full_tables_cleanup)) { zend_module_entry *module; - ZEND_HASH_REVERSE_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(&module_registry, module) { if (module->request_shutdown_func) { zend_try { module->request_shutdown_func(module->type, module->module_number); @@ -3009,12 +3009,12 @@ ZEND_API void zend_post_deactivate_modules(void) /* {{{ */ zval *zv; zend_string *key; - ZEND_HASH_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { if (module->post_deactivate_func) { module->post_deactivate_func(); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(&module_registry, key, zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL(&module_registry, key, zv) { module = Z_PTR_P(zv); if (module->type != MODULE_TEMPORARY) { break; @@ -3022,7 +3022,7 @@ ZEND_API void zend_post_deactivate_modules(void) /* {{{ */ module_destructor(module); free(module); zend_string_release_ex(key, 0); - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } else { zend_module_entry **p = module_post_deactivate_handlers; @@ -3267,14 +3267,14 @@ ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_nam INIT_CLASS_ENTRY_INIT_METHODS((*disabled_class), disabled_class_new); disabled_class->create_object = display_disabled_class; - ZEND_HASH_FOREACH_PTR(&disabled_class->function_table, fn) { + ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->function_table, fn) { if ((fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) && fn->common.scope == disabled_class) { zend_free_internal_arg_info(&fn->internal_function); } } ZEND_HASH_FOREACH_END(); zend_hash_clean(&disabled_class->function_table); - ZEND_HASH_FOREACH_PTR(&disabled_class->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->properties_info, prop) { if (prop->ce == disabled_class) { zend_string_release(prop->name); zend_type_release(prop->type, /* persistent */ 1); @@ -3919,7 +3919,7 @@ ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args)); fci->params = params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval)); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), arg) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), arg) { if (func && !Z_ISREF_P(arg) && ARG_SHOULD_BE_SENT_BY_REF(func, n)) { ZVAL_NEW_REF(params, arg); Z_TRY_ADDREF_P(arg); @@ -3928,7 +3928,7 @@ ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function } params++; n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 5e02856d45f52..aa0fe9fad5908 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2798,10 +2798,10 @@ static void *tracked_realloc(void *ptr, size_t new_size) { static void tracked_free_all() { HashTable *tracked_allocs = AG(mm_heap)->tracked_allocs; zend_ulong h; - ZEND_ARRAY_FOREACH_NUM_KEY(tracked_allocs, h) { + ZEND_HASH_FOREACH_NUM_KEY(tracked_allocs, h) { void *ptr = (void *) (uintptr_t) (h << ZEND_MM_ALIGNMENT_LOG2); free(ptr); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } #endif diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 34bd2dfc6d889..a064927f93a87 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -460,7 +460,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) { zval *val; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { if (key) { zend_hash_update(Z_ARRVAL_P(result), key, val); } else { @@ -471,7 +471,7 @@ static zend_result zend_ast_add_unpacked_element(zval *result, zval *expr) { } } Z_TRY_ADDREF_P(val); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } @@ -1418,7 +1418,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit zval *val; bool first = true; smart_str_appendc(str, '['); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(zv), idx, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(zv), idx, key, val) { if (first) { first = false; } else { @@ -1433,7 +1433,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, zval *zv, int priorit smart_str_appends(str, " => "); } zend_ast_export_zval(str, val, 0, indent); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendc(str, ']'); break; } diff --git a/Zend/zend_attributes.c b/Zend/zend_attributes.c index a4c71c738b1cc..28c4a4483637b 100644 --- a/Zend/zend_attributes.c +++ b/Zend/zend_attributes.c @@ -78,11 +78,11 @@ static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, if (attributes) { zend_attribute *attr; - ZEND_PACKED_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, lcname)) { return attr; } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return NULL; @@ -93,13 +93,13 @@ static zend_attribute *get_attribute_str(HashTable *attributes, const char *str, if (attributes) { zend_attribute *attr; - ZEND_PACKED_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && ZSTR_LEN(attr->lcname) == len) { if (0 == memcmp(ZSTR_VAL(attr->lcname), str, len)) { return attr; } } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return NULL; @@ -173,13 +173,13 @@ ZEND_API bool zend_is_attribute_repeated(HashTable *attributes, zend_attribute * { zend_attribute *other; - ZEND_PACKED_FOREACH_PTR(attributes, other) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, other) { if (other != attr && other->offset == attr->offset) { if (zend_string_equals(other->lcname, attr->lcname)) { return 1; } } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 0; } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 53e861383a660..89475235d818e 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -418,7 +418,7 @@ static bool validate_constant_array_argument(HashTable *ht, int argument_number) zval *val; GC_PROTECT_RECURSION(ht); - ZEND_ARRAY_FOREACH_VAL(ht, val) { + ZEND_HASH_FOREACH_VAL(ht, val) { ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_ARRAY && Z_REFCOUNTED_P(val)) { if (Z_IS_RECURSIVE_P(val)) { @@ -430,7 +430,7 @@ static bool validate_constant_array_argument(HashTable *ht, int argument_number) break; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_UNPROTECT_RECURSION(ht); return ret; } @@ -443,7 +443,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */ zval *new_val, *val; array_init_size(dst, zend_hash_num_elements(Z_ARRVAL_P(src))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(src), idx, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(src), idx, key, val) { /* constant arrays can't contain references */ ZVAL_DEREF(val); if (key) { @@ -458,7 +458,7 @@ static void copy_constant_array(zval *dst, zval *src) /* {{{ */ } else { Z_TRY_ADDREF_P(val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -669,7 +669,7 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s zend_string *key; zval *default_properties_table = CE_DEFAULT_PROPERTIES_TABLE(ce); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { if (((prop_info->flags & ZEND_ACC_PROTECTED) && !zend_check_protected(prop_info->ce, scope)) || ((prop_info->flags & ZEND_ACC_PRIVATE) && @@ -758,7 +758,7 @@ ZEND_FUNCTION(get_object_vars) } else { array_init_size(return_value, zend_hash_num_elements(properties)); - ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, value) { + ZEND_HASH_MAP_FOREACH_KEY_VAL(properties, num_key, key, value) { bool is_dynamic = 1; if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); @@ -838,7 +838,7 @@ ZEND_FUNCTION(get_class_methods) array_init(return_value); scope = zend_get_executed_scope(); - ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) || (scope && (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) && @@ -1094,7 +1094,7 @@ ZEND_FUNCTION(get_included_files) ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&EG(included_files), entry) { if (entry) { add_next_index_str(return_value, zend_string_copy(entry)); } @@ -1248,7 +1248,7 @@ static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int fla array_init(return_value); zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_HASH_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { ce = Z_PTR_P(zv); if ((ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags && key @@ -1309,7 +1309,7 @@ ZEND_FUNCTION(get_defined_functions) array_init(&user); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), key, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(function_table), key, func) { if (key && ZSTR_VAL(key)[0] != 0) { if (func->type == ZEND_INTERNAL_FUNCTION) { add_next_index_str(&internal, zend_string_copy(key)); @@ -1399,20 +1399,20 @@ ZEND_FUNCTION(get_resources) if (!type) { array_init(return_value); - ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (zend_string_equals_literal(type, "Unknown")) { array_init(return_value); - ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) <= 0) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { int id = zend_fetch_list_dtor_id(ZSTR_VAL(type)); @@ -1422,12 +1422,12 @@ ZEND_FUNCTION(get_resources) } array_init(return_value); - ZEND_ARRAY_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) == id) { Z_ADDREF_P(val); zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ @@ -1455,7 +1455,7 @@ ZEND_FUNCTION(get_loaded_extensions) } else { zend_module_entry *module; - ZEND_HASH_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { add_next_index_string(return_value, module->name); } ZEND_HASH_FOREACH_END(); } @@ -1485,13 +1485,13 @@ ZEND_FUNCTION(get_defined_constants) module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *)); module_names[0] = "internal"; - ZEND_HASH_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { module_names[module->module_number] = (char *)module->name; i++; } ZEND_HASH_FOREACH_END(); module_names[i] = "user"; - ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), val) { if (!val->name) { /* skip special constants */ continue; @@ -1521,7 +1521,7 @@ ZEND_FUNCTION(get_defined_constants) zend_constant *constant; zval const_val; - ZEND_HASH_FOREACH_PTR(EG(zend_constants), constant) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) { if (!constant->name) { /* skip special constants */ continue; @@ -1606,7 +1606,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) / zend_string *name; zval *arg; SEPARATE_ARRAY(arg_array); - ZEND_HASH_FOREACH_STR_KEY_VAL(call->extra_named_params, name, arg) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(call->extra_named_params, name, arg) { ZVAL_DEREF(arg); Z_TRY_ADDREF_P(arg); zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg); @@ -1902,7 +1902,7 @@ ZEND_FUNCTION(get_extension_funcs) array = 0; } - ZEND_HASH_FOREACH_PTR(CG(function_table), zif) { + ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), zif) { if (zif->common.type == ZEND_INTERNAL_FUNCTION && zif->internal_function.module == module) { if (!array) { diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index e2ea9eacc34d2..122931ff7aebb 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -560,7 +560,7 @@ static HashTable *zend_closure_get_debug_info(zend_object *object, int *is_temp) array_init(&val); - ZEND_HASH_FOREACH_STR_KEY_VAL(static_variables, key, var) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(static_variables, key, var) { zval copy; if (Z_TYPE_P(var) == IS_CONSTANT_AST) { diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 9c7535a99c553..09ad2b3854728 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1728,7 +1728,7 @@ ZEND_API void zend_activate_auto_globals(void) /* {{{ */ { zend_auto_global *auto_global; - ZEND_HASH_FOREACH_PTR(CG(auto_globals), auto_global) { + ZEND_HASH_MAP_FOREACH_PTR(CG(auto_globals), auto_global) { if (auto_global->jit) { auto_global->armed = 1; } else if (auto_global->auto_global_callback) { @@ -4079,7 +4079,7 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args ZVAL_TRUE(&tmp); if (strict) { - ZEND_ARRAY_FOREACH_VAL(src, val) { + ZEND_HASH_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) == IS_STRING) { zend_hash_add(dst, Z_STR_P(val), &tmp); } else if (Z_TYPE_P(val) == IS_LONG) { @@ -4089,9 +4089,9 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args ok = 0; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { - ZEND_ARRAY_FOREACH_VAL(src, val) { + ZEND_HASH_FOREACH_VAL(src, val) { if (Z_TYPE_P(val) != IS_STRING || is_numeric_string(Z_STRVAL_P(val), Z_STRLEN_P(val), NULL, NULL, 0)) { zend_array_destroy(dst); @@ -4099,7 +4099,7 @@ static zend_result zend_compile_func_in_array(znode *result, zend_ast_list *args break; } zend_hash_add(dst, Z_STR_P(val), &tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } zend_array_destroy(src); @@ -5765,7 +5765,7 @@ static void zend_compile_try(zend_ast *ast) /* {{{ */ /* label: try { } must not be equal to try { label: } */ if (CG(context).labels) { zend_label *label; - ZEND_HASH_REVERSE_FOREACH_PTR(CG(context).labels, label) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(CG(context).labels, label) { if (label->opline_num == get_next_op_number()) { zend_emit_op(NULL, ZEND_NOP, NULL, NULL); } @@ -6437,7 +6437,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3 } /* Validate attributes in a secondary loop (needed to detect repeated attributes). */ - ZEND_PACKED_FOREACH_PTR(*attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(*attributes, attr) { if (attr->offset != offset || NULL == (config = zend_internal_attribute_get(attr->lcname))) { continue; } @@ -6460,7 +6460,7 @@ static void zend_compile_attributes(HashTable **attributes, zend_ast *ast, uint3 if (config->validator != NULL) { config->validator(attr, target, CG(active_class_entry)); } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6878,7 +6878,7 @@ static void compile_implicit_lexical_binds( op_array->static_variables = zend_new_array(8); } - ZEND_HASH_FOREACH_STR_KEY(&info->uses, var_name) + ZEND_HASH_MAP_FOREACH_STR_KEY(&info->uses, var_name) zval *value = zend_hash_add( op_array->static_variables, var_name, &EG(uninitialized_zval)); uint32_t offset = (uint32_t)((char*)value - (char*)op_array->static_variables->arData); @@ -6927,7 +6927,7 @@ static void zend_compile_closure_uses(zend_ast *ast) /* {{{ */ static void zend_compile_implicit_closure_uses(closure_info *info) { zend_string *var_name; - ZEND_HASH_FOREACH_STR_KEY(&info->uses, var_name) + ZEND_HASH_MAP_FOREACH_STR_KEY(&info->uses, var_name) zval zv; ZVAL_NULL(&zv); zend_compile_static_var_common(var_name, &zv, ZEND_BIND_IMPLICIT); @@ -8402,7 +8402,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ zval *val; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { if (key) { zend_hash_update(Z_ARRVAL_P(result), key, val); } else if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), val)) { @@ -8410,7 +8410,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ return 0; } Z_TRY_ADDREF_P(val); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); continue; } else { @@ -8954,22 +8954,22 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */ opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &assign_node, NULL); SET_NODE(opline->result, result); - ZEND_ARRAY_FOREACH_PTR(CG(memoized_exprs), node) { + ZEND_HASH_FOREACH_PTR(CG(memoized_exprs), node) { if (node->op_type == IS_TMP_VAR || node->op_type == IS_VAR) { need_frees = 1; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Free DUPed expressions if there are any */ if (need_frees) { uint32_t jump_opnum = zend_emit_jump(0); zend_update_jump_target_to_next(coalesce_opnum); - ZEND_ARRAY_FOREACH_PTR(CG(memoized_exprs), node) { + ZEND_HASH_FOREACH_PTR(CG(memoized_exprs), node) { if (node->op_type == IS_TMP_VAR || node->op_type == IS_VAR) { zend_emit_op(NULL, ZEND_FREE, node, NULL); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_update_jump_target_to_next(jump_opnum); } else { zend_update_jump_target_to_next(coalesce_opnum); diff --git a/Zend/zend_enum.c b/Zend/zend_enum.c index 4494782d565c1..ab4e6e4e6f938 100644 --- a/Zend/zend_enum.c +++ b/Zend/zend_enum.c @@ -53,7 +53,7 @@ static void zend_verify_enum_properties(zend_class_entry *ce) { zend_property_info *property_info; - ZEND_HASH_FOREACH_PTR(&ce->properties_info, property_info) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, property_info) { if (zend_string_equals_literal(property_info->name, "name")) { continue; } @@ -192,7 +192,7 @@ static ZEND_NAMED_FUNCTION(zend_enum_cases_func) array_init(return_value); - ZEND_HASH_FOREACH_PTR(CE_CONSTANTS_TABLE(ce), c) { + ZEND_HASH_MAP_FOREACH_PTR(CE_CONSTANTS_TABLE(ce), c) { if (!(ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE)) { continue; } diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index d7c98d0f925d6..da4b664981f19 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -566,13 +566,13 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* zend_string *name; zval *arg; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), name, arg) { if (name) { smart_str_append(str, name); smart_str_appends(str, ": "); } _build_trace_args(arg, str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (last_len != ZSTR_LEN(str->s)) { ZSTR_LEN(str->s) -= 2; /* remove last ', ' */ @@ -591,14 +591,14 @@ ZEND_API zend_string *zend_trace_to_string(HashTable *trace, bool include_main) uint32_t num = 0; smart_str str = {0}; - ZEND_ARRAY_FOREACH_NUM_KEY_VAL(trace, index, frame) { + ZEND_HASH_FOREACH_NUM_KEY_VAL(trace, index, frame) { if (Z_TYPE_P(frame) != IS_ARRAY) { zend_error(E_WARNING, "Expected array for frame " ZEND_ULONG_FMT, index); continue; } _build_trace_string(&str, Z_ARRVAL_P(frame), num++); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (include_main) { smart_str_appendc(&str, '#'); diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 31ca08a2ce932..dce0f32e835ff 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1224,7 +1224,7 @@ static void zend_verify_internal_func_info(zend_function *fn, zval *retval) { uint32_t num_checked = 0; zend_string *str; zval *val; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, str, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str, val) { if (str) { if (!(type_mask & MAY_BE_ARRAY_KEY_STRING)) { zend_error_noreturn(E_CORE_ERROR, @@ -1248,7 +1248,7 @@ static void zend_verify_internal_func_info(zend_function *fn, zval *retval) { if (++num_checked > 16) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } #endif } diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 996673a36b8c0..96ee0f33c3d0f 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -280,7 +280,7 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown) if (EG(full_tables_cleanup)) { zend_hash_reverse_apply(EG(zend_constants), clean_non_persistent_constant_full); } else { - ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(zend_constants), key, zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL(EG(zend_constants), key, zv) { zend_constant *c = Z_PTR_P(zv); if (_idx == EG(persistent_constants_count)) { break; @@ -291,12 +291,12 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown) } efree(c); zend_string_release_ex(key, 0); - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } /* Release static properties and static variables prior to the final GC run, * as they may hold GC roots. */ - ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(function_table), zv) { zend_op_array *op_array = Z_PTR_P(zv); if (op_array->type == ZEND_INTERNAL_FUNCTION) { break; @@ -309,7 +309,7 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown) } } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) { zend_class_entry *ce = Z_PTR_P(zv); if (ce->default_static_members_count) { @@ -323,7 +323,7 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown) } else if (ce->type == ZEND_USER_CLASS && !(ce->ce_flags & ZEND_ACC_IMMUTABLE)) { /* Constants may contain objects, destroy the values before the object store. */ zend_class_constant *c; - ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { if (c->ce == ce) { zval_ptr_dtor_nogc(&c->value); ZVAL_UNDEF(&c->value); @@ -333,7 +333,7 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown) if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) { zend_op_array *op_array; - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->type == ZEND_USER_FUNCTION) { if (ZEND_MAP_PTR(op_array->static_variables_ptr)) { HashTable *ht = ZEND_MAP_PTR_GET(op_array->static_variables_ptr); @@ -412,22 +412,22 @@ void shutdown_executor(void) /* {{{ */ zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function_full); zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class_full); } else { - ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(function_table), key, zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL(EG(function_table), key, zv) { zend_function *func = Z_PTR_P(zv); if (_idx == EG(persistent_functions_count)) { break; } destroy_op_array(&func->op_array); zend_string_release_ex(key, 0); - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); - ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { if (_idx == EG(persistent_classes_count)) { break; } destroy_zend_class(zv); zend_string_release_ex(key, 0); - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } while (EG(symtable_cache_ptr) > EG(symtable_cache)) { @@ -816,7 +816,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_ zval *arg; uint32_t arg_num = ZEND_CALL_NUM_ARGS(call) + 1; bool have_named_params = 0; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(fci->named_params, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(fci->named_params, name, arg) { bool must_wrap = 0; zval *target; if (name) { @@ -867,7 +867,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_ ZEND_CALL_NUM_ARGS(call)++; arg_num++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_MAY_HAVE_UNDEF)) { diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index fa64f8c3560fa..965b9edb60b8f 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -171,10 +171,10 @@ static void zend_generator_remove_child(zend_generator_node *node, zend_generato zend_hash_index_del(ht, (zend_ulong) child); if (node->children == 2) { zend_generator *other_child; - ZEND_ARRAY_FOREACH_PTR(ht, other_child) { + ZEND_HASH_FOREACH_PTR(ht, other_child) { node->child.single = other_child; break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(ht); efree(ht); } diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 74409e574e28b..91d8469a076da 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -441,7 +441,7 @@ static uint32_t zend_array_recalc_elements(HashTable *ht) zval *val; uint32_t num = ht->nNumOfElements; - ZEND_HASH_FOREACH_VAL(ht, val) { + ZEND_HASH_MAP_FOREACH_VAL(ht, val) { if (Z_TYPE_P(val) == IS_INDIRECT) { if (UNEXPECTED(Z_TYPE_P(Z_INDIRECT_P(val)) == IS_UNDEF)) { num--; @@ -3171,7 +3171,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht) goto convert; } - ZEND_HASH_FOREACH_STR_KEY(ht, str_key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, str_key) { if (!str_key) { goto convert; } @@ -3187,7 +3187,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht) { HashTable *new_ht = zend_new_array(zend_hash_num_elements(ht)); - ZEND_ARRAY_FOREACH_KEY_VAL(ht, num_key, str_key, zv) { + ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) { if (!str_key) { str_key = zend_long_to_str(num_key); zend_string_delref(str_key); @@ -3204,7 +3204,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_symtable_to_proptable(HashTable *ht) } } while (0); zend_hash_update(new_ht, str_key, zv); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return new_ht; } @@ -3221,7 +3221,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_proptable_to_symtable(HashTable *ht, bool zval *zv; if (!HT_IS_PACKED(ht)) { - ZEND_HASH_FOREACH_STR_KEY(ht, str_key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, str_key) { /* The `str_key &&` here might seem redundant: property tables should * only have string keys. Unfortunately, this isn't true, at the very * least because of ArrayObject, which stores a symtable where the @@ -3247,7 +3247,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_proptable_to_symtable(HashTable *ht, bool { HashTable *new_ht = zend_new_array(zend_hash_num_elements(ht)); - ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, str_key, zv) { + ZEND_HASH_MAP_FOREACH_KEY_VAL_IND(ht, num_key, str_key, zv) { do { if (Z_OPT_REFCOUNTED_P(zv)) { if (Z_ISREF_P(zv) && Z_REFCOUNT_P(zv) == 1) { diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 094542a3750de..414a173702618 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -959,17 +959,65 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define zend_hash_get_current_data_ptr(ht) \ zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer) -/* Hash array iterators */ +/* Common hash/packed array iterators */ +#if 0 +# define ZEND_HASH_ELEMET_SIZE(__ht) \ + (HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket)) +#else /* optimized version */ +# define ZEND_HASH_ELEMET_SIZE(__ht) \ + (sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED)) +#endif + +#define ZEND_HASH_ELEMET(__ht, _idx, _size) \ + ((zval*)(((char*)(__ht)->arPacked) + ((_idx) * (_size)))) + +#define ZEND_HASH_NEXT_ELEMENT(_el, _size) \ + ((zval*)(((char*)(_el)) + (_size))) + +#define ZEND_HASH_PREV_ELEMENT(_el, _size) \ + ((zval*)(((char*)(_el)) - (_size))) + +#define _ZEND_HASH_FOREACH_VAL(_ht) do { \ + HashTable *__ht = (_ht); \ + uint32_t _count = __ht->nNumUsed; \ + size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ + zval *_z = __ht->arPacked; \ + for (; _count > 0; _z = ZEND_HASH_NEXT_ELEMENT(_z, _size), _count--) { \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + +#define _ZEND_HASH_REVERSE_FOREACH_VAL(_ht) do { \ + HashTable *__ht = (_ht); \ + uint32_t _idx = __ht->nNumUsed; \ + size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ + zval *_z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + for (;_idx > 0; _idx--) { \ + _z = ZEND_HASH_PREV_ELEMENT(_z, _size); \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; + #define ZEND_HASH_FOREACH_FROM(_ht, indirect, _from) do { \ HashTable *__ht = (_ht); \ - Bucket *_p = __ht->arData + (_from); \ - Bucket *_end = __ht->arData + __ht->nNumUsed; \ - ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ - for (; _p != _end; _p++) { \ - zval *_z = &_p->val; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + uint32_t _idx = (_from); \ + size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ + zval *__z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + uint32_t _count = __ht->nNumUsed - _idx; \ + for (;_count > 0; _count--) { \ + zval *_z = __z; \ + if (HT_IS_PACKED(__ht)) { \ + __z++; \ + __h = _idx; \ + _idx++; \ + } else { \ + Bucket *_p = (Bucket*)__z; \ + __z = &(_p + 1)->val; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ } \ + (void) __h; (void) __key; (void) _idx; \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define ZEND_HASH_FOREACH(_ht, indirect) ZEND_HASH_FOREACH_FROM(_ht, indirect, 0) @@ -977,15 +1025,28 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define ZEND_HASH_REVERSE_FOREACH(_ht, indirect) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ - Bucket *_p = __ht->arData + _idx; \ zval *_z; \ - ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ - for (_idx = __ht->nNumUsed; _idx > 0; _idx--) { \ - _p--; \ - _z = &_p->val; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ + zend_ulong __h; \ + zend_string *__key = NULL; \ + size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ + zval *__z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + for (;_idx > 0; _idx--) { \ + if (HT_IS_PACKED(__ht)) { \ + __z--; \ + _z = __z; \ + __h = _idx - 1; \ + } else { \ + Bucket *_p = (Bucket*)__z; \ + _p--; \ + __z = &_p->val; \ + _z = __z; \ + __h = _p->h; \ + __key = _p->key; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ } \ + (void) __h; (void) __key; (void) __z; \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; #define ZEND_HASH_FOREACH_END() \ @@ -993,44 +1054,23 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, } while (0) #define ZEND_HASH_FOREACH_END_DEL() \ - __ht->nNumOfElements--; \ - do { \ - uint32_t j = HT_IDX_TO_HASH(_idx - 1); \ - uint32_t nIndex = _p->h | __ht->nTableMask; \ - uint32_t i = HT_HASH(__ht, nIndex); \ - if (UNEXPECTED(j != i)) { \ - Bucket *prev = HT_HASH_TO_BUCKET(__ht, i); \ - while (Z_NEXT(prev->val) != j) { \ - i = Z_NEXT(prev->val); \ - prev = HT_HASH_TO_BUCKET(__ht, i); \ - } \ - Z_NEXT(prev->val) = Z_NEXT(_p->val); \ - } else { \ - HT_HASH(__ht, nIndex) = Z_NEXT(_p->val); \ - } \ - } while (0); \ - } \ - __ht->nNumUsed = _idx; \ - } while (0) + ZEND_HASH_MAP_FOREACH_END_DEL() #define ZEND_HASH_FOREACH_BUCKET(ht, _bucket) \ - ZEND_HASH_FOREACH(ht, 0); \ - _bucket = _p; + ZEND_HASH_MAP_FOREACH_BUCKET(ht, _bucket) #define ZEND_HASH_FOREACH_BUCKET_FROM(ht, _bucket, _from) \ - ZEND_HASH_FOREACH_FROM(ht, 0, _from); \ - _bucket = _p; + ZEND_HASH_MAP_FOREACH_BUCKET_FROM(ht, _bucket, _from) #define ZEND_HASH_REVERSE_FOREACH_BUCKET(ht, _bucket) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _bucket = _p; + ZEND_HASH_MAP_REVERSE_FOREACH_BUCKET(ht, _bucket) #define ZEND_HASH_FOREACH_VAL(ht, _val) \ - ZEND_HASH_FOREACH(ht, 0); \ + _ZEND_HASH_FOREACH_VAL(ht); \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _ZEND_HASH_REVERSE_FOREACH_VAL(ht); \ _val = _z; #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \ @@ -1042,7 +1082,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _val = _z; #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \ - ZEND_HASH_FOREACH(ht, 0); \ + _ZEND_HASH_FOREACH_VAL(ht); \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_PTR_FROM(ht, _ptr, _from) \ @@ -1050,426 +1090,400 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _ZEND_HASH_REVERSE_FOREACH_VAL(ht, 0); \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; + _h = __h; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; + _h = __h; #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; + _key = __key; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; + _key = __key; #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; + _h = __h; \ + _key = __key; #define ZEND_HASH_REVERSE_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; + _h = __h; \ + _key = __key; #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ ZEND_HASH_FOREACH_FROM(ht, 0, _from); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _key = _p->key; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _val = _z; #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ + _h = __h; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->key; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _ptr = Z_PTR_P(_z); #define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _h = _p->h; \ - _key = _p->key; \ + _h = __h; \ + _key = __key; \ _ptr = Z_PTR_P(_z); -/* Packed array iterators */ -#define ZEND_PACKED_FOREACH_FROM(_ht, _from) do { \ +/* Hash array iterators */ +#define ZEND_HASH_MAP_FOREACH_FROM(_ht, indirect, _from) do { \ HashTable *__ht = (_ht); \ - zend_ulong _idx = (_from); \ - zval *_z = __ht->arPacked + (_from); \ - zval *_end = __ht->arPacked + __ht->nNumUsed; \ - ZEND_ASSERT(HT_IS_PACKED(__ht)); \ - for (;_z != _end; _z++, _idx++) { \ - (void) _idx; \ + Bucket *_p = __ht->arData + (_from); \ + Bucket *_end = __ht->arData + __ht->nNumUsed; \ + ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ + for (; _p != _end; _p++) { \ + zval *_z = &_p->val; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; -#define ZEND_PACKED_FOREACH(_ht) ZEND_PACKED_FOREACH_FROM(_ht, 0) +#define ZEND_HASH_MAP_FOREACH(_ht, indirect) ZEND_HASH_MAP_FOREACH_FROM(_ht, indirect, 0) -#define ZEND_PACKED_REVERSE_FOREACH(_ht) do { \ +#define ZEND_HASH_MAP_REVERSE_FOREACH(_ht, indirect) do { \ HashTable *__ht = (_ht); \ - zend_ulong _idx = __ht->nNumUsed; \ - zval *_z = __ht->arPacked + _idx; \ - ZEND_ASSERT(HT_IS_PACKED(__ht)); \ - while (_idx > 0) { \ - _z--; \ - _idx--; \ - (void) _idx; \ + uint32_t _idx = __ht->nNumUsed; \ + Bucket *_p = __ht->arData + _idx; \ + zval *_z; \ + ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ + for (_idx = __ht->nNumUsed; _idx > 0; _idx--) { \ + _p--; \ + _z = &_p->val; \ + if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ + _z = Z_INDIRECT_P(_z); \ + } \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; -#define ZEND_PACKED_FOREACH_END() \ +#define ZEND_HASH_MAP_FOREACH_END_DEL() \ + ZEND_ASSERT(!HT_IS_PACKED(__ht)); \ + __ht->nNumOfElements--; \ + do { \ + uint32_t j = HT_IDX_TO_HASH(_idx - 1); \ + uint32_t nIndex = _p->h | __ht->nTableMask; \ + uint32_t i = HT_HASH(__ht, nIndex); \ + if (UNEXPECTED(j != i)) { \ + Bucket *prev = HT_HASH_TO_BUCKET(__ht, i); \ + while (Z_NEXT(prev->val) != j) { \ + i = Z_NEXT(prev->val); \ + prev = HT_HASH_TO_BUCKET(__ht, i); \ + } \ + Z_NEXT(prev->val) = Z_NEXT(_p->val); \ + } else { \ + HT_HASH(__ht, nIndex) = Z_NEXT(_p->val); \ + } \ + } while (0); \ } \ + __ht->nNumUsed = _idx; \ } while (0) -#define ZEND_PACKED_FOREACH_VAL(ht, _val) \ - ZEND_PACKED_FOREACH(ht); \ - _val = _z; - -#define ZEND_PACKED_REVERSE_FOREACH_VAL(ht, _val) \ - ZEND_PACKED_REVERSE_FOREACH(ht); \ - _val = _z; +#define ZEND_HASH_MAP_FOREACH_BUCKET(ht, _bucket) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _bucket = _p; -#define ZEND_PACKED_FOREACH_PTR(ht, _ptr) \ - ZEND_PACKED_FOREACH(ht); \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_MAP_FOREACH_BUCKET_FROM(ht, _bucket, _from) \ + ZEND_HASH_MAP_FOREACH_FROM(ht, 0, _from); \ + _bucket = _p; -#define ZEND_PACKED_REVERSE_FOREACH_PTR(ht, _ptr) \ - ZEND_PACKED_REVERSE_FOREACH(ht); \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_MAP_REVERSE_FOREACH_BUCKET(ht, _bucket) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _bucket = _p; -#define ZEND_PACKED_FOREACH_KEY(ht, _h) \ - ZEND_PACKED_FOREACH(ht); \ - _h = _idx; +#define ZEND_HASH_MAP_FOREACH_VAL(ht, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _val = _z; -#define ZEND_PACKED_REVERSE_FOREACH_KEY(ht, _h) \ - ZEND_PACKED_REVERSE_FOREACH(ht); \ - _h = _idx; +#define ZEND_HASH_MAP_REVERSE_FOREACH_VAL(ht, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _val = _z; -#define ZEND_PACKED_FOREACH_KEY_VAL(ht, _h, _val) \ - ZEND_PACKED_FOREACH(ht); \ - _h = _idx; \ +#define ZEND_HASH_MAP_FOREACH_VAL_IND(ht, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 1); \ _val = _z; -#define ZEND_PACKED_REVERSE_FOREACH_KEY_VAL(ht, _h, _val) \ - ZEND_PACKED_REVERSE_FOREACH(ht); \ - _h = _idx; \ +#define ZEND_HASH_MAP_REVERSE_FOREACH_VAL_IND(ht, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 1); \ _val = _z; -#define ZEND_PACKED_FOREACH_KEY_PTR(ht, _h, _ptr) \ - ZEND_PACKED_FOREACH(ht); \ - _h = _idx; \ +#define ZEND_HASH_MAP_FOREACH_PTR(ht, _ptr) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ _ptr = Z_PTR_P(_z); -#define ZEND_PACKED_REVERSE_FOREACH_KEY_PTR(ht, _h, _ptr) \ - ZEND_PACKED_REVERSE_FOREACH(ht); \ - _h = _idx; \ +#define ZEND_HASH_MAP_FOREACH_PTR_FROM(ht, _ptr, _from) \ + ZEND_HASH_MAP_FOREACH_FROM(ht, 0, _from); \ _ptr = Z_PTR_P(_z); -/* Common hash/packed array iterators */ - -#if 0 -# define ZEND_ARRAY_ELEMET_SIZE(__ht) \ - (HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket)) -#else /* optimized version */ -# define ZEND_ARRAY_ELEMET_SIZE(__ht) \ - (sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED)) -#endif - -#define ZEND_ARRAY_ELEMET(__ht, _idx, _size) \ - ((zval*)(((char*)(__ht)->arPacked) + ((_idx) * (_size)))) - -#define ZEND_ARRAY_NEXT_ELEMENT(_el, _size) \ - ((zval*)(((char*)(_el)) + (_size))) +#define ZEND_HASH_MAP_REVERSE_FOREACH_PTR(ht, _ptr) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_PREV_ELEMENT(_el, _size) \ - ((zval*)(((char*)(_el)) - (_size))) +#define ZEND_HASH_MAP_FOREACH_NUM_KEY(ht, _h) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; -#define ZEND_ARRAY_FOREACH(_ht, indirect) do { \ - HashTable *__ht = (_ht); \ - bool _is_packed = HT_IS_PACKED(__ht); \ - zval *__z = __ht->arPacked; \ - zend_ulong __h; \ - zend_string *__key = NULL; \ - uint32_t _idx = 0; \ - uint32_t _count = __ht->nNumUsed; \ - for (;_count > 0; _count--) { \ - zval *_z = __z; \ - if (_is_packed) { \ - __z++; \ - __h = _idx; \ - _idx++; \ - } else { \ - Bucket *_p = (Bucket*)__z; \ - __z = &(_p + 1)->val; \ - __h = _p->h; \ - __key = _p->key; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ - } \ - } \ - (void) __h; (void) __key; (void) _idx; \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; +#define ZEND_HASH_MAP_REVERSE_FOREACH_NUM_KEY(ht, _h) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; -#define ZEND_ARRAY_REVERSE_FOREACH(_ht, indirect) do { \ - HashTable *__ht = (_ht); \ - uint32_t _idx = __ht->nNumUsed; \ - zval *_z; \ - zend_ulong __h; \ - zend_string *__key = NULL; \ - bool _is_packed = HT_IS_PACKED(__ht); \ - size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ - zval *__z = ZEND_ARRAY_ELEMET(__ht, _idx, _size); \ - for (;_idx > 0; _idx--) { \ - if (_is_packed) { \ - __z--; \ - _z = __z; \ - __h = _idx - 1; \ - } else { \ - Bucket *_p = (Bucket*)__z; \ - _p--; \ - __z = &_p->val; \ - _z = __z; \ - __h = _p->h; \ - __key = _p->key; \ - if (indirect && Z_TYPE_P(_z) == IS_INDIRECT) { \ - _z = Z_INDIRECT_P(_z); \ - } \ - } \ - (void) __h; (void) __key; (void) __z; \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; +#define ZEND_HASH_MAP_FOREACH_STR_KEY(ht, _key) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _key = _p->key; -#define ZEND_ARRAY_FOREACH_END() \ - } \ - } while (0) +#define ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY(ht, _key) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _key = _p->key; -#define _ZEND_ARRAY_FOREACH_VAL(_ht) do { \ - HashTable *__ht = (_ht); \ - uint32_t _count = __ht->nNumUsed; \ - size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ - zval *_z = __ht->arPacked; \ - for (; _count > 0; _z = ZEND_ARRAY_NEXT_ELEMENT(_z, _size), _count--) { \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; +#define ZEND_HASH_MAP_FOREACH_KEY(ht, _h, _key) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; -#define _ZEND_ARRAY_REVERSE_FOREACH_VAL(_ht) do { \ - HashTable *__ht = (_ht); \ - uint32_t _idx = __ht->nNumUsed; \ - size_t _size = ZEND_ARRAY_ELEMET_SIZE(__ht); \ - zval *_z = ZEND_ARRAY_ELEMET(__ht, _idx, _size); \ - for (;_idx > 0; _idx--) { \ - _z = ZEND_ARRAY_PREV_ELEMENT(_z, _size); \ - if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; +#define ZEND_HASH_MAP_REVERSE_FOREACH_KEY(ht, _h, _key) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; -#define ZEND_ARRAY_FOREACH_VAL(ht, _val) \ - _ZEND_ARRAY_FOREACH_VAL(ht); \ +#define ZEND_HASH_MAP_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; \ _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_VAL(ht, _val) \ - _ZEND_ARRAY_REVERSE_FOREACH_VAL(ht); \ +#define ZEND_HASH_MAP_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ _val = _z; -#define ZEND_ARRAY_FOREACH_VAL_IND(ht, _val) \ - ZEND_ARRAY_FOREACH(ht, 1); \ +#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, _key, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _key = _p->key; \ _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_VAL_IND(ht, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ +#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_FROM(ht, _key, _val, _from) \ + ZEND_HASH_MAP_FOREACH_FROM(ht, 0, _from); \ + _key = _p->key; \ _val = _z; -#define ZEND_ARRAY_FOREACH_PTR(ht, _ptr) \ - _ZEND_ARRAY_FOREACH_VAL(ht); \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_PTR(ht, _ptr) \ - _ZEND_ARRAY_REVERSE_FOREACH_VAL(ht, 0); \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_MAP_FOREACH_KEY_VAL(ht, _h, _key, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_FOREACH_NUM_KEY(ht, _h) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; +#define ZEND_HASH_MAP_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY(ht, _h) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; +#define ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 1); \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_FOREACH_STR_KEY(ht, _key) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _key = __key; +#define ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 1); \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY(ht, _key) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _key = __key; +#define ZEND_HASH_MAP_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ + ZEND_HASH_MAP_FOREACH(ht, 1); \ + _h = _p->h; \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_FOREACH_KEY(ht, _h, _key) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; +#define ZEND_HASH_MAP_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 1); \ + _h = _p->h; \ + _key = _p->key; \ + _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_KEY(ht, _h, _key) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; +#define ZEND_HASH_MAP_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; \ - _val = _z; +#define ZEND_HASH_MAP_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _val = _z; +#define ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, _key, _val) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _key = __key; \ - _val = _z; +#define ZEND_HASH_MAP_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _key = __key; \ - _val = _z; +#define ZEND_HASH_MAP_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ + ZEND_HASH_MAP_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_FOREACH_KEY_VAL(ht, _h, _key, _val) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ - _val = _z; +#define ZEND_HASH_MAP_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ + ZEND_HASH_MAP_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(ht, _h, _key, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ - _val = _z; +/* Packed array iterators */ +#define ZEND_HASH_PACKED_FOREACH_FROM(_ht, _from) do { \ + HashTable *__ht = (_ht); \ + zend_ulong _idx = (_from); \ + zval *_z = __ht->arPacked + (_from); \ + zval *_end = __ht->arPacked + __ht->nNumUsed; \ + ZEND_ASSERT(HT_IS_PACKED(__ht)); \ + for (;_z != _end; _z++, _idx++) { \ + (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; -#define ZEND_ARRAY_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ - ZEND_ARRAY_FOREACH(ht, 1); \ - _key = __key; \ - _val = _z; +#define ZEND_HASH_PACKED_FOREACH(_ht) ZEND_HASH_PACKED_FOREACH_FROM(_ht, 0) -#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ - _key = __key; \ - _val = _z; +#define ZEND_HASH_PACKED_REVERSE_FOREACH(_ht) do { \ + HashTable *__ht = (_ht); \ + zend_ulong _idx = __ht->nNumUsed; \ + zval *_z = __ht->arPacked + _idx; \ + ZEND_ASSERT(HT_IS_PACKED(__ht)); \ + while (_idx > 0) { \ + _z--; \ + _idx--; \ + (void) _idx; \ + if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; -#define ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ - ZEND_ARRAY_FOREACH(ht, 1); \ - _h = __h; \ - _key = __key; \ +#define ZEND_HASH_PACKED_FOREACH_VAL(ht, _val) \ + ZEND_HASH_PACKED_FOREACH(ht); \ _val = _z; -#define ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL_IND(ht, _h, _key, _val) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 1); \ - _h = __h; \ - _key = __key; \ +#define ZEND_HASH_PACKED_REVERSE_FOREACH_VAL(ht, _val) \ + ZEND_HASH_PACKED_REVERSE_FOREACH(ht); \ _val = _z; -#define ZEND_ARRAY_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; \ +#define ZEND_HASH_PACKED_FOREACH_PTR(ht, _ptr) \ + ZEND_HASH_PACKED_FOREACH(ht); \ _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_REVERSE_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ +#define ZEND_HASH_PACKED_REVERSE_FOREACH_PTR(ht, _ptr) \ + ZEND_HASH_PACKED_REVERSE_FOREACH(ht); \ _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _key = __key; \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_PACKED_FOREACH_KEY(ht, _h) \ + ZEND_HASH_PACKED_FOREACH(ht); \ + _h = _idx; -#define ZEND_ARRAY_REVERSE_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _key = __key; \ - _ptr = Z_PTR_P(_z); +#define ZEND_HASH_PACKED_REVERSE_FOREACH_KEY(ht, _h) \ + ZEND_HASH_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; -#define ZEND_ARRAY_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ - ZEND_ARRAY_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ +#define ZEND_HASH_PACKED_FOREACH_KEY_VAL(ht, _h, _val) \ + ZEND_HASH_PACKED_FOREACH(ht); \ + _h = _idx; \ + _val = _z; + +#define ZEND_HASH_PACKED_REVERSE_FOREACH_KEY_VAL(ht, _h, _val) \ + ZEND_HASH_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; \ + _val = _z; + +#define ZEND_HASH_PACKED_FOREACH_KEY_PTR(ht, _h, _ptr) \ + ZEND_HASH_PACKED_FOREACH(ht); \ + _h = _idx; \ _ptr = Z_PTR_P(_z); -#define ZEND_ARRAY_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ - ZEND_ARRAY_REVERSE_FOREACH(ht, 0); \ - _h = __h; \ - _key = __key; \ +#define ZEND_HASH_PACKED_REVERSE_FOREACH_KEY_PTR(ht, _h, _ptr) \ + ZEND_HASH_PACKED_REVERSE_FOREACH(ht); \ + _h = _idx; \ _ptr = Z_PTR_P(_z); /* The following macros are useful to insert a sequence of new elements @@ -1552,14 +1566,14 @@ static zend_always_inline bool zend_array_is_list(zend_array *array) return 1; } /* Check if the list could theoretically be repacked */ - ZEND_PACKED_FOREACH_KEY(array, num_idx) { + ZEND_HASH_PACKED_FOREACH_KEY(array, num_idx) { if (num_idx != expected_idx++) { return 0; } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { /* Check if the list could theoretically be repacked */ - ZEND_HASH_FOREACH_KEY(array, num_idx, str_idx) { + ZEND_HASH_MAP_FOREACH_KEY(array, num_idx, str_idx) { if (str_idx != NULL || num_idx != expected_idx++) { return 0; } diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index d9295bab6832e..ffb8fbe9e6553 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -979,7 +979,7 @@ static void ZEND_COLD emit_incompatible_method_error( if (status == INHERITANCE_UNRESOLVED) { /* Fetch the first unresolved class from registered autoloads */ zend_string *unresolved_class = NULL; - ZEND_HASH_FOREACH_STR_KEY(CG(delayed_autoloads), unresolved_class) { + ZEND_HASH_MAP_FOREACH_STR_KEY(CG(delayed_autoloads), unresolved_class) { break; } ZEND_HASH_FOREACH_END(); ZEND_ASSERT(unresolved_class); @@ -1397,7 +1397,7 @@ void zend_build_properties_info_table(zend_class_entry *ce) } } - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { if (prop->ce == ce && (prop->flags & ZEND_ACC_STATIC) == 0) { table[OBJ_PROP_TO_NUM(prop->offset)] = prop; } @@ -1529,7 +1529,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par } } - ZEND_HASH_FOREACH_PTR(&ce->properties_info, property_info) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, property_info) { if (property_info->ce == ce) { if (property_info->flags & ZEND_ACC_STATIC) { property_info->offset += parent_ce->default_static_members_count; @@ -1544,7 +1544,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par zend_hash_num_elements(&ce->properties_info) + zend_hash_num_elements(&parent_ce->properties_info), 0); - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->properties_info, key, property_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->properties_info, key, property_info) { do_inherit_property(property_info, key, ce); } ZEND_HASH_FOREACH_END(); } @@ -1556,7 +1556,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par zend_hash_num_elements(&ce->constants_table) + zend_hash_num_elements(&parent_ce->constants_table), 0); - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->constants_table, key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->constants_table, key, c) { do_inherit_class_constant(key, c, ce); } ZEND_HASH_FOREACH_END(); } @@ -1567,11 +1567,11 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par zend_hash_num_elements(&parent_ce->function_table), 0); if (checked) { - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, func) { do_inherit_method(key, func, ce, 0, 1); } ZEND_HASH_FOREACH_END(); } else { - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, func) { do_inherit_method(key, func, ce, 0, 0); } ZEND_HASH_FOREACH_END(); } @@ -1649,11 +1649,11 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry * zend_string *key; zend_class_constant *c; - ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { do_inherit_iface_constant(key, c, ce, iface); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->function_table, key, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->function_table, key, func) { do_inherit_method(key, func, ce, 1, 0); } ZEND_HASH_FOREACH_END(); @@ -1688,7 +1688,7 @@ ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry } if (ignore) { /* Check for attempt to redeclare interface constants */ - ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { do_inherit_constant_check(ce, c, key); } ZEND_HASH_FOREACH_END(); } else { @@ -1733,7 +1733,7 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry return; } /* skip duplications */ - ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) { do_inherit_constant_check(ce, c, key); } ZEND_HASH_FOREACH_END(); @@ -2104,7 +2104,7 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry for (i = 0; i < ce->num_traits; i++) { if (traits[i]) { /* copies functions, applies defined aliasing, and excludes unused trait methods */ - ZEND_HASH_FOREACH_STR_KEY_PTR(&traits[i]->function_table, key, fn) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&traits[i]->function_table, key, fn) { zend_traits_copy_functions(key, fn, ce, exclude_tables[i], aliases); } ZEND_HASH_FOREACH_END(); @@ -2118,14 +2118,14 @@ static void zend_do_traits_method_binding(zend_class_entry *ce, zend_class_entry } else { for (i = 0; i < ce->num_traits; i++) { if (traits[i]) { - ZEND_HASH_FOREACH_STR_KEY_PTR(&traits[i]->function_table, key, fn) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&traits[i]->function_table, key, fn) { zend_traits_copy_functions(key, fn, ce, NULL, aliases); } ZEND_HASH_FOREACH_END(); } } } - ZEND_HASH_FOREACH_PTR(&ce->function_table, fn) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, fn) { zend_fixup_trait_method(fn, ce); } ZEND_HASH_FOREACH_END(); } @@ -2168,7 +2168,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent if (!traits[i]) { continue; } - ZEND_HASH_FOREACH_STR_KEY_PTR(&traits[i]->properties_info, prop_name, property_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&traits[i]->properties_info, prop_name, property_info) { uint32_t flags = property_info->flags; /* next: check for conflicts with current class */ @@ -2313,7 +2313,7 @@ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */ bool is_explicit_abstract = (ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) != 0; memset(&ai, 0, sizeof(ai)); - ZEND_HASH_FOREACH_PTR(&ce->function_table, func) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, func) { if (func->common.fn_flags & ZEND_ACC_ABSTRACT) { /* If the class is explicitly abstract, we only check private abstract methods, * because only they must be declared in the same class. */ @@ -2492,7 +2492,7 @@ static void load_delayed_classes(zend_class_entry *ce) { /* Take ownership of this HT, to avoid concurrent modification during autoloading. */ CG(delayed_autoloads) = NULL; - ZEND_HASH_FOREACH_STR_KEY(delayed_autoloads, name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(delayed_autoloads, name) { zend_lookup_class(name); if (EG(exception)) { zend_exception_uncaught_error( @@ -2530,7 +2530,7 @@ static void report_variance_errors(zend_class_entry *ce) { obligations = zend_hash_index_find_ptr(all_obligations, num_key); ZEND_ASSERT(obligations != NULL); - ZEND_PACKED_FOREACH_PTR(obligations, obligation) { + ZEND_HASH_PACKED_FOREACH_PTR(obligations, obligation) { if (obligation->type == OBLIGATION_COMPATIBILITY) { /* Just used to populate the delayed_autoloads table, * which will be used when printing the "unresolved" error. */ @@ -2546,7 +2546,7 @@ static void report_variance_errors(zend_class_entry *ce) { } else { zend_error_noreturn(E_CORE_ERROR, "Bug #78647"); } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Only warnings were thrown above -- that means that there are incompatibilities, but only * ones that we permit. Mark all classes with open obligations as fully linked. */ @@ -2953,7 +2953,7 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e zend_property_info *parent_info; inheritance_status overall_status = INHERITANCE_SUCCESS; - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, parent_func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, parent_func) { zval *zv = zend_hash_find_known_hash(&ce->function_table, key); if (zv) { zend_function *child_func = Z_FUNC_P(zv); @@ -2970,7 +2970,7 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->properties_info, key, parent_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&parent_ce->properties_info, key, parent_info) { zval *zv; if ((parent_info->flags & ZEND_ACC_PRIVATE) || !ZEND_TYPE_IS_SET(parent_info->type)) { continue; diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index 59c8184381862..3ce92cc509523 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -125,7 +125,7 @@ ZEND_API void zend_ini_deactivate(void) /* {{{ */ if (EG(modified_ini_directives)) { zend_ini_entry *ini_entry; - ZEND_HASH_FOREACH_PTR(EG(modified_ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(modified_ini_directives), ini_entry) { zend_restore_ini_entry_cb(ini_entry, ZEND_INI_STAGE_DEACTIVATE); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(EG(modified_ini_directives)); @@ -266,7 +266,7 @@ ZEND_API void zend_ini_refresh_caches(int stage) /* {{{ */ { zend_ini_entry *p; - ZEND_HASH_FOREACH_PTR(EG(ini_directives), p) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), p) { if (p->on_modify) { p->on_modify(p, p->value, p->mh_arg1, p->mh_arg2, p->mh_arg3, stage); } diff --git a/Zend/zend_list.c b/Zend/zend_list.c index a7b992b567090..d667a21c80a9d 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -285,11 +285,11 @@ ZEND_API int zend_fetch_list_dtor_id(const char *type_name) { zend_rsrc_list_dtors_entry *lde; - ZEND_ARRAY_FOREACH_PTR(&list_destructors, lde) { + ZEND_HASH_FOREACH_PTR(&list_destructors, lde) { if (lde->type_name && (strcmp(type_name, lde->type_name) == 0)) { return lde->resource_id; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 0; } diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index 7e3fa03912a87..b09ce3b990d5c 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -238,7 +238,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, HT_FLAGS(new_object->properties) |= HT_FLAGS(old_object->properties) & HASH_FLAG_HAS_EMPTY_IND; - ZEND_HASH_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) { + ZEND_HASH_MAP_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) { if (Z_TYPE_P(prop) == IS_INDIRECT) { ZVAL_INDIRECT(&new_prop, new_object->properties_table + (Z_INDIRECT_P(prop) - old_object->properties_table)); } else { diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index aa77fb4798f81..566595783005e 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -249,7 +249,7 @@ ZEND_API void zend_cleanup_mutable_class_data(zend_class_entry *ce) if (constants_table && constants_table != &ce->constants_table) { zend_class_constant *c; - ZEND_HASH_FOREACH_PTR(constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) { zval_ptr_dtor_nogc(&c->value); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(constants_table); @@ -285,7 +285,7 @@ ZEND_API void destroy_zend_class(zval *zv) zend_class_constant *c; zval *p, *end; - ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { if (c->ce == ce) { zval_ptr_dtor_nogc(&c->value); } @@ -362,7 +362,7 @@ ZEND_API void destroy_zend_class(zval *zv) } efree(ce->default_static_members_table); } - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop_info) { if (prop_info->ce == ce) { zend_string_release_ex(prop_info->name, 0); if (prop_info->doc_comment) { @@ -379,7 +379,7 @@ ZEND_API void destroy_zend_class(zval *zv) if (zend_hash_num_elements(&ce->constants_table)) { zend_class_constant *c; - ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { if (c->ce == ce) { zval_ptr_dtor_nogc(&c->value); if (c->doc_comment) { @@ -421,7 +421,7 @@ ZEND_API void destroy_zend_class(zval *zv) free(ce->default_static_members_table); } - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop_info) { if (prop_info->ce == ce) { zend_string_release(prop_info->name); zend_type_release(prop_info->type, /* persistent */ 1); @@ -432,7 +432,7 @@ ZEND_API void destroy_zend_class(zval *zv) zend_string_release_ex(ce->name, 1); /* TODO: eliminate this loop for classes without functions with arg_info */ - ZEND_HASH_FOREACH_PTR(&ce->function_table, fn) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, fn) { if ((fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) && fn->common.scope == ce) { zend_free_internal_arg_info(&fn->internal_function); @@ -443,7 +443,7 @@ ZEND_API void destroy_zend_class(zval *zv) if (zend_hash_num_elements(&ce->constants_table)) { zend_class_constant *c; - ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { if (c->ce == ce) { if (Z_TYPE(c->value) == IS_CONSTANT_AST) { /* We marked this as IMMUTABLE, but do need to free it when the @@ -1116,9 +1116,9 @@ ZEND_API void pass_two(zend_op_array *op_array) /* absolute indexes to relative offsets */ HashTable *jumptable = Z_ARRVAL_P(CT_CONSTANT(opline->op2)); zval *zv; - ZEND_ARRAY_FOREACH_VAL(jumptable, zv) { + ZEND_HASH_FOREACH_VAL(jumptable, zv) { Z_LVAL_P(zv) = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, Z_LVAL_P(zv)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); opline->extended_value = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline->extended_value); break; diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 5be3d3a258b86..eb5148f370761 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5032,7 +5032,7 @@ ZEND_VM_C_LABEL(send_again): bool separate = 0; /* check if any of arguments are going to be passed by reference */ - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; tmp_arg_num = zend_get_arg_offset_by_name( @@ -5043,14 +5043,14 @@ ZEND_VM_C_LABEL(send_again): break; } tmp_arg_num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (separate) { SEPARATE_ARRAY(args); ht = Z_ARRVAL_P(args); } } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -5088,7 +5088,7 @@ ZEND_VM_C_LABEL(send_again): } arg_num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(args) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(args); @@ -5277,7 +5277,7 @@ ZEND_VM_C_LABEL(send_array): zend_vm_stack_extend_call_frame(&EX(call), 0, len); arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); - ZEND_ARRAY_FOREACH_VAL(ht, arg) { + ZEND_HASH_FOREACH_VAL(ht, arg) { bool must_wrap = 0; if (skip > 0) { skip--; @@ -5309,7 +5309,7 @@ ZEND_VM_C_LABEL(send_array): ZEND_CALL_NUM_ARGS(EX(call))++; arg_num++; param++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } FREE_OP2(); } else { @@ -5319,7 +5319,7 @@ ZEND_VM_C_LABEL(send_array): arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); have_named_params = 0; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (name) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -5364,7 +5364,7 @@ ZEND_VM_C_LABEL(send_array): arg_num++; param++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } FREE_OP1(); @@ -5559,7 +5559,7 @@ ZEND_VM_HANDLER(164, ZEND_RECV_VARIADIC, NUM, UNUSED, CACHE_SLOT) zend_arg_info *arg_info = &EX(func)->common.arg_info[EX(func)->common.num_args]; if (ZEND_TYPE_IS_SET(arg_info->type)) { SEPARATE_ARRAY(params); - ZEND_HASH_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { if (UNEXPECTED(!zend_verify_variadic_arg_type(EX(func), arg_info, arg_num, param, CACHE_ADDR(opline->extended_value)))) { HANDLE_EXCEPTION(); } @@ -5571,7 +5571,7 @@ ZEND_VM_HANDLER(164, ZEND_RECV_VARIADIC, NUM, UNUSED, CACHE_SLOT) ZVAL_ARR(params, EX(extra_named_params)); } else { SEPARATE_ARRAY(params); - ZEND_HASH_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { Z_TRY_ADDREF_P(param); zend_hash_add_new(Z_ARRVAL_P(params), name, param); } ZEND_HASH_FOREACH_END(); @@ -6008,7 +6008,7 @@ ZEND_VM_C_LABEL(add_unpack_again): zval *val; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -6022,7 +6022,7 @@ ZEND_VM_C_LABEL(add_unpack_again): break; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(op1) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(op1); zend_object_iterator *iter; @@ -9044,7 +9044,7 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(189, ZEND_IN_ARRAY, CONST|TMP|VAR|CV, CONST, NUM } SAVE_OPLINE(); - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { FREE_OP1(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 10dc9e43f19a2..1e310523f3575 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2134,7 +2134,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ bool separate = 0; /* check if any of arguments are going to be passed by reference */ - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; tmp_arg_num = zend_get_arg_offset_by_name( @@ -2145,14 +2145,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ break; } tmp_arg_num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (separate) { SEPARATE_ARRAY(args); ht = Z_ARRVAL_P(args); } } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (UNEXPECTED(name)) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -2190,7 +2190,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_UNPACK_SPEC_HANDLER(ZEND_ } arg_num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(args) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(args); @@ -2379,7 +2379,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O zend_vm_stack_extend_call_frame(&EX(call), 0, len); arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); - ZEND_ARRAY_FOREACH_VAL(ht, arg) { + ZEND_HASH_FOREACH_VAL(ht, arg) { bool must_wrap = 0; if (skip > 0) { skip--; @@ -2411,7 +2411,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O ZEND_CALL_NUM_ARGS(EX(call))++; arg_num++; param++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } FREE_OP(opline->op2_type, opline->op2.var); } else { @@ -2421,7 +2421,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O arg_num = 1; param = ZEND_CALL_ARG(EX(call), 1); have_named_params = 0; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, name, arg) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, name, arg) { if (name) { void *cache_slot[2] = {NULL, NULL}; have_named_params = 1; @@ -2466,7 +2466,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_SEND_ARRAY_SPEC_HANDLER(ZEND_O arg_num++; param++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } FREE_OP(opline->op1_type, opline->op1.var); @@ -2543,7 +2543,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER( zval *val; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, key, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -2557,7 +2557,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_ARRAY_UNPACK_SPEC_HANDLER( break; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (EXPECTED(Z_TYPE_P(op1) == IS_OBJECT)) { zend_class_entry *ce = Z_OBJCE_P(op1); zend_object_iterator *iter; @@ -3849,7 +3849,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RECV_VARIADIC_SPEC_UNUSED_HAND zend_arg_info *arg_info = &EX(func)->common.arg_info[EX(func)->common.num_args]; if (ZEND_TYPE_IS_SET(arg_info->type)) { SEPARATE_ARRAY(params); - ZEND_HASH_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { if (UNEXPECTED(!zend_verify_variadic_arg_type(EX(func), arg_info, arg_num, param, CACHE_ADDR(opline->extended_value)))) { HANDLE_EXCEPTION(); } @@ -3861,7 +3861,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_RECV_VARIADIC_SPEC_UNUSED_HAND ZVAL_ARR(params, EX(extra_named_params)); } else { SEPARATE_ARRAY(params); - ZEND_HASH_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, param) { Z_TRY_ADDREF_P(param); zend_hash_add_new(Z_ARRVAL_P(params), name, param); } ZEND_HASH_FOREACH_END(); @@ -7683,7 +7683,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_IN_ARRAY_SPEC_CON } SAVE_OPLINE(); - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { @@ -19909,7 +19909,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_IN_ARRAY_SPEC_TMP_CONST_HANDLE } SAVE_OPLINE(); - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { zval_ptr_dtor_nogc(EX_VAR(opline->op1.var)); @@ -24885,7 +24885,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_IN_ARRAY_SPEC_VAR_CONST_HANDLE } SAVE_OPLINE(); - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { zval_ptr_dtor_nogc(EX_VAR(opline->op1.var)); @@ -42512,7 +42512,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_IN_ARRAY_SPEC_CV_CONST_HANDLER } SAVE_OPLINE(); - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { ZVAL_STR(&key_tmp, key); if (zend_compare(op1, &key_tmp) == 0) { diff --git a/Zend/zend_vm_trace_handlers.h b/Zend/zend_vm_trace_handlers.h index 414d4d5f95f67..eaf97e012cac7 100644 --- a/Zend/zend_vm_trace_handlers.h +++ b/Zend/zend_vm_trace_handlers.h @@ -71,7 +71,7 @@ static void zend_vm_trace_finish(void) f = fopen("zend_vm_trace.log", "w+"); if (f) { zend_hash_sort(&vm_trace_ht, (compare_func_t)zend_vm_trace_compare, 0); - ZEND_HASH_FOREACH_STR_KEY_VAL(&vm_trace_ht, key, val) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(&vm_trace_ht, key, val) { fprintf(f, "%s "ZEND_LONG_FMT"\n", ZSTR_VAL(key), Z_LVAL_P(val)); } ZEND_HASH_FOREACH_END(); fclose(f); diff --git a/Zend/zend_vm_trace_map.h b/Zend/zend_vm_trace_map.h index 96695312a93d0..d84aa0442d263 100644 --- a/Zend/zend_vm_trace_map.h +++ b/Zend/zend_vm_trace_map.h @@ -65,7 +65,7 @@ static void zend_vm_trace_init(void) if (f) { zend_hash_sort(&vm_trace_ht, (bucket_compare_func_t)zend_vm_trace_compare, 0); prev_key = NULL; - ZEND_HASH_FOREACH_STR_KEY_VAL(&vm_trace_ht, key, val) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(&vm_trace_ht, key, val) { if (prev_key) { fprintf(f, ADDR_FMT" "ADDR_FMT" t %s\n", prev_addr, Z_LVAL_P(val) - prev_addr, ZSTR_VAL(prev_key)); } diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c index aa6114fa6d8d6..e5f8a4b220de8 100644 --- a/Zend/zend_weakrefs.c +++ b/Zend/zend_weakrefs.c @@ -72,7 +72,7 @@ static void zend_weakref_unref(zend_ulong obj_addr, void *tagged_ptr) { uintptr_t tag = ZEND_WEAKREF_GET_TAG(tagged_ptr); if (tag == ZEND_WEAKREF_TAG_HT) { HashTable *ht = ptr; - ZEND_HASH_FOREACH_PTR(ht, tagged_ptr) { + ZEND_HASH_MAP_FOREACH_PTR(ht, tagged_ptr) { zend_weakref_unref_single( ZEND_WEAKREF_GET_PTR(tagged_ptr), ZEND_WEAKREF_GET_TAG(tagged_ptr), obj_addr); } ZEND_HASH_FOREACH_END(); @@ -209,7 +209,7 @@ static zend_always_inline bool zend_weakref_find(zend_object *referent, zval *re } if (tag == ZEND_WEAKREF_TAG_HT) { - ZEND_HASH_FOREACH(ptr, tagged_ptr) { + ZEND_HASH_MAP_FOREACH(ptr, tagged_ptr) { if (ZEND_WEAKREF_GET_TAG(tagged_ptr) == ZEND_WEAKREF_TAG_REF) { ptr = ZEND_WEAKREF_GET_PTR(tagged_ptr); goto found_weakref; @@ -290,7 +290,7 @@ static void zend_weakmap_free_obj(zend_object *object) { zend_weakmap *wm = zend_weakmap_from(object); zend_ulong obj_addr; - ZEND_HASH_FOREACH_NUM_KEY(&wm->ht, obj_addr) { + ZEND_HASH_MAP_FOREACH_NUM_KEY(&wm->ht, obj_addr) { zend_weakref_unregister( (zend_object *) obj_addr, ZEND_WEAKREF_ENCODE(&wm->ht, ZEND_WEAKREF_TAG_MAP)); } ZEND_HASH_FOREACH_END(); @@ -412,7 +412,7 @@ static HashTable *zend_weakmap_get_properties_for(zend_object *object, zend_prop zend_ulong obj_addr; zval *val; - ZEND_HASH_FOREACH_NUM_KEY_VAL(&wm->ht, obj_addr, val) { + ZEND_HASH_MAP_FOREACH_NUM_KEY_VAL(&wm->ht, obj_addr, val) { zend_object *obj = (zend_object*)obj_addr; zval pair; array_init(&pair); @@ -433,7 +433,7 @@ static HashTable *zend_weakmap_get_gc(zend_object *object, zval **table, int *n) zend_weakmap *wm = zend_weakmap_from(object); zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create(); zval *val; - ZEND_HASH_FOREACH_VAL(&wm->ht, val) { + ZEND_HASH_MAP_FOREACH_VAL(&wm->ht, val) { zend_get_gc_buffer_add_zval(gc_buffer, val); } ZEND_HASH_FOREACH_END(); zend_get_gc_buffer_use(gc_buffer, table, n); @@ -449,7 +449,7 @@ static zend_object *zend_weakmap_clone_obj(zend_object *old_object) zend_ulong obj_addr; zval *val; - ZEND_HASH_FOREACH_NUM_KEY_VAL(&new_wm->ht, obj_addr, val) { + ZEND_HASH_MAP_FOREACH_NUM_KEY_VAL(&new_wm->ht, obj_addr, val) { zend_weakref_register( (zend_object *) obj_addr, ZEND_WEAKREF_ENCODE(new_wm, ZEND_WEAKREF_TAG_MAP)); zval_add_ref(val); diff --git a/ext/curl/interface.c b/ext/curl/interface.c index eb5878960946e..3292458d63554 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2017,7 +2017,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo } #endif - ZEND_ARRAY_FOREACH_KEY_VAL(postfields, num_key, string_key, current) { + ZEND_HASH_FOREACH_KEY_VAL(postfields, num_key, string_key, current) { zend_string *postval, *tmp_postval; /* Pretend we have a string_key here */ if (!string_key) { @@ -2212,7 +2212,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo #endif zend_tmp_string_release(tmp_postval); zend_string_release_ex(string_key, 0); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); SAVE_CURL_ERROR(ch, error); if (error != CURLE_OK) { @@ -2753,7 +2753,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue } ph = Z_ARRVAL_P(zvalue); - ZEND_ARRAY_FOREACH_VAL(ph, current) { + ZEND_HASH_FOREACH_VAL(ph, current) { ZVAL_DEREF(current); val = zval_get_tmp_string(current, &tmp_val); slist = curl_slist_append(slist, ZSTR_VAL(val)); @@ -2762,7 +2762,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue php_error_docref(NULL, E_WARNING, "Could not build curl_slist"); return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (slist) { if ((*ch->clone) == 1) { @@ -3015,7 +3015,7 @@ PHP_FUNCTION(curl_setopt_array) ch = Z_CURL_P(zid); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arr), option, string_key, entry) { if (string_key) { zend_argument_value_error(2, "contains an invalid cURL option"); RETURN_THROWS(); @@ -3025,7 +3025,7 @@ PHP_FUNCTION(curl_setopt_array) if (_php_curl_setopt(ch, (zend_long) option, entry, 1) == FAILURE) { RETURN_FALSE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); RETURN_TRUE; } diff --git a/ext/dom/node.c b/ext/dom/node.c index e4421ddfefe1e..fc1b725bb28ae 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -1596,7 +1596,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ zval *tmpns; zend_string *prefix; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), prefix, tmpns) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(tmp), prefix, tmpns) { if (Z_TYPE_P(tmpns) == IS_STRING) { if (prefix) { xmlXPathRegisterNs(ctxp, (xmlChar *) ZSTR_VAL(prefix), (xmlChar *) Z_STRVAL_P(tmpns)); @@ -1626,11 +1626,11 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ inclusive_ns_prefixes = safe_emalloc(zend_hash_num_elements(Z_ARRVAL_P(ns_prefixes)) + 1, sizeof(xmlChar *), 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(ns_prefixes), tmpns) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(ns_prefixes), tmpns) { if (Z_TYPE_P(tmpns) == IS_STRING) { inclusive_ns_prefixes[nscount++] = (xmlChar *) Z_STRVAL_P(tmpns); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); inclusive_ns_prefixes[nscount] = NULL; } else { php_error_docref(NULL, E_NOTICE, diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 01a206c0985bd..f9e7f2e0b45ee 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -405,7 +405,7 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) / object_str = zend_string_init("(object value omitted)", sizeof("(object value omitted)")-1, 0); - ZEND_HASH_FOREACH_STR_KEY_PTR(prop_handlers, string_key, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(prop_handlers, string_key, entry) { zval value; if (entry->read_func(obj, &value) == FAILURE || !string_key) { diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index 8d30edabf2876..876d8b00dae0e 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -500,12 +500,12 @@ PHP_METHOD(DOMXPath, registerPhpFunctions) ZEND_PARSE_PARAMETERS_END(); if (ht) { - ZEND_ARRAY_FOREACH_VAL(ht, entry) { + ZEND_HASH_FOREACH_VAL(ht, entry) { zend_string *str = zval_get_string(entry); ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_string_release_ex(str, 0); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); intern->registerPhpFunctions = 2; } else if (name) { ZVAL_LONG(&new_string, 1); diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index f70723ff59d68..08ef410aa9b22 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -296,7 +296,7 @@ static ffi_type* zend_ffi_face_struct_add_fields(ffi_type* t, zend_ffi_type *typ { zend_ffi_field *field; - ZEND_HASH_FOREACH_PTR(&type->record.fields, field) { + ZEND_HASH_MAP_FOREACH_PTR(&type->record.fields, field) { switch (ZEND_FFI_TYPE(field->type)->kind) { case ZEND_FFI_TYPE_FLOAT: t->elements[(*i)++] = &ffi_type_float; @@ -811,9 +811,9 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */ zend_ffi_type *arg_type; size_t arg_size = 0; - ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return arg_size; } /* }}} */ @@ -885,11 +885,11 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v int n = 0; zend_ffi_type *arg_type; - ZEND_ARRAY_FOREACH_PTR(callback_data->type->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(callback_data->type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); zend_ffi_cdata_to_zval(NULL, args[n], arg_type, BP_VAR_R, &fci.params[n], (zend_ffi_flags)(arg_type->attr & ZEND_FFI_ATTR_CONST), 0, 0); n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZVAL_UNDEF(&retval); @@ -959,7 +959,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ * int n = 0; zend_ffi_type *arg_type; - ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); callback_data->arg_types[n] = zend_ffi_get_type(arg_type); if (!callback_data->arg_types[n]) { @@ -969,7 +969,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ * return NULL; } n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } callback_data->ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); if (!callback_data->ret_type) { @@ -1991,7 +1991,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zend_object *obj, int *is_temp) break; case ZEND_FFI_TYPE_STRUCT: ht = zend_new_array(zend_hash_num_elements(&type->record.fields)); - ZEND_HASH_FOREACH_STR_KEY_PTR(&type->record.fields, key, f) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&type->record.fields, key, f) { if (key) { if (!f->bits) { void *f_ptr = (void*)(((char*)ptr) + f->offset); @@ -2652,7 +2652,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2661,7 +2661,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ goto exit; } n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } for (; n < EX_NUM_ARGS(); n++) { arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); @@ -2697,7 +2697,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_ARRAY_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2706,7 +2706,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ goto exit; } n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); @@ -2903,7 +2903,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */ zend_string *name; zend_ffi_symbol *sym; - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { if (sym->kind == ZEND_FFI_SYM_VAR) { addr = DL_FETCH_SYMBOL(handle, ZSTR_VAL(name)); if (!addr) { @@ -2968,7 +2968,7 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ Bucket *b = type->record.fields.arData; ZEND_ASSERT(!HT_IS_PACKED(&type->record.fields)); - ZEND_HASH_FOREACH_STR_KEY_PTR(&old->record.fields, key, old_field) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&old->record.fields, key, old_field) { while (Z_TYPE(b->val) == IS_UNDEF) { b++; } @@ -3004,7 +3004,7 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ if (HT_IS_PACKED(type->func.args)) { zval *zv = type->func.args->arPacked; - ZEND_ARRAY_FOREACH_PTR(old->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { while (Z_TYPE_P(zv) == IS_UNDEF) { zv++; } @@ -3012,11 +3012,11 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ return 0; } zv++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { Bucket *b = type->func.args->arData; - ZEND_ARRAY_FOREACH_PTR(old->func.args, arg_type) { + ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { while (Z_TYPE(b->val) == IS_UNDEF) { b++; } @@ -3024,7 +3024,7 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ return 0; } b++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } break; @@ -3084,15 +3084,15 @@ static bool zend_ffi_subst_old_type(zend_ffi_type **dcl, zend_ffi_type *old, zen if (dcl_type->func.args) { zval *zv; - ZEND_ARRAY_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_old_type((zend_ffi_type**)&Z_PTR_P(zv), old, type)) { return 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case ZEND_FFI_TYPE_STRUCT: - ZEND_HASH_FOREACH_PTR(&dcl_type->record.fields, field) { + ZEND_HASH_MAP_FOREACH_PTR(&dcl_type->record.fields, field) { if (zend_ffi_subst_old_type(&field->type, old, type)) { return 1; } @@ -3110,12 +3110,12 @@ static void zend_ffi_cleanup_type(zend_ffi_type *old, zend_ffi_type *type) /* {{ zend_ffi_tag *tag; if (FFI_G(symbols)) { - ZEND_HASH_FOREACH_PTR(FFI_G(symbols), sym) { + ZEND_HASH_MAP_FOREACH_PTR(FFI_G(symbols), sym) { zend_ffi_subst_old_type(&sym->type, old, type); } ZEND_HASH_FOREACH_END(); } if (FFI_G(tags)) { - ZEND_HASH_FOREACH_PTR(FFI_G(tags), tag) { + ZEND_HASH_MAP_FOREACH_PTR(FFI_G(tags), tag) { zend_ffi_subst_old_type(&tag->type, old, type); } ZEND_HASH_FOREACH_END(); } @@ -3238,7 +3238,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */ } if (FFI_G(symbols)) { - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { if (sym->kind == ZEND_FFI_SYM_VAR) { addr = DL_FETCH_SYMBOL(handle, ZSTR_VAL(name)); if (!addr) { @@ -3296,7 +3296,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */ if (preload) { if (scope && scope->tags && FFI_G(tags)) { - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(tags), name, tag) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(tags), name, tag) { zend_ffi_tag *old_tag = zend_hash_find_ptr(scope->tags, name); if (old_tag) { @@ -3335,7 +3335,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */ scope->symbols = FFI_G(symbols); FFI_G(symbols) = NULL; } else { - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(symbols), name, sym) { if (!zend_hash_add_ptr(scope->symbols, name, sym)) { zend_ffi_type_dtor(sym->type); free(sym); @@ -3350,7 +3350,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */ scope->tags = FFI_G(tags); FFI_G(tags) = NULL; } else { - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(tags), name, tag) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(tags), name, tag) { if (!zend_hash_add_ptr(scope->tags, name, tag)) { zend_ffi_type_dtor(tag->type); free(tag); @@ -3499,7 +3499,7 @@ static zend_result zend_ffi_validate_incomplete_type(zend_ffi_type *type, bool a zend_string *key; zend_ffi_tag *tag; - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(tags), key, tag) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(tags), key, tag) { if (ZEND_FFI_TYPE(tag->type) == type) { if (type->kind == ZEND_FFI_TYPE_ENUM) { zend_ffi_throw_parser_error("Incomplete enum \"%s\" at line %d", ZSTR_VAL(key), FFI_G(line)); @@ -3516,7 +3516,7 @@ static zend_result zend_ffi_validate_incomplete_type(zend_ffi_type *type, bool a zend_string *key; zend_ffi_symbol *sym; - ZEND_HASH_FOREACH_STR_KEY_PTR(FFI_G(symbols), key, sym) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(symbols), key, sym) { if (type == ZEND_FFI_TYPE(sym->type)) { zend_ffi_throw_parser_error("Incomplete C type %s at line %d", ZSTR_VAL(key), FFI_G(line)); return FAILURE; @@ -3588,15 +3588,15 @@ static bool zend_ffi_subst_type(zend_ffi_type **dcl, zend_ffi_type *type) /* {{{ if (dcl_type->func.args) { zval *zv; - ZEND_ARRAY_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_type((zend_ffi_type**)&Z_PTR_P(zv), type)) { return 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case ZEND_FFI_TYPE_STRUCT: - ZEND_HASH_FOREACH_PTR(&dcl_type->record.fields, field) { + ZEND_HASH_MAP_FOREACH_PTR(&dcl_type->record.fields, field) { if (zend_ffi_subst_type(&field->type, type)) { return 1; } @@ -3611,7 +3611,7 @@ static bool zend_ffi_subst_type(zend_ffi_type **dcl, zend_ffi_type *type) /* {{{ static void zend_ffi_tags_cleanup(zend_ffi_dcl *dcl) /* {{{ */ { zend_ffi_tag *tag; - ZEND_HASH_FOREACH_PTR(FFI_G(tags), tag) { + ZEND_HASH_MAP_FOREACH_PTR(FFI_G(tags), tag) { if (ZEND_FFI_TYPE_IS_OWNED(tag->type)) { zend_ffi_type *type = ZEND_FFI_TYPE(tag->type); zend_ffi_subst_type(&dcl->type, type); @@ -4091,7 +4091,7 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ } } - ZEND_ARRAY_REVERSE_FOREACH_VAL(dims, val) { + ZEND_HASH_REVERSE_FOREACH_VAL(dims, val) { zend_long n = zval_get_long(val); zend_ffi_type *new_type; @@ -4118,7 +4118,7 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ } type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ctype = (zend_ffi_ctype*)zend_ffi_ctype_new(zend_ffi_ctype_ce); ctype->type = type; @@ -4640,7 +4640,7 @@ ZEND_METHOD(FFI_CType, getStructFieldNames) /* {{{ */ ht = zend_new_array(zend_hash_num_elements(&type->record.fields)); RETVAL_ARR(ht); - ZEND_HASH_FOREACH_STR_KEY(&type->record.fields, name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&type->record.fields, name) { ZVAL_STR_COPY(&zv, name); zend_hash_next_index_insert_new(ht, &zv); } ZEND_HASH_FOREACH_END(); @@ -5917,7 +5917,7 @@ static zend_result zend_ffi_validate_prev_field_type(zend_ffi_type *struct_type) if (zend_hash_num_elements(&struct_type->record.fields) > 0) { zend_ffi_field *field = NULL; - ZEND_HASH_REVERSE_FOREACH_PTR(&struct_type->record.fields, field) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(&struct_type->record.fields, field) { break; } ZEND_HASH_FOREACH_END(); if (ZEND_FFI_TYPE(field->type)->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY) { @@ -6020,7 +6020,7 @@ void zend_ffi_add_anonymous_field(zend_ffi_dcl *struct_dcl, zend_ffi_dcl *field_ } } - ZEND_HASH_FOREACH_STR_KEY_PTR(&field_type->record.fields, key, field) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&field_type->record.fields, key, field) { zend_ffi_field *new_field = pemalloc(sizeof(zend_ffi_field), FFI_G(persistent)); if (struct_type->attr & ZEND_FFI_ATTR_UNION) { @@ -6124,7 +6124,7 @@ void zend_ffi_add_bit_field(zend_ffi_dcl *struct_dcl, const char *name, size_t n zend_ffi_field *prev_field = NULL; if (zend_hash_num_elements(&struct_type->record.fields) > 0) { - ZEND_HASH_REVERSE_FOREACH_PTR(&struct_type->record.fields, prev_field) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(&struct_type->record.fields, prev_field) { break; } ZEND_HASH_FOREACH_END(); } @@ -6280,7 +6280,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n int no_args = 0; zend_ffi_type *arg_type; - ZEND_ARRAY_FOREACH_PTR(args, arg_type) { + ZEND_HASH_FOREACH_PTR(args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); if (arg_type->kind == ZEND_FFI_TYPE_VOID) { if (zend_hash_num_elements(args) != 1) { @@ -6294,7 +6294,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n no_args = 1; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (no_args) { zend_hash_destroy(args); pefree(args, FFI_G(persistent)); @@ -6307,7 +6307,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ulong i; zend_ffi_type *arg_type; - ZEND_ARRAY_FOREACH_NUM_KEY_PTR(args, i, arg_type) { + ZEND_HASH_FOREACH_NUM_KEY_PTR(args, i, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); # ifdef _WIN64 if (i >= 4 && i <= 5 && (arg_type->kind == ZEND_FFI_TYPE_FLOAT || arg_type->kind == ZEND_FFI_TYPE_DOUBLE)) { @@ -6321,7 +6321,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ffi_parser_error("Type float/double is not allowed at position " ZEND_ULONG_FMT " with __vectorcall at line %d", i+1, FFI_G(line)); return; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } #endif diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 39ad1fd03e758..836ee8345affb 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -446,7 +446,7 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f } Z_PROTECT_RECURSION_P(value); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(value), element) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(value), element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) == IS_ARRAY) { SEPARATE_ARRAY(element); @@ -454,7 +454,7 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f } else { php_zval_filter(element, filter, flags, options, charset, copy); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); Z_UNPROTECT_RECURSION_P(value); } else { php_zval_filter(value, filter, flags, options, charset, copy); @@ -616,7 +616,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op } else { array_init(return_value); - ZEND_ARRAY_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) { + ZEND_HASH_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) { if (arg_key == NULL) { zend_argument_type_error(2, "must contain only string keys"); RETURN_THROWS(); @@ -640,7 +640,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op ); zend_hash_update(Z_ARRVAL_P(return_value), arg_key, &nval); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 3623ce88cd09a..d7b030d134535 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -801,9 +801,9 @@ PHP_FUNCTION(imagesetstyle) /* copy the style values in the stylearr */ stylearr = safe_emalloc(sizeof(int), num_styles, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(styles), item) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(styles), item) { stylearr[index++] = zval_get_long(item); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); gdImageSetStyle(im, stylearr, index); @@ -3234,7 +3234,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode) /* walk the assoc array */ if (!HT_IS_PACKED(Z_ARRVAL_P(EXT))) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(EXT), key, item) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(EXT), key, item) { if (key == NULL) { continue; } @@ -3489,9 +3489,9 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS) colors = emalloc(num_colors * sizeof(int)); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(hash_colors), color) { *(colors + i++) = (int) zval_get_long(color); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); RETVAL_BOOL(gdImageScatterColor(im, (int)scatter_sub, (int)scatter_plus, colors, num_colors)); diff --git a/ext/hash/hash.c b/ext/hash/hash.c index a89939e634127..62b82263dc7e3 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -860,7 +860,7 @@ PHP_FUNCTION(hash_algos) } array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_hash_hashtable, str) { add_next_index_str(return_value, zend_string_copy(str)); } ZEND_HASH_FOREACH_END(); } @@ -877,7 +877,7 @@ PHP_FUNCTION(hash_hmac_algos) } array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) { if (ops->is_crypto) { add_next_index_str(return_value, zend_string_copy(str)); } @@ -1663,7 +1663,7 @@ PHP_MINFO_FUNCTION(hash) zend_string *str; char *s = buffer, *e = s + sizeof(buffer); - ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_hash_hashtable, str) { s += slprintf(s, e - s, "%s ", ZSTR_VAL(str)); } ZEND_HASH_FOREACH_END(); *s = 0; diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 62103ab1addd1..b6d2dd8b74da8 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -3139,7 +3139,7 @@ PHP_FUNCTION(imap_mail_compose) if (Z_TYPE_P(pvalue) == IS_ARRAY) { custom_headers_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pvalue), env_data) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pvalue), env_data) { custom_headers_param = mail_newbody_parameter(); convert_to_string(env_data); CHECK_HEADER_INJECTION(Z_STR_P(env_data), 0, "custom_headers"); @@ -3148,12 +3148,12 @@ PHP_FUNCTION(imap_mail_compose) memcpy(custom_headers_param->value, Z_STRVAL_P(env_data), Z_STRLEN_P(env_data) + 1); custom_headers_param->next = tmp_param; tmp_param = custom_headers_param; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } first = 1; - ZEND_ARRAY_FOREACH_VAL(body, data) { + ZEND_HASH_FOREACH_VAL(body, data) { if (first) { first = 0; @@ -3196,7 +3196,7 @@ PHP_FUNCTION(imap_mail_compose) if(Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { if (key == NULL) continue; CHECK_HEADER_INJECTION(key, 0, "body disposition key"); disp_param = mail_newbody_parameter(); @@ -3236,7 +3236,7 @@ PHP_FUNCTION(imap_mail_compose) if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { if (key == NULL) continue; CHECK_HEADER_INJECTION(key, 0, "body type.parameters key"); disp_param = mail_newbody_parameter(); @@ -3318,7 +3318,7 @@ PHP_FUNCTION(imap_mail_compose) if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { if (key == NULL) continue; CHECK_HEADER_INJECTION(key, 0, "body type.parameters key"); disp_param = mail_newbody_parameter(); @@ -3358,7 +3358,7 @@ PHP_FUNCTION(imap_mail_compose) if (Z_TYPE_P(pvalue) == IS_ARRAY && !HT_IS_PACKED(Z_ARRVAL_P(pvalue))) { disp_param = tmp_param = NULL; SEPARATE_ARRAY(pvalue); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pvalue), key, disp_data) { if (key == NULL) continue; CHECK_HEADER_INJECTION(key, 0, "body disposition key"); disp_param = mail_newbody_parameter(); @@ -3399,7 +3399,7 @@ PHP_FUNCTION(imap_mail_compose) bod->md5 = cpystr(Z_STRVAL_P(pvalue)); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (bod && bod->type == TYPEMULTIPART && (!bod->nested.part || !bod->nested.part->next)) { php_error_docref(NULL, E_WARNING, "Cannot generate multipart e-mail without components."); diff --git a/ext/intl/collator/collator_convert.c b/ext/intl/collator/collator_convert.c index a74ed27871a62..55f2995895b88 100644 --- a/ext/intl/collator/collator_convert.c +++ b/ext/intl/collator/collator_convert.c @@ -118,13 +118,13 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* stat zval *hashData; zend_string *hashKey; - ZEND_ARRAY_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { + ZEND_HASH_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE. */ collator_convert_hash_item_from_utf8_to_utf16( hash, hashData, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) return; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -137,14 +137,14 @@ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* stat zend_string *hashKey; zval *hashData; - ZEND_ARRAY_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { + ZEND_HASH_FOREACH_KEY_VAL(hash, hashIndex, hashKey, hashData) { /* Convert current hash item from UTF-16LE to UTF-8. */ collator_convert_hash_item_from_utf16_to_utf8( hash, hashData, hashKey, hashIndex, status ); if( U_FAILURE( *status ) ) { return; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index 2dcc572243c1f..0634e68fc7a36 100644 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -384,7 +384,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) utf16_buf = eumalloc( utf16_buf_size ); /* Iterate through input hash and create a sort key for each value. */ - ZEND_ARRAY_FOREACH_VAL(hash, hashData) { + ZEND_HASH_FOREACH_VAL(hash, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf. */ utf16_len = utf16_buf_size; @@ -457,7 +457,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) sortKeyBufOffset += sortKeyLen; ++sortKeyCount; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* update ptrs to point to valid keys. */ for( j = 0; j < sortKeyCount; j++ ) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 7557dea541fd7..c3d54e8a84a4d 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -190,9 +190,9 @@ static void php_converter_append_toUnicode_target(zval *val, UConverterToUnicode HashTable *ht = Z_ARRVAL_P(val); zval *tmpzval; - ZEND_ARRAY_FOREACH_VAL(ht, tmpzval) { + ZEND_HASH_FOREACH_VAL(ht, tmpzval) { php_converter_append_toUnicode_target(tmpzval, args, objval); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return; } default: @@ -274,9 +274,9 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni { HashTable *ht = Z_ARRVAL_P(val); zval *tmpzval; - ZEND_ARRAY_FOREACH_VAL(ht, tmpzval) { + ZEND_HASH_FOREACH_VAL(ht, tmpzval) { php_converter_append_fromUnicode_target(tmpzval, args, objval); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return; } default: diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index 34f7c7bd4db0c..6afc9e6dca503 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -99,7 +99,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) uint32_t idx = 0; zval *z; - ZEND_ARRAY_FOREACH_VAL(ht, z) { + ZEND_HASH_FOREACH_VAL(ht, z) { if (!valid_format(z)) { if (idx == 0) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, @@ -120,7 +120,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) timeStyle = (DateFormat::EStyle)Z_LVAL_P(z); } idx++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ZEND_ASSERT(idx == 2 && "We checked that there are two elements above"); } else if (Z_TYPE_P(format) == IS_LONG) { if (!valid_format(format)) { diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index 49a6ee04b7b7b..1782dd6ecb43f 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -774,7 +774,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, HashTable *arr = Z_ARRVAL_P(ele_value); zval *data; - ZEND_ARRAY_FOREACH_VAL(arr, data) { + ZEND_HASH_FOREACH_VAL(arr, data) { if(Z_TYPE_P(data) != IS_STRING) { return FAILURE; } @@ -783,7 +783,7 @@ static int append_multiple_key_values(smart_str* loc_name, HashTable* hash_arr, } smart_str_appendl(loc_name, SEPARATOR , sizeof(SEPARATOR)-1); smart_str_appendl(loc_name, Z_STRVAL_P(data) , Z_STRLEN_P(data)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } else { return FAILURE; @@ -1342,7 +1342,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr, zend_string* return_value = NULL; char **cur_arr = ecalloc(zend_hash_num_elements(hash_arr)*2, sizeof(char *)); - ZEND_ARRAY_FOREACH_VAL(hash_arr, ele_value) { + ZEND_HASH_FOREACH_VAL(hash_arr, ele_value) { /* convert the array to lowercase , also replace hyphens with the underscore and store it in cur_arr */ if(Z_TYPE_P(ele_value)!= IS_STRING) { /* element value is not a string */ @@ -1357,7 +1357,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr, } cur_arr[cur_arr_len*2+1] = Z_STRVAL_P(ele_value); cur_arr_len++ ; - } ZEND_ARRAY_FOREACH_END(); /* end of for */ + } ZEND_HASH_FOREACH_END(); /* end of for */ /* Canonicalize array elements */ if(canonicalize) { diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index 6ea5333849e52..5ca44b8ab346b 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -391,7 +391,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, zend_string *str_index; zend_ulong num_index; - ZEND_ARRAY_FOREACH_KEY_VAL(args, num_index, str_index, elem) { + ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; UnicodeString& key = farg_names[argNum]; Formattable::Type argType = Formattable::kObject, //unknown @@ -586,7 +586,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, } } argNum++; - } ZEND_ARRAY_FOREACH_END(); // visiting each argument + } ZEND_HASH_FOREACH_END(); // visiting each argument if (U_FAILURE(err.code)) { return; diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 75429400f09ce..b0f703041b068 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -223,7 +223,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso zval *data; zend_ulong index; - ZEND_ARRAY_FOREACH_KEY_VAL_IND(myht, index, key, data) { + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, data) { if (r == PHP_JSON_OUTPUT_ARRAY) { if (need_comma) { smart_str_appendc(buf, ','); @@ -281,7 +281,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso zend_release_properties(prop_ht); return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } PHP_JSON_HASH_UNPROTECT_RECURSION(myht); diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index cc1536c12830f..6e0f28f68080e 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -757,7 +757,7 @@ static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array, uint32 ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0); *ctrls = NULL; ctrlp = ctrls; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) { if (Z_TYPE_P(ctrlarray) != IS_ARRAY) { zend_argument_type_error(arg_num, "must contain only arrays, where each array is a control"); error = 1; @@ -772,7 +772,7 @@ static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array, uint32 } *ctrlp = NULL; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (error) { ctrlp = ctrls; diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 39938a4be5a25..0f63b90a947e1 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -370,7 +370,7 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) if (Z_TYPE(s->wrapperdata) == IS_ARRAY) { zval *header; - ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL(s->wrapperdata), header) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL(s->wrapperdata), header) { const char buf[] = "Content-Type:"; if (Z_TYPE_P(header) == IS_STRING && !zend_binary_strncasecmp(Z_STRVAL_P(header), Z_STRLEN_P(header), buf, sizeof(buf)-1, sizeof(buf)-1)) { @@ -407,7 +407,7 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc) efree(needle); break; /* found content-type */ } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 7cc2f1215166a..a7dfcbe7d4c82 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -350,7 +350,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi bool included_auto = 0; size_t n = 0; zval *hash_entry; - ZEND_ARRAY_FOREACH_VAL(target_hash, hash_entry) { + ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) { zend_string *encoding_str = zval_try_get_string(hash_entry); if (UNEXPECTED(!encoding_str)) { efree(ZEND_VOIDP(list)); @@ -382,7 +382,7 @@ static int php_mb_parse_encoding_array(HashTable *target_hash, const mbfl_encodi } } zend_string_release(encoding_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *return_list = list; *return_size = n; return SUCCESS; @@ -2429,7 +2429,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons } GC_TRY_PROTECT_RECURSION(input); output = zend_new_array(zend_hash_num_elements(input)); - ZEND_ARRAY_FOREACH_KEY_VAL(input, idx, key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(input, idx, key, entry) { /* convert key */ if (key) { ckey = php_mb_convert_encoding( @@ -2482,7 +2482,7 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons } else { zend_hash_index_add(output, idx, &entry_tmp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(input); return output; @@ -3009,7 +3009,7 @@ static int mb_recursive_encoder_detector_feed(mbfl_encoding_detector *identd, zv ht = HASH_OF(var); if (ht != NULL) { - ZEND_ARRAY_FOREACH_VAL_IND(ht, entry) { + ZEND_HASH_FOREACH_VAL_IND(ht, entry) { if (mb_recursive_encoder_detector_feed(identd, entry, recursion_error)) { if (Z_REFCOUNTED_P(var)) { Z_UNPROTECT_RECURSION_P(var); @@ -3021,7 +3021,7 @@ static int mb_recursive_encoder_detector_feed(mbfl_encoding_detector *identd, zv } return 0; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (Z_REFCOUNTED_P(var)) { @@ -3062,14 +3062,14 @@ static int mb_recursive_convert_variable(mbfl_buffer_converter *convd, zval *var ht = HASH_OF(var); if (ht != NULL) { - ZEND_ARRAY_FOREACH_VAL_IND(ht, entry) { + ZEND_HASH_FOREACH_VAL_IND(ht, entry) { if (mb_recursive_convert_variable(convd, entry)) { if (Z_REFCOUNTED_P(var)) { Z_UNPROTECT_RECURSION_P(var); } return 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (Z_REFCOUNTED_P(var)) { @@ -3209,9 +3209,9 @@ static int *make_conversion_map(HashTable *target_hash, int *convmap_size) int *convmap = (int *)safe_emalloc(n_elems, sizeof(int), 0); int *mapelm = convmap; - ZEND_ARRAY_FOREACH_VAL(target_hash, hash_entry) { + ZEND_HASH_FOREACH_VAL(target_hash, hash_entry) { *mapelm++ = zval_get_long(hash_entry); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *convmap_size = n_elems / 4; return convmap; @@ -3924,7 +3924,7 @@ static int php_mb_check_encoding_recursive(HashTable *vars, const mbfl_encoding return 0; } GC_TRY_PROTECT_RECURSION(vars); - ZEND_ARRAY_FOREACH_KEY_VAL(vars, idx, key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(vars, idx, key, entry) { ZVAL_DEREF(entry); if (key) { if (!php_mb_check_encoding(ZSTR_VAL(key), ZSTR_LEN(key), encoding)) { @@ -3956,7 +3956,7 @@ static int php_mb_check_encoding_recursive(HashTable *vars, const mbfl_encoding valid = 0; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(vars); return valid; } diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 0ed4d51fc02d0..3782820e77d62 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -398,7 +398,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp) retval = zend_new_array(zend_hash_num_elements(props) + 1); - ZEND_ARRAY_FOREACH_PTR(props, entry) { + ZEND_HASH_FOREACH_PTR(props, entry) { zval rv; zval *value; @@ -406,7 +406,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp) if (value != &EG(uninitialized_zval)) { zend_hash_add(retval, entry->name, value); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *is_temp = 1; return retval; diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index c73059eeec7d0..96dee255b2b96 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -846,11 +846,11 @@ PHP_FUNCTION(mysqli_stmt_execute) ZEND_ASSERT(params); index = 0; - ZEND_ARRAY_FOREACH_VAL(input_params, tmp) { + ZEND_HASH_FOREACH_VAL(input_params, tmp) { ZVAL_COPY_VALUE(¶ms[index].zv, tmp); params[index].type = MYSQL_TYPE_VAR_STRING; index++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (mysqlnd_stmt_bind_param(stmt->stmt, params)) { MYSQLI_REPORT_STMT_ERROR(stmt->stmt); diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 961ac290cf5e8..b4f80f6df38c6 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -772,7 +772,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar return SUCCESS; } *out_array = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(in_array)) + 1, sizeof(MYSQLND *)); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(in_array), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_array), elem) { i++; if (Z_TYPE_P(elem) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) { @@ -793,7 +793,7 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar } (*out_array)[current++] = mysql->mysql; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } /* }}} */ @@ -808,7 +808,7 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a array_init_size(&dest_array, zend_hash_num_elements(Z_ARRVAL_P(out_array))); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(out_array), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(out_array), elem) { if (Z_TYPE_P(elem) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) { continue; @@ -831,7 +831,7 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND **in_array, zval *out_a p++; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* destroy old array and add new one */ zval_ptr_dtor(out_array); @@ -850,7 +850,7 @@ static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, z array_init(&proxy); if (in_array) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(in_zval_array), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(in_zval_array), elem) { MY_MYSQL *mysql; mysqli_object *intern = Z_MYSQLI_P(elem); mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)intern->ptr)->ptr; @@ -862,7 +862,7 @@ static int mysqlnd_dont_poll_zval_array_from_mysqlnd_array(MYSQLND **in_array, z ret++; p++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* destroy old array and add new one */ diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 0d76d2e4f6af1..6a33a16892436 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -430,7 +430,7 @@ MYSQLND_METHOD(mysqlnd_debug, close)(MYSQLND_DEBUG * self) self->m->log_va(self, __LINE__, __FILE__, 0, "info : ", "number of functions: %d", zend_hash_num_elements(&self->function_profiles)); - ZEND_HASH_FOREACH_STR_KEY_PTR(&self->function_profiles, string_key, f_profile) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&self->function_profiles, string_key, f_profile) { self->m->log_va(self, __LINE__, __FILE__, -1, "info : ", "%-40s\tcalls=%5" PRIu64 " own_slow=%5" PRIu64 diff --git a/ext/mysqlnd/mysqlnd_plugin.c b/ext/mysqlnd/mysqlnd_plugin.c index dad8187ba9646..4bd9894b8c4bb 100644 --- a/ext/mysqlnd/mysqlnd_plugin.c +++ b/ext/mysqlnd/mysqlnd_plugin.c @@ -167,7 +167,7 @@ PHPAPI void mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void zval *val; int result; - ZEND_HASH_FOREACH_VAL(&mysqlnd_registered_plugins, val) { + ZEND_HASH_MAP_FOREACH_VAL(&mysqlnd_registered_plugins, val) { result = apply_func(val, argument); if (result & ZEND_HASH_APPLY_REMOVE) { php_error_docref(NULL, E_WARNING, "mysqlnd_plugin_apply_with_argument must not remove table entries"); diff --git a/ext/mysqlnd/mysqlnd_reverse_api.c b/ext/mysqlnd/mysqlnd_reverse_api.c index ae4b4e74c8031..982aac065eb04 100644 --- a/ext/mysqlnd/mysqlnd_reverse_api.c +++ b/ext/mysqlnd/mysqlnd_reverse_api.c @@ -67,7 +67,7 @@ PHPAPI MYSQLND * zval_to_mysqlnd(zval * zv, const unsigned int client_api_capabilities, unsigned int * save_client_api_capabilities) { MYSQLND_REVERSE_API *api; - ZEND_HASH_FOREACH_PTR(&mysqlnd_api_ext_ht, api) { + ZEND_HASH_MAP_FOREACH_PTR(&mysqlnd_api_ext_ht, api) { if (api->conversion_cb) { MYSQLND *retval = api->conversion_cb(zv); if (retval) { diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index 77d0c31aa6dda..644909cc4ba98 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -573,7 +573,7 @@ size_t php_mysqlnd_auth_write(MYSQLND_CONN_DATA * conn, void * _packet) { zend_string * key; zval * entry_value; - ZEND_HASH_FOREACH_STR_KEY_VAL(packet->connect_attr, key, entry_value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(packet->connect_attr, key, entry_value) { if (key) { /* HASH_KEY_IS_STRING */ size_t value_len = Z_STRLEN_P(entry_value); @@ -591,7 +591,7 @@ size_t php_mysqlnd_auth_write(MYSQLND_CONN_DATA * conn, void * _packet) { zend_string * key; zval * entry_value; - ZEND_HASH_FOREACH_STR_KEY_VAL(packet->connect_attr, key, entry_value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(packet->connect_attr, key, entry_value) { if (key) { /* HASH_KEY_IS_STRING */ size_t value_len = Z_STRLEN_P(entry_value); diff --git a/ext/mysqlnd/php_mysqlnd.c b/ext/mysqlnd/php_mysqlnd.c index ff31a54b454f3..368c253a64f9f 100644 --- a/ext/mysqlnd/php_mysqlnd.c +++ b/ext/mysqlnd/php_mysqlnd.c @@ -31,7 +31,7 @@ mysqlnd_minfo_print_hash(zval *values) zval *values_entry; zend_string *string_key; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), string_key, values_entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), string_key, values_entry) { convert_to_string(values_entry); php_info_print_table_row(2, ZSTR_VAL(string_key), Z_STRVAL_P(values_entry)); } ZEND_HASH_FOREACH_END(); @@ -63,7 +63,7 @@ mysqlnd_minfo_dump_api_plugins(smart_str * buffer) HashTable *ht = mysqlnd_reverse_api_get_api_list(); MYSQLND_REVERSE_API *ext; - ZEND_HASH_FOREACH_PTR(ht, ext) { + ZEND_HASH_MAP_FOREACH_PTR(ht, ext) { if (buffer->s) { smart_str_appendc(buffer, ','); } diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 810f8717e71d3..a99785985ffc2 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -151,14 +151,14 @@ static void _close_odbc_conn(zend_resource *rsrc) odbc_connection *conn = (odbc_connection *)rsrc->ptr; - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* If aborted via timer expiration, don't try to call any unixODBC function */ if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) { @@ -178,14 +178,14 @@ static void _close_odbc_pconn(zend_resource *rsrc) odbc_result *res; odbc_connection *conn = (odbc_connection *)rsrc->ptr; - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* If aborted via timer expiration, don't try to call any unixODBC function */ if (!(PG(connection_status) & PHP_CONNECTION_TIMEOUT)) { @@ -822,14 +822,14 @@ PHP_FUNCTION(odbc_close_all) } /* Loop through list and close all statements */ - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { zend_list_close(p); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Second loop through list, now close all connections */ - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr) { if (p->type == le_conn){ zend_list_close(p); @@ -840,7 +840,7 @@ PHP_FUNCTION(odbc_close_all) (apply_func_arg_t) _close_pconn_with_res, (void *)p); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -1014,7 +1014,7 @@ PHP_FUNCTION(odbc_execute) } i = 1; - ZEND_ARRAY_FOREACH_VAL(pv_param_ht, tmp) { + ZEND_HASH_FOREACH_VAL(pv_param_ht, tmp) { unsigned char otype = Z_TYPE_P(tmp); zend_string *tmpstr = zval_try_get_string(tmp); if (!tmpstr) { @@ -1084,7 +1084,7 @@ PHP_FUNCTION(odbc_execute) RETURN_FALSE; } if (++i > result->numparams) break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* Close cursor, needed for doing multiple selects */ rc = SQLFreeStmt(result->stmt, SQL_CLOSE); @@ -2351,14 +2351,14 @@ PHP_FUNCTION(odbc_close) is_pconn = 1; } - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), p) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), p) { if (p->ptr && (p->type == le_result)) { res = (odbc_result *)p->ptr; if (res->conn_ptr == conn) { zend_list_close(p); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_list_close(Z_RES_P(pv_conn)); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 8fe2d271f7f49..e06d3ca67250f 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -601,7 +601,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } /* function table hash keys */ - ZEND_HASH_FOREACH_BUCKET(CG(function_table), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(CG(function_table), p) { if (p->key) { p->key = new_interned_string(p->key); } @@ -630,7 +630,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } ZEND_HASH_FOREACH_END(); /* class table hash keys, class names, properties, methods, constants, etc */ - ZEND_HASH_FOREACH_BUCKET(CG(class_table), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(CG(class_table), p) { zend_class_entry *ce; ce = (zend_class_entry*)Z_PTR(p->val); @@ -644,7 +644,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int ZEND_ASSERT(ZSTR_HAS_CE_CACHE(ce->name)); } - ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, q) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->properties_info, q) { zend_property_info *info; info = (zend_property_info*)Z_PTR(q->val); @@ -658,7 +658,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(&ce->function_table, q) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->function_table, q) { if (q->key) { q->key = new_interned_string(q->key); } @@ -667,7 +667,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(&ce->constants_table, q) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->constants_table, q) { if (q->key) { q->key = new_interned_string(q->key); } @@ -675,7 +675,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } ZEND_HASH_FOREACH_END(); /* constant hash keys */ - ZEND_HASH_FOREACH_BUCKET(EG(zend_constants), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(EG(zend_constants), p) { zend_constant *c; if (p->key) { @@ -691,7 +691,7 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } ZEND_HASH_FOREACH_END(); /* auto globals hash keys and names */ - ZEND_HASH_FOREACH_BUCKET(CG(auto_globals), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(CG(auto_globals), p) { zend_auto_global *auto_global; auto_global = (zend_auto_global*)Z_PTR(p->val); @@ -703,13 +703,13 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(&module_registry, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&module_registry, p) { if (p->key) { p->key = new_interned_string(p->key); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(EG(ini_directives), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(EG(ini_directives), p) { zend_ini_entry *entry = (zend_ini_entry*)Z_PTR(p->val); if (p->key) { @@ -727,21 +727,21 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int } ZEND_HASH_FOREACH_END(); ht = php_get_stream_filters_hash_global(); - ZEND_HASH_FOREACH_BUCKET(ht, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(ht, p) { if (p->key) { p->key = new_interned_string(p->key); } } ZEND_HASH_FOREACH_END(); ht = php_stream_get_url_stream_wrappers_hash_global(); - ZEND_HASH_FOREACH_BUCKET(ht, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(ht, p) { if (p->key) { p->key = new_interned_string(p->key); } } ZEND_HASH_FOREACH_END(); ht = php_stream_xport_get_hash(); - ZEND_HASH_FOREACH_BUCKET(ht, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(ht, p) { if (p->key) { p->key = new_interned_string(p->key); } @@ -2405,7 +2405,7 @@ static zend_class_entry* zend_accel_inheritance_cache_add(zend_class_entry *ce, i = 0; entry->dependencies_count = zend_hash_num_elements(dependencies); entry->dependencies = (zend_class_dependency*)ZCG(mem); - ZEND_HASH_FOREACH_STR_KEY_PTR(dependencies, dep_name, dep_ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(dependencies, dep_name, dep_ce) { #if ZEND_DEBUG ZEND_ASSERT(zend_accel_in_shm(dep_name)); #endif @@ -2588,7 +2588,7 @@ static void accel_reset_pcre_cache(void) return; } - ZEND_HASH_FOREACH_BUCKET(&PCRE_G(pcre_cache), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&PCRE_G(pcre_cache), p) { /* Remove PCRE cache entries with inconsistent keys */ if (zend_accel_in_shm(p->key)) { p->key = NULL; @@ -3462,31 +3462,31 @@ static void preload_shutdown(void) #if 0 if (EG(zend_constants)) { - ZEND_HASH_REVERSE_FOREACH_VAL(EG(zend_constants), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(zend_constants), zv) { zend_constant *c = Z_PTR_P(zv); if (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) { break; } - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } #endif if (EG(function_table)) { - ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(function_table), zv) { zend_function *func = Z_PTR_P(zv); if (func->type == ZEND_INTERNAL_FUNCTION) { break; } - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } if (EG(class_table)) { - ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) { zend_class_entry *ce = Z_PTR_P(zv); if (ce->type == ZEND_INTERNAL_CLASS) { break; } - } ZEND_HASH_FOREACH_END_DEL(); + } ZEND_HASH_MAP_FOREACH_END_DEL(); } } @@ -3530,7 +3530,7 @@ static void preload_move_user_functions(HashTable *src, HashTable *dst) src->pDestructor = NULL; zend_hash_extend(dst, dst->nNumUsed + src->nNumUsed, 0); - ZEND_HASH_REVERSE_FOREACH_BUCKET(src, p) { + ZEND_HASH_MAP_REVERSE_FOREACH_BUCKET(src, p) { zend_function *function = Z_PTR(p->val); if (EXPECTED(function->type == ZEND_USER_FUNCTION)) { @@ -3569,7 +3569,7 @@ static void preload_move_user_classes(HashTable *src, HashTable *dst) src->pDestructor = NULL; zend_hash_extend(dst, dst->nNumUsed + src->nNumUsed, 0); - ZEND_HASH_FOREACH_BUCKET_FROM(src, p, EG(persistent_classes_count)) { + ZEND_HASH_MAP_FOREACH_BUCKET_FROM(src, p, EG(persistent_classes_count)) { zend_class_entry *ce = Z_PTR(p->val); ZEND_ASSERT(ce->type == ZEND_USER_CLASS); if (ce->info.user.filename != filename) { @@ -3734,7 +3734,7 @@ static bool preload_try_resolve_constants(zend_class_entry *ce) do { ok = 1; changed = 0; - ZEND_HASH_FOREACH_PTR(&ce->constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->constants_table, c) { val = &c->value; if (Z_TYPE_P(val) == IS_CONSTANT_AST) { if (EXPECTED(preload_update_constant(val, c->ce) == SUCCESS)) { @@ -3875,7 +3875,7 @@ static void preload_link(void) do { changed = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL_FROM(EG(class_table), key, zv, EG(persistent_classes_count)) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_FROM(EG(class_table), key, zv, EG(persistent_classes_count)) { ce = Z_PTR_P(zv); ZEND_ASSERT(ce->type != ZEND_INTERNAL_CLASS); @@ -3966,7 +3966,7 @@ static void preload_link(void) do { changed = 0; - ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) { + ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) { ce = Z_PTR_P(zv); if (ce->type == ZEND_INTERNAL_CLASS) { break; @@ -3984,7 +3984,7 @@ static void preload_link(void) } while (changed); /* Warn for classes that could not be linked. */ - ZEND_HASH_FOREACH_STR_KEY_VAL_FROM( + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_FROM( EG(class_table), key, zv, EG(persistent_classes_count)) { ce = Z_PTR_P(zv); ZEND_ASSERT(ce->type != ZEND_INTERNAL_CLASS); @@ -4015,7 +4015,7 @@ static void preload_link(void) zend_hash_destroy(&errors); - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { zend_op_array *op_array = &script->script.main_op_array; preload_remove_declares(op_array); @@ -4030,12 +4030,12 @@ static void preload_link(void) /* Dynamic defs inside functions and methods need to be removed as well. */ zend_op_array *op_array; - ZEND_HASH_FOREACH_PTR_FROM(EG(function_table), op_array, EG(persistent_functions_count)) { + ZEND_HASH_MAP_FOREACH_PTR_FROM(EG(function_table), op_array, EG(persistent_functions_count)) { ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION); preload_remove_declares(op_array); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_PTR_FROM(EG(class_table), ce, EG(persistent_classes_count)) { - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR_FROM(EG(class_table), ce, EG(persistent_classes_count)) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->type == ZEND_USER_FUNCTION) { preload_remove_declares(op_array); } @@ -4057,14 +4057,14 @@ static void preload_remove_empty_includes(void) bool changed; /* mark all as empty */ - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { script->empty = 1; } ZEND_HASH_FOREACH_END(); /* find non empty scripts */ do { changed = 0; - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { if (script->empty) { int empty = 1; zend_op *opline = script->script.main_op_array.opcodes; @@ -4106,7 +4106,7 @@ static void preload_remove_empty_includes(void) } while (changed); /* remove empty includes */ - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { zend_op *opline = script->script.main_op_array.opcodes; zend_op *end = opline + script->script.main_op_array.last; @@ -4139,7 +4139,7 @@ static void preload_remove_empty_includes(void) static void preload_register_trait_methods(zend_class_entry *ce) { zend_op_array *op_array; - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) { ZEND_ASSERT(op_array->refcount && "Must have refcount pointer"); zend_shared_alloc_register_xlat_entry(op_array->refcount, op_array); @@ -4151,7 +4151,7 @@ static void preload_fix_trait_methods(zend_class_entry *ce) { zend_op_array *op_array; - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE) { zend_op_array *orig_op_array = zend_shared_alloc_get_xlat_entry(op_array->refcount); ZEND_ASSERT(orig_op_array && "Must be in xlat table"); @@ -4178,14 +4178,14 @@ static void preload_optimize(zend_persistent_script *script) zend_shared_alloc_init_xlat_table(); - ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(&script->script.class_table, ce) { if (ce->ce_flags & ZEND_ACC_TRAIT) { preload_register_trait_methods(ce); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_PTR(preload_scripts, tmp_script) { - ZEND_HASH_FOREACH_PTR(&tmp_script->script.class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, tmp_script) { + ZEND_HASH_MAP_FOREACH_PTR(&tmp_script->script.class_table, ce) { if (ce->ce_flags & ZEND_ACC_TRAIT) { preload_register_trait_methods(ce); } @@ -4195,19 +4195,19 @@ static void preload_optimize(zend_persistent_script *script) zend_optimize_script(&script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level); zend_accel_finalize_delayed_early_binding_list(script); - ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(&script->script.class_table, ce) { preload_fix_trait_methods(ce); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { - ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(&script->script.class_table, ce) { preload_fix_trait_methods(ce); } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END(); zend_shared_alloc_destroy_xlat_table(); - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { zend_optimize_script(&script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level); zend_accel_finalize_delayed_early_binding_list(script); } ZEND_HASH_FOREACH_END(); @@ -4442,7 +4442,7 @@ static int accel_preload(const char *config, bool in_child) if (EG(zend_constants)) { /* Remember __COMPILER_HALT_OFFSET__(s). Do this early, * as zend_shutdown_executor_values() destroys constants. */ - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { zend_execute_data *orig_execute_data = EG(current_execute_data); zend_execute_data fake_execute_data; zval *offset; @@ -4547,7 +4547,7 @@ static int accel_preload(const char *config, bool in_child) i = 0; ZCSG(saved_scripts) = zend_shared_alloc((zend_hash_num_elements(preload_scripts) + 1) * sizeof(void*)); - ZEND_HASH_FOREACH_PTR(preload_scripts, script) { + ZEND_HASH_MAP_FOREACH_PTR(preload_scripts, script) { if (zend_hash_num_elements(&script->script.class_table) > 1) { zend_hash_sort_ex(&script->script.class_table, preload_sort_classes, NULL, 0); } diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index dc2e3a33fedf1..720680a8f19d6 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -4266,7 +4266,7 @@ void zend_jit_check_funcs(HashTable *function_table, bool is_method) { uintptr_t counter; zend_jit_op_array_extension *jit_extension; - ZEND_HASH_REVERSE_FOREACH_PTR(function_table, func) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(function_table, func) { if (func->type == ZEND_INTERNAL_FUNCTION) { break; } @@ -4570,8 +4570,8 @@ ZEND_EXT_API int zend_jit_script(zend_script *script) zend_class_entry *ce; zend_op_array *op_array; - ZEND_HASH_FOREACH_PTR(&script->class_table, ce) { - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&script->class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (!ZEND_FUNC_INFO(op_array)) { void *jit_extension = zend_shared_alloc_get_xlat_entry(op_array->opcodes); @@ -5053,7 +5053,7 @@ ZEND_EXT_API void zend_jit_deactivate(void) zend_jit_unprotect(); zend_jit_check_funcs(EG(function_table), 0); - ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) { + ZEND_HASH_MAP_REVERSE_FOREACH_PTR(EG(class_table), ce) { if (ce->type == ZEND_INTERNAL_CLASS) { break; } @@ -5108,12 +5108,12 @@ static void zend_jit_restart_preloaded_script(zend_persistent_script *script) zend_jit_restart_preloaded_op_array(&script->script.main_op_array); - ZEND_HASH_FOREACH_PTR(&script->script.function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&script->script.function_table, op_array) { zend_jit_restart_preloaded_op_array(op_array); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) { - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&script->script.class_table, ce) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->type == ZEND_USER_FUNCTION) { zend_jit_restart_preloaded_op_array(op_array); } diff --git a/ext/opcache/jit/zend_jit_disasm.c b/ext/opcache/jit/zend_jit_disasm.c index 621bf1991b8ea..afa0da5dc3af3 100644 --- a/ext/opcache/jit/zend_jit_disasm.c +++ b/ext/opcache/jit/zend_jit_disasm.c @@ -415,7 +415,7 @@ static int zend_jit_disasm(const char *name, /* label numbering */ n = 0; m = 0; - ZEND_HASH_FOREACH_VAL(&labels, z) { + ZEND_HASH_MAP_FOREACH_VAL(&labels, z) { if (Z_TYPE_P(z) == IS_FALSE) { m--; ZVAL_LONG(z, m); diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index da1696bb92083..f785303c936a7 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -649,7 +649,7 @@ ZEND_FUNCTION(opcache_get_status) zend_op_array *op_array; array_init(&scripts); - ZEND_HASH_FOREACH_PTR(&ZCSG(preload_script)->script.function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ZCSG(preload_script)->script.function_table, op_array) { add_next_index_str(&scripts, op_array->function_name); } ZEND_HASH_FOREACH_END(); add_assoc_zval(&statistics, "functions", &scripts); @@ -660,7 +660,7 @@ ZEND_FUNCTION(opcache_get_status) zend_string *key; array_init(&scripts); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ZCSG(preload_script)->script.class_table, key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ZCSG(preload_script)->script.class_table, key, ce) { if (ce->refcount > 1 && !zend_string_equals_ci(key, ce->name)) { add_next_index_str(&scripts, key); } else { diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 38fecae79b0dd..0523f052ebd13 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -228,13 +228,13 @@ static void zend_persist_zval(zval *z) if (HT_IS_PACKED(ht)) { zval *zv; - ZEND_PACKED_FOREACH_VAL(ht, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(ht, zv) { zend_persist_zval(zv); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { Bucket *p; - ZEND_HASH_FOREACH_BUCKET(ht, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(ht, p) { if (p->key) { zend_accel_store_interned_string(p->key); } @@ -285,7 +285,7 @@ static HashTable *zend_persist_attributes(HashTable *attributes) zend_hash_persist(attributes); - ZEND_PACKED_FOREACH_VAL(attributes, v) { + ZEND_HASH_PACKED_FOREACH_VAL(attributes, v) { zend_attribute *attr = Z_PTR_P(v); zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc)); @@ -300,7 +300,7 @@ static HashTable *zend_persist_attributes(HashTable *attributes) } ZVAL_PTR(v, copy); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable)); GC_SET_REFCOUNT(ptr, 2); @@ -344,13 +344,13 @@ static HashTable *zend_persist_backed_enum_table(HashTable *backed_enum_table) if (HT_IS_PACKED(backed_enum_table)) { zval *zv; - ZEND_PACKED_FOREACH_VAL(backed_enum_table, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(backed_enum_table, zv) { zend_persist_zval(zv); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { Bucket *p; - ZEND_HASH_FOREACH_BUCKET(backed_enum_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(backed_enum_table, p) { if (p->key != NULL) { zend_accel_store_interned_string(p->key); } @@ -513,7 +513,7 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc Bucket *p; zend_hash_persist(op_array->static_variables); - ZEND_HASH_FOREACH_BUCKET(op_array->static_variables, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(op_array->static_variables, p) { ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); zend_persist_zval(&p->val); @@ -902,7 +902,7 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce) } zend_hash_persist(&ce->function_table); - ZEND_HASH_FOREACH_BUCKET(&ce->function_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->function_table, p) { ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); zend_persist_class_method(&p->val, ce); @@ -936,7 +936,7 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce) } zend_hash_persist(&ce->constants_table); - ZEND_HASH_FOREACH_BUCKET(&ce->constants_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->constants_table, p) { ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); zend_persist_class_constant(&p->val); @@ -944,7 +944,7 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce) HT_FLAGS(&ce->constants_table) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS); zend_hash_persist(&ce->properties_info); - ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->properties_info, p) { zend_property_info *prop = Z_PTR(p->val); ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); @@ -1228,12 +1228,12 @@ static void zend_accel_persist_class_table(HashTable *class_table) JIT_G(on) = 0; #endif zend_hash_persist(class_table); - ZEND_HASH_FOREACH_BUCKET(class_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) { ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); Z_CE(p->val) = zend_persist_class_entry(Z_CE(p->val)); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(class_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) { if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) { ce = Z_PTR(p->val); zend_update_parent_ce(ce); @@ -1245,10 +1245,10 @@ static void zend_accel_persist_class_table(HashTable *class_table) !ZCG(current_persistent_script)->corrupted) { zend_op_array *op_array; - ZEND_HASH_FOREACH_BUCKET(class_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) { if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) { ce = Z_PTR(p->val); - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->type == ZEND_USER_FUNCTION) { if (op_array->scope == ce && !(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) { @@ -1261,10 +1261,10 @@ static void zend_accel_persist_class_table(HashTable *class_table) } ZEND_HASH_FOREACH_END(); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_BUCKET(class_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) { if (EXPECTED(Z_TYPE(p->val) != IS_ALIAS_PTR)) { ce = Z_PTR(p->val); - ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, op_array) { if (op_array->type == ZEND_USER_FUNCTION) { if ((op_array->scope != ce || (op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) @@ -1348,7 +1348,7 @@ zend_persistent_script *zend_accel_script_persist(zend_persistent_script *script zend_accel_persist_class_table(&script->script.class_table); zend_hash_persist(&script->script.function_table); - ZEND_HASH_FOREACH_BUCKET(&script->script.function_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&script->script.function_table, p) { ZEND_ASSERT(p->key != NULL); zend_accel_store_interned_string(p->key); zend_persist_op_array(&p->val); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index db010cef3ed14..1eac4684c58af 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -121,13 +121,13 @@ static void zend_persist_zval_calc(zval *z) if (HT_IS_PACKED(ht)) { zval *zv; - ZEND_PACKED_FOREACH_VAL(Z_ARRVAL_P(z), zv) { + ZEND_HASH_PACKED_FOREACH_VAL(Z_ARRVAL_P(z), zv) { zend_persist_zval_calc(zv); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { Bucket *p; - ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(z), p) { + ZEND_HASH_MAP_FOREACH_BUCKET(Z_ARRVAL_P(z), p) { if (p->key) { ADD_INTERNED_STRING(p->key); } @@ -164,7 +164,7 @@ static void zend_persist_attributes_calc(HashTable *attributes) ADD_SIZE(sizeof(HashTable)); zend_hash_persist_calc(attributes); - ZEND_PACKED_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { ADD_SIZE(ZEND_ATTRIBUTE_SIZE(attr->argc)); ADD_INTERNED_STRING(attr->name); ADD_INTERNED_STRING(attr->lcname); @@ -175,7 +175,7 @@ static void zend_persist_attributes_calc(HashTable *attributes) } zend_persist_zval_calc(&attr->args[i].value); } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -228,7 +228,7 @@ static void zend_persist_op_array_calc_ex(zend_op_array *op_array) zend_shared_alloc_register_xlat_entry(op_array->static_variables, op_array->static_variables); ADD_SIZE(sizeof(HashTable)); zend_hash_persist_calc(op_array->static_variables); - ZEND_HASH_FOREACH_BUCKET(op_array->static_variables, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(op_array->static_variables, p) { ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); zend_persist_zval_calc(&p->val); @@ -419,7 +419,7 @@ void zend_persist_class_entry_calc(zend_class_entry *ce) } zend_hash_persist_calc(&ce->function_table); - ZEND_HASH_FOREACH_BUCKET(&ce->function_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->function_table, p) { ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); zend_persist_class_method_calc(&p->val); @@ -443,14 +443,14 @@ void zend_persist_class_entry_calc(zend_class_entry *ce) } } zend_hash_persist_calc(&ce->constants_table); - ZEND_HASH_FOREACH_BUCKET(&ce->constants_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->constants_table, p) { ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); zend_persist_class_constant_calc(&p->val); } ZEND_HASH_FOREACH_END(); zend_hash_persist_calc(&ce->properties_info); - ZEND_HASH_FOREACH_BUCKET(&ce->properties_info, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&ce->properties_info, p) { zend_property_info *prop = Z_PTR(p->val); ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); @@ -551,13 +551,13 @@ void zend_persist_class_entry_calc(zend_class_entry *ce) if (HT_IS_PACKED(ce->backed_enum_table)) { zval *zv; - ZEND_PACKED_FOREACH_VAL(ce->backed_enum_table, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(ce->backed_enum_table, zv) { zend_persist_zval_calc(zv); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { Bucket *p; - ZEND_HASH_FOREACH_BUCKET(ce->backed_enum_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(ce->backed_enum_table, p) { if (p->key != NULL) { ADD_INTERNED_STRING(p->key); } @@ -573,7 +573,7 @@ static void zend_accel_persist_class_table_calc(HashTable *class_table) Bucket *p; zend_hash_persist_calc(class_table); - ZEND_HASH_FOREACH_BUCKET(class_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(class_table, p) { ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); zend_persist_class_entry_calc(Z_CE(p->val)); @@ -631,7 +631,7 @@ uint32_t zend_accel_script_persist_calc(zend_persistent_script *new_persistent_s zend_hash_rehash(&new_persistent_script->script.function_table); } zend_hash_persist_calc(&new_persistent_script->script.function_table); - ZEND_HASH_FOREACH_BUCKET(&new_persistent_script->script.function_table, p) { + ZEND_HASH_MAP_FOREACH_BUCKET(&new_persistent_script->script.function_table, p) { ZEND_ASSERT(p->key != NULL); ADD_INTERNED_STRING(p->key); zend_persist_op_array_calc(&p->val); diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 9f67744e80b9d..506074172a3b3 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -2374,7 +2374,7 @@ static X509_STORE *php_openssl_setup_verify(zval *calist) } if (calist && (Z_TYPE_P(calist) == IS_ARRAY)) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(calist), item) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(calist), item) { zend_string *str = zval_try_get_string(item); if (UNEXPECTED(!str)) { return NULL; @@ -2406,7 +2406,7 @@ static X509_STORE *php_openssl_setup_verify(zval *calist) dir_lookup = NULL; } zend_string_release(str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (nfiles == 0) { file_lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); @@ -2484,7 +2484,7 @@ static STACK_OF(X509) * php_array_to_X509_sk(zval * zcerts) /* {{{ */ /* get certs */ if (Z_TYPE_P(zcerts) == IS_ARRAY) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zcerts), zcertval) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zcerts), zcertval) { cert = php_openssl_x509_from_zval(zcertval, &free_cert); if (cert == NULL) { // TODO Add Warning? @@ -2501,7 +2501,7 @@ static STACK_OF(X509) * php_array_to_X509_sk(zval * zcerts) /* {{{ */ } sk_X509_push(sk, cert); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { /* a single certificate */ cert = php_openssl_x509_from_zval(zcerts, &free_cert); @@ -2859,7 +2859,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z subj = X509_REQ_get_subject_name(csr); /* apply values from the dn hash */ - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(dn), strindex, item) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(dn), strindex, item) { if (strindex) { int nid = OBJ_txt2nid(ZSTR_VAL(strindex)); if (nid != NID_undef) { @@ -2884,7 +2884,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z php_error_docref(NULL, E_WARNING, "dn: %s is not a recognized name", ZSTR_VAL(strindex)); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Finally apply defaults from config file */ for(i = 0; i < sk_CONF_VALUE_num(dn_sk); i++) { @@ -2936,7 +2936,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z } } if (attribs) { - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(attribs), strindex, item) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(attribs), strindex, item) { int nid; if (NULL == strindex) { @@ -2960,7 +2960,7 @@ static int php_openssl_make_REQ(struct php_x509_request * req, X509_REQ * csr, z } else { php_error_docref(NULL, E_WARNING, "dn: %s is not a recognized name", ZSTR_VAL(strindex)); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); for (i = 0; i < sk_CONF_VALUE_num(attr_sk); i++) { v = sk_CONF_VALUE_value(attr_sk, i); /* if it is already set, skip this */ @@ -5346,7 +5346,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) /* get certs */ if (Z_TYPE_P(zrecipcerts) == IS_ARRAY) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { bool free_cert; cert = php_openssl_x509_from_zval(zcertval, &free_cert); @@ -5365,7 +5365,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) } } sk_X509_push(recipcerts, cert); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { /* a single certificate */ bool free_cert; @@ -5405,7 +5405,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) /* tack on extra headers */ if (zheaders) { - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { zend_string *str = zval_try_get_string(zcertval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -5416,7 +5416,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt) BIO_printf(outfile, "%s\n", ZSTR_VAL(str)); } zend_string_release(str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } (void)BIO_reset(infile); @@ -5626,7 +5626,7 @@ PHP_FUNCTION(openssl_pkcs7_sign) if (zheaders) { int ret; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { zend_string *str = zval_try_get_string(hval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -5640,7 +5640,7 @@ PHP_FUNCTION(openssl_pkcs7_sign) if (ret < 0) { php_openssl_store_errors(); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* write the signed data */ if (!SMIME_write_PKCS7(outfile, p7, infile, (int)flags)) { @@ -5976,7 +5976,7 @@ PHP_FUNCTION(openssl_cms_encrypt) /* get certs */ if (Z_TYPE_P(zrecipcerts) == IS_ARRAY) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zrecipcerts), zcertval) { bool free_cert; cert = php_openssl_x509_from_zval(zcertval, &free_cert); @@ -5994,7 +5994,7 @@ PHP_FUNCTION(openssl_cms_encrypt) } } sk_X509_push(recipcerts, cert); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { /* a single certificate */ bool free_cert; @@ -6037,7 +6037,7 @@ PHP_FUNCTION(openssl_cms_encrypt) /* tack on extra headers */ if (zheaders && encoding == ENCODING_SMIME) { - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, zcertval) { zend_string *str = zval_try_get_string(zcertval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -6048,7 +6048,7 @@ PHP_FUNCTION(openssl_cms_encrypt) BIO_printf(outfile, "%s\n", ZSTR_VAL(str)); } zend_string_release(str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } (void)BIO_reset(infile); @@ -6317,7 +6317,7 @@ PHP_FUNCTION(openssl_cms_sign) if (zheaders && encoding == ENCODING_SMIME) { int ret; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zheaders), strindex, hval) { zend_string *str = zval_try_get_string(hval); if (UNEXPECTED(!str)) { goto clean_exit; @@ -6331,7 +6331,7 @@ PHP_FUNCTION(openssl_cms_sign) if (ret < 0) { php_openssl_store_errors(); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* writing the signed data depends on the encoding */ switch (encoding) { @@ -6885,7 +6885,7 @@ PHP_FUNCTION(openssl_seal) /* get the public keys we are using to seal this data */ i = 0; - ZEND_ARRAY_FOREACH_VAL(pubkeysht, pubkey) { + ZEND_HASH_FOREACH_VAL(pubkeysht, pubkey) { pkeys[i] = php_openssl_pkey_from_zval(pubkey, 1, NULL, 0); if (pkeys[i] == NULL) { if (!EG(exception)) { @@ -6896,7 +6896,7 @@ PHP_FUNCTION(openssl_seal) } eks[i] = emalloc(EVP_PKEY_size(pkeys[i]) + 1); i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ctx = EVP_CIPHER_CTX_new(); if (ctx == NULL || !EVP_EncryptInit(ctx,cipher,NULL,NULL)) { diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 88e2329adc04c..5564bf6f08681 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -184,13 +184,13 @@ static int php_openssl_is_http_stream_talking_to_iis(php_stream *stream) /* {{{ #define SERVER_MICROSOFT_IIS "Server: Microsoft-IIS" #define SERVER_GOOGLE "Server: GFE/" - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(stream->wrapperdata), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(stream->wrapperdata), tmp) { if (zend_string_equals_literal_ci(Z_STR_P(tmp), SERVER_MICROSOFT_IIS)) { return 1; } else if (zend_string_equals_literal_ci(Z_STR_P(tmp), SERVER_GOOGLE)) { return 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return 0; } @@ -358,7 +358,7 @@ static bool php_openssl_x509_fingerprint_match(X509 *peer, zval *val) return 0; } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), key, current) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), key, current) { if (key == NULL || Z_TYPE_P(current) != IS_STRING) { php_error_docref(NULL, E_WARNING, "Invalid peer_fingerprint array; [algo => fingerprint] form required"); return 0; @@ -366,7 +366,7 @@ static bool php_openssl_x509_fingerprint_match(X509 *peer, zval *val) if (php_openssl_x509_fingerprint_cmp(peer, ZSTR_VAL(key), Z_STRVAL_P(current)) != 0) { return 0; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 1; } else { @@ -1417,7 +1417,7 @@ static int php_openssl_enable_server_sni(php_stream *stream, php_openssl_netstre ); memset(sslsock->sni_certs, 0, sslsock->sni_cert_count * sizeof(php_openssl_sni_cert_t)); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(val), key_index, key, current) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(val), key_index, key, current) { (void) key_index; if (!key) { @@ -1496,7 +1496,7 @@ static int php_openssl_enable_server_sni(php_stream *stream, php_openssl_netstre sslsock->sni_certs[i].ctx = ctx; ++i; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); SSL_CTX_set_tlsext_servername_callback(sslsock->ctx, php_openssl_server_sni_callback); diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index 3c8ff256d4c2d..54ed5c4b90e91 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -837,7 +837,7 @@ PHP_FUNCTION(pcntl_exec) argv = safe_emalloc((argc + 2), sizeof(char *), 0); *argv = path; current_arg = argv+1; - ZEND_ARRAY_FOREACH_VAL(args_hash, element) { + ZEND_HASH_FOREACH_VAL(args_hash, element) { if (argi >= argc) break; if (!try_convert_to_string(element)) { efree(argv); @@ -847,7 +847,7 @@ PHP_FUNCTION(pcntl_exec) *current_arg = Z_STRVAL_P(element); argi++; current_arg++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *current_arg = NULL; } else { argv = emalloc(2 * sizeof(char *)); @@ -862,7 +862,7 @@ PHP_FUNCTION(pcntl_exec) envc = zend_hash_num_elements(envs_hash); pair = envp = safe_emalloc((envc + 1), sizeof(char *), 0); - ZEND_ARRAY_FOREACH_KEY_VAL(envs_hash, key_num, key, element) { + ZEND_HASH_FOREACH_KEY_VAL(envs_hash, key_num, key, element) { if (envi >= envc) break; if (!key) { key = zend_long_to_str(key_num); @@ -889,7 +889,7 @@ PHP_FUNCTION(pcntl_exec) zend_string_release_ex(key, 0); envi++; pair++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *(pair) = NULL; if (execve(path, argv, envp) == -1) { @@ -1048,14 +1048,14 @@ PHP_FUNCTION(pcntl_sigprocmask) RETURN_FALSE; } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { signo = zval_get_long(user_signo); if (sigaddset(&set, signo) != 0) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (sigprocmask(how, &set, &oldset) != 0) { PCNTL_G(last_error) = errno; @@ -1109,14 +1109,14 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{ RETURN_FALSE; } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(user_set), user_signo) { signo = zval_get_long(user_signo); if (sigaddset(&set, signo) != 0) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (timedwait) { timeout.tv_sec = (time_t) tv_sec; diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index ea0c3b025b9c0..bde53d589dbda 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2101,7 +2101,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, uint32_t replace_idx = 0; /* For each entry in the regex array, get the entry */ - ZEND_ARRAY_FOREACH_VAL(regex, regex_entry) { + ZEND_HASH_FOREACH_VAL(regex, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_str; zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str); @@ -2136,13 +2136,13 @@ static zend_string *php_pcre_replace_array(HashTable *regex, if (UNEXPECTED(result == NULL)) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { ZEND_ASSERT(replace_str != NULL); /* For each entry in the regex array, get the entry */ - ZEND_ARRAY_FOREACH_VAL(regex, regex_entry) { + ZEND_HASH_FOREACH_VAL(regex, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_str; zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str); @@ -2158,7 +2158,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, if (UNEXPECTED(result == NULL)) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return subject_str; @@ -2206,7 +2206,7 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl zend_string_addref(subject); /* For each entry in the regex array, get the entry */ - ZEND_ARRAY_FOREACH_VAL(regex_ht, regex_entry) { + ZEND_HASH_FOREACH_VAL(regex_ht, regex_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_regex_entry_str; zend_string *regex_entry_str = zval_get_tmp_string(regex_entry, &tmp_regex_entry_str); @@ -2221,7 +2221,7 @@ static zend_string *php_replace_in_subject_func(zend_string *regex_str, HashTabl if (UNEXPECTED(result == NULL)) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return subject; } @@ -2257,7 +2257,7 @@ static size_t preg_replace_func_impl(zval *return_value, /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { zend_string *tmp_subject_entry_str; zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str); @@ -2273,7 +2273,7 @@ static size_t preg_replace_func_impl(zval *return_value, } } zend_tmp_string_release(tmp_subject_entry_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return replace_count; @@ -2337,7 +2337,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, bool is_filter) /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { old_replace_count = replace_count; zend_string *tmp_subject_entry_str; zend_string *subject_entry_str = zval_get_tmp_string(subject_entry, &tmp_subject_entry_str); @@ -2358,7 +2358,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, bool is_filter) } } zend_tmp_string_release(tmp_subject_entry_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (zcount) { @@ -2438,7 +2438,7 @@ PHP_FUNCTION(preg_replace_callback_array) GC_TRY_ADDREF(subject_str); } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(pattern, str_idx_regex, replace) { + ZEND_HASH_FOREACH_STR_KEY_VAL(pattern, str_idx_regex, replace) { if (!str_idx_regex) { php_error_docref(NULL, E_WARNING, "Delimiter must not be alphanumeric or backslash"); RETVAL_NULL(); @@ -2474,7 +2474,7 @@ PHP_FUNCTION(preg_replace_callback_array) if (EG(exception)) { goto error; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (zcount) { ZEND_TRY_ASSIGN_REF_LONG(zcount, replace_count); @@ -2922,7 +2922,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return options = (pce->compile_options & PCRE2_UTF) ? 0 : PCRE2_NO_UTF_CHECK; /* Go through the input array */ - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { zend_string *tmp_subject_str; zend_string *subject_str = zval_get_tmp_string(entry, &tmp_subject_str); @@ -2970,7 +2970,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return } zend_tmp_string_release(tmp_subject_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (match_data != mdata) { pcre2_match_data_free(match_data); } diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index b18efe462842a..f11b983a9a82f 100644 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -71,7 +71,7 @@ PHP_FUNCTION(pdo_drivers) array_init(return_value); - ZEND_HASH_FOREACH_PTR(&pdo_driver_hash, pdriver) { + ZEND_HASH_MAP_FOREACH_PTR(&pdo_driver_hash, pdriver) { add_next_index_stringl(return_value, pdriver->driver_name, pdriver->driver_name_len); } ZEND_HASH_FOREACH_END(); } @@ -277,7 +277,7 @@ PHP_MINFO_FUNCTION(pdo) php_info_print_table_start(); php_info_print_table_header(2, "PDO support", "enabled"); - ZEND_HASH_FOREACH_PTR(&pdo_driver_hash, pdriver) { + ZEND_HASH_MAP_FOREACH_PTR(&pdo_driver_hash, pdriver) { spprintf(&drivers, 0, "%s, %s", ldrivers, pdriver->driver_name); efree(ldrivers); ldrivers = drivers; diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 4edb9f3b5104f..479959db42bb0 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -403,7 +403,7 @@ PHP_METHOD(PDO, __construct) zend_ulong long_key; zend_string *str_key = NULL; - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(options), long_key, str_key, attr_value) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), long_key, str_key, attr_value) { if (str_key) { continue; } @@ -411,7 +411,7 @@ PHP_METHOD(PDO, __construct) /* TODO: Should the constructor fail when the attribute cannot be set? */ pdo_dbh_attribute_set(dbh, long_key, attr_value); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } zend_restore_error_handling(&zeh); @@ -1187,7 +1187,7 @@ PHP_METHOD(PDO, getAvailableDrivers) array_init(return_value); - ZEND_HASH_FOREACH_PTR(&pdo_driver_hash, pdriver) { + ZEND_HASH_MAP_FOREACH_PTR(&pdo_driver_hash, pdriver) { add_next_index_stringl(return_value, (char*)pdriver->driver_name, pdriver->driver_name_len); } ZEND_HASH_FOREACH_END(); } diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 3ee74d962f107..5320d50cf9c9f 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -68,7 +68,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p return 0; } - ZEND_ARRAY_FOREACH_PTR(stmt->bound_param_map, name) { + ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) { if (!zend_string_equals(name, param->name)) { position++; continue; @@ -80,7 +80,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p } param->paramno = position; return 1; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* TODO Error? */ pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined"); return 0; @@ -108,12 +108,12 @@ static bool dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_ty iterate: if (ht) { - ZEND_ARRAY_FOREACH_PTR(ht, param) { + ZEND_HASH_FOREACH_PTR(ht, param) { if (!stmt->methods->param_hook(stmt, param, event_type)) { ret = 0; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (ret && is_param) { ht = stmt->bound_columns; @@ -409,7 +409,7 @@ PHP_METHOD(PDOStatement, execute) stmt->bound_params = NULL; } - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input_params), num_index, key, tmp) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input_params), num_index, key, tmp) { memset(¶m, 0, sizeof(param)); if (key) { @@ -431,7 +431,7 @@ PHP_METHOD(PDOStatement, execute) } RETURN_FALSE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (PDO_PLACEHOLDER_NONE == stmt->supports_placeholders) { @@ -592,7 +592,7 @@ static bool do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, ze /* update those bound column variables now */ struct pdo_bound_param_data *param; - ZEND_ARRAY_FOREACH_PTR(stmt->bound_columns, param) { + ZEND_HASH_FOREACH_PTR(stmt->bound_columns, param) { if (param->paramno >= 0) { if (!Z_ISREF(param->parameter)) { continue; @@ -609,7 +609,7 @@ static bool do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, ze * it's better to use LAZY or BOUND fetches if you want to shave * off those cycles */ } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return 1; @@ -1981,7 +1981,7 @@ PHP_METHOD(PDOStatement, debugDumpParams) if (stmt->bound_params) { zend_ulong num; zend_string *key = NULL; - ZEND_ARRAY_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { + ZEND_HASH_FOREACH_KEY_PTR(stmt->bound_params, num, key, param) { if (key) { php_stream_printf(out, "Key: Name: [%zd] %.*s\n", ZSTR_LEN(key), (int) ZSTR_LEN(key), ZSTR_VAL(key)); @@ -1999,7 +1999,7 @@ PHP_METHOD(PDOStatement, debugDumpParams) param->is_param, param->param_type); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } php_stream_close(out); diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 12c360f2c73fa..be9e8c012252e 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -610,7 +610,7 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray) zval *tmp; PQclear(pgsql_result); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) { size_t query_len; if (!try_convert_to_string(tmp)) { efree(query); @@ -633,7 +633,7 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlCopyFromArray) PDO_HANDLE_DBH_ERR(); RETURN_FALSE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (query) { efree(query); } diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index f4ad80d8f13e1..82c1af88aa16c 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1194,7 +1194,7 @@ PHP_FUNCTION(pg_query_params) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -1208,7 +1208,7 @@ PHP_FUNCTION(pg_query_params) zend_string_release(param_str); } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } pgsql_result = PQexecParams(pgsql, query, num_params, @@ -1380,7 +1380,7 @@ PHP_FUNCTION(pg_execute) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -1393,7 +1393,7 @@ PHP_FUNCTION(pg_execute) } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } pgsql_result = PQexecPrepared(pgsql, stmtname, num_params, @@ -3221,7 +3221,7 @@ PHP_FUNCTION(pg_copy_from) if (pgsql_result) { int command_failed = 0; PQclear(pgsql_result); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), value) { zend_string *tmp = zval_try_get_string(value); if (UNEXPECTED(!tmp)) { return; @@ -3239,7 +3239,7 @@ PHP_FUNCTION(pg_copy_from) } efree(query); zend_string_release(tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (PQputCopyEnd(pgsql, NULL) != 1) { PHP_PQ_ERROR("putcopyend failed: %s", pgsql); @@ -3745,7 +3745,7 @@ PHP_FUNCTION(pg_send_query_params) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -3758,7 +3758,7 @@ PHP_FUNCTION(pg_send_query_params) } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (PQsendQueryParams(pgsql, query, num_params, NULL, (const char * const *)params, NULL, NULL, 0)) { @@ -3912,7 +3912,7 @@ PHP_FUNCTION(pg_send_execute) int i = 0; params = (char **)safe_emalloc(sizeof(char *), num_params, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pv_param_arr), tmp) { if (Z_TYPE_P(tmp) == IS_NULL) { params[i] = NULL; @@ -3927,7 +3927,7 @@ PHP_FUNCTION(pg_send_execute) } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (PQsendQueryPrepared(pgsql, stmtname, num_params, (const char * const *)params, NULL, NULL, 0)) { @@ -4582,7 +4582,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * return FAILURE; } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(values), field, val) { skip_field = 0; ZVAL_NULL(&new_val); @@ -5193,7 +5193,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string * PQfreemem(escaped); } } - } ZEND_ARRAY_FOREACH_END(); /* for */ + } ZEND_HASH_FOREACH_END(); /* for */ zval_ptr_dtor(&meta); @@ -5333,7 +5333,7 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t build_tablename(&querystr, pg_link, table); smart_str_appends(&querystr, " ("); - ZEND_ARRAY_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) { + ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) { if (fld == NULL) { zend_value_error("Array of values must be an associative array with string keys"); goto cleanup; @@ -5346,12 +5346,12 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t smart_str_append(&querystr, fld); } smart_str_appendc(&querystr, ','); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ZSTR_LEN(querystr.s)--; smart_str_appends(&querystr, ") VALUES ("); /* make values string */ - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(var_array), val) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(var_array), val) { /* we can avoid the key_type check here, because we tested it in the other loop */ switch (Z_TYPE_P(val)) { case IS_STRING: @@ -5382,7 +5382,7 @@ PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *t goto cleanup; } smart_str_appendc(&querystr, ','); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Remove the trailing "," */ ZSTR_LEN(querystr.s)--; smart_str_appends(&querystr, ");"); @@ -5508,7 +5508,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr, zend_string *fld; zval *val; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(ht, fld, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, fld, val) { if (fld == NULL) { zend_value_error("Array of values must be an associative array with string keys"); return -1; @@ -5556,7 +5556,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr, return -1; } smart_str_appendl(querystr, pad, pad_len); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (querystr->s) { ZSTR_LEN(querystr->s) -= pad_len; } diff --git a/ext/phar/phar.c b/ext/phar/phar.c index bc08e4edde05d..91310c21e4967 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2015,7 +2015,7 @@ int phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const } else { zend_string *str_key; - ZEND_HASH_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&PHAR_G(phar_fname_map), str_key, pphar) { if (ZSTR_LEN(str_key) > (uint32_t) filename_len) { continue; } @@ -2028,7 +2028,7 @@ int phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const } ZEND_HASH_FOREACH_END(); if (PHAR_G(manifest_cached)) { - ZEND_HASH_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&cached_phars, str_key, pphar) { if (ZSTR_LEN(str_key) > (uint32_t) filename_len) { continue; } @@ -2723,7 +2723,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv } new_manifest_count = 0; offset = 0; - ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&phar->manifest, entry) { if (entry->cfp) { /* did we forget to get rid of cfp last time? */ php_stream_close(entry->cfp); @@ -2955,7 +2955,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv manifest_ftell = php_stream_tell(newfile); /* now write the manifest */ - ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&phar->manifest, entry) { const zend_string *metadata_str; if (entry->is_deleted || entry->is_mounted) { /* remove this from the new phar if deleted, ignore if mounted */ @@ -3039,7 +3039,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv /* now copy the actual file data to the new phar */ offset = php_stream_tell(newfile); - ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&phar->manifest, entry) { if (entry->is_deleted || entry->is_dir || entry->is_mounted) { continue; } @@ -3251,7 +3251,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv if (shared_cfp != NULL) { php_stream_close(shared_cfp); } - ZEND_HASH_FOREACH_PTR(&phar->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&phar->manifest, entry) { if (entry->cfp) { entry->cfp = NULL; entry->header_offset = 0; @@ -3504,7 +3504,7 @@ void phar_request_initialize(void) /* {{{ */ phar_archive_data *pphar; phar_entry_fp *stuff = (phar_entry_fp *) ecalloc(zend_hash_num_elements(&cached_phars), sizeof(phar_entry_fp)); - ZEND_HASH_FOREACH_PTR(&cached_phars, pphar) { + ZEND_HASH_MAP_FOREACH_PTR(&cached_phars, pphar) { stuff[pphar->phar_pos].manifest = (phar_entry_fp_info *) ecalloc( zend_hash_num_elements(&(pphar->manifest)), sizeof(phar_entry_fp_info)); } ZEND_HASH_FOREACH_END(); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 5fcfbac357c0c..a9bad08aa39f9 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -878,7 +878,7 @@ PHP_METHOD(Phar, mungServer) phar_request_initialize(); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) { if (Z_TYPE_P(data) != IS_STRING) { zend_throw_exception_ex(phar_ce_PharException, 0, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); @@ -895,7 +895,7 @@ PHP_METHOD(Phar, mungServer) PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_FILENAME; } // TODO Warning for invalid value? - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -2250,7 +2250,7 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert phar_metadata_tracker_copy(&phar->metadata_tracker, &source->metadata_tracker, phar->is_persistent); /* first copy each file's uncompressed contents to a temporary file and set per-file flags */ - ZEND_HASH_FOREACH_PTR(&source->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&source->manifest, entry) { newentry = *entry; @@ -4269,13 +4269,13 @@ static int extract_helper(phar_archive_data *archive, zend_string *search, char if (!search) { /* nothing to match -- extract all files */ - ZEND_HASH_FOREACH_PTR(&archive->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) { if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; extracted++; } ZEND_HASH_FOREACH_END(); } else if ('/' == ZSTR_VAL(search)[ZSTR_LEN(search) - 1]) { /* ends in "/" -- extract all entries having that prefix */ - ZEND_HASH_FOREACH_PTR(&archive->manifest, entry) { + ZEND_HASH_MAP_FOREACH_PTR(&archive->manifest, entry) { if (0 != strncmp(ZSTR_VAL(search), entry->filename, ZSTR_LEN(search))) continue; if (FAILURE == phar_extract_file(overwrite, entry, pathto, pathto_len, error)) return -1; extracted++; @@ -4357,7 +4357,7 @@ PHP_METHOD(Phar, extractTo) RETURN_FALSE; } - ZEND_ARRAY_FOREACH_VAL(files_ht, zval_file) { + ZEND_HASH_FOREACH_VAL(files_ht, zval_file) { ZVAL_DEREF(zval_file); if (IS_STRING != Z_TYPE_P(zval_file)) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, @@ -4376,7 +4376,7 @@ PHP_METHOD(Phar, extractTo) ZSTR_VAL(Z_STR_P(zval_file)), phar_obj->archive->fname); RETURN_THROWS(); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); RETURN_TRUE; } diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 745c3b429cf70..9bba67c6fc963 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -613,7 +613,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f if (HT_IS_INITIALIZED(&phar->mounted_dirs) && zend_hash_num_elements(&phar->mounted_dirs)) { zend_string *str_key; - ZEND_HASH_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) { if (ZSTR_LEN(str_key) >= internal_file_len || strncmp(ZSTR_VAL(str_key), internal_file, ZSTR_LEN(str_key))) { continue; } else { @@ -883,7 +883,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from uint32_t from_len = ZSTR_LEN(resource_from->path) - 1; uint32_t to_len = ZSTR_LEN(resource_to->path) - 1; - ZEND_HASH_FOREACH_BUCKET(&phar->manifest, b) { + ZEND_HASH_MAP_FOREACH_BUCKET(&phar->manifest, b) { str_key = b->key; entry = Z_PTR(b->val); if (!entry->is_deleted && @@ -910,7 +910,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from } ZEND_HASH_FOREACH_END(); zend_hash_rehash(&phar->manifest); - ZEND_HASH_FOREACH_BUCKET(&phar->virtual_dirs, b) { + ZEND_HASH_MAP_FOREACH_BUCKET(&phar->virtual_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && @@ -928,7 +928,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from } ZEND_HASH_FOREACH_END(); zend_hash_rehash(&phar->virtual_dirs); - ZEND_HASH_FOREACH_BUCKET(&phar->mounted_dirs, b) { + ZEND_HASH_MAP_FOREACH_BUCKET(&phar->mounted_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && diff --git a/ext/phar/util.c b/ext/phar/util.c index 515830bf2c70a..72e633a5b3324 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -1290,7 +1290,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, si if (HT_IS_INITIALIZED(&phar->mounted_dirs) && zend_hash_num_elements(&phar->mounted_dirs)) { zend_string *str_key; - ZEND_HASH_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) { if (ZSTR_LEN(str_key) >= path_len || strncmp(ZSTR_VAL(str_key), path, ZSTR_LEN(str_key))) { continue; } else { @@ -2056,7 +2056,7 @@ static void phar_copy_cached_phar(phar_archive_data **pphar) /* {{{ */ *pphar = phar; /* now, scan the list of persistent Phar objects referencing this phar and update the pointers */ - ZEND_HASH_FOREACH_PTR(&PHAR_G(phar_persist_map), objphar) { + ZEND_HASH_MAP_FOREACH_PTR(&PHAR_G(phar_persist_map), objphar) { if (objphar->archive->fname_len == phar->fname_len && !memcmp(objphar->archive->fname, phar->fname, phar->fname_len)) { objphar->archive = phar; } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 32bd596b61ebc..9d3b9c3c2076c 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -384,7 +384,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char zend_string *key; zend_class_constant *c; - ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, c) { _class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent)); if (UNEXPECTED(EG(exception))) { zend_string_release(sub_indent); @@ -400,7 +400,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char if (count > 0) { zend_property_info *prop; - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { if ((prop->flags & ZEND_ACC_PRIVATE) && prop->ce != ce) { count_shadow_props++; } else if (prop->flags & ZEND_ACC_STATIC) { @@ -414,7 +414,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char if (count_static_props > 0) { zend_property_info *prop; - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { if ((prop->flags & ZEND_ACC_STATIC) && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) { _property_string(str, prop, NULL, ZSTR_VAL(sub_indent)); } @@ -428,7 +428,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char if (count > 0) { zend_function *mptr; - ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -442,7 +442,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char if (count_static_funcs > 0) { zend_function *mptr; - ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -461,7 +461,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char if (count > 0) { zend_property_info *prop; - ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { if (!(prop->flags & ZEND_ACC_STATIC) && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) { _property_string(str, prop, NULL, ZSTR_VAL(sub_indent)); @@ -477,7 +477,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char count = 0; if (properties && zend_hash_num_elements(properties)) { - ZEND_HASH_FOREACH_STR_KEY(properties, prop_name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(properties, prop_name) { if (prop_name && ZSTR_LEN(prop_name) && ZSTR_VAL(prop_name)[0]) { /* skip all private and protected properties */ if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; @@ -500,7 +500,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char smart_str method_str = {0}; count = 0; - ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -619,7 +619,7 @@ static int format_default_value(smart_str *str, zval *value) { bool is_list = zend_array_is_list(Z_ARRVAL_P(value)); bool first = true; smart_str_appendc(str, '['); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(value), num_key, str_key, zv) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(value), num_key, str_key, zv) { if (!first) { smart_str_appends(str, ", "); } @@ -636,7 +636,7 @@ static int format_default_value(smart_str *str, zval *value) { smart_str_appends(str, " => "); } format_default_value(str, zv); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendc(str, ']'); } else { ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST); @@ -748,7 +748,7 @@ static void _function_closure_string(smart_str *str, zend_function *fptr, char* smart_str_append_printf(str, "\n"); smart_str_append_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables)); i = 0; - ZEND_HASH_FOREACH_STR_KEY(static_variables, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(static_variables, key) { smart_str_append_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key)); } ZEND_HASH_FOREACH_END(); smart_str_append_printf(str, "%s}\n", indent); @@ -1020,7 +1020,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i { smart_str str_ini = {0}; zend_ini_entry *ini_entry; - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), ini_entry) { _extension_ini_string(ini_entry, &str_ini, indent, module->module_number); } ZEND_HASH_FOREACH_END(); if (smart_str_get_len(&str_ini) > 0) { @@ -1036,7 +1036,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i zend_constant *constant; int num_constants = 0; - ZEND_HASH_FOREACH_PTR(EG(zend_constants), constant) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) { if (ZEND_CONSTANT_MODULE_NUMBER(constant) == module->module_number) { _const_string(&str_constants, ZSTR_VAL(constant->name), &constant->value, indent); num_constants++; @@ -1055,7 +1055,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i zend_function *fptr; int first = 1; - ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { + ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { if (first) { @@ -1077,7 +1077,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i zend_class_entry *ce; int num_classes = 0; - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { _extension_class_string(ce, key, &str_classes, ZSTR_VAL(sub_indent), module, &num_classes); } ZEND_HASH_FOREACH_END(); if (num_classes) { @@ -1125,18 +1125,18 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s // Name based filtering using lowercased key. zend_string *filter = zend_string_tolower(name); - ZEND_ARRAY_FOREACH_PTR(attributes, attr) { + ZEND_HASH_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, filter)) { reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_string_release(filter); return SUCCESS; } - ZEND_ARRAY_FOREACH_PTR(attributes, attr) { + ZEND_HASH_FOREACH_PTR(attributes, attr) { if (attr->offset != offset) { continue; } @@ -1161,7 +1161,7 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } @@ -1905,7 +1905,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getStaticVariables) ht = zend_array_dup(fptr->op_array.static_variables); ZEND_MAP_PTR_SET(fptr->op_array.static_variables_ptr, ht); } - ZEND_HASH_FOREACH_VAL(ht, val) { + ZEND_HASH_MAP_FOREACH_VAL(ht, val) { if (UNEXPECTED(zval_update_constant_ex(val, fptr->common.scope) != SUCCESS)) { RETURN_THROWS(); } @@ -3954,7 +3954,7 @@ static void add_class_vars(zend_class_entry *ce, bool statics, zval *return_valu zval *prop, prop_copy; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { if (((prop_info->flags & ZEND_ACC_PRIVATE) && prop_info->ce != ce)) { continue; @@ -4012,7 +4012,7 @@ ZEND_METHOD(ReflectionClass, getStaticProperties) array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { if (((prop_info->flags & ZEND_ACC_PRIVATE) && prop_info->ce != ce)) { continue; @@ -4404,7 +4404,7 @@ ZEND_METHOD(ReflectionClass, getMethods) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { _addmethod(mptr, ce, Z_ARRVAL_P(return_value), filter); } ZEND_HASH_FOREACH_END(); @@ -4580,14 +4580,14 @@ ZEND_METHOD(ReflectionClass, getProperties) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { _addproperty(prop_info, key, ce, Z_ARRVAL_P(return_value), filter); } ZEND_HASH_FOREACH_END(); if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) { HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj)); zval *prop; - ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, prop) { _adddynproperty(prop, key, ce, return_value); } ZEND_HASH_FOREACH_END(); } @@ -4636,7 +4636,7 @@ ZEND_METHOD(ReflectionClass, getConstants) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, constant) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, constant) { if (UNEXPECTED(zval_update_constant_ex(&constant->value, ce) != SUCCESS)) { RETURN_THROWS(); } @@ -4670,7 +4670,7 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) { if (ZEND_CLASS_CONST_FLAGS(constant) & filter) { zval class_const; reflection_class_constant_factory(name, constant, &class_const); @@ -4695,7 +4695,7 @@ ZEND_METHOD(ReflectionClass, getConstant) GET_REFLECTION_OBJECT_PTR(ce); constants_table = CE_CONSTANTS_TABLE(ce); - ZEND_HASH_FOREACH_PTR(constants_table, c) { + ZEND_HASH_MAP_FOREACH_PTR(constants_table, c) { if (UNEXPECTED(zval_update_constant_ex(&c->value, ce) != SUCCESS)) { RETURN_THROWS(); } @@ -5919,7 +5919,7 @@ ZEND_METHOD(ReflectionExtension, getFunctions) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { + ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { reflection_function_factory(fptr, NULL, &function); @@ -5942,7 +5942,7 @@ ZEND_METHOD(ReflectionExtension, getConstants) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_FOREACH_PTR(EG(zend_constants), constant) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) { if (module->module_number == ZEND_CONSTANT_MODULE_NUMBER(constant)) { zval const_val; ZVAL_COPY_OR_DUP(&const_val, &constant->value); @@ -5980,7 +5980,7 @@ ZEND_METHOD(ReflectionExtension, getINIEntries) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), ini_entry) { _addinientry(ini_entry, return_value, module->module_number); } ZEND_HASH_FOREACH_END(); } @@ -6024,7 +6024,7 @@ ZEND_METHOD(ReflectionExtension, getClasses) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { add_extension_class(ce, key, return_value, module, 1); } ZEND_HASH_FOREACH_END(); } @@ -6044,7 +6044,7 @@ ZEND_METHOD(ReflectionExtension, getClassNames) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { add_extension_class(ce, key, return_value, module, 0); } ZEND_HASH_FOREACH_END(); } @@ -6777,7 +6777,7 @@ ZEND_METHOD(ReflectionEnum, getCases) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->constants_table, name, constant) { if (ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE) { zval class_const; reflection_enum_case_factory(ce, name, constant, &class_const); diff --git a/ext/session/php_session.h b/ext/session/php_session.h index 0c1eb0ca9c639..bc8c3548c7059 100644 --- a/ext/session/php_session.h +++ b/ext/session/php_session.h @@ -289,7 +289,7 @@ PHPAPI int php_session_reset_id(void); #define PS_ENCODE_LOOP(code) do { \ HashTable *_ht = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); \ - ZEND_ARRAY_FOREACH_KEY(_ht, num_key, key) { \ + ZEND_HASH_FOREACH_KEY(_ht, num_key, key) { \ if (key == NULL) { \ php_error_docref(NULL, E_WARNING, \ "Skipping numeric key " ZEND_LONG_FMT, num_key);\ @@ -298,7 +298,7 @@ PHPAPI int php_session_reset_id(void); if ((struc = php_get_session_var(key))) { \ code; \ } \ - } ZEND_ARRAY_FOREACH_END(); \ + } ZEND_HASH_FOREACH_END(); \ } while(0) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps) diff --git a/ext/session/session.c b/ext/session/session.c index 426a037872c83..32e2f33ae3028 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -1727,7 +1727,7 @@ PHP_FUNCTION(session_set_cookie_params) zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array"); RETURN_THROWS(); } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(options_ht, key, value) { + ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) { if (key) { ZVAL_DEREF(value); if (zend_string_equals_literal_ci(key, "lifetime")) { @@ -1756,7 +1756,7 @@ PHP_FUNCTION(session_set_cookie_params) } else { php_error_docref(NULL, E_WARNING, "Argument #1 ($lifetime_or_options) cannot contain numeric keys"); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (found == 0) { zend_argument_value_error(1, "must contain at least 1 valid key"); @@ -1985,7 +1985,7 @@ PHP_FUNCTION(session_set_save_handler) /* For compatibility reason, implemented interface is not checked */ /* Find implemented methods - SessionHandlerInterface */ i = 0; - ZEND_HASH_FOREACH_STR_KEY(&php_session_iface_entry->function_table, func_name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_session_iface_entry->function_table, func_name) { if ((current_mptr = zend_hash_find_ptr(&Z_OBJCE_P(obj)->function_table, func_name))) { if (!Z_ISUNDEF(PS(mod_user_names).names[i])) { zval_ptr_dtor(&PS(mod_user_names).names[i]); @@ -2004,7 +2004,7 @@ PHP_FUNCTION(session_set_save_handler) } ZEND_HASH_FOREACH_END(); /* Find implemented methods - SessionIdInterface (optional) */ - ZEND_HASH_FOREACH_STR_KEY(&php_session_id_iface_entry->function_table, func_name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_session_id_iface_entry->function_table, func_name) { if ((current_mptr = zend_hash_find_ptr(&Z_OBJCE_P(obj)->function_table, func_name))) { if (!Z_ISUNDEF(PS(mod_user_names).names[i])) { zval_ptr_dtor(&PS(mod_user_names).names[i]); @@ -2024,7 +2024,7 @@ PHP_FUNCTION(session_set_save_handler) } ZEND_HASH_FOREACH_END(); /* Find implemented methods - SessionUpdateTimestampInterface (optional) */ - ZEND_HASH_FOREACH_STR_KEY(&php_session_update_timestamp_iface_entry->function_table, func_name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_session_update_timestamp_iface_entry->function_table, func_name) { if ((current_mptr = zend_hash_find_ptr(&Z_OBJCE_P(obj)->function_table, func_name))) { if (!Z_ISUNDEF(PS(mod_user_names).names[i])) { zval_ptr_dtor(&PS(mod_user_names).names[i]); @@ -2491,7 +2491,7 @@ PHP_FUNCTION(session_start) /* set options */ if (options) { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) { if (str_idx) { switch(Z_TYPE_P(value)) { case IS_STRING: @@ -2517,7 +2517,7 @@ PHP_FUNCTION(session_start) } } (void) num_idx; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } php_session_start(); diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index d3f707b9e3642..ef3b08730c92d 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -695,7 +695,7 @@ static bool php_snmp_parse_oid( } objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0); objid_query->array_output = (st & SNMP_CMD_SET) == 0; - ZEND_ARRAY_FOREACH_VAL(oid_ht, tmp_oid) { + ZEND_HASH_FOREACH_VAL(oid_ht, tmp_oid) { convert_to_string(tmp_oid); objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid); if (st & SNMP_CMD_SET) { @@ -769,7 +769,7 @@ static bool php_snmp_parse_oid( } } objid_query->count++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* now parse all OIDs */ @@ -1821,7 +1821,7 @@ static HashTable *php_snmp_get_properties(zend_object *object) obj = php_snmp_fetch_object(object); props = zend_std_get_properties(object); - ZEND_HASH_FOREACH_STR_KEY_PTR(&php_snmp_properties, key, hnd) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&php_snmp_properties, key, hnd) { if (!hnd->read_func || hnd->read_func(obj, &rv) != SUCCESS) { ZVAL_NULL(&rv); } diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index ab14938480284..49a8bdd185301 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -270,11 +270,11 @@ static encodePtr find_encoder_by_type_name(sdlPtr sdl, const char *type) if (sdl && sdl->encoders) { encodePtr enc; - ZEND_ARRAY_FOREACH_PTR(sdl->encoders, enc) { + ZEND_HASH_FOREACH_PTR(sdl->encoders, enc) { if (strcmp(enc->details.type_str, type) == 0) { return enc; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return NULL; } @@ -448,7 +448,7 @@ static xmlNodePtr master_to_xml_int(encodePtr encode, zval *data, int style, xml zval *tmp; zend_string *type_name; - ZEND_HASH_FOREACH_STR_KEY_VAL(SOAP_GLOBAL(class_map), type_name, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(SOAP_GLOBAL(class_map), type_name, tmp) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_STRING && ZSTR_LEN(ce->name) == Z_STRLEN_P(tmp) && @@ -1346,13 +1346,13 @@ static void model_to_zval_object(zval *ret, sdlContentModelPtr model, xmlNodePtr sdlContentModelPtr tmp; sdlContentModelPtr any = NULL; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { if (tmp->kind == XSD_CONTENT_ANY) { any = tmp; } else { model_to_zval_object(ret, tmp, data, sdl); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (any) { model_to_zval_any(ret, data->children); } @@ -1490,7 +1490,7 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z if (sdlType->attributes) { sdlAttributePtr attr; - ZEND_ARRAY_FOREACH_PTR(sdlType->attributes, attr) { + ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) { if (attr->name) { xmlAttrPtr val = get_attribute(data->properties, attr->name); char *str_val = NULL; @@ -1524,7 +1524,7 @@ static zval *to_zval_object_ex(zval *ret, encodeTypePtr type, xmlNodePtr data, z set_zval_property(ret, attr->name, &data); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else { ZVAL_NULL(ret); @@ -1607,7 +1607,7 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * HashTable *ht = Z_ARRVAL_P(data); zval *val; - ZEND_ARRAY_FOREACH_VAL(ht, val) { + ZEND_HASH_FOREACH_VAL(ht, val) { ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_NULL && model->u.element->nillable) { property = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -1627,7 +1627,7 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * xmlNsPtr nsp = encode_add_ns(property, model->u.element->namens); xmlSetNs(property, nsp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { if (Z_TYPE_P(data) == IS_NULL && model->u.element->nillable) { property = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -1686,9 +1686,9 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * HashTable *ht = Z_ARRVAL_P(data); zval *val; - ZEND_ARRAY_FOREACH_VAL(ht, val) { + ZEND_HASH_FOREACH_VAL(ht, val) { master_to_xml(enc, val, style, node); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { master_to_xml(enc, data, style, node); } @@ -1707,28 +1707,28 @@ static int model_to_xml_object(xmlNodePtr node, sdlContentModelPtr model, zval * case XSD_CONTENT_ALL: { sdlContentModelPtr tmp; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { if (!model_to_xml_object(node, tmp, object, style, strict && (tmp->min_occurs > 0))) { if (!strict || tmp->min_occurs > 0) { return 0; } } strict = 1; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 1; } case XSD_CONTENT_CHOICE: { sdlContentModelPtr tmp; int ret = 0; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { int tmp_ret = model_to_xml_object(node, tmp, object, style, 0); if (tmp_ret == 1) { return 1; } else if (tmp_ret != 0) { ret = 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return ret; } case XSD_CONTENT_GROUP: { @@ -1758,9 +1758,9 @@ static sdlTypePtr model_array_element(sdlContentModelPtr model) if (zend_hash_num_elements(model->u.content) != 1) { return NULL; } - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { return model_array_element(tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* TODO Check this is correct */ ZEND_FALLTHROUGH; @@ -1863,7 +1863,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo (array_el = model_array_element(sdlType->model)) != NULL) { zval *val; - ZEND_ARRAY_FOREACH_VAL(prop, val) { + ZEND_HASH_FOREACH_VAL(prop, val) { xmlNodePtr property; ZVAL_DEREF(val); if (Z_TYPE_P(val) == IS_NULL && array_el->nillable) { @@ -1880,7 +1880,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlNsPtr nsp = encode_add_ns(property, array_el->namens); xmlSetNs(property, nsp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (sdlType->model) { model_to_xml_object(xmlParam, sdlType->model, data, style, 1); } @@ -1888,7 +1888,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo sdlAttributePtr attr; zval *zattr, rv; - ZEND_ARRAY_FOREACH_PTR(sdlType->attributes, attr) { + ZEND_HASH_FOREACH_PTR(sdlType->attributes, attr) { if (attr->name) { zattr = get_zval_property(data, attr->name, &rv); if (zattr) { @@ -1916,7 +1916,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlFreeNode(dummy); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } if (style == SOAP_ENCODED) { @@ -1934,7 +1934,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo zend_string *str_key; xmlNodePtr property; - ZEND_ARRAY_FOREACH_STR_KEY_VAL_IND(prop, str_key, zprop) { + ZEND_HASH_FOREACH_STR_KEY_VAL_IND(prop, str_key, zprop) { ZVAL_DEREF(zprop); property = master_to_xml(get_conversion(Z_TYPE_P(zprop)), zprop, style, xmlParam); @@ -1952,7 +1952,7 @@ static xmlNodePtr to_xml_object(encodeTypePtr type, zval *data, int style, xmlNo xmlNodeSetName(property, BAD_CAST(prop_name)); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (style == SOAP_ENCODED) { set_ns_and_type(xmlParam, type); @@ -2088,7 +2088,7 @@ static void add_xml_array_elements(xmlNodePtr xmlParam, xmlNodePtr xparam; if (data && Z_TYPE_P(data) == IS_ARRAY) { - ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL_P(data), zdata) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(data), zdata) { if (j >= dims[0]) { break; } @@ -2112,7 +2112,7 @@ static void add_xml_array_elements(xmlNodePtr xmlParam, add_xml_array_elements(xmlParam, type, enc, ns, dimension-1, dims+1, zdata, style); } j++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (dimension == 1) { while (j < dims[0]) { @@ -2284,9 +2284,9 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod for (i = 1; i < dimension; i++) { if (el != NULL && Z_TYPE_P(el) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(el)) > 0) { - ZEND_ARRAY_FOREACH_VAL_IND(Z_ARRVAL_P(el), el) { + ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(el), el) { break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ZVAL_DEREF(el); if (Z_TYPE_P(el) == IS_ARRAY) { dims[i] = zend_hash_num_elements(Z_ARRVAL_P(el)); @@ -2646,7 +2646,7 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP FIND_ZVAL_NULL(data, xmlParam, style); if (Z_TYPE_P(data) == IS_ARRAY) { - ZEND_ARRAY_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(data), int_val, key_val, temp_data) { + ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(data), int_val, key_val, temp_data) { item = xmlNewNode(NULL, BAD_CAST("item")); xmlAddChild(xmlParam, item); key = xmlNewNode(NULL, BAD_CAST("key")); @@ -2672,7 +2672,7 @@ static xmlNodePtr to_xml_map(encodeTypePtr type, zval *data, int style, xmlNodeP ZVAL_DEREF(temp_data); xparam = master_to_xml(get_conversion(Z_TYPE_P(temp_data)), temp_data, style, item); xmlNodeSetName(xparam, BAD_CAST("value")); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (style == SOAP_ENCODED) { set_ns_and_type(xmlParam, type); @@ -2951,10 +2951,10 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP if (enc->sdl_type && enc->sdl_type->kind == XSD_TYPEKIND_LIST && enc->sdl_type->elements) { sdlTypePtr type; - ZEND_ARRAY_FOREACH_PTR(enc->sdl_type->elements, type) { + ZEND_HASH_FOREACH_PTR(enc->sdl_type->elements, type) { list_enc = type->encode; break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ret = xmlNewNode(NULL, BAD_CAST("BOGUS")); @@ -2965,7 +2965,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP smart_str list = {0}; HashTable *ht = Z_ARRVAL_P(data); - ZEND_ARRAY_FOREACH_VAL(ht, tmp) { + ZEND_HASH_FOREACH_VAL(ht, tmp) { xmlNodePtr dummy = master_to_xml(list_enc, tmp, SOAP_LITERAL, ret); if (dummy && dummy->children && dummy->children->content) { if (list.s && ZSTR_LEN(list.s) != 0) { @@ -2977,7 +2977,7 @@ static xmlNodePtr to_xml_list(encodeTypePtr enc, zval *data, int style, xmlNodeP } xmlUnlinkNode(dummy); xmlFreeNode(dummy); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_0(&list); if (list.s) { xmlNodeSetContentLen(ret, BAD_CAST(ZSTR_VAL(list.s)), ZSTR_LEN(list.s)); @@ -3091,7 +3091,7 @@ static xmlNodePtr to_xml_any(encodeTypePtr type, zval *data, int style, xmlNodeP encodePtr enc = get_conversion(XSD_ANYXML); zend_string *name; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), name, el) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), name, el) { ret = master_to_xml(enc, el, style, parent); if (ret && ret->name != xmlStringTextNoenc) { @@ -3459,12 +3459,12 @@ static int is_map(zval *array) return FALSE; } - ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(array), index, key) { + ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(array), index, key) { if (key || index != i) { return TRUE; } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return FALSE; } @@ -3485,7 +3485,7 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type) cur_type = prev_type = 0; ht = Z_ARRVAL_P(array); - ZEND_ARRAY_FOREACH_VAL_IND(ht, tmp) { + ZEND_HASH_FOREACH_VAL_IND(ht, tmp) { ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_OBJECT && Z_OBJCE_P(tmp) == soap_var_class_entry) { @@ -3534,7 +3534,7 @@ static encodePtr get_array_type(xmlNodePtr node, zval *array, smart_str *type) prev_stype = cur_stype; prev_ns = cur_ns; i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (different || i == 0) { smart_str_appendl(type, "xsd:anyType", sizeof("xsd:anyType")-1); diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 1cd73ed792876..f61357128bfc1 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -828,7 +828,7 @@ int make_http_soap_request(zval *this_ptr, zend_string *key; has_cookies = 1; smart_str_append_const(&soap_headers, "Cookie: "); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { if (key && Z_TYPE_P(data) == IS_ARRAY) { zval *value; diff --git a/ext/soap/php_packet_soap.c b/ext/soap/php_packet_soap.c index d822f4e82bcc8..c93451506ee3b 100644 --- a/ext/soap/php_packet_soap.c +++ b/ext/soap/php_packet_soap.c @@ -265,7 +265,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction if (fn->responseParameters) { res_count = zend_hash_num_elements(fn->responseParameters); - ZEND_ARRAY_FOREACH_PTR(fn->responseParameters, param) { + ZEND_HASH_FOREACH_PTR(fn->responseParameters, param) { if (fnb->style == SOAP_DOCUMENT) { if (param->element) { name = param->element->name; @@ -329,7 +329,7 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction add_assoc_zval(return_value, param->paramName, &tmp); param_count++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else { /* Function has no WSDL description */ diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index b2e3a8f507bba..68d78326e30ae 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -2197,10 +2197,10 @@ static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model) if (model->max_occurs != 1) { sdlContentModelPtr tmp; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { tmp->min_occurs = 0; tmp->max_occurs = model->max_occurs; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); model->kind = XSD_CONTENT_ALL; model->min_occurs = 1; @@ -2212,9 +2212,9 @@ static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model) case XSD_CONTENT_ALL: { sdlContentModelPtr tmp; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { schema_content_model_fixup(ctx, tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); break; } default: @@ -2253,9 +2253,9 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type) type->ref = NULL; } if (type->elements) { - ZEND_ARRAY_FOREACH_PTR(type->elements, tmp) { + ZEND_HASH_FOREACH_PTR(type->elements, tmp) { schema_type_fixup(ctx, tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (type->model) { schema_content_model_fixup(ctx, type->model); @@ -2264,14 +2264,14 @@ static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type) zend_string *str_key; zend_ulong index; - ZEND_ARRAY_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) { + ZEND_HASH_FOREACH_KEY_PTR(type->attributes, index, str_key, attr) { if (str_key) { schema_attribute_fixup(ctx, attr); } else { schema_attributegroup_fixup(ctx, attr, type->attributes); zend_hash_index_del(type->attributes, index); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -2282,29 +2282,29 @@ void schema_pass2(sdlCtx *ctx) sdlTypePtr type; if (ctx->attributes) { - ZEND_ARRAY_FOREACH_PTR(ctx->attributes, attr) { + ZEND_HASH_FOREACH_PTR(ctx->attributes, attr) { schema_attribute_fixup(ctx, attr); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (ctx->attributeGroups) { - ZEND_HASH_FOREACH_PTR(ctx->attributeGroups, type) { + ZEND_HASH_MAP_FOREACH_PTR(ctx->attributeGroups, type) { schema_type_fixup(ctx, type); } ZEND_HASH_FOREACH_END(); } if (sdl->elements) { - ZEND_HASH_FOREACH_PTR(sdl->elements, type) { + ZEND_HASH_MAP_FOREACH_PTR(sdl->elements, type) { schema_type_fixup(ctx, type); } ZEND_HASH_FOREACH_END(); } if (sdl->groups) { - ZEND_HASH_FOREACH_PTR(sdl->groups, type) { + ZEND_HASH_MAP_FOREACH_PTR(sdl->groups, type) { schema_type_fixup(ctx, type); } ZEND_HASH_FOREACH_END(); } if (sdl->types) { - ZEND_ARRAY_FOREACH_PTR(sdl->types, type) { + ZEND_HASH_FOREACH_PTR(sdl->types, type) { schema_type_fixup(ctx, type); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (ctx->attributes) { zend_hash_destroy(ctx->attributes); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index e41296fcaec89..2049f44821331 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -184,7 +184,7 @@ sdlBindingPtr get_binding_from_type(sdlPtr sdl, sdlBindingType type) return NULL; } - ZEND_HASH_FOREACH_PTR(sdl->bindings, binding) { + ZEND_HASH_MAP_FOREACH_PTR(sdl->bindings, binding) { if (binding->bindingType == type) { return binding; } @@ -593,7 +593,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap if (*parts == '\0') break; end = strchr(parts, ' '); if (end) *end = '\0'; - ZEND_ARRAY_FOREACH_PTR(params, param) { + ZEND_HASH_FOREACH_PTR(params, param) { if (param->paramName && strcmp(parts, param->paramName) == 0) { sdlParamPtr x_param; @@ -604,7 +604,7 @@ static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap found = 1; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (!found) { soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in ", parts); } @@ -1860,7 +1860,7 @@ static void sdl_serialize_attribute(sdlAttributePtr attr, HashTable *tmp_encoder sdlExtraAttributePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_string(tmp->ns, out); sdl_serialize_string(tmp->val, out); @@ -1884,9 +1884,9 @@ static void sdl_serialize_model(sdlContentModelPtr model, HashTable *tmp_types, int i = zend_hash_num_elements(model->u.content); WSDL_CACHE_PUT_INT(i, out); - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { sdl_serialize_model(tmp, tmp_types, tmp_elements, out); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; case XSD_CONTENT_GROUP_REF: @@ -1960,7 +1960,7 @@ static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTab sdlRestrictionCharPtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { sdl_serialize_resriction_char(tmp, out); sdl_serialize_key(key, out); } ZEND_HASH_FOREACH_END(); @@ -1982,13 +1982,13 @@ static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTab tmp_elements = emalloc(sizeof(HashTable)); zend_hash_init(tmp_elements, i, NULL, NULL, 0); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, tmp_encoders, tmp_types, out); ZVAL_LONG(&zv, i); zend_hash_str_add(tmp_elements, (char*)&tmp, sizeof(tmp), &zv); i--; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (type->attributes) { @@ -2001,10 +2001,10 @@ static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTab sdlAttributePtr tmp; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_attribute(tmp, tmp_encoders, out); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (type->model) { WSDL_CACHE_PUT_1(1, out); @@ -2040,13 +2040,13 @@ static void sdl_serialize_parameters(HashTable *ht, HashTable *tmp_encoders, Has sdlParamPtr tmp; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_PTR(ht, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(ht, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_string(tmp->paramName, out); WSDL_CACHE_PUT_INT(tmp->order, out); sdl_serialize_encoder_ref(tmp->encode, tmp_encoders, out); sdl_serialize_type_ref(tmp->element, tmp_types, out); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -2069,7 +2069,7 @@ static void sdl_serialize_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTabl sdlSoapBindingFunctionHeaderPtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(body->headers, key, tmp) { sdl_serialize_key(key, out); WSDL_CACHE_PUT_1(tmp->use, out); if (tmp->use == SOAP_ENCODED) { @@ -2089,7 +2089,7 @@ static void sdl_serialize_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTabl sdlSoapBindingFunctionHeaderPtr tmp2; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(body->headers, key, tmp2) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(body->headers, key, tmp2) { sdl_serialize_key(key, out); WSDL_CACHE_PUT_1(tmp2->use, out); if (tmp2->use == SOAP_ENCODED) { @@ -2147,7 +2147,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zval zv; - ZEND_HASH_FOREACH_PTR(sdl->groups, tmp) { + ZEND_HASH_MAP_FOREACH_PTR(sdl->groups, tmp) { ZVAL_LONG(&zv, type_num); zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); ++type_num; @@ -2164,11 +2164,11 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zval zv; - ZEND_ARRAY_FOREACH_PTR(sdl->types, tmp) { + ZEND_HASH_FOREACH_PTR(sdl->types, tmp) { ZVAL_LONG(&zv, type_num); zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); ++type_num; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (sdl->elements) { @@ -2181,7 +2181,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zval zv; - ZEND_HASH_FOREACH_PTR(sdl->elements, tmp) { + ZEND_HASH_MAP_FOREACH_PTR(sdl->elements, tmp) { ZVAL_LONG(&zv, type_num); zend_hash_str_add(&tmp_types, (char*)&tmp, sizeof(tmp), &zv); ++type_num; @@ -2198,11 +2198,11 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s encodePtr tmp; zval zv; - ZEND_ARRAY_FOREACH_PTR(sdl->encoders, tmp) { + ZEND_HASH_FOREACH_PTR(sdl->encoders, tmp) { ZVAL_LONG(&zv, encoder_num); zend_hash_str_add(&tmp_encoders, (char*)&tmp, sizeof(tmp), &zv); ++encoder_num; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } enc = defaultEncoding; while (enc->details.type != END_KNOWN_TYPES) { @@ -2218,7 +2218,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); } ZEND_HASH_FOREACH_END(); @@ -2228,17 +2228,17 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s sdlTypePtr tmp; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (sdl->elements) { sdlTypePtr tmp; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_type(tmp, &tmp_encoders, &tmp_types, out); } ZEND_HASH_FOREACH_END(); @@ -2248,10 +2248,10 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s encodePtr tmp; zend_string *key; - ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_encoder(tmp, &tmp_types, out); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* serialize bindings */ @@ -2267,7 +2267,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s zval zv; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_string(tmp->name, out); sdl_serialize_string(tmp->location, out); @@ -2295,7 +2295,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s int function_num = 1; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { sdl_serialize_key(key, out); sdl_serialize_string(tmp->functionName, out); sdl_serialize_string(tmp->requestName, out); @@ -2327,7 +2327,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s WSDL_CACHE_PUT_INT(zend_hash_num_elements(tmp->faults), out); - ZEND_HASH_FOREACH_STR_KEY_PTR(tmp->faults, key, fault) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(tmp->faults, key, fault) { sdl_serialize_key(key, out); sdl_serialize_string(fault->name, out); sdl_serialize_parameters(fault->details, &tmp_encoders, &tmp_types, out); @@ -2364,7 +2364,7 @@ static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr s zval *function_num; zend_string *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->requests, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->requests, key, tmp) { function_num = zend_hash_str_find(&tmp_functions, (char*)&tmp, sizeof(tmp)); WSDL_CACHE_PUT_INT(Z_LVAL_P(function_num), out); sdl_serialize_key(key, out); @@ -2444,7 +2444,7 @@ static HashTable* make_persistent_sdl_function_headers(HashTable *headers, HashT pheaders = malloc(sizeof(HashTable)); zend_hash_init(pheaders, zend_hash_num_elements(headers), NULL, delete_header_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(headers, key, tmp) { pheader = malloc(sizeof(sdlSoapBindingFunctionHeader)); memset(pheader, 0, sizeof(sdlSoapBindingFunctionHeader)); *pheader = *tmp; @@ -2508,7 +2508,7 @@ static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *p pparams = malloc(sizeof(HashTable)); zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(params, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) { pparam = malloc(sizeof(sdlParam)); memset(pparam, 0, sizeof(sdlParam)); *pparam = *tmp; @@ -2536,7 +2536,7 @@ static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *p } else { zend_hash_next_index_insert_ptr(pparams, pparam); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return pparams; } @@ -2550,7 +2550,7 @@ static HashTable* make_persistent_sdl_function_faults(sdlFunctionPtr func, HashT pfaults = malloc(sizeof(HashTable)); zend_hash_init(pfaults, zend_hash_num_elements(faults), NULL, delete_fault_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(faults, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(faults, key, tmp) { pfault = malloc(sizeof(sdlFault)); memset(pfault, 0, sizeof(sdlFault)); *pfault = *tmp; @@ -2624,7 +2624,7 @@ static sdlAttributePtr make_persistent_sdl_attribute(sdlAttributePtr attr, HashT pattr->extraAttributes = malloc(sizeof(HashTable)); zend_hash_init(pattr->extraAttributes, zend_hash_num_elements(attr->extraAttributes), NULL, delete_extra_attribute_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(attr->extraAttributes, key, tmp) { if (key) { pextra = malloc(sizeof(sdlExtraAttribute)); memset(pextra, 0, sizeof(sdlExtraAttribute)); @@ -2668,10 +2668,10 @@ static sdlContentModelPtr make_persistent_sdl_model(sdlContentModelPtr model, Ha pmodel->u.content = malloc(sizeof(HashTable)); zend_hash_init(pmodel->u.content, zend_hash_num_elements(model->u.content), NULL, delete_model_persistent, 1); - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { pcontent = make_persistent_sdl_model(tmp, ptr_map, bp_types, bp_encoders); zend_hash_next_index_insert_ptr(pmodel->u.content, pcontent); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); break; case XSD_CONTENT_GROUP_REF: @@ -2768,7 +2768,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, sdlRestrictionCharPtr tmp, penum; ptype->restrictions->enumeration = malloc(sizeof(HashTable)); zend_hash_init(ptype->restrictions->enumeration, zend_hash_num_elements(type->restrictions->enumeration), NULL, delete_restriction_var_char_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(type->restrictions->enumeration, key, tmp) { penum = tmp; make_persistent_restriction_char_int(&penum); /* We have to duplicate key emalloc->malloc */ @@ -2783,7 +2783,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, ptype->elements = malloc(sizeof(HashTable)); zend_hash_init(ptype->elements, zend_hash_num_elements(type->elements), NULL, delete_type_persistent, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(type->elements, key, tmp) { pelem = make_persistent_sdl_type(tmp, ptr_map, bp_types, bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2792,7 +2792,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, zend_hash_next_index_insert_ptr(ptype->elements, pelem); } zend_hash_str_add_ptr(ptr_map, (char*)&tmp, sizeof(tmp), pelem); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (ptype->attributes) { @@ -2801,7 +2801,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, ptype->attributes = malloc(sizeof(HashTable)); zend_hash_init(ptype->attributes, zend_hash_num_elements(type->attributes), NULL, delete_attribute_persistent, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(type->attributes, key, tmp) { pattr = make_persistent_sdl_attribute(tmp, ptr_map, bp_types, bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2809,7 +2809,7 @@ static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, } else { zend_hash_next_index_insert_ptr(ptype->attributes, pattr); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (type->model) { @@ -2953,7 +2953,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->groups = malloc(sizeof(HashTable)); zend_hash_init(psdl->groups, zend_hash_num_elements(sdl->groups), NULL, delete_type_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->groups, key, tmp) { ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2972,7 +2972,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->types = malloc(sizeof(HashTable)); zend_hash_init(psdl->types, zend_hash_num_elements(sdl->types), NULL, delete_type_persistent, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->types, key, tmp) { ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -2981,7 +2981,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) zend_hash_next_index_insert_ptr(psdl->types, ptype); } zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), ptype); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (sdl->elements) { @@ -2991,7 +2991,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->elements = malloc(sizeof(HashTable)); zend_hash_init(psdl->elements, zend_hash_num_elements(sdl->elements), NULL, delete_type_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->elements, key, tmp) { ptype = make_persistent_sdl_type(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -3010,7 +3010,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->encoders = malloc(sizeof(HashTable)); zend_hash_init(psdl->encoders, zend_hash_num_elements(sdl->encoders), NULL, delete_encoder_persistent, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { + ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->encoders, key, tmp) { penc = make_persistent_sdl_encoder(tmp, &ptr_map, &bp_types, &bp_encoders); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -3019,29 +3019,29 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) zend_hash_next_index_insert_ptr(psdl->encoders, penc); } zend_hash_str_add_ptr(&ptr_map, (char*)&tmp, sizeof(tmp), penc); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* do backpatching here */ if (zend_hash_num_elements(&bp_types)) { sdlTypePtr *tmp, ptype = NULL; - ZEND_ARRAY_FOREACH_PTR(&bp_types, tmp) { + ZEND_HASH_FOREACH_PTR(&bp_types, tmp) { if ((ptype = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { assert(0); } *tmp = ptype; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (zend_hash_num_elements(&bp_encoders)) { encodePtr *tmp, penc = NULL; - ZEND_ARRAY_FOREACH_PTR(&bp_encoders, tmp) { + ZEND_HASH_FOREACH_PTR(&bp_encoders, tmp) { if ((penc = zend_hash_str_find_ptr(&ptr_map, (char*)tmp, sizeof(*tmp))) == NULL) { assert(0); } *tmp = penc; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } @@ -3052,7 +3052,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->bindings = malloc(sizeof(HashTable)); zend_hash_init(psdl->bindings, zend_hash_num_elements(sdl->bindings), NULL, delete_binding_persistent, 1); - ZEND_HASH_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(sdl->bindings, key, tmp) { pbind = make_persistent_sdl_binding(tmp, &ptr_map); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -3069,7 +3069,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) sdlFunctionPtr tmp; sdlFunctionPtr pfunc; - ZEND_HASH_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&sdl->functions, key, tmp) { pfunc = make_persistent_sdl_function(tmp, &ptr_map); if (key) { /* We have to duplicate key emalloc->malloc */ @@ -3089,7 +3089,7 @@ static sdlPtr make_persistent_sdl(sdlPtr sdl) psdl->requests = malloc(sizeof(HashTable)); zend_hash_init(psdl->requests, zend_hash_num_elements(sdl->requests), NULL, NULL, 1); - ZEND_HASH_FOREACH_STR_KEY_VAL(sdl->requests, key, zv) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(sdl->requests, key, zv) { tmp = Z_PTR_P(zv); if ((preq = zend_hash_str_find_ptr(&ptr_map, (char*)&tmp, sizeof(tmp))) == NULL) { assert(0); @@ -3352,7 +3352,7 @@ sdlPtr get_sdl(zval *this_ptr, char *uri, zend_long cache_wsdl) time_t latest = t; zend_string *latest_key = NULL, *key; - ZEND_HASH_FOREACH_STR_KEY_PTR(SOAP_GLOBAL(mem_cache), key, q) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(SOAP_GLOBAL(mem_cache), key, q) { if (q->time < latest) { latest = q->time; latest_key = key; diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 24a42344f08fc..11a4984d02c9c 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -730,7 +730,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ HashTable *ht2; HashTable *typemap = NULL; - ZEND_ARRAY_FOREACH_VAL(ht, tmp) { + ZEND_HASH_FOREACH_VAL(ht, tmp) { char *type_name = NULL; char *type_ns = NULL; zval *to_xml = NULL; @@ -745,7 +745,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ ht2 = Z_ARRVAL_P(tmp); if (!HT_IS_PACKED(ht2)) { - ZEND_HASH_FOREACH_STR_KEY_VAL(ht2, name, tmp) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht2, name, tmp) { if (name) { if (zend_string_equals_literal(name, "type_name")) { if (Z_TYPE_P(tmp) == IS_STRING) { @@ -821,7 +821,7 @@ static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */ zend_hash_update_ptr(typemap, nscat.s, new_enc); smart_str_free(&nscat); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return typemap; } /* }}} */ @@ -1065,14 +1065,14 @@ PHP_METHOD(SoapServer, getFunctions) } else if (service->soap_functions.ft != NULL) { zval *name; - ZEND_HASH_FOREACH_VAL(service->soap_functions.ft, name) { + ZEND_HASH_MAP_FOREACH_VAL(service->soap_functions.ft, name) { add_next_index_str(return_value, zend_string_copy(Z_STR_P(name))); } ZEND_HASH_FOREACH_END(); } if (ft != NULL) { zend_function *f; - ZEND_HASH_FOREACH_PTR(ft, f) { + ZEND_HASH_MAP_FOREACH_PTR(ft, f) { if ((service->type != SOAP_OBJECT && service->type != SOAP_CLASS) || (f->common.fn_flags & ZEND_ACC_PUBLIC)) { add_next_index_str(return_value, zend_string_copy(f->common.function_name)); } @@ -1109,7 +1109,7 @@ PHP_METHOD(SoapServer, addFunction) service->soap_functions.ft = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(function_name))); } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) { zend_string *key; zend_function *f; @@ -1129,7 +1129,7 @@ PHP_METHOD(SoapServer, addFunction) zend_hash_update(service->soap_functions.ft, key, &function_copy); zend_string_release_ex(key, 0); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else if (Z_TYPE_P(function_name) == IS_STRING) { zend_string *key; @@ -2419,12 +2419,12 @@ static void verify_soap_headers_array(HashTable *ht) /* {{{ */ { zval *tmp; - ZEND_ARRAY_FOREACH_VAL(ht, tmp) { + ZEND_HASH_FOREACH_VAL(ht, tmp) { if (Z_TYPE_P(tmp) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(tmp), soap_header_class_entry)) { php_error_docref(NULL, E_ERROR, "Invalid SOAP header"); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -2501,12 +2501,12 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, bool is_soap_call) soap_headers = zend_array_dup(soap_headers); free_soap_headers = 1; } - ZEND_ARRAY_FOREACH_VAL(default_headers, tmp) { + ZEND_HASH_FOREACH_VAL(default_headers, tmp) { if(Z_TYPE_P(tmp) == IS_OBJECT) { Z_ADDREF_P(tmp); zend_hash_next_index_insert(soap_headers, tmp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { soap_headers = Z_ARRVAL_P(tmp); free_soap_headers = 0; @@ -2517,12 +2517,12 @@ void soap_client_call_impl(INTERNAL_FUNCTION_PARAMETERS, bool is_soap_call) if (arg_count > 0) { real_args = safe_emalloc(sizeof(zval), arg_count, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), param) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), param) { /*zval_add_ref(param);*/ ZVAL_DEREF(param); ZVAL_COPY_VALUE(&real_args[i], param); i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (output_headers) { output_headers = zend_try_array_init(output_headers); @@ -2570,7 +2570,7 @@ PHP_METHOD(SoapClient, __getFunctions) sdlFunctionPtr function; array_init(return_value); - ZEND_HASH_FOREACH_PTR(&sdl->functions, function) { + ZEND_HASH_MAP_FOREACH_PTR(&sdl->functions, function) { function_to_string(function, &buf); add_next_index_stringl(return_value, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s)); smart_str_free(&buf); @@ -2597,11 +2597,11 @@ PHP_METHOD(SoapClient, __getTypes) array_init(return_value); if (sdl->types) { - ZEND_ARRAY_FOREACH_PTR(sdl->types, type) { + ZEND_HASH_FOREACH_PTR(sdl->types, type) { type_to_string(type, &buf, 0); add_next_index_stringl(return_value, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s)); smart_str_free(&buf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } } @@ -2881,14 +2881,14 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, i return; } num_of_params = zend_hash_num_elements(function->requestParameters); - ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { + ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { if (get_node(params, param->paramName) != NULL) { use_names = 1; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (use_names) { tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0); - ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { + ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { val = get_node(params, param->paramName); if (!val) { /* TODO: may be "nil" is not OK? */ @@ -2897,7 +2897,7 @@ static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, i master_to_zval(&tmp_parameters[cur_param], param->encode, val); } cur_param++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *parameters = tmp_parameters; *num_params = num_of_params; return; @@ -3361,7 +3361,7 @@ static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, ch zend_string *param_name; zend_ulong param_index = i; - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) { parameter = get_param(function, ZSTR_VAL(param_name), param_index, TRUE); if (style == SOAP_RPC) { param = serialize_parameter(parameter, data, i, ZSTR_VAL(param_name), use, method); @@ -3378,7 +3378,7 @@ static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, ch i++; param_index = i; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (use == SOAP_ENCODED && version == SOAP_1_2 && method != NULL) { xmlSetNsProp(method, body->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE)); @@ -3891,7 +3891,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function if (head) { zval* header; - ZEND_ARRAY_FOREACH_VAL(soap_headers, header) { + ZEND_HASH_FOREACH_VAL(soap_headers, header) { if (Z_TYPE_P(header) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(header), soap_header_class_entry)) { continue; @@ -3935,7 +3935,7 @@ static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function xmlSetNs(h, nsptr); set_soap_header_attributes(h, header, version); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (use == SOAP_ENCODED) { @@ -4051,11 +4051,11 @@ static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int inde if ((tmp = zend_hash_str_find_ptr(ht, param_name, strlen(param_name))) != NULL) { return tmp; } else { - ZEND_ARRAY_FOREACH_PTR(ht, tmp) { + ZEND_HASH_FOREACH_PTR(ht, tmp) { if (tmp->paramName && strcmp(param_name, tmp->paramName) == 0) { return tmp; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else { if ((tmp = zend_hash_index_find_ptr(ht, index)) != NULL) { @@ -4093,7 +4093,7 @@ static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */ sdlFunctionPtr tmp; sdlParamPtr param; - ZEND_HASH_FOREACH_PTR(&sdl->functions, tmp) { + ZEND_HASH_MAP_FOREACH_PTR(&sdl->functions, tmp) { if (tmp->binding && tmp->binding->bindingType == BINDING_SOAP) { sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)tmp->bindingAttributes; if (fnb->style == SOAP_DOCUMENT) { @@ -4107,7 +4107,7 @@ static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */ int ok = 1; xmlNodePtr node = params; - ZEND_ARRAY_FOREACH_PTR(tmp->requestParameters, param) { + ZEND_HASH_FOREACH_PTR(tmp->requestParameters, param) { if (param->element) { if (strcmp(param->element->name, (char*)node->name) != 0) { ok = 0; @@ -4127,7 +4127,7 @@ static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */ break; } node = node->next; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (ok /*&& node == NULL*/) { return tmp; } @@ -4159,7 +4159,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * } else { i = 0; smart_str_appendl(buf, "list(", 5); - ZEND_ARRAY_FOREACH_PTR(function->responseParameters, param) { + ZEND_HASH_FOREACH_PTR(function->responseParameters, param) { if (i > 0) { smart_str_appendl(buf, ", ", 2); } @@ -4171,7 +4171,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, " $", 2); smart_str_appendl(buf, param->paramName, strlen(param->paramName)); i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendl(buf, ") ", 2); } } else { @@ -4183,7 +4183,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendc(buf, '('); if (function->requestParameters) { i = 0; - ZEND_ARRAY_FOREACH_PTR(function->requestParameters, param) { + ZEND_HASH_FOREACH_PTR(function->requestParameters, param) { if (i > 0) { smart_str_appendl(buf, ", ", 2); } @@ -4195,7 +4195,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, " $", 2); smart_str_appendl(buf, param->paramName, strlen(param->paramName)); i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } smart_str_appendc(buf, ')'); smart_str_0(buf); @@ -4222,9 +4222,9 @@ static void model_to_string(sdlContentModelPtr model, smart_str *buf, int level) case XSD_CONTENT_CHOICE: { sdlContentModelPtr tmp; - ZEND_ARRAY_FOREACH_PTR(model->u.content, tmp) { + ZEND_HASH_FOREACH_PTR(model->u.content, tmp) { model_to_string(tmp, buf, level); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); break; } case XSD_CONTENT_GROUP: @@ -4263,9 +4263,9 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ sdlTypePtr item_type; smart_str_appendl(buf, " {", 2); - ZEND_ARRAY_FOREACH_PTR(type->elements, item_type) { + ZEND_HASH_FOREACH_PTR(type->elements, item_type) { smart_str_appendl(buf, item_type->name, strlen(item_type->name)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendc(buf, '}'); } break; @@ -4277,13 +4277,13 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ int first = 0; smart_str_appendl(buf, " {", 2); - ZEND_ARRAY_FOREACH_PTR(type->elements, item_type) { + ZEND_HASH_FOREACH_PTR(type->elements, item_type) { if (!first) { smart_str_appendc(buf, ','); first = 0; } smart_str_appendl(buf, item_type->name, strlen(item_type->name)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendc(buf, '}'); } break; @@ -4380,7 +4380,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ if (type->attributes) { sdlAttributePtr attr; - ZEND_ARRAY_FOREACH_PTR(type->attributes, attr) { + ZEND_HASH_FOREACH_PTR(type->attributes, attr) { if (spaces.s) { smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s)); } @@ -4393,7 +4393,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ } smart_str_appends(buf, attr->name); smart_str_appendl(buf, ";\n", 2); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if (spaces.s) { smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s)); diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index 7a77026839761..ba5b1d8a5ad67 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -213,7 +213,7 @@ static unsigned from_array_iterate(const zval *arr, /* Note i starts at 1, not 0! */ i = 1; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if ((size_t)snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } @@ -226,7 +226,7 @@ static unsigned from_array_iterate(const zval *arr, break; } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return i -1; } @@ -936,7 +936,7 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c control_len = (size_t)num_elems * CMSG_SPACE(20); cur_offset = 0; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if (ctx->err.has_error) { break; } @@ -949,7 +949,7 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c from_zval_write_control(elem, &control_buf, alloc, &control_len, &cur_offset, ctx); zend_llist_remove_tail(&ctx->keys); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); msg->msg_control = control_buf; msg->msg_controllen = cur_offset; /* not control_len, which may be larger */ diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index f6f8e04343c1c..1df6eaa09d659 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -656,7 +656,7 @@ static int php_sock_array_to_fd_set(uint32_t arg_num, zval *sock_array, fd_set * if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(sock_array), element) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(sock_array), element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) != IS_OBJECT || Z_OBJCE_P(element) != socket_ce) { @@ -675,7 +675,7 @@ static int php_sock_array_to_fd_set(uint32_t arg_num, zval *sock_array, fd_set * *max_fd = php_sock->bsd_socket; } num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return num ? 1 : 0; } @@ -694,7 +694,7 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ ZEND_ASSERT(Z_TYPE_P(sock_array) == IS_ARRAY); array_init(&new_hash); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) { ZVAL_DEREF(element); php_sock = Z_SOCKET_P(element); @@ -713,7 +713,7 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ } } num++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Destroy old array, add new one */ zval_ptr_dtor(sock_array); @@ -2354,7 +2354,7 @@ PHP_FUNCTION(socket_addrinfo_lookup) memset(&hints, 0, sizeof(hints)); if (zhints && !HT_IS_PACKED(Z_ARRVAL_P(zhints))) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) { if (key) { if (zend_string_equals_literal(key, "ai_flags")) { hints.ai_flags = zval_get_long(hint); diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 8e187fe966b22..53d7f116652de 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -113,7 +113,7 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { zval *trace = zend_read_property(zend_get_exception_base(obj), obj, "trace", sizeof("trace")-1, 0, &rv); if (trace && Z_TYPE_P(trace) == IS_ARRAY) { zval *frame; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { if (Z_TYPE_P(frame) == IS_ARRAY) { zval *args = zend_hash_str_find(Z_ARRVAL_P(frame), "args", sizeof("args")-1); if (args) { @@ -121,7 +121,7 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { ZVAL_EMPTY_ARRAY(args); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 3ac5430a44a15..22b4e52b44496 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -410,7 +410,7 @@ static zend_class_entry *spl_perform_autoload(zend_string *class_name, zend_stri return NULL; } - /* We don't use ZEND_HASH_FOREACH here, + /* We don't use ZEND_HASH_MAP_FOREACH here, * because autoloaders may be added/removed during autoloading. */ HashPosition pos; zend_hash_internal_pointer_reset_ex(spl_autoload_functions, &pos); @@ -479,7 +479,7 @@ static Bucket *spl_find_registered_function(autoload_func_info *find_alfi) { } autoload_func_info *alfi; - ZEND_HASH_FOREACH_PTR(spl_autoload_functions, alfi) { + ZEND_HASH_MAP_FOREACH_PTR(spl_autoload_functions, alfi) { if (autoload_func_info_equals(alfi, find_alfi)) { return _p; } @@ -600,7 +600,7 @@ PHP_FUNCTION(spl_autoload_functions) array_init(return_value); if (spl_autoload_functions) { - ZEND_HASH_FOREACH_PTR(spl_autoload_functions, alfi) { + ZEND_HASH_MAP_FOREACH_PTR(spl_autoload_functions, alfi) { if (alfi->closure) { GC_ADDREF(alfi->closure); add_next_index_object(return_value, alfi->closure); @@ -676,9 +676,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Interfaces", strg + 2); efree(strg); @@ -686,9 +686,9 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); php_info_print_table_row(2, "Classes", strg + 2); efree(strg); diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index cbedb7de59820..8a429fdf3f8bc 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1259,13 +1259,13 @@ static zend_long spl_array_object_count_elements_helper(spl_array_object *intern zend_string *key; zval *val; /* Count public/dynamic properties */ - ZEND_ARRAY_FOREACH_STR_KEY_VAL(aht, key, val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(aht, key, val) { if (Z_TYPE_P(val) == IS_INDIRECT) { if (Z_TYPE_P(Z_INDIRECT_P(val)) == IS_UNDEF) continue; if (key && ZSTR_VAL(key)[0] == '\0') continue; } count++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return count; } else { return zend_hash_num_elements(aht); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index b55ad85db2fa6..893f81325baf1 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -1156,9 +1156,9 @@ PHP_METHOD(SplDoublyLinkedList, __unserialize) { intern->flags = (int) Z_LVAL_P(flags_zv); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) { spl_ptr_llist_push(intern->llist, elem); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); object_properties_load(&intern->std, Z_ARRVAL_P(members_zv)); } /* }}} */ diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index d1195c5eec3a1..9503baeaba87b 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -579,10 +579,10 @@ PHP_METHOD(SplFixedArray, __wakeup) spl_fixedarray_init(&intern->array, size); - ZEND_ARRAY_FOREACH_VAL(intern_ht, data) { + ZEND_HASH_FOREACH_VAL(intern_ht, data) { ZVAL_COPY(&intern->array.elements[index], data); index++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Remove the unserialised properties, since we now have the elements * within the spl_fixedarray_object structure. */ @@ -644,7 +644,7 @@ PHP_METHOD(SplFixedArray, fromArray) zend_ulong num_index, max_index = 0; zend_long tmp; - ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { + ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { if (str_index != NULL || (zend_long)num_index < 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys"); RETURN_THROWS(); @@ -653,7 +653,7 @@ PHP_METHOD(SplFixedArray, fromArray) if (num_index > max_index) { max_index = num_index; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); tmp = max_index + 1; if (tmp <= 0) { @@ -662,9 +662,9 @@ PHP_METHOD(SplFixedArray, fromArray) } spl_fixedarray_init(&array, tmp); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_index, str_index, element) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_index, str_index, element) { ZVAL_COPY_DEREF(&array.elements[num_index], element); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (num > 0 && !save_indexes) { zval *element; @@ -672,10 +672,10 @@ PHP_METHOD(SplFixedArray, fromArray) spl_fixedarray_init(&array, num); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(data), element) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), element) { ZVAL_COPY_DEREF(&array.elements[i], element); i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { spl_fixedarray_init(&array, 0); } diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 7b4e5f897c533..be826b2f06d4d 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -182,9 +182,9 @@ static int spl_object_storage_detach(spl_SplObjectStorage *intern, zend_object * void spl_object_storage_addall(spl_SplObjectStorage *intern, spl_SplObjectStorage *other) { /* {{{ */ spl_SplObjectStorageElement *element; - ZEND_ARRAY_FOREACH_PTR(&other->storage, element) { + ZEND_HASH_FOREACH_PTR(&other->storage, element) { spl_object_storage_attach(intern, element->obj, &element->inf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); intern->index = 0; } /* }}} */ @@ -257,7 +257,7 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{ array_init(&storage); - ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { + ZEND_HASH_FOREACH_PTR(&intern->storage, element) { array_init(&tmp); /* Incrementing the refcount of obj and inf would confuse the garbage collector. * Prefer to null the destructor */ @@ -267,7 +267,7 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{ add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj); add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf); zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zname = spl_gen_private_prop_name(spl_ce_SplObjectStorage, "storage", sizeof("storage")-1); zend_symtable_update(debug_info, zname, &storage); @@ -284,10 +284,10 @@ static HashTable *spl_object_storage_get_gc(zend_object *obj, zval **table, int spl_SplObjectStorageElement *element; zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create(); - ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { + ZEND_HASH_FOREACH_PTR(&intern->storage, element) { zend_get_gc_buffer_add_obj(gc_buffer, element->obj); zend_get_gc_buffer_add_zval(gc_buffer, &element->inf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_get_gc_buffer_use(gc_buffer, table, n); return zend_std_get_properties(obj); @@ -474,11 +474,11 @@ PHP_METHOD(SplObjectStorage, removeAllExcept) other = Z_SPLOBJSTORAGE_P(obj); - ZEND_ARRAY_FOREACH_PTR(&intern->storage, element) { + ZEND_HASH_FOREACH_PTR(&intern->storage, element) { if (!spl_object_storage_contains(other, element->obj)) { spl_object_storage_detach(intern, element->obj); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); intern->index = 0; @@ -803,13 +803,13 @@ PHP_METHOD(SplObjectStorage, __serialize) /* storage */ array_init_size(&tmp, 2 * zend_hash_num_elements(&intern->storage)); - ZEND_ARRAY_FOREACH_PTR(&intern->storage, elem) { + ZEND_HASH_FOREACH_PTR(&intern->storage, elem) { zval obj; ZVAL_OBJ_COPY(&obj, elem->obj); zend_hash_next_index_insert(Z_ARRVAL(tmp), &obj); Z_TRY_ADDREF(elem->inf); zend_hash_next_index_insert(Z_ARRVAL(tmp), &elem->inf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &tmp); /* members */ @@ -844,7 +844,7 @@ PHP_METHOD(SplObjectStorage, __unserialize) } key = NULL; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(storage_zv), val) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), val) { if (key) { if (Z_TYPE_P(key) != IS_OBJECT) { zend_throw_exception(spl_ce_UnexpectedValueException, "Non-object key", 0); @@ -856,7 +856,7 @@ PHP_METHOD(SplObjectStorage, __unserialize) } else { key = val; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); object_properties_load(&intern->std, Z_ARRVAL_P(members_zv)); } diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 91ebc6f798edc..55ebf911e94d4 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1493,7 +1493,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ int return_code; if (stmt_obj->bound_params) { - ZEND_ARRAY_FOREACH_PTR(stmt_obj->bound_params, param) { + ZEND_HASH_FOREACH_PTR(stmt_obj->bound_params, param) { zval *parameter; /* parameter must be a reference? */ if (Z_ISREF(param->parameter)) { @@ -1586,7 +1586,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ php_sqlite3_error(stmt_obj->db_obj, "Unknown parameter type: %pd for parameter %pd", param->type, param->param_number); return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return SUCCESS; diff --git a/ext/standard/array.c b/ext/standard/array.c index 911aa8e192b3b..15cca7539aee8 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -660,12 +660,12 @@ PHPAPI zend_long php_count_recursive(HashTable *ht) /* {{{ */ } cnt = zend_hash_num_elements(ht); - ZEND_ARRAY_FOREACH_VAL(ht, element) { + ZEND_HASH_FOREACH_VAL(ht, element) { ZVAL_DEREF(element); if (Z_TYPE_P(element) == IS_ARRAY) { cnt += php_count_recursive(Z_ARRVAL_P(element)); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_TRY_UNPROTECT_RECURSION(ht); return cnt; @@ -1501,7 +1501,7 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) if (strict) { if (Z_TYPE_P(value) == IS_LONG) { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG && Z_LVAL_P(entry) == Z_LVAL_P(value)) { if (behavior == 0) { @@ -1514,9 +1514,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (fast_is_identical_function(value, entry)) { if (behavior == 0) { @@ -1529,11 +1529,11 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else { if (Z_TYPE_P(value) == IS_LONG) { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_long(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1545,9 +1545,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (Z_TYPE_P(value) == IS_STRING) { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_string(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1559,9 +1559,9 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (fast_equal_check_function(value, entry)) { if (behavior == 0) { RETURN_TRUE; @@ -1573,7 +1573,7 @@ static inline void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -1676,7 +1676,7 @@ static zend_long php_extract_ref_if_exists(zend_array *arr, zend_array *symbol_t if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1722,7 +1722,7 @@ static zend_long php_extract_if_exists(zend_array *arr, zend_array *symbol_table if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1766,7 +1766,7 @@ static zend_long php_extract_ref_overwrite(zend_array *arr, zend_array *symbol_t if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1816,7 +1816,7 @@ static zend_long php_extract_overwrite(zend_array *arr, zend_array *symbol_table if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1861,7 +1861,7 @@ static zend_long php_extract_ref_prefix_if_exists(zend_array *arr, zend_array *s if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1920,7 +1920,7 @@ static zend_long php_extract_prefix_if_exists(zend_array *arr, zend_array *symbo if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -1974,7 +1974,7 @@ static zend_long php_extract_ref_prefix_same(zend_array *arr, zend_array *symbol if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -2051,7 +2051,7 @@ static zend_long php_extract_prefix_same(zend_array *arr, zend_array *symbol_tab if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -2118,7 +2118,7 @@ static zend_long php_extract_ref_prefix_all(zend_array *arr, zend_array *symbol_ zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (ZSTR_LEN(var_name) == 0) { continue; @@ -2152,7 +2152,7 @@ static zend_long php_extract_ref_prefix_all(zend_array *arr, zend_array *symbol_ } } zval_ptr_dtor_str(&final_name); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return count; } @@ -2165,7 +2165,7 @@ static zend_long php_extract_prefix_all(zend_array *arr, zend_array *symbol_tabl zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (ZSTR_LEN(var_name) == 0) { continue; @@ -2199,7 +2199,7 @@ static zend_long php_extract_prefix_all(zend_array *arr, zend_array *symbol_tabl } } zval_ptr_dtor_str(&final_name); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return count; } @@ -2212,7 +2212,7 @@ static zend_long php_extract_ref_prefix_invalid(zend_array *arr, zend_array *sym zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (!php_valid_var_name(ZSTR_VAL(var_name), ZSTR_LEN(var_name)) || zend_string_equals_literal(var_name, "this")) { @@ -2254,7 +2254,7 @@ static zend_long php_extract_ref_prefix_invalid(zend_array *arr, zend_array *sym count++; } zval_ptr_dtor_str(&final_name); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return count; } @@ -2267,7 +2267,7 @@ static zend_long php_extract_prefix_invalid(zend_array *arr, zend_array *symbol_ zend_ulong num_key; zval *entry, *orig_var, final_name; - ZEND_ARRAY_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arr, num_key, var_name, entry) { if (var_name) { if (!php_valid_var_name(ZSTR_VAL(var_name), ZSTR_LEN(var_name)) || zend_string_equals_literal(var_name, "this")) { @@ -2309,7 +2309,7 @@ static zend_long php_extract_prefix_invalid(zend_array *arr, zend_array *symbol_ count++; } zval_ptr_dtor_str(&final_name); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return count; } @@ -2324,7 +2324,7 @@ static zend_long php_extract_ref_skip(zend_array *arr, zend_array *symbol_table) if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -2372,7 +2372,7 @@ static zend_long php_extract_skip(zend_array *arr, zend_array *symbol_table) /* if (HT_IS_PACKED(arr)) { return 0; } - ZEND_HASH_FOREACH_STR_KEY_VAL(arr, var_name, entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(arr, var_name, entry) { if (!var_name) { continue; } @@ -2535,9 +2535,9 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu } Z_PROTECT_RECURSION_P(entry); } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(entry), value_ptr) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(entry), value_ptr) { php_compact_var(eg_active_symbol_table, return_value, value_ptr, pos); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (Z_REFCOUNTED_P(entry)) { Z_UNPROTECT_RECURSION_P(entry); } @@ -2659,7 +2659,7 @@ PHP_FUNCTION(array_fill_keys) /* Initialize return array */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(keys))); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) { ZVAL_DEREF(entry); Z_TRY_ADDREF_P(val); if (Z_TYPE_P(entry) == IS_LONG) { @@ -2670,7 +2670,7 @@ PHP_FUNCTION(array_fill_keys) zend_symtable_update(Z_ARRVAL_P(return_value), key, val); zend_tmp_string_release(tmp_key); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -3055,11 +3055,11 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H /* If there are entries to insert.. */ if (replace) { - ZEND_ARRAY_FOREACH_VAL(replace, entry) { + ZEND_HASH_FOREACH_VAL(replace, entry) { Z_TRY_ADDREF_P(entry); zend_hash_next_index_insert_new(&out_hash, entry); pos++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* Copy the remaining input hash entries to the output hash */ @@ -3125,11 +3125,11 @@ static void php_splice(HashTable *in_hash, zend_long offset, zend_long length, H /* If there are entries to insert.. */ if (replace) { - ZEND_ARRAY_FOREACH_VAL(replace, entry) { + ZEND_HASH_FOREACH_VAL(replace, entry) { Z_TRY_ADDREF_P(entry); zend_hash_next_index_insert_new(&out_hash, entry); pos++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* Copy the remaining input hash entries to the output hash */ @@ -3400,13 +3400,13 @@ PHP_FUNCTION(array_unshift) zend_hash_next_index_insert_new(&new_hash, &args[i]); } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) { if (key) { zend_hash_add_new(&new_hash, key, value); } else { zend_hash_next_index_insert_new(&new_hash, value); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (UNEXPECTED(HT_HAS_ITERATORS(Z_ARRVAL_P(stack)))) { zend_hash_iterators_advance(Z_ARRVAL_P(stack), argc); @@ -3510,7 +3510,7 @@ static inline Bucket* find_bucket_at_offset(HashTable* ht, zend_long offset) } /* Otherwise, this code has to iterate over the HashTable and skip holes in the array. */ pos = 0; - ZEND_HASH_FOREACH_BUCKET(ht, bucket) { + ZEND_HASH_MAP_FOREACH_BUCKET(ht, bucket) { if (pos >= offset) { /* This is the bucket of the array element at the requested offset */ return bucket; @@ -3537,13 +3537,13 @@ static inline zval* find_packed_val_at_offset(HashTable* ht, zend_long offset) } /* Otherwise, this code has to iterate over the HashTable and skip holes in the array. */ pos = 0; - ZEND_PACKED_FOREACH_VAL(ht, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(ht, zv) { if (pos >= offset) { /* This is the bucket of the array element at the requested offset */ return zv; } ++pos; - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Return a pointer to the end of the bucket array. */ return ht->arPacked + ht->nNumUsed; @@ -3600,7 +3600,7 @@ PHP_FUNCTION(array_slice) /* Initialize returned array */ array_init_size(return_value, (uint32_t)length); - // Contains modified variants of ZEND_HASH_FOREACH_VAL + // Contains modified variants of ZEND_HASH_MAP_FOREACH_VAL { HashTable *ht = Z_ARRVAL_P(input); @@ -3687,7 +3687,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *src_entry, *dest_entry; zend_string *string_key; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { + ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { if (string_key) { if ((dest_entry = zend_hash_find_known_hash(dest, string_key)) != NULL) { zval *src_zval = src_entry; @@ -3744,7 +3744,7 @@ PHPAPI int php_array_merge_recursive(HashTable *dest, HashTable *src) /* {{{ */ zval *zv = zend_hash_next_index_insert(dest, src_entry); zval_add_ref(zv); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 1; } /* }}} */ @@ -3757,17 +3757,17 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ if (HT_IS_PACKED(dest) && HT_IS_PACKED(src)) { zend_hash_extend(dest, zend_hash_num_elements(dest) + zend_hash_num_elements(src), 1); ZEND_HASH_FILL_PACKED(dest) { - ZEND_PACKED_FOREACH_VAL(src, src_entry) { + ZEND_HASH_PACKED_FOREACH_VAL(src, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry)) && UNEXPECTED(Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); } Z_TRY_ADDREF_P(src_entry); ZEND_HASH_FILL_ADD(src_entry); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_ARRAY_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { + ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); @@ -3778,7 +3778,7 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src) /* {{{ */ } else { zend_hash_next_index_insert_new(dest, src_entry); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return 1; } @@ -3791,7 +3791,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * zend_ulong num_key; int ret; - ZEND_ARRAY_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { + ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { src_zval = src_entry; ZVAL_DEREF(src_zval); if (string_key) { @@ -3848,7 +3848,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ * if (!ret) { return 0; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return 1; } @@ -3938,12 +3938,12 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET bool copy = 1; zend_string *string_key; - ZEND_ARRAY_FOREACH_STR_KEY(Z_ARRVAL_P(ret), string_key) { + ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(ret), string_key) { if (!string_key) { copy = 0; break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (copy) { ZVAL_COPY(return_value, ret); return; @@ -3960,19 +3960,19 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET if (HT_IS_PACKED(src)) { zend_hash_real_init_packed(dest); ZEND_HASH_FILL_PACKED(dest) { - ZEND_PACKED_FOREACH_VAL(src, src_entry) { + ZEND_HASH_PACKED_FOREACH_VAL(src, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); } Z_TRY_ADDREF_P(src_entry); ZEND_HASH_FILL_ADD(src_entry); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { zend_string *string_key; zend_hash_real_init_mixed(dest); - ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(src, string_key, src_entry) { if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) { src_entry = Z_REFVAL_P(src_entry); @@ -4059,7 +4059,7 @@ PHP_FUNCTION(array_keys) array_init(return_value); if (strict) { - ZEND_ARRAY_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (fast_is_identical_function(search_value, entry)) { if (str_idx) { @@ -4069,9 +4069,9 @@ PHP_FUNCTION(array_keys) } zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &new_val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { - ZEND_ARRAY_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(arrval, num_idx, str_idx, entry) { if (fast_equal_check_function(search_value, entry)) { if (str_idx) { ZVAL_STR_COPY(&new_val, str_idx); @@ -4080,7 +4080,7 @@ PHP_FUNCTION(array_keys) } zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &new_val); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } else { array_init_size(return_value, elem_count); @@ -4096,14 +4096,14 @@ PHP_FUNCTION(array_keys) } } else { /* Go through input array and add keys to the return array */ - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_idx, str_idx, entry) { if (str_idx) { ZEND_HASH_FILL_SET_STR_COPY(str_idx); } else { ZEND_HASH_FILL_SET_LONG(num_idx); } ZEND_HASH_FILL_NEXT(); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } ZEND_HASH_FILL_END(); } @@ -4173,13 +4173,13 @@ PHP_FUNCTION(array_values) /* Go through input array and add values to the return array */ ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_ARRAY_FOREACH_VAL(arrval, entry) { + ZEND_HASH_FOREACH_VAL(arrval, entry) { if (UNEXPECTED(Z_ISREF_P(entry) && Z_REFCOUNT_P(entry) == 1)) { entry = Z_REFVAL_P(entry); } Z_TRY_ADDREF_P(entry); ZEND_HASH_FILL_ADD(entry); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } /* }}} */ @@ -4201,7 +4201,7 @@ PHP_FUNCTION(array_count_values) /* Go through input array and add values to the return array */ myht = Z_ARRVAL_P(input); - ZEND_ARRAY_FOREACH_VAL(myht, entry) { + ZEND_HASH_FOREACH_VAL(myht, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) { @@ -4222,7 +4222,7 @@ PHP_FUNCTION(array_count_values) } else { php_error_docref(NULL, E_WARNING, "Can only count string and integer values, entry skipped"); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4297,7 +4297,7 @@ PHP_FUNCTION(array_column) if (index_is_null) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_ARRAY_FOREACH_VAL(input, data) { + ZEND_HASH_FOREACH_VAL(input, data) { ZVAL_DEREF(data); if (column_is_null) { Z_TRY_ADDREF_P(data); @@ -4306,10 +4306,10 @@ PHP_FUNCTION(array_column) continue; } ZEND_HASH_FILL_ADD(colval); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_ARRAY_FOREACH_VAL(input, data) { + ZEND_HASH_FOREACH_VAL(input, data) { ZVAL_DEREF(data); if (column_is_null) { @@ -4328,7 +4328,7 @@ PHP_FUNCTION(array_column) } else { zend_hash_next_index_insert(Z_ARRVAL_P(return_value), colval); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ @@ -4353,17 +4353,17 @@ PHP_FUNCTION(array_reverse) if (HT_IS_PACKED(Z_ARRVAL_P(input)) && !preserve_keys) { zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_PACKED_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_HASH_PACKED_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (UNEXPECTED(Z_ISREF_P(entry) && Z_REFCOUNT_P(entry) == 1)) { entry = Z_REFVAL_P(entry); } Z_TRY_ADDREF_P(entry); ZEND_HASH_FILL_ADD(entry); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } else { - ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { + ZEND_HASH_REVERSE_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) { if (string_key) { entry = zend_hash_add_new(Z_ARRVAL_P(return_value), string_key, entry); } else { @@ -4374,7 +4374,7 @@ PHP_FUNCTION(array_reverse) } } zval_add_ref(entry); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } /* }}} */ @@ -4430,10 +4430,10 @@ PHP_FUNCTION(array_pad) } ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { - ZEND_PACKED_FOREACH_VAL(Z_ARRVAL_P(input), value) { + ZEND_HASH_PACKED_FOREACH_VAL(Z_ARRVAL_P(input), value) { Z_TRY_ADDREF_P(value); ZEND_HASH_FILL_ADD(value); - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); if (pad_size > 0) { @@ -4450,7 +4450,7 @@ PHP_FUNCTION(array_pad) } } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(input), key, value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(input), key, value) { Z_TRY_ADDREF_P(value); if (key) { zend_hash_add_new(Z_ARRVAL_P(return_value), key, value); @@ -4481,7 +4481,7 @@ PHP_FUNCTION(array_flip) array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if (str_idx) { @@ -4500,7 +4500,7 @@ PHP_FUNCTION(array_flip) } else { php_error_docref(NULL, E_WARNING, "Can only flip string and integer values, entry skipped"); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4521,7 +4521,7 @@ PHP_FUNCTION(array_change_key_case) array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) { if (!string_key) { entry = zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry); } else { @@ -4535,7 +4535,7 @@ PHP_FUNCTION(array_change_key_case) } zval_add_ref(entry); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4584,7 +4584,7 @@ PHP_FUNCTION(array_unique) zend_hash_init(&seen, zend_hash_num_elements(Z_ARRVAL_P(array)), NULL, NULL, 0); array_init(return_value); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, str_key, val) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, str_key, val) { zval *retval; if (Z_TYPE_P(val) == IS_STRING) { retval = zend_hash_add_empty_element(&seen, Z_STR_P(val)); @@ -4608,7 +4608,7 @@ PHP_FUNCTION(array_unique) zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, val); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&seen); return; @@ -4734,7 +4734,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa array_init(return_value); /* Iterate over keys of the first array, to compute keys that are in all of the other arrays. */ - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -4769,7 +4769,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa zend_hash_add_new(Z_ARRVAL_P(return_value), key, val); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -5119,7 +5119,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty array_init(return_value); /* Iterate over keys of the first array, to compute keys that aren't in the other arrays. */ - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), h, key, val) { if (Z_ISREF_P(val) && Z_REFCOUNT_P(val) == 1) { val = Z_REFVAL_P(val); } @@ -5154,7 +5154,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty zend_hash_add_new(Z_ARRVAL_P(return_value), key, val); } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -5459,9 +5459,9 @@ PHP_FUNCTION(array_diff) zend_string *search_str, *tmp_search_str; value = NULL; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[0]), value) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[0]), value) { break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (!value) { for (i = 1; i < argc; i++) { @@ -5481,7 +5481,7 @@ PHP_FUNCTION(array_diff) RETURN_THROWS(); } if (!found) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), value) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), value) { str = zval_get_tmp_string(value, &tmp_str); if (zend_string_equals(search_str, str)) { zend_tmp_string_release(tmp_str); @@ -5489,7 +5489,7 @@ PHP_FUNCTION(array_diff) break; } zend_tmp_string_release(tmp_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -5522,16 +5522,16 @@ PHP_FUNCTION(array_diff) /* create exclude map */ zend_hash_init(&exclude, num, NULL, NULL, 0); for (i = 1; i < argc; i++) { - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), value) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), value) { str = zval_get_tmp_string(value, &tmp_str); zend_hash_add(&exclude, str, &dummy); zend_tmp_string_release(tmp_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* copy all elements of first array that are not in exclude set */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0]))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), idx, key, value) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(args[0]), idx, key, value) { str = zval_get_tmp_string(value, &tmp_str); if (!zend_hash_exists(&exclude, str)) { if (key) { @@ -5542,7 +5542,7 @@ PHP_FUNCTION(array_diff) zval_add_ref(value); } zend_tmp_string_release(tmp_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&exclude); } @@ -5844,7 +5844,7 @@ PHP_FUNCTION(array_rand) /* If less than 1/2 of elements are used, don't sample. Instead search for a * specific offset using linear scan. */ zend_long i = 0, randval = php_mt_rand_range(0, num_avail - 1); - ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { + ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { if (i == randval) { if (string_key) { RETURN_STR_COPY(string_key); @@ -5853,7 +5853,7 @@ PHP_FUNCTION(array_rand) } } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* Sample random buckets until we hit one that is not empty. @@ -5913,7 +5913,7 @@ PHP_FUNCTION(array_rand) ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { /* We can't use zend_hash_index_find() * because the array may have string keys or gaps. */ - ZEND_ARRAY_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { + ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) { if (zend_bitset_in(bitset, i) ^ negative_bitset) { if (string_key) { ZEND_HASH_FILL_SET_STR_COPY(string_key); @@ -5923,7 +5923,7 @@ PHP_FUNCTION(array_rand) ZEND_HASH_FILL_NEXT(); } i++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); free_alloca(bitset, use_heap); @@ -5943,14 +5943,14 @@ PHP_FUNCTION(array_sum) ZVAL_LONG(return_value, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) { continue; } ZVAL_COPY(&entry_n, entry); convert_scalar_to_number(&entry_n); fast_add_function(return_value, return_value, &entry_n); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -5971,7 +5971,7 @@ PHP_FUNCTION(array_product) return; } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) { continue; } @@ -5988,7 +5988,7 @@ PHP_FUNCTION(array_product) convert_to_double(return_value); convert_to_double(&entry_n); Z_DVAL_P(return_value) *= Z_DVAL(entry_n); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6030,7 +6030,7 @@ PHP_FUNCTION(array_reduce) fci.retval = &retval; fci.param_count = 2; - ZEND_ARRAY_FOREACH_VAL(htbl, operand) { + ZEND_HASH_FOREACH_VAL(htbl, operand) { ZVAL_COPY_VALUE(&args[0], return_value); ZVAL_COPY(&args[1], operand); fci.params = args; @@ -6047,7 +6047,7 @@ PHP_FUNCTION(array_reduce) zval_ptr_dtor(&args[0]); RETURN_NULL(); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6091,7 +6091,7 @@ PHP_FUNCTION(array_filter) } } - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) { if (have_callback) { if (use_type) { /* Set up the key */ @@ -6135,7 +6135,7 @@ PHP_FUNCTION(array_filter) operand = zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, operand); } zval_add_ref(operand); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -6176,7 +6176,7 @@ PHP_FUNCTION(array_map) array_init_size(return_value, maxlen); zend_hash_real_init(Z_ARRVAL_P(return_value), HT_IS_PACKED(Z_ARRVAL(arrays[0]))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { fci.retval = &result; fci.param_count = 1; fci.params = &arg; @@ -6193,7 +6193,7 @@ PHP_FUNCTION(array_map) } else { zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, &result); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { uint32_t *array_pos = (HashPosition *)ecalloc(n_arrays, sizeof(HashPosition)); @@ -6398,7 +6398,7 @@ PHP_FUNCTION(array_chunk) ZVAL_UNDEF(&chunk); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) { /* If new chunk, create and initialize it. */ if (Z_TYPE(chunk) == IS_UNDEF) { array_init_size(&chunk, (uint32_t)size); @@ -6422,7 +6422,7 @@ PHP_FUNCTION(array_chunk) add_next_index_zval(return_value, &chunk); ZVAL_UNDEF(&chunk); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Add the final chunk if there is one. */ if (Z_TYPE(chunk) != IS_UNDEF) { @@ -6457,7 +6457,7 @@ PHP_FUNCTION(array_combine) } array_init_size(return_value, num_keys); - ZEND_ARRAY_FOREACH_VAL(keys, entry_keys) { + ZEND_HASH_FOREACH_VAL(keys, entry_keys) { while (1) { if (pos_values >= values->nNumUsed) { break; @@ -6484,6 +6484,6 @@ PHP_FUNCTION(array_combine) } pos_values++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 06b869e374ac0..911e41842fd40 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1069,14 +1069,14 @@ PHP_FUNCTION(getopt) argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0); /* Iterate over the hash to construct the argv array. */ - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), entry) { zend_string *tmp_arg_str; zend_string *arg_str = zval_get_tmp_string(entry, &tmp_arg_str); argv[pos++] = estrdup(ZSTR_VAL(arg_str)); zend_tmp_string_release(tmp_arg_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* The C Standard requires argv[argc] to be NULL - this might * keep some getopt implementations happy. */ @@ -1103,7 +1103,7 @@ PHP_FUNCTION(getopt) memset(opts, 0, count * sizeof(opt_struct)); /* Iterate over the hash to construct the argv array. */ - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(p_longopts), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(p_longopts), entry) { zend_string *tmp_arg_str; zend_string *arg_str = zval_get_tmp_string(entry, &tmp_arg_str); @@ -1122,7 +1122,7 @@ PHP_FUNCTION(getopt) opts++; zend_tmp_string_release(tmp_arg_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1)); orig_opts = opts; @@ -1383,9 +1383,9 @@ static void add_config_entries(HashTable *hash, zval *return_value) /* {{{ */ zend_string *key; zval *zv; - ZEND_ARRAY_FOREACH_KEY_VAL(hash, h, key, zv) + ZEND_HASH_FOREACH_KEY_VAL(hash, h, key, zv) add_config_entry(h, key, zv, return_value); - ZEND_ARRAY_FOREACH_END(); + ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -2015,7 +2015,7 @@ PHP_FUNCTION(ini_get_all) } array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(ini_directives), key, ini_entry) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(ini_directives), key, ini_entry) { zval option; if (module_number != 0 && ini_entry->module_number != module_number) { diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index f2e0125f1dcec..ab2ae983d76e2 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -727,11 +727,11 @@ PHP_FUNCTION(get_browser) if (found_entry == NULL) { browscap_entry *entry; - ZEND_ARRAY_FOREACH_PTR(bdata->htab, entry) { + ZEND_HASH_FOREACH_PTR(bdata->htab, entry) { if (browser_reg_compare(entry, lookup_browser_name, &found_entry)) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (found_entry == NULL) { found_entry = zend_hash_str_find_ptr(bdata->htab, diff --git a/ext/standard/file.c b/ext/standard/file.c index 916ceaab1f4fb..4c31ee0eae661 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -675,7 +675,7 @@ PHP_FUNCTION(file_put_contents) ssize_t bytes_written; zval *tmp; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(data), tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), tmp) { zend_string *t; zend_string *str = zval_get_tmp_string(tmp, &t); if (ZSTR_LEN(str)) { @@ -689,7 +689,7 @@ PHP_FUNCTION(file_put_contents) } } zend_tmp_string_release(t); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } break; @@ -1902,7 +1902,7 @@ PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, cha ZEND_ASSERT((escape_char >= 0 && escape_char <= UCHAR_MAX) || escape_char == PHP_CSV_NO_ESCAPE); count = zend_hash_num_elements(Z_ARRVAL_P(fields)); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) { zend_string *tmp_field_str; zend_string *field_str = zval_get_tmp_string(field_tmp, &tmp_field_str); @@ -1940,7 +1940,7 @@ PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, cha smart_str_appendl(&csvline, &delimiter, 1); } zend_tmp_string_release(tmp_field_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (eol_str) { smart_str_append(&csvline, eol_str); diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index 98434fb3a114a..b988422df21ca 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -744,10 +744,10 @@ static zval *php_formatted_print_get_array(zend_array *array, int *argc) n = zend_hash_num_elements(array); args = (zval *)safe_emalloc(n, sizeof(zval), 0); n = 0; - ZEND_ARRAY_FOREACH_VAL(array, zv) { + ZEND_HASH_FOREACH_VAL(array, zv) { ZVAL_COPY_VALUE(&args[n], zv); n++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); *argc = n; return args; diff --git a/ext/standard/head.c b/ext/standard/head.c index 2c822262ba7f6..ab64fecf381aa 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -198,7 +198,7 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_ zend_string *key; zval *value; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(options, key, value) { + ZEND_HASH_FOREACH_STR_KEY_VAL(options, key, value) { if (!key) { zend_value_error("%s(): option array cannot have numeric keys", get_active_function_name()); return FAILURE; @@ -219,7 +219,7 @@ static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_ zend_value_error("%s(): option \"%s\" is invalid", get_active_function_name(), ZSTR_VAL(key)); return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } diff --git a/ext/standard/http.c b/ext/standard/http.c index 8f4b8ef452013..e0e95d8d6d529 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -48,7 +48,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } arg_sep_len = strlen(arg_sep); - ZEND_ARRAY_FOREACH_KEY_VAL(ht, idx, key, zdata) { + ZEND_HASH_FOREACH_KEY_VAL(ht, idx, key, zdata) { bool is_dynamic = 1; if (Z_TYPE_P(zdata) == IS_INDIRECT) { zdata = Z_INDIRECT_P(zdata); @@ -215,7 +215,7 @@ PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 0821886ae7e56..b5132d9e005a3 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -256,7 +256,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, if (Z_TYPE_P(tmpzval) == IS_ARRAY) { zval *tmpheader = NULL; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { if (Z_TYPE_P(tmpheader) == IS_STRING) { s = Z_STRVAL_P(tmpheader); do { @@ -280,7 +280,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, while (*s == '\r' || *s == '\n') s++; } while (*s != 0); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else if (Z_TYPE_P(tmpzval) == IS_STRING && Z_STRLEN_P(tmpzval)) { s = Z_STRVAL_P(tmpzval); do { @@ -425,12 +425,12 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, zval *tmpheader = NULL; smart_str tmpstr = {0}; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) { if (Z_TYPE_P(tmpheader) == IS_STRING) { smart_str_append(&tmpstr, Z_STR_P(tmpheader)); smart_str_appendl(&tmpstr, "\r\n", sizeof("\r\n") - 1); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_0(&tmpstr); /* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */ if (tmpstr.s) { diff --git a/ext/standard/info.c b/ext/standard/info.c index cf301a6d3536f..e97faf627a639 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -100,7 +100,7 @@ static ZEND_COLD void php_info_print_stream_hash(const char *name, HashTable *ht } if (!HT_IS_PACKED(ht)) { - ZEND_HASH_FOREACH_STR_KEY(ht, key) { + ZEND_HASH_MAP_FOREACH_STR_KEY(ht, key) { if (key) { if (first) { first = 0; @@ -175,7 +175,7 @@ static ZEND_COLD void php_print_gpcse_array(char *name, uint32_t name_length) zend_is_auto_global(key); if ((data = zend_hash_find_deref(&EG(symbol_table), key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) { - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) { if (!sapi_module.phpinfo_as_text) { php_info_print(""); php_info_print(""); @@ -232,7 +232,7 @@ static ZEND_COLD void php_print_gpcse_array(char *name, uint32_t name_length) } else { php_info_print("\n"); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } zend_string_efree(key); } @@ -928,7 +928,7 @@ PHPAPI ZEND_COLD void php_print_info(int flag) zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&sorted_registry, module) { if (module->info_func || module->version) { php_info_print_module(module); } @@ -937,7 +937,7 @@ PHPAPI ZEND_COLD void php_print_info(int flag) SECTION("Additional Modules"); php_info_print_table_start(); php_info_print_table_header(1, "Module Name"); - ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&sorted_registry, module) { if (!module->info_func && !module->version) { php_info_print_module(module); } diff --git a/ext/standard/mail.c b/ext/standard/mail.c index 8e17065bee8fb..bc5a06bec9cc3 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -131,7 +131,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v zend_string *tmp_key; zval *tmp_val; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), tmp_key, tmp_val) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(val), tmp_key, tmp_val) { if (tmp_key) { zend_type_error("Header \"%s\" must only contain numeric keys, \"%s\" found", ZSTR_VAL(key), ZSTR_VAL(tmp_key)); break; @@ -141,7 +141,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v break; } php_mail_build_headers_elem(s, key, tmp_val); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } @@ -152,7 +152,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers) zval *val; smart_str s = {0}; - ZEND_ARRAY_FOREACH_KEY_VAL(headers, idx, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(headers, idx, key, val) { if (!key) { zend_type_error("Header name cannot be numeric, " ZEND_LONG_FMT " given", idx); break; @@ -188,7 +188,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers) smart_str_free(&s); return NULL; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Remove the last \r\n */ if (s.s) s.s->len -= 2; diff --git a/ext/standard/password.c b/ext/standard/password.c index 651cffc9fe656..98b27ff34bd0c 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -678,7 +678,7 @@ PHP_FUNCTION(password_algos) { ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY(&php_password_algos, algo) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&php_password_algos, algo) { add_next_index_str(return_value, zend_string_copy(algo)); } ZEND_HASH_FOREACH_END(); } diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index f9f4af2f010cd..a57e66bd97954 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -161,7 +161,7 @@ static php_process_env _php_array_to_envp(zval *environment) zend_hash_init(env_hash, cnt, NULL, NULL, 0); /* first, we have to get the size of all the elements in the hash */ - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(environment), key, element) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(environment), key, element) { str = zval_get_string(element); if (ZSTR_LEN(str) == 0) { @@ -177,14 +177,14 @@ static php_process_env _php_array_to_envp(zval *environment) } else { zend_hash_next_index_insert_ptr(env_hash, str); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); #ifndef PHP_WIN32 ep = env.envarray = (char **) ecalloc(cnt + 1, sizeof(char *)); #endif p = env.envp = (char *) ecalloc(sizeenv + 4, 1); - ZEND_ARRAY_FOREACH_STR_KEY_PTR(env_hash, key, str) { + ZEND_HASH_FOREACH_STR_KEY_PTR(env_hash, key, str) { #ifndef PHP_WIN32 *ep = p; ++ep; @@ -200,7 +200,7 @@ static php_process_env _php_array_to_envp(zval *environment) p += ZSTR_LEN(str); *p++ = '\0'; zend_string_release_ex(str, 0); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); assert((uint32_t)(p - env.envp) <= sizeenv); @@ -524,7 +524,7 @@ static zend_string *create_win_command_from_args(HashTable *args) bool is_prog_name = 1; int elem_num = 0; - ZEND_ARRAY_FOREACH_VAL(args, arg_zv) { + ZEND_HASH_FOREACH_VAL(args, arg_zv) { zend_string *arg_str = get_valid_arg_string(arg_zv, ++elem_num); if (!arg_str) { smart_str_free(&str); @@ -539,7 +539,7 @@ static zend_string *create_win_command_from_args(HashTable *args) is_prog_name = 0; zend_string_release(arg_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_0(&str); return str.s; } @@ -620,7 +620,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n *argv = safe_emalloc(sizeof(char *), num_elems + 1, 0); - ZEND_ARRAY_FOREACH_VAL(array, arg_zv) { + ZEND_HASH_FOREACH_VAL(array, arg_zv) { zend_string *arg_str = get_valid_arg_string(arg_zv, i + 1); if (!arg_str) { /* Terminate with NULL so exit_fail code knows how many entries to free */ @@ -637,7 +637,7 @@ static zend_string* get_command_from_array(HashTable *array, char ***argv, int n (*argv)[i++] = estrdup(ZSTR_VAL(arg_str)); zend_string_release(arg_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); (*argv)[i] = NULL; return command; @@ -1088,7 +1088,7 @@ PHP_FUNCTION(proc_open) descriptors = alloc_descriptor_array(descriptorspec); /* Walk the descriptor spec and set up files/pipes */ - ZEND_ARRAY_FOREACH_KEY_VAL(descriptorspec, nindex, str_index, descitem) { + ZEND_HASH_FOREACH_KEY_VAL(descriptorspec, nindex, str_index, descitem) { if (str_index) { zend_argument_value_error(2, "must be an integer indexed array"); goto exit_fail; @@ -1110,7 +1110,7 @@ PHP_FUNCTION(proc_open) goto exit_fail; } ndesc++; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); #ifdef PHP_WIN32 if (cwd == NULL) { diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index b0ee8d531f994..dfbfe032d6d4a 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -571,7 +571,7 @@ PHP_FUNCTION(stream_get_transports) stream_xport_hash = php_stream_xport_get_hash(); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY(stream_xport_hash, stream_xport) { + ZEND_HASH_MAP_FOREACH_STR_KEY(stream_xport_hash, stream_xport) { add_next_index_str(return_value, zend_string_copy(stream_xport)); } ZEND_HASH_FOREACH_END(); } @@ -587,7 +587,7 @@ PHP_FUNCTION(stream_get_wrappers) url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash(); array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY(url_stream_wrappers_hash, stream_protocol) { + ZEND_HASH_MAP_FOREACH_STR_KEY(url_stream_wrappers_hash, stream_protocol) { if (stream_protocol) { add_next_index_str(return_value, zend_string_copy(stream_protocol)); } @@ -607,7 +607,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t return 0; } - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) { /* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast() would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave the higher bits of a SOCKET variable uninitialized on systems with little endian. */ @@ -632,7 +632,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t } cnt++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return cnt ? 1 : 0; } @@ -650,7 +650,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds) } ht = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(stream_array))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { php_socket_t this_fd; ZVAL_DEREF(elem); @@ -676,7 +676,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds) continue; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* destroy old array and add new one */ zval_ptr_dtor(stream_array); @@ -699,7 +699,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) } ht = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(stream_array))); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) { ZVAL_DEREF(elem); php_stream_from_zval_no_verify(stream, elem); if (stream == NULL) { @@ -721,7 +721,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array) ret++; continue; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (ret > 0) { /* destroy old array and add new one */ @@ -891,11 +891,11 @@ static int parse_context_options(php_stream_context *context, HashTable *options zend_string *wkey, *okey; int ret = SUCCESS; - ZEND_ARRAY_FOREACH_STR_KEY_VAL(options, wkey, wval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(options, wkey, wval) { ZVAL_DEREF(wval); if (wkey && Z_TYPE_P(wval) == IS_ARRAY) { if (!HT_IS_PACKED(Z_ARRVAL_P(wval))) { - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) { if (okey) { php_stream_context_set_option(context, ZSTR_VAL(wkey), ZSTR_VAL(okey), oval); } @@ -905,7 +905,7 @@ static int parse_context_options(php_stream_context *context, HashTable *options zend_value_error("Options should have the form [\"wrappername\"][\"optionname\"] = $value"); return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return ret; } diff --git a/ext/standard/string.c b/ext/standard/string.c index a8463bc6bf025..0f29cbb038a73 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1156,14 +1156,14 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return RETURN_EMPTY_STRING(); } else if (numelems == 1) { /* loop to search the first not undefined element... */ - ZEND_ARRAY_FOREACH_VAL(pieces, tmp) { + ZEND_HASH_FOREACH_VAL(pieces, tmp) { RETURN_STR(zval_get_string(tmp)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } ptr = strings = do_alloca((sizeof(*strings)) * numelems, use_heap); - ZEND_ARRAY_FOREACH_VAL(pieces, tmp) { + ZEND_HASH_FOREACH_VAL(pieces, tmp) { if (EXPECTED(Z_TYPE_P(tmp) == IS_STRING)) { ptr->str = Z_STR_P(tmp); len += ZSTR_LEN(ptr->str); @@ -1188,7 +1188,7 @@ PHPAPI void php_implode(const zend_string *glue, HashTable *pieces, zval *return ptr->lval = 1; ptr++; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* numelems cannot be 0, we checked above */ str = zend_string_safe_alloc(numelems - 1, ZSTR_LEN(glue), len, 0); @@ -2404,7 +2404,7 @@ PHP_FUNCTION(substr_replace) from_idx = len_idx = repl_idx = 0; - ZEND_ARRAY_FOREACH_KEY_VAL(str_ht, num_index, str_index, tmp_str) { + ZEND_HASH_FOREACH_KEY_VAL(str_ht, num_index, str_index, tmp_str) { zend_string *tmp_orig_str; zend_string *orig_str = zval_get_tmp_string(tmp_str, &tmp_orig_str); @@ -2556,7 +2556,7 @@ PHP_FUNCTION(substr_replace) } zend_tmp_string_release(tmp_orig_str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* if */ } /* }}} */ @@ -2846,7 +2846,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p memset(bitset, 0, sizeof(bitset)); /* check if original array has numeric keys */ - ZEND_ARRAY_FOREACH_STR_KEY(pats, str_key) { + ZEND_HASH_FOREACH_STR_KEY(pats, str_key) { if (UNEXPECTED(!str_key)) { num_keys = 1; } else { @@ -2868,13 +2868,13 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p num_bitset[len / sizeof(zend_ulong)] |= Z_UL(1) << (len % sizeof(zend_ulong)); bitset[((unsigned char)ZSTR_VAL(str_key)[0]) / sizeof(zend_ulong)] |= Z_UL(1) << (((unsigned char)ZSTR_VAL(str_key)[0]) % sizeof(zend_ulong)); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (UNEXPECTED(num_keys)) { zend_string *key_used; /* we have to rebuild HashTable with numeric keys */ zend_hash_init(&str_hash, zend_hash_num_elements(pats), NULL, NULL, 0); - ZEND_ARRAY_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, str_key, entry) { if (UNEXPECTED(!str_key)) { key_used = zend_long_to_str(num_key); len = ZSTR_LEN(key_used); @@ -2904,7 +2904,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p if (UNEXPECTED(!str_key)) { zend_string_release_ex(key_used, 0); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); pats = &str_hash; } @@ -3307,7 +3307,7 @@ PHP_FUNCTION(strtr) zend_string *str_key, *tmp_str, *replace, *tmp_replace; zval *entry; - ZEND_ARRAY_FOREACH_KEY_VAL(from_ht, num_key, str_key, entry) { + ZEND_HASH_FOREACH_KEY_VAL(from_ht, num_key, str_key, entry) { tmp_str = NULL; if (UNEXPECTED(!str_key)) { str_key = tmp_str = zend_long_to_str(num_key); @@ -3332,7 +3332,7 @@ PHP_FUNCTION(strtr) zend_tmp_string_release(tmp_str); zend_tmp_string_release(tmp_replace); return; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { php_strtr_array(return_value, str, from_ht); } @@ -4187,7 +4187,7 @@ static zend_long php_str_replace_in_subject( } /* For each entry in the search array, get the entry */ - ZEND_ARRAY_FOREACH_VAL(search_ht, search_entry) { + ZEND_HASH_FOREACH_VAL(search_ht, search_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_search_str; zend_string *search_str = zval_get_tmp_string(search_entry, &tmp_search_str); @@ -4284,7 +4284,7 @@ static zend_long php_str_replace_in_subject( return replace_count; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ZVAL_STR(result, subject_str); if (lc_subject_str) { zend_string_release_ex(lc_subject_str, 0); @@ -4355,7 +4355,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit /* For each subject entry, convert it to string, then perform replacement and add the result to the return_value array. */ - ZEND_ARRAY_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { + ZEND_HASH_FOREACH_KEY_VAL(subject_ht, num_key, string_key, subject_entry) { zend_string *tmp_subject_str; ZVAL_DEREF(subject_entry); subject_str = zval_get_tmp_string(subject_entry, &tmp_subject_str); @@ -4368,7 +4368,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit } else { zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, &result); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { /* if subject is not an array */ count = php_str_replace_in_subject(search_str, search_ht, replace_str, replace_ht, subject_str, return_value, case_sensitivity); } @@ -4660,13 +4660,13 @@ PHP_FUNCTION(strip_tags) zval *tmp; zend_string *tag; - ZEND_ARRAY_FOREACH_VAL(allow_ht, tmp) { + ZEND_HASH_FOREACH_VAL(allow_ht, tmp) { tag = zval_get_string(tmp); smart_str_appendc(&tags_ss, '<'); smart_str_append(&tags_ss, tag); smart_str_appendc(&tags_ss, '>'); zend_string_release(tag); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (tags_ss.s) { smart_str_0(&tags_ss); allowed_tags = ZSTR_VAL(tags_ss.s); @@ -4776,7 +4776,7 @@ PHP_FUNCTION(setlocale) for (uint32_t i = 0; i < num_args; i++) { if (Z_TYPE(args[i]) == IS_ARRAY) { zval *elem; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL(args[i]), elem) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), elem) { zend_string *result = try_setlocale_zval(cat, elem); if (EG(exception)) { RETURN_THROWS(); @@ -4784,7 +4784,7 @@ PHP_FUNCTION(setlocale) if (result) { RETURN_STR(result); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { zend_string *result = try_setlocale_zval(cat, &args[i]); if (EG(exception)) { diff --git a/ext/standard/url.c b/ext/standard/url.c index c61c60eabcc22..e3d95768fb019 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -707,7 +707,7 @@ PHP_FUNCTION(get_headers) array_init(return_value); - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(&stream->wrapperdata), hdr) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&stream->wrapperdata), hdr) { if (Z_TYPE_P(hdr) != IS_STRING) { continue; } @@ -738,7 +738,7 @@ PHP_FUNCTION(get_headers) goto no_name_header; } } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); php_stream_close(stream); } diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index f98e9067f409c..dcbfc381d295f 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -498,7 +498,7 @@ PHP_FUNCTION(stream_get_filters) filters_hash = php_get_stream_filters_hash(); if (filters_hash && !HT_IS_PACKED(filters_hash)) { - ZEND_HASH_FOREACH_STR_KEY(filters_hash, filter_name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(filters_hash, filter_name) { if (filter_name) { add_next_index_str(return_value, zend_string_copy(filter_name)); } diff --git a/ext/standard/var.c b/ext/standard/var.c index 655196065aed4..ef4b019fb6e76 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -134,9 +134,9 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ } count = zend_hash_num_elements(myht); php_printf("%sarray(%d) {\n", COMMON, count); - ZEND_ARRAY_FOREACH_KEY_VAL(myht, num, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { php_array_element_dump(val, num, key, level); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -170,7 +170,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ zend_string *key; zval *val; - ZEND_ARRAY_FOREACH_KEY_VAL(myht, num, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { zend_property_info *prop_info = NULL; if (Z_TYPE_P(val) == IS_INDIRECT) { @@ -183,7 +183,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ if (!Z_ISUNDEF_P(val) || prop_info) { php_object_property_dump(prop_info, val, num, key, level); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_release_properties(myht); } if (level > 1) { @@ -330,9 +330,9 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ } else { php_printf("array(%d) interned {\n", count); } - ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { zval_array_element_dump(val, index, key, level); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -356,7 +356,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ php_printf("object(%s)#%d (%d) refcount(%u){\n", ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0, Z_REFCOUNT_P(struc)); zend_string_release_ex(class_name, 0); if (myht) { - ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { zend_property_info *prop_info = NULL; if (Z_TYPE_P(val) == IS_INDIRECT) { @@ -369,7 +369,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */ if (!Z_ISUNDEF_P(val) || prop_info) { zval_object_property_dump(prop_info, val, index, key, level); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_UNPROTECT_RECURSION(myht); zend_release_properties(myht); } @@ -537,9 +537,9 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */ buffer_append_spaces(buf, level - 1); } smart_str_appendl(buf, "array (\n", 8); - ZEND_ARRAY_FOREACH_KEY_VAL(myht, index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) { php_array_element_export(val, index, key, level, buf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) { GC_UNPROTECT_RECURSION(myht); GC_DELREF(myht); @@ -588,9 +588,9 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf) /* {{{ */ if (myht) { if (!is_enum) { - ZEND_ARRAY_FOREACH_KEY_VAL_IND(myht, index, key, val) { + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) { php_object_element_export(val, index, key, level, buf); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } GC_TRY_UNPROTECT_RECURSION(myht); zend_release_properties(myht); @@ -856,7 +856,7 @@ static int php_var_serialize_get_sleep_props( zend_hash_init(ht, zend_hash_num_elements(sleep_retval), NULL, ZVAL_PTR_DTOR, 0); /* TODO: Rewrite this by fetching the property info instead of trying out different * name manglings? */ - ZEND_ARRAY_FOREACH_VAL_IND(sleep_retval, name_val) { + ZEND_HASH_FOREACH_VAL_IND(sleep_retval, name_val) { zend_string *name, *tmp_name, *priv_name, *prot_name; ZVAL_DEREF(name_val); @@ -912,7 +912,7 @@ static int php_var_serialize_get_sleep_props( php_error_docref(NULL, E_WARNING, "\"%s\" returned as member variable from __sleep() but does not exist", ZSTR_VAL(name)); zend_tmp_string_release(tmp_name); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_release_properties(props); return retval; @@ -928,7 +928,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable zval *data; zend_ulong index; - ZEND_ARRAY_FOREACH_KEY_VAL_IND(ht, index, key, data) { + ZEND_HASH_FOREACH_KEY_VAL_IND(ht, index, key, data) { if (incomplete_class && zend_string_equals_literal(key, MAGIC_MEMBER)) { incomplete_class = 0; continue; @@ -963,7 +963,7 @@ static void php_var_serialize_nested_data(smart_str *buf, zval *struc, HashTable } else { php_var_serialize_intern(buf, data, var_hash); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } smart_str_appendc(buf, '}'); } @@ -1090,7 +1090,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ php_var_serialize_class_name(buf, &obj); smart_str_append_unsigned(buf, zend_hash_num_elements(Z_ARRVAL(retval))); smart_str_appendl(buf, ":{", 2); - ZEND_ARRAY_FOREACH_KEY_VAL(Z_ARRVAL(retval), index, key, data) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(retval), index, key, data) { if (!key) { php_var_serialize_long(buf, index); } else { @@ -1101,7 +1101,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_ data = Z_REFVAL_P(data); } php_var_serialize_intern(buf, data, var_hash); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); smart_str_appendc(buf, '}'); zval_ptr_dtor(&obj); @@ -1357,12 +1357,12 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co zval *entry; zend_string *lcname; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(classes), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(classes), entry) { convert_to_string(entry); lcname = zend_string_tolower(Z_STR_P(entry)); zend_hash_add_empty_element(class_hash, lcname); zend_string_release_ex(lcname, 0); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); /* Exception during string conversion. */ if (EG(exception)) { diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 4de56b13d2923..4ed51ab3127fe 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -775,7 +775,7 @@ static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options) zend_string *opt_name; if (!HT_IS_PACKED(ht_options)) { - ZEND_HASH_FOREACH_STR_KEY_VAL(ht_options, opt_name, opt_val) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht_options, opt_name, opt_val) { if (opt_name == NULL) { continue; } diff --git a/ext/tokenizer/tokenizer.c b/ext/tokenizer/tokenizer.c index aa762e07b6871..f3af90cdd0e84 100644 --- a/ext/tokenizer/tokenizer.c +++ b/ext/tokenizer/tokenizer.c @@ -168,7 +168,7 @@ PHP_METHOD(PhpToken, is) } else if (Z_TYPE_P(kind) == IS_ARRAY) { zval *id_zval = NULL, *entry; zend_string *text = NULL; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(kind), entry) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(kind), entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if (!id_zval) { @@ -194,7 +194,7 @@ PHP_METHOD(PhpToken, is) zend_argument_type_error(1, "must only have elements of type string|int, %s given", zend_zval_type_name(entry)); RETURN_THROWS(); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); RETURN_FALSE; } else { zend_argument_type_error(1, "must be of type string|int|array, %s given", zend_zval_type_name(kind)); @@ -435,12 +435,12 @@ void on_event( case ON_FEEDBACK: { HashTable *tokens_ht = Z_ARRVAL_P(ctx->tokens); zval *token_zv, *id_zv = NULL; - ZEND_ARRAY_REVERSE_FOREACH_VAL(tokens_ht, token_zv) { + ZEND_HASH_REVERSE_FOREACH_VAL(tokens_ht, token_zv) { id_zv = extract_token_id_to_replace(token_zv, text, length); if (id_zv) { break; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); ZEND_ASSERT(id_zv); ZVAL_LONG(id_zv, token); break; diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 62c1d7ba7a63a..5c73837c385a1 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -814,7 +814,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) zval tag; zval *curtag, *mytype, *myval; - ZEND_ARRAY_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) { + ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) { if ((mytype = zend_hash_str_find(Z_ARRVAL_P(curtag),"type", sizeof("type") - 1))) { if (zend_string_equals_literal(Z_STR_P(mytype), "cdata")) { if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) { @@ -828,7 +828,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) } } break; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (parser->level <= XML_MAXLEVEL && parser->level > 0 && (doprint || (! parser->skipwhite))) { array_init(&tag); diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index acc1724e36b9a..c62c0a13ceaec 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -65,7 +65,7 @@ static char **php_xsl_xslt_make_params(HashTable *parht, int xpath_params) params = (char **)safe_emalloc((2 * zend_hash_num_elements(parht) + 1), sizeof(char *), 0); memset((char *)params, 0, parsize); - ZEND_HASH_FOREACH_STR_KEY_VAL(parht, string_key, value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(parht, string_key, value) { ZEND_ASSERT(string_key != NULL); if (Z_TYPE_P(value) != IS_STRING) { if (!try_convert_to_string(value)) { @@ -681,7 +681,7 @@ PHP_METHOD(XSLTProcessor, setParameter) RETURN_THROWS(); } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(array_value, string_key, entry) { + ZEND_HASH_FOREACH_STR_KEY_VAL(array_value, string_key, entry) { zval tmp; zend_string *str; @@ -695,7 +695,7 @@ PHP_METHOD(XSLTProcessor, setParameter) } ZVAL_STR(&tmp, str); zend_hash_update(intern->parameter, string_key, &tmp); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); RETURN_TRUE; } else { if (!value) { @@ -771,7 +771,7 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) intern = Z_XSL_P(id); if (restrict_ht) { - ZEND_ARRAY_FOREACH_VAL(restrict_ht, entry) { + ZEND_HASH_FOREACH_VAL(restrict_ht, entry) { zend_string *str = zval_try_get_string(entry); if (UNEXPECTED(!str)) { return; @@ -779,7 +779,7 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) ZVAL_LONG(&new_string, 1); zend_hash_update(intern->registered_phpfunctions, str, &new_string); zend_string_release(str); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); intern->registerPhpFunctions = 2; } else if (restrict_str) { diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 3ebb795604e57..d0de996d99777 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -510,9 +510,9 @@ PHP_RINIT_FUNCTION(zend_test) PHP_RSHUTDOWN_FUNCTION(zend_test) { zend_ulong objptr; - ZEND_ARRAY_FOREACH_NUM_KEY(&ZT_G(global_weakmap), objptr) { + ZEND_HASH_FOREACH_NUM_KEY(&ZT_G(global_weakmap), objptr) { zend_weakrefs_hash_del(&ZT_G(global_weakmap), (zend_object *)(uintptr_t)objptr); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&ZT_G(global_weakmap)); return SUCCESS; } diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index ca040b52e2b36..e54c497624794 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -993,7 +993,7 @@ static HashTable *php_zip_get_properties(zend_object *object)/* {{{ */ return NULL; } - ZEND_HASH_FOREACH_STR_KEY_PTR(obj->prop_handler, key, hnd) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(obj->prop_handler, key, hnd) { zval *ret, val; ret = php_zip_property_reader(obj, hnd, &val); if (ret == NULL) { diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 81445e85cbddc..81a23c48c8444 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -810,7 +810,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_ zend_string **strings = emalloc(sizeof(zend_string *) * zend_hash_num_elements(dictionary)); zend_string **end, **ptr = strings - 1; - ZEND_ARRAY_FOREACH_VAL(dictionary, cur) { + ZEND_HASH_FOREACH_VAL(dictionary, cur) { size_t i; *++ptr = zval_get_string(cur); @@ -839,7 +839,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_ } *dictlen += ZSTR_LEN(*ptr) + 1; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); dictptr = *dict = emalloc(*dictlen); ptr = strings; diff --git a/main/output.c b/main/output.c index 0044750873e8d..3efc0294f85b8 100644 --- a/main/output.c +++ b/main/output.c @@ -560,11 +560,11 @@ PHPAPI int php_output_handler_start(php_output_handler *handler) } } if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { - ZEND_ARRAY_FOREACH_PTR(rconflicts, conflict) { + ZEND_HASH_FOREACH_PTR(rconflicts, conflict) { if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) { return FAILURE; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* zend_stack_push returns stack level */ handler->level = zend_stack_push(&OG(handlers), &handler); diff --git a/main/php_ini.c b/main/php_ini.c index fd6f366488212..c41da5b432c38 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -125,7 +125,7 @@ PHPAPI ZEND_COLD void display_ini_entries(zend_module_entry *module) module_number = 0; } - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), ini_entry) { if (ini_entry->module_number != module_number) { continue; } @@ -812,7 +812,7 @@ PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int zval *data; /* Walk through config hash and alter matching ini entries using the values found in the hash */ - ZEND_HASH_FOREACH_STR_KEY_VAL(source_hash, str, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(source_hash, str, data) { zend_string *data_str = zend_string_dup(Z_STR_P(data), 0); zend_alter_ini_entry_ex(str, data_str, modify_type, stage, 0); zend_string_release(data_str); diff --git a/main/php_variables.c b/main/php_variables.c index 82b28d9e05379..127196779f221 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -691,7 +691,7 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) zend_ulong num_key; int globals_check = (dest == (&EG(symbol_table))); - ZEND_ARRAY_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { + ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { if (Z_TYPE_P(src_entry) != IS_ARRAY || (string_key && (dest_entry = zend_hash_find(dest, string_key)) == NULL) || (string_key == NULL && (dest_entry = zend_hash_index_find(dest, num_key)) == NULL) @@ -711,7 +711,7 @@ static void php_autoglobal_merge(HashTable *dest, HashTable *src) SEPARATE_ARRAY(dest_entry); php_autoglobal_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry)); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ diff --git a/main/rfc1867.c b/main/rfc1867.c index aaafbd4c5fc9d..a242e04bf3f11 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -191,7 +191,7 @@ PHPAPI void destroy_uploaded_files_hash(void) /* {{{ */ { zval *el; - ZEND_HASH_FOREACH_VAL(SG(rfc1867_uploaded_files), el) { + ZEND_HASH_MAP_FOREACH_VAL(SG(rfc1867_uploaded_files), el) { zend_string *filename = Z_STR_P(el); VCWD_UNLINK(ZSTR_VAL(filename)); } ZEND_HASH_FOREACH_END(); diff --git a/main/streams/streams.c b/main/streams/streams.c index c06f1b7ed1a13..883a31c5a6fa6 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -91,9 +91,9 @@ PHP_RSHUTDOWN_FUNCTION(streams) { zval *el; - ZEND_ARRAY_FOREACH_VAL(&EG(persistent_list), el) { + ZEND_HASH_FOREACH_VAL(&EG(persistent_list), el) { forget_persistent_resource_id_numbers(el); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return SUCCESS; } @@ -119,13 +119,13 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * * regular list; allowing the same resource in several entries in the * regular list causes trouble (see bug #54623) */ *stream = (php_stream*)le->ptr; - ZEND_ARRAY_FOREACH_PTR(&EG(regular_list), regentry) { + ZEND_HASH_FOREACH_PTR(&EG(regular_list), regentry) { if (regentry->ptr == le->ptr) { GC_ADDREF(regentry); (*stream)->res = regentry; return PHP_STREAM_PERSISTENT_SUCCESS; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); GC_ADDREF(le); (*stream)->res = zend_register_resource(*stream, le_pstream); } diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c index 4ce90c0a1ba4c..e051964a81591 100644 --- a/sapi/apache2handler/apache_config.c +++ b/sapi/apache2handler/apache_config.c @@ -157,7 +157,7 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) n = create_php_config(p, "merge_php_config"); /* copy old config */ #ifdef ZTS - ZEND_HASH_FOREACH_STR_KEY_VAL(&d->config, str, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(&d->config, str, data) { zend_string *key; zval *new_entry; @@ -195,7 +195,7 @@ void apply_config(void *dummy) zend_string *str; php_dir_entry *data; - ZEND_HASH_FOREACH_STR_KEY_PTR(&d->config, str, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&d->config, str, data) { phpapdebug((stderr, "APPLYING (%s)(%s)\n", ZSTR_VAL(str), data->value)); if (zend_alter_ini_entry_chars(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { phpapdebug((stderr, "..FAILED\n")); diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 178b6f3de479a..7933e6accea38 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -562,7 +562,7 @@ typedef struct { zend_string *str; php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php_module); - ZEND_HASH_FOREACH_STR_KEY(&c->config, str) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&c->config, str) { zend_restore_ini_entry(str, ZEND_INI_STAGE_SHUTDOWN); } ZEND_HASH_FOREACH_END(); } diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 499a7932bed17..75511ef3bd701 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -254,7 +254,7 @@ static void print_modules(void) zend_hash_init(&sorted_registry, 64, NULL, NULL, 1); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&sorted_registry, module) { php_printf("%s\n", module->name); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 0ad53e813c944..fdd604cec53b0 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -193,7 +193,7 @@ static void print_modules(void) /* {{{ */ zend_hash_init(&sorted_registry, 50, NULL, NULL, 0); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&sorted_registry, module) { php_printf("%s\n", module->name); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 02e0c52088374..55df8b9edac1f 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -398,7 +398,7 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ array_init_size(return_value, zend_hash_num_elements(headers)); - ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, value) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(headers, key, value) { ZVAL_STRING(&tmp, value); zend_symtable_update(Z_ARRVAL_P(return_value), key, &tmp); } ZEND_HASH_FOREACH_END(); diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index a8d7f73406e11..657ff72b673a1 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -200,7 +200,7 @@ static void print_modules(void) /* {{{ */ zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); zend_hash_copy(&sorted_registry, &module_registry, NULL); zend_hash_sort(&sorted_registry, module_name_cmp, 0); - ZEND_HASH_FOREACH_PTR(&sorted_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&sorted_registry, module) { php_printf("%s\n", module->name); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&sorted_registry); diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index fbe3873e04189..96648f44372db 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -278,11 +278,11 @@ char* fpm_php_get_string_from_table(zend_string *table, char *key) /* {{{ */ return NULL; } - ZEND_ARRAY_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) { if (str && !strncmp(ZSTR_VAL(str), key, ZSTR_LEN(str))) { return Z_STRVAL_P(tmp); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return NULL; } diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 2cd1cae554a0e..42a2a9c036432 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -526,9 +526,9 @@ PHP_FUNCTION(phpdbg_get_executable) files = &files_tmp; zend_hash_init(files, 0, NULL, NULL, 0); - ZEND_ARRAY_FOREACH_VAL(Z_ARR_P(option_buffer), filename) { + ZEND_HASH_FOREACH_VAL(Z_ARR_P(option_buffer), filename) { zend_hash_add_empty_element(files, zval_get_string(filename)); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } else { GC_ADDREF(files); } @@ -538,7 +538,7 @@ PHP_FUNCTION(phpdbg_get_executable) array_init(return_value); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), name, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(function_table), name, func) { if (func->type == ZEND_USER_FUNCTION) { if (zend_hash_exists(files, func->op_array.filename)) { insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), func->op_array.filename); @@ -552,10 +552,10 @@ PHP_FUNCTION(phpdbg_get_executable) } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), name, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), name, ce) { if (ce->type == ZEND_USER_CLASS) { if (zend_hash_exists(files, ce->info.user.filename)) { - ZEND_HASH_FOREACH_PTR(&ce->function_table, func) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, func) { if (func->type == ZEND_USER_FUNCTION && zend_hash_exists(files, func->op_array.filename)) { insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), func->op_array.filename); @@ -572,7 +572,7 @@ PHP_FUNCTION(phpdbg_get_executable) } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY(files, name) { + ZEND_HASH_MAP_FOREACH_STR_KEY(files, name) { phpdbg_file_source *source = zend_hash_find_ptr(&PHPDBG_G(file_sources), name); if (source) { phpdbg_oplog_fill_executable( diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c index 098b0ce65ab6d..a79efef4161bd 100644 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@ -97,13 +97,13 @@ PHPDBG_API void phpdbg_reset_breakpoints(void) /* {{{ */ { HashTable *table; - ZEND_ARRAY_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) { + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) { phpdbg_breakbase_t *brake; - ZEND_ARRAY_FOREACH_PTR(table, brake) { + ZEND_HASH_FOREACH_PTR(table, brake) { brake->hits = 0; - } ZEND_ARRAY_FOREACH_END(); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } /* }}} */ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle) /* {{{ */ @@ -125,10 +125,10 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ phpdbg_notice("Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])); /* this only looks like magic, it isn't */ - ZEND_ARRAY_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) { + ZEND_HASH_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) { phpdbg_breakbase_t *brake; - ZEND_ARRAY_FOREACH_PTR(table, brake) { + ZEND_HASH_FOREACH_PTR(table, brake) { if (brake->id == id) { char *new_str = NULL; @@ -244,8 +244,8 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ } *str = new_str; } - } ZEND_ARRAY_FOREACH_END(); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } if ((*str) && !(*str)[0]) { @@ -312,7 +312,7 @@ PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, size_t path_len, ze if (pending) { zend_string *file; - ZEND_HASH_FOREACH_STR_KEY(&PHPDBG_G(file_sources), file) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&PHPDBG_G(file_sources), file) { HashTable *fileht; phpdbg_debug("Compare against loaded %s\n", file); @@ -362,7 +362,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin master = zend_hash_str_add_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable)); } - ZEND_ARRAY_FOREACH_PTR(fileht, brake) { + ZEND_HASH_FOREACH_PTR(fileht, brake) { new_brake = *brake; new_brake.filename = estrndup(file, filelen); PHPDBG_BREAK_UNMAPPING(brake->id); @@ -370,7 +370,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin if (zend_hash_index_add_mem(master, brake->line, &new_brake, sizeof(phpdbg_breakfile_t))) { PHPDBG_BREAK_MAPPING(brake->id, master); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur); @@ -394,7 +394,7 @@ PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file) /* {{{ */ phpdbg_debug("was compiled: %s\n", file); - ZEND_HASH_FOREACH_STR_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, fileht) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, fileht) { phpdbg_debug("check bp: %s\n", cur); phpdbg_resolve_pending_file_break_ex(file, filelen, cur, fileht); @@ -551,7 +551,7 @@ PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array) /* {{{ * return; } - ZEND_HASH_FOREACH_PTR(oplines_table, brake) { + ZEND_HASH_MAP_FOREACH_PTR(oplines_table, brake) { if (phpdbg_resolve_op_array_break(brake, op_array) == SUCCESS) { phpdbg_breakline_t *opline_break; @@ -1095,7 +1095,7 @@ static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execut phpdbg_breakcond_t *bp; int breakpoint = FAILURE; - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], bp) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], bp) { zval retval; const zend_op *orig_opline = EG(current_execute_data)->opline; zend_function *orig_func = EG(current_execute_data)->func; @@ -1431,11 +1431,11 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable if ((*table = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id))) { phpdbg_breakbase_t *brake; - ZEND_ARRAY_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) { + ZEND_HASH_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) { if (brake->id == id) { return brake; } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } return NULL; @@ -1449,7 +1449,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Function Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], brake) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], brake) { phpdbg_writeln("#%d\t\t%s%s", brake->id, brake->symbol, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1461,10 +1461,10 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Method Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_table) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_table) { phpdbg_breakmethod_t *brake; - ZEND_HASH_FOREACH_PTR(class_table, brake) { + ZEND_HASH_MAP_FOREACH_PTR(class_table, brake) { phpdbg_writeln("#%d\t\t%s::%s%s", brake->id, brake->class_name, brake->func_name, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1477,10 +1477,10 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("File Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], points) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], points) { phpdbg_breakfile_t *brake; - ZEND_HASH_FOREACH_PTR(points, brake) { + ZEND_HASH_MAP_FOREACH_PTR(points, brake) { phpdbg_writeln("#%d\t\t%s:"ZEND_ULONG_FMT"%s", brake->id, brake->filename, brake->line, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1491,10 +1491,10 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Pending File Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], points) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], points) { phpdbg_breakfile_t *brake; - ZEND_HASH_FOREACH_PTR(points, brake) { + ZEND_HASH_MAP_FOREACH_PTR(points, brake) { phpdbg_writeln("#%d\t\t%s:"ZEND_ULONG_FMT"%s", brake->id, brake->filename, brake->line, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1507,7 +1507,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Opline Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], brake) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], brake) { const char *type; switch (brake->type) { case PHPDBG_BREAK_METHOD_OPLINE: @@ -1547,11 +1547,11 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Method opline Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], class_table) { - ZEND_HASH_FOREACH_PTR(class_table, method_table) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], class_table) { + ZEND_HASH_MAP_FOREACH_PTR(class_table, method_table) { phpdbg_breakopline_t *brake; - ZEND_HASH_FOREACH_PTR(method_table, brake) { + ZEND_HASH_MAP_FOREACH_PTR(method_table, brake) { phpdbg_writeln("#%d\t\t%s::%s opline "ZEND_ULONG_FMT"%s", brake->id, brake->class_name, brake->func_name, brake->opline_num, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1565,10 +1565,10 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Function opline Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], function_table) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], function_table) { phpdbg_breakopline_t *brake; - ZEND_HASH_FOREACH_PTR(function_table, brake) { + ZEND_HASH_MAP_FOREACH_PTR(function_table, brake) { phpdbg_writeln("#%d\t\t%s opline "ZEND_ULONG_FMT"%s", brake->id, brake->func_name, brake->opline_num, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1581,10 +1581,10 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("File opline Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], file_table) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], file_table) { phpdbg_breakopline_t *brake; - ZEND_HASH_FOREACH_PTR(file_table, brake) { + ZEND_HASH_MAP_FOREACH_PTR(file_table, brake) { phpdbg_writeln("#%d\t\t%s opline "ZEND_ULONG_FMT"%s", brake->id, brake->class_name, brake->opline_num, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); @@ -1597,7 +1597,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Conditional Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], brake) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], brake) { if (brake->paramed) { switch (brake->param.type) { case STR_PARAM: @@ -1653,7 +1653,7 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */ phpdbg_out(SEPARATE "\n"); phpdbg_out("Opcode Breakpoints:\n"); - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], brake) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], brake) { phpdbg_writeln("#%d\t\t%s%s", brake->id, brake->name, ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : ""); diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index f5a2cd2220631..644668d8d14e5 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -205,7 +205,7 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ m = func ? func->common.num_args : 0; - ZEND_ARRAY_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) { if (j) { phpdbg_out(", "); } @@ -234,7 +234,7 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ php_printf("%s", arg_print); efree(arg_print); } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (is_variadic) { phpdbg_out("]"); diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index c526d0e68e305..0a1e7570a493c 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -69,7 +69,7 @@ PHPDBG_INFO(files) /* {{{ */ } phpdbg_end_try_access(); phpdbg_try_access { - ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), fname) { + ZEND_HASH_MAP_FOREACH_STR_KEY(&EG(included_files), fname) { phpdbg_writeln("File: %s", ZSTR_VAL(fname)); } ZEND_HASH_FOREACH_END(); } phpdbg_catch_access { @@ -105,7 +105,7 @@ PHPDBG_INFO(constants) /* {{{ */ if (EG(zend_constants)) { phpdbg_try_access { - ZEND_HASH_FOREACH_PTR(EG(zend_constants), data) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), data) { if (ZEND_CONSTANT_MODULE_NUMBER(data) == PHP_USER_CONSTANT) { zend_hash_update_ptr(&consts, data->name, data); } @@ -119,7 +119,7 @@ PHPDBG_INFO(constants) /* {{{ */ if (zend_hash_num_elements(&consts)) { phpdbg_out("Address Refs Type Constant\n"); - ZEND_HASH_FOREACH_PTR(&consts, data) { + ZEND_HASH_MAP_FOREACH_PTR(&consts, data) { #define VARIABLEINFO(msg, ...) \ phpdbg_writeln( \ @@ -196,7 +196,7 @@ static int phpdbg_print_symbols(bool show_globals) { zend_hash_init(&vars, 8, NULL, NULL, 0); phpdbg_try_access { - ZEND_HASH_FOREACH_STR_KEY_VAL(symtable, var, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(symtable, var, data) { if (zend_is_auto_global(var) ^ !show_globals) { zend_hash_update(&vars, var, data); } @@ -227,7 +227,7 @@ static int phpdbg_print_symbols(bool show_globals) { if (zend_hash_num_elements(&vars)) { phpdbg_out("Address Refs Type Variable\n"); - ZEND_HASH_FOREACH_STR_KEY_VAL(&vars, var, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(&vars, var, data) { phpdbg_try_access { const char *isref = ""; #define VARIABLEINFO(msg, ...) \ @@ -387,7 +387,7 @@ PHPDBG_INFO(classes) /* {{{ */ zend_hash_init(&classes, 8, NULL, NULL, 0); phpdbg_try_access { - ZEND_HASH_FOREACH_PTR(EG(class_table), ce) { + ZEND_HASH_MAP_FOREACH_PTR(EG(class_table), ce) { if (ce->type == ZEND_USER_CLASS) { zend_hash_next_index_insert_ptr(&classes, ce); } @@ -399,7 +399,7 @@ PHPDBG_INFO(classes) /* {{{ */ phpdbg_notice("User Classes (%d)", zend_hash_num_elements(&classes)); /* once added, assume that classes are stable... until shutdown. */ - ZEND_PACKED_FOREACH_PTR(&classes, ce) { + ZEND_HASH_PACKED_FOREACH_PTR(&classes, ce) { phpdbg_print_class_name(ce); if (ce->parent) { @@ -416,7 +416,7 @@ PHPDBG_INFO(classes) /* {{{ */ } else { phpdbg_writeln("|---- no source code"); } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&classes); @@ -431,7 +431,7 @@ PHPDBG_INFO(funcs) /* {{{ */ zend_hash_init(&functions, 8, NULL, NULL, 0); phpdbg_try_access { - ZEND_HASH_FOREACH_PTR(EG(function_table), zf) { + ZEND_HASH_MAP_FOREACH_PTR(EG(function_table), zf) { if (zf->type == ZEND_USER_FUNCTION) { zend_hash_next_index_insert_ptr(&functions, zf); } @@ -442,7 +442,7 @@ PHPDBG_INFO(funcs) /* {{{ */ phpdbg_notice("User Functions (%d)", zend_hash_num_elements(&functions)); - ZEND_PACKED_FOREACH_PTR(&functions, zf) { + ZEND_HASH_PACKED_FOREACH_PTR(&functions, zf) { zend_op_array *op_array = &zf->op_array; phpdbg_write("|-------- %s", op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}"); @@ -452,7 +452,7 @@ PHPDBG_INFO(funcs) /* {{{ */ } else { phpdbg_writeln(" (no source code)"); } - } ZEND_PACKED_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&functions); diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 67d68b9da3588..c28576de3bc9c 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -140,7 +140,7 @@ PHPDBG_PRINT(class) /* {{{ */ if (zend_hash_num_elements(&ce->function_table)) { zend_function *method; - ZEND_HASH_FOREACH_PTR(&ce->function_table, method) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, method) { phpdbg_print_function_helper(method); } ZEND_HASH_FOREACH_END(); } @@ -291,7 +291,7 @@ static void phpdbg_print_opcodes_ce(zend_class_entry *ce) { } phpdbg_out("%d methods: ", zend_hash_num_elements(&ce->function_table)); - ZEND_HASH_FOREACH_PTR(&ce->function_table, method) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, method) { if (first) { first = 0; } else { @@ -304,7 +304,7 @@ static void phpdbg_print_opcodes_ce(zend_class_entry *ce) { } phpdbg_out("\n"); - ZEND_HASH_FOREACH_PTR(&ce->function_table, method) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, method) { phpdbg_print_function_helper(method); } ZEND_HASH_FOREACH_END(); } @@ -332,13 +332,13 @@ void phpdbg_print_opcodes(const char *function) phpdbg_print_opcodes_main(); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), name, func) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(function_table), name, func) { if (func->type == ZEND_USER_FUNCTION) { phpdbg_print_opcodes_function(ZSTR_VAL(name), ZSTR_LEN(name)); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_PTR(EG(class_table), ce) { + ZEND_HASH_MAP_FOREACH_PTR(EG(class_table), ce) { if (ce->type == ZEND_USER_CLASS) { phpdbg_out("\n"); phpdbg_print_opcodes_ce(ce); diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c index 4304a5cc4d671..344b9c73e476d 100644 --- a/sapi/phpdbg/phpdbg_utils.c +++ b/sapi/phpdbg/phpdbg_utils.c @@ -487,7 +487,7 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable if (new_index && index_len == 0) { zend_ulong numkey; zend_string *strkey; - ZEND_ARRAY_FOREACH_KEY_VAL_IND(parent, numkey, strkey, zv) { + ZEND_HASH_FOREACH_KEY_VAL_IND(parent, numkey, strkey, zv) { if (i == len || (i == len - 1 && input[len - 1] == ']')) { char *key, *propkey; size_t namelen, keylen; @@ -538,7 +538,7 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable } else { /* Ignore silently */ } - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); return ret; } else if (new_index) { char last_chr = last_index[index_len]; diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index bb2e94aaf47ad..8122956789413 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -628,9 +628,9 @@ void phpdbg_recurse_watch_element(phpdbg_watch_element *element) { zend_long idx; ZEND_ASSERT(element->watch->type == WATCH_ON_HASHTABLE); - ZEND_ARRAY_FOREACH_KEY_VAL(HT_WATCH_HT(element->watch), idx, str, zv) { + ZEND_HASH_FOREACH_KEY_VAL(HT_WATCH_HT(element->watch), idx, str, zv) { phpdbg_add_recursive_watch_from_ht(element, idx, str, zv); - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } } @@ -771,7 +771,7 @@ void phpdbg_automatic_dequeue_free(phpdbg_watch_element *element) { void phpdbg_dequeue_elements_for_recreation(void) { phpdbg_watch_element *element; - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watch_recreation), element) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(watch_recreation), element) { ZEND_ASSERT(element->flags & (PHPDBG_WATCH_IMPLICIT | PHPDBG_WATCH_RECURSIVE_ROOT | PHPDBG_WATCH_SIMPLE)); if (element->parent || zend_hash_index_find(&PHPDBG_G(watch_free), (zend_ulong) element->parent_container)) { zval _zv, *zv = &_zv; @@ -816,7 +816,7 @@ void phpdbg_remove_watch_element_recursively(phpdbg_watch_element *element) { element->child = NULL; } else if (element->flags & (PHPDBG_WATCH_ARRAY | PHPDBG_WATCH_OBJECT)) { phpdbg_watch_element *child; - ZEND_HASH_FOREACH_PTR(&element->child_container, child) { + ZEND_HASH_MAP_FOREACH_PTR(&element->child_container, child) { phpdbg_remove_watch_element_recursively(child); phpdbg_free_watch_element(child); } ZEND_HASH_FOREACH_END(); @@ -933,11 +933,11 @@ void phpdbg_update_watch_collision_elements(phpdbg_watchpoint_t *watch) { phpdbg_watchpoint_t *parent; phpdbg_watch_element *element; - ZEND_HASH_FOREACH_PTR(&watch->coll->parents, parent) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->coll->parents, parent) { if (parent->coll) { phpdbg_update_watch_collision_elements(parent); } else { - ZEND_HASH_FOREACH_PTR(&parent->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&parent->elements, element) { phpdbg_update_watch_element_watch(element); } ZEND_HASH_FOREACH_END(); } @@ -957,7 +957,7 @@ void phpdbg_remove_watchpoint(phpdbg_watchpoint_t *watch) { } watch->elements.nNumOfElements++; /* dirty hack to avoid double free */ - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { phpdbg_update_watch_element_watch(element); } ZEND_HASH_FOREACH_END(); zend_hash_destroy(&watch->elements); @@ -980,7 +980,7 @@ zend_string *phpdbg_watchpoint_change_collision_name(phpdbg_watchpoint_t *watch) phpdbg_watch_element *element; zend_string *name = NULL; if (watch->coll) { - ZEND_HASH_FOREACH_PTR(&watch->coll->parents, parent) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->coll->parents, parent) { if (name) { zend_string_release(name); } @@ -988,7 +988,7 @@ zend_string *phpdbg_watchpoint_change_collision_name(phpdbg_watchpoint_t *watch) } ZEND_HASH_FOREACH_END(); return name; } - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { if (element->flags & PHPDBG_WATCH_IMPLICIT) { if ((watch->type == WATCH_ON_ZVAL || watch->type == WATCH_ON_BUCKET) && Z_TYPE(watch->backup.zv) > IS_STRING) { phpdbg_update_watch_element_watch(element->child); @@ -1012,12 +1012,12 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { zend_string *str; zend_long idx; zval *zv; - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { if (element->flags & PHPDBG_WATCH_RECURSIVE) { phpdbg_btree_result *res = phpdbg_btree_find(&PHPDBG_G(watch_HashTables), (zend_ulong) HT_WATCH_HT(watch)); phpdbg_watch_ht_info *hti = res ? res->ptr : NULL; - ZEND_ARRAY_REVERSE_FOREACH_KEY_VAL(HT_WATCH_HT(watch), idx, str, zv) { + ZEND_HASH_REVERSE_FOREACH_KEY_VAL(HT_WATCH_HT(watch), idx, str, zv) { if (!str) { str = zend_long_to_str(idx); // TODO: hack, use proper int handling for name in parent } else { @@ -1027,7 +1027,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { zend_string_release(str); break; } - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { if (element->flags & PHPDBG_WATCH_RECURSIVE) { phpdbg_add_recursive_watch_from_ht(element, idx, str, zv); } @@ -1035,7 +1035,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { phpdbg_notice("Element %.*s has been added to watchpoint", (int) ZSTR_LEN(str), ZSTR_VAL(str)); zend_string_release(str); PHPDBG_G(watchpoint_hit) = 1; - } ZEND_ARRAY_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); break; } @@ -1067,7 +1067,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { phpdbg_watch_element *element = NULL; zval *new; - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { break; } ZEND_HASH_FOREACH_END(); @@ -1107,7 +1107,7 @@ void phpdbg_check_watchpoint(phpdbg_watchpoint_t *watch) { if (watch->type == WATCH_ON_ZVAL || watch->type == WATCH_ON_BUCKET) { phpdbg_watch_element *element; phpdbg_update_watch_ref(watch); - ZEND_HASH_FOREACH_PTR(&watch->elements, element) { + ZEND_HASH_MAP_FOREACH_PTR(&watch->elements, element) { if (element->flags & PHPDBG_WATCH_RECURSIVE) { phpdbg_recurse_watch_element(element); } @@ -1122,7 +1122,7 @@ void phpdbg_reenable_memory_watches(void) { phpdbg_btree_result *res; phpdbg_watchpoint_t *watch; - ZEND_HASH_FOREACH_NUM_KEY(PHPDBG_G(watchlist_mem), page) { + ZEND_HASH_MAP_FOREACH_NUM_KEY(PHPDBG_G(watchlist_mem), page) { /* Disable writing again if there are any watchers on that page */ res = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), page + phpdbg_pagesize - 1); if (res) { @@ -1165,7 +1165,7 @@ int phpdbg_print_changed_zvals(void) { mem_list = PHPDBG_G(watchlist_mem); PHPDBG_G(watchlist_mem) = PHPDBG_G(watchlist_mem_backup); - ZEND_HASH_FOREACH_NUM_KEY(mem_list, page) { + ZEND_HASH_MAP_FOREACH_NUM_KEY(mem_list, page) { phpdbg_btree_position pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), page, page + phpdbg_pagesize); while ((res = phpdbg_btree_next(&pos))) { @@ -1210,7 +1210,7 @@ void phpdbg_watch_efree(void *ptr) { phpdbg_watch_element *element; phpdbg_watch_ht_info *hti = (phpdbg_watch_ht_info *) watch; - ZEND_HASH_FOREACH_PTR(&hti->watches, element) { + ZEND_HASH_MAP_FOREACH_PTR(&hti->watches, element) { zend_ulong num = zend_hash_num_elements(&hti->watches); phpdbg_remove_watchpoint(element->watch); if (num == 1) { /* prevent access into freed memory */ @@ -1240,7 +1240,7 @@ void phpdbg_watch_efree(void *ptr) { void phpdbg_list_watchpoints(void) { phpdbg_watch_element *element; - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watch_elements), element) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(watch_elements), element) { phpdbg_writeln("%.*s (%s, %s)", (int) ZSTR_LEN(element->str), ZSTR_VAL(element->str), (element->flags & (PHPDBG_WATCH_ARRAY|PHPDBG_WATCH_OBJECT)) ? "array" : "variable", (element->flags & PHPDBG_WATCH_RECURSIVE) ? "recursive" : "simple"); } ZEND_HASH_FOREACH_END(); } @@ -1493,7 +1493,7 @@ void phpdbg_destroy_watchpoints(void) { phpdbg_watch_element *element; /* unconditionally free all remaining elements to avoid memory leaks */ - ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watch_recreation), element) { + ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(watch_recreation), element) { phpdbg_automatic_dequeue_free(element); } ZEND_HASH_FOREACH_END(); diff --git a/win32/registry.c b/win32/registry.c index 9aa2005443acf..cd9fc38c199fe 100644 --- a/win32/registry.c +++ b/win32/registry.c @@ -116,7 +116,7 @@ static int LoadDirectory(HashTable *directories, HKEY key, char *path, int path_ zend_ulong num; zval *tmpdata; - ZEND_HASH_FOREACH_KEY_VAL(parent_ht, num, index, tmpdata) { + ZEND_HASH_MAP_FOREACH_KEY_VAL(parent_ht, num, index, tmpdata) { zend_hash_add(ht, index, tmpdata); } ZEND_HASH_FOREACH_END(); } @@ -263,7 +263,7 @@ void UpdateIniFromRegistry(char *path) zend_string *index; zval *data; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, index, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(ht, index, data) { zend_alter_ini_entry(index, Z_STR_P(data), PHP_INI_USER, PHP_INI_STAGE_ACTIVATE); } ZEND_HASH_FOREACH_END(); } From bf4bf2251c836af782e53baae8cafc9f269b1e04 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 1 Nov 2021 22:32:50 +0300 Subject: [PATCH 13/21] Fixed typo --- Zend/zend_hash.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 414a173702618..955e299a65307 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -961,14 +961,14 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, /* Common hash/packed array iterators */ #if 0 -# define ZEND_HASH_ELEMET_SIZE(__ht) \ +# define ZEND_HASH_ELEMENT_SIZE(__ht) \ (HT_IS_PACKED(__ht) ? sizeof(zval) : sizeof(Bucket)) #else /* optimized version */ -# define ZEND_HASH_ELEMET_SIZE(__ht) \ +# define ZEND_HASH_ELEMENT_SIZE(__ht) \ (sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED)) #endif -#define ZEND_HASH_ELEMET(__ht, _idx, _size) \ +#define ZEND_HASH_ELEMENT(__ht, _idx, _size) \ ((zval*)(((char*)(__ht)->arPacked) + ((_idx) * (_size)))) #define ZEND_HASH_NEXT_ELEMENT(_el, _size) \ @@ -980,7 +980,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define _ZEND_HASH_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ uint32_t _count = __ht->nNumUsed; \ - size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ + size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ zval *_z = __ht->arPacked; \ for (; _count > 0; _z = ZEND_HASH_NEXT_ELEMENT(_z, _size), _count--) { \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; @@ -988,8 +988,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, #define _ZEND_HASH_REVERSE_FOREACH_VAL(_ht) do { \ HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ - size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ - zval *_z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ + zval *_z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ _z = ZEND_HASH_PREV_ELEMENT(_z, _size); \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; @@ -999,8 +999,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zend_ulong __h; \ zend_string *__key = NULL; \ uint32_t _idx = (_from); \ - size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ - zval *__z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ + zval *__z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ uint32_t _count = __ht->nNumUsed - _idx; \ for (;_count > 0; _count--) { \ zval *_z = __z; \ @@ -1028,8 +1028,8 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zval *_z; \ zend_ulong __h; \ zend_string *__key = NULL; \ - size_t _size = ZEND_HASH_ELEMET_SIZE(__ht); \ - zval *__z = ZEND_HASH_ELEMET(__ht, _idx, _size); \ + size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ + zval *__z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ if (HT_IS_PACKED(__ht)) { \ __z--; \ From a9f8192ce1c94bd95b5a28ac1932f77179122481 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 12:30:35 +0300 Subject: [PATCH 14/21] Fixed comment --- ext/standard/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/array.c b/ext/standard/array.c index 15cca7539aee8..dc99a703a05d0 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3600,7 +3600,7 @@ PHP_FUNCTION(array_slice) /* Initialize returned array */ array_init_size(return_value, (uint32_t)length); - // Contains modified variants of ZEND_HASH_MAP_FOREACH_VAL + // Contains modified variants of ZEND_HASH_FOREACH_VAL { HashTable *ht = Z_ARRVAL_P(input); From 7b81cde63ae520a9be8d338e0ac6924ce02ddb2e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 12:30:48 +0300 Subject: [PATCH 15/21] Remove redundand HT_IS_PACKED asserts and add a missed one --- Zend/zend_hash.c | 7 +------ ext/ffi/ffi.c | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 91d8469a076da..24c4ced4b434a 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1339,8 +1339,6 @@ ZEND_API void ZEND_FASTCALL zend_hash_rehash(HashTable *ht) static zend_always_inline void _zend_hash_packed_del_val(HashTable *ht, uint32_t idx, zval *zv) { - ZEND_ASSERT(HT_IS_PACKED(ht)); - idx = HT_HASH_TO_IDX(idx); ht->nNumOfElements--; if (ht->nInternalPointer == idx || UNEXPECTED(HT_HAS_ITERATORS(ht))) { @@ -1378,8 +1376,6 @@ static zend_always_inline void _zend_hash_packed_del_val(HashTable *ht, uint32_t static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint32_t idx, Bucket *p, Bucket *prev) { - ZEND_ASSERT(!HT_IS_PACKED(ht)); - if (prev) { Z_NEXT(prev->val) = Z_NEXT(p->val); } else { @@ -1429,8 +1425,6 @@ static zend_always_inline void _zend_hash_del_el(HashTable *ht, uint32_t idx, Bu uint32_t nIndex; uint32_t i; - ZEND_ASSERT(!HT_IS_PACKED(ht)); - nIndex = p->h | ht->nTableMask; i = HT_HASH(ht, nIndex); @@ -2592,6 +2586,7 @@ ZEND_API zval* ZEND_FASTCALL _zend_hash_index_find(const HashTable *ht, zend_ulo Bucket *p; IS_CONSISTENT(ht); + ZEND_ASSERT(!HT_IS_PACKED(ht)); p = zend_hash_index_find_bucket(ht, h); return p ? &p->val : NULL; diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 08ef410aa9b22..0ce40822a0cb7 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -2967,7 +2967,6 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ zend_string *key; Bucket *b = type->record.fields.arData; - ZEND_ASSERT(!HT_IS_PACKED(&type->record.fields)); ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&old->record.fields, key, old_field) { while (Z_TYPE(b->val) == IS_UNDEF) { b++; From 570fadd1b46c75d631e36dea8b1d881191478f6d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 14:55:45 +0300 Subject: [PATCH 16/21] Use specialized packed/hash iterators --- Zend/zend_list.c | 2 +- ext/ffi/ffi.c | 51 ++++++++++++--------------------- ext/mysqli/mysqli.c | 2 +- ext/reflection/php_reflection.c | 4 +-- ext/spl/php_spl.c | 4 +-- main/output.c | 2 +- sapi/phpdbg/phpdbg_watch.c | 2 +- 7 files changed, 26 insertions(+), 41 deletions(-) diff --git a/Zend/zend_list.c b/Zend/zend_list.c index d667a21c80a9d..b9b042b2f427e 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -285,7 +285,7 @@ ZEND_API int zend_fetch_list_dtor_id(const char *type_name) { zend_rsrc_list_dtors_entry *lde; - ZEND_HASH_FOREACH_PTR(&list_destructors, lde) { + ZEND_HASH_PACKED_FOREACH_PTR(&list_destructors, lde) { if (lde->type_name && (strcmp(type_name, lde->type_name) == 0)) { return lde->resource_id; } diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 0ce40822a0cb7..ee6e33e433f0c 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -811,7 +811,7 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */ zend_ffi_type *arg_type; size_t arg_size = 0; - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(type->func.args, arg_type) { arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t)); } ZEND_HASH_FOREACH_END(); return arg_size; @@ -885,7 +885,7 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v int n = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(callback_data->type->func.args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(callback_data->type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); zend_ffi_cdata_to_zval(NULL, args[n], arg_type, BP_VAR_R, &fci.params[n], (zend_ffi_flags)(arg_type->attr & ZEND_FFI_ATTR_CONST), 0, 0); n++; @@ -959,7 +959,7 @@ static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ * int n = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); callback_data->arg_types[n] = zend_ffi_get_type(arg_type); if (!callback_data->arg_types[n]) { @@ -2652,7 +2652,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2697,7 +2697,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ (sizeof(void*) + ZEND_FFI_SIZEOF_ARG) * EX_NUM_ARGS(), arg_values_use_heap); n = 0; if (type->func.args) { - ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(type->func.args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); arg_values[n] = ((char*)arg_values) + (sizeof(void*) * EX_NUM_ARGS()) + (ZEND_FFI_SIZEOF_ARG * n); if (zend_ffi_pass_arg(EX_VAR_NUM(n), arg_type, &arg_types[n], arg_values, n, execute_data) == FAILURE) { @@ -2999,32 +2999,17 @@ static bool zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ return 0; } else if (old->func.args) { zend_ffi_type *arg_type; + zval *zv = type->func.args->arPacked; - if (HT_IS_PACKED(type->func.args)) { - zval *zv = type->func.args->arPacked; - - ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { - while (Z_TYPE_P(zv) == IS_UNDEF) { - zv++; - } - if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR_P(zv)))) { - return 0; - } + ZEND_HASH_PACKED_FOREACH_PTR(old->func.args, arg_type) { + while (Z_TYPE_P(zv) == IS_UNDEF) { zv++; - } ZEND_HASH_FOREACH_END(); - } else { - Bucket *b = type->func.args->arData; - - ZEND_HASH_FOREACH_PTR(old->func.args, arg_type) { - while (Z_TYPE(b->val) == IS_UNDEF) { - b++; - } - if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR(b->val)))) { - return 0; - } - b++; - } ZEND_HASH_FOREACH_END(); - } + } + if (!zend_ffi_same_types(ZEND_FFI_TYPE(arg_type), ZEND_FFI_TYPE(Z_PTR_P(zv)))) { + return 0; + } + zv++; + } ZEND_HASH_FOREACH_END(); } break; default: @@ -3083,7 +3068,7 @@ static bool zend_ffi_subst_old_type(zend_ffi_type **dcl, zend_ffi_type *old, zen if (dcl_type->func.args) { zval *zv; - ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_old_type((zend_ffi_type**)&Z_PTR_P(zv), old, type)) { return 1; } @@ -3587,7 +3572,7 @@ static bool zend_ffi_subst_type(zend_ffi_type **dcl, zend_ffi_type *type) /* {{{ if (dcl_type->func.args) { zval *zv; - ZEND_HASH_FOREACH_VAL(dcl_type->func.args, zv) { + ZEND_HASH_PACKED_FOREACH_VAL(dcl_type->func.args, zv) { if (zend_ffi_subst_type((zend_ffi_type**)&Z_PTR_P(zv), type)) { return 1; } @@ -6279,7 +6264,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n int no_args = 0; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_PTR(args, arg_type) { + ZEND_HASH_PACKED_FOREACH_PTR(args, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); if (arg_type->kind == ZEND_FFI_TYPE_VOID) { if (zend_hash_num_elements(args) != 1) { @@ -6306,7 +6291,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ulong i; zend_ffi_type *arg_type; - ZEND_HASH_FOREACH_NUM_KEY_PTR(args, i, arg_type) { + ZEND_HASH_PACKED_FOREACH_NUM_KEY_PTR(args, i, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); # ifdef _WIN64 if (i >= 4 && i <= 5 && (arg_type->kind == ZEND_FFI_TYPE_FLOAT || arg_type->kind == ZEND_FFI_TYPE_DOUBLE)) { diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 3782820e77d62..cf16f198a812c 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -398,7 +398,7 @@ HashTable *mysqli_object_get_debug_info(zend_object *object, int *is_temp) retval = zend_new_array(zend_hash_num_elements(props) + 1); - ZEND_HASH_FOREACH_PTR(props, entry) { + ZEND_HASH_MAP_FOREACH_PTR(props, entry) { zval rv; zval *value; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 9d3b9c3c2076c..820520c0aedd1 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1125,7 +1125,7 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s // Name based filtering using lowercased key. zend_string *filter = zend_string_tolower(name); - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, filter)) { reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); @@ -1136,7 +1136,7 @@ static int read_attributes(zval *ret, HashTable *attributes, zend_class_entry *s return SUCCESS; } - ZEND_HASH_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { if (attr->offset != offset) { continue; } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 22b4e52b44496..839e978ec61ad 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -676,7 +676,7 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); @@ -686,7 +686,7 @@ PHP_MINFO_FUNCTION(spl) array_init(&list); SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) strg = estrdup(""); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { + ZEND_HASH_MAP_FOREACH_VAL(Z_ARRVAL_P(&list), zv) { spl_build_class_list_string(zv, &strg); } ZEND_HASH_FOREACH_END(); zend_array_destroy(Z_ARR(list)); diff --git a/main/output.c b/main/output.c index 3efc0294f85b8..3e29f8f152673 100644 --- a/main/output.c +++ b/main/output.c @@ -560,7 +560,7 @@ PHPAPI int php_output_handler_start(php_output_handler *handler) } } if (NULL != (rconflicts = zend_hash_find_ptr(&php_output_handler_reverse_conflicts, handler->name))) { - ZEND_HASH_FOREACH_PTR(rconflicts, conflict) { + ZEND_HASH_PACKED_FOREACH_PTR(rconflicts, conflict) { if (SUCCESS != conflict(ZSTR_VAL(handler->name), ZSTR_LEN(handler->name))) { return FAILURE; } diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c index 8122956789413..6e7494c931760 100644 --- a/sapi/phpdbg/phpdbg_watch.c +++ b/sapi/phpdbg/phpdbg_watch.c @@ -1240,7 +1240,7 @@ void phpdbg_watch_efree(void *ptr) { void phpdbg_list_watchpoints(void) { phpdbg_watch_element *element; - ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(watch_elements), element) { + ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watch_elements), element) { phpdbg_writeln("%.*s (%s, %s)", (int) ZSTR_LEN(element->str), ZSTR_VAL(element->str), (element->flags & (PHPDBG_WATCH_ARRAY|PHPDBG_WATCH_OBJECT)) ? "array" : "variable", (element->flags & PHPDBG_WATCH_RECURSIVE) ? "recursive" : "simple"); } ZEND_HASH_FOREACH_END(); } From cc3b921946bde306d0d71782d5cf5a13119594c7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 15:49:38 +0300 Subject: [PATCH 17/21] Use general hash iteration macros --- ext/soap/php_encoding.c | 2 +- ext/soap/php_http.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 49a8bdd185301..3b7d6c3885dcb 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -3091,7 +3091,7 @@ static xmlNodePtr to_xml_any(encodeTypePtr type, zval *data, int style, xmlNodeP encodePtr enc = get_conversion(XSD_ANYXML); zend_string *name; - ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), name, el) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), name, el) { ret = master_to_xml(enc, el, style, parent); if (ret && ret->name != xmlStringTextNoenc) { diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index f61357128bfc1..1cd73ed792876 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -828,7 +828,7 @@ int make_http_soap_request(zval *this_ptr, zend_string *key; has_cookies = 1; smart_str_append_const(&soap_headers, "Cookie: "); - ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { if (key && Z_TYPE_P(data) == IS_ARRAY) { zval *value; From 361eb147467a0a9b321ec9a36c809e91816576aa Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 16:22:24 +0300 Subject: [PATCH 18/21] Attempt to fix Windows build --- ext/ffi/ffi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index ee6e33e433f0c..352a732a49626 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -6291,7 +6291,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *n zend_ulong i; zend_ffi_type *arg_type; - ZEND_HASH_PACKED_FOREACH_NUM_KEY_PTR(args, i, arg_type) { + ZEND_HASH_PACKED_FOREACH_KEY_PTR(args, i, arg_type) { arg_type = ZEND_FFI_TYPE(arg_type); # ifdef _WIN64 if (i >= 4 && i <= 5 && (arg_type->kind == ZEND_FFI_TYPE_FLOAT || arg_type->kind == ZEND_FFI_TYPE_DOUBLE)) { From bf316ba13e652ad7b6131541518c00892fc224e7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 2 Nov 2021 17:12:04 +0300 Subject: [PATCH 19/21] Use genral macro "ZEND_HASH_ELEMENT(ht, i)" instead of "HT_IS_PACKED(ht) ? &ht->arPacked[i] : &ht->arData[i].val" --- Zend/zend_hash.h | 11 +++++++---- Zend/zend_list.c | 2 +- ext/pcre/php_pcre.c | 4 +--- ext/standard/array.c | 6 +----- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index 955e299a65307..b7559257d27e5 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -968,9 +968,12 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, (sizeof(zval) + (~HT_FLAGS(__ht) & HASH_FLAG_PACKED) * ((sizeof(Bucket)-sizeof(zval))/HASH_FLAG_PACKED)) #endif -#define ZEND_HASH_ELEMENT(__ht, _idx, _size) \ +#define ZEND_HASH_ELEMENT_EX(__ht, _idx, _size) \ ((zval*)(((char*)(__ht)->arPacked) + ((_idx) * (_size)))) +#define ZEND_HASH_ELEMENT(__ht, _idx) \ + ZEND_HASH_ELEMENT_EX(__ht, _idx, ZEND_HASH_ELEMENT_SIZE(__ht)) + #define ZEND_HASH_NEXT_ELEMENT(_el, _size) \ ((zval*)(((char*)(_el)) + (_size))) @@ -989,7 +992,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashTable *__ht = (_ht); \ uint32_t _idx = __ht->nNumUsed; \ size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ - zval *_z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ + zval *_z = ZEND_HASH_ELEMENT_EX(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ _z = ZEND_HASH_PREV_ELEMENT(_z, _size); \ if (UNEXPECTED(Z_TYPE_P(_z) == IS_UNDEF)) continue; @@ -1000,7 +1003,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zend_string *__key = NULL; \ uint32_t _idx = (_from); \ size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ - zval *__z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ + zval *__z = ZEND_HASH_ELEMENT_EX(__ht, _idx, _size); \ uint32_t _count = __ht->nNumUsed - _idx; \ for (;_count > 0; _count--) { \ zval *_z = __z; \ @@ -1029,7 +1032,7 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, zend_ulong __h; \ zend_string *__key = NULL; \ size_t _size = ZEND_HASH_ELEMENT_SIZE(__ht); \ - zval *__z = ZEND_HASH_ELEMENT(__ht, _idx, _size); \ + zval *__z = ZEND_HASH_ELEMENT_EX(__ht, _idx, _size); \ for (;_idx > 0; _idx--) { \ if (HT_IS_PACKED(__ht)) { \ __z--; \ diff --git a/Zend/zend_list.c b/Zend/zend_list.c index b9b042b2f427e..51ef3e1d92eb3 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -218,7 +218,7 @@ void zend_close_rsrc_list(HashTable *ht) uint32_t i = ht->nNumUsed; while (i-- > 0) { - zval *p = HT_IS_PACKED(ht) ? &ht->arPacked[i] : &ht->arData[i].val; + zval *p = ZEND_HASH_ELEMENT(ht, i); if (Z_TYPE_P(p) != IS_UNDEF) { zend_resource *res = Z_PTR_P(p); if (res->type >= 0) { diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index bde53d589dbda..cb2a44c1cf57a 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2115,9 +2115,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, tmp_replace_entry_str = NULL; break; } - zv = HT_IS_PACKED(replace_ht) ? - &replace_ht->arPacked[replace_idx] : - &replace_ht->arData[replace_idx].val; + zv = ZEND_HASH_ELEMENT(replace_ht, replace_idx); replace_idx++; if (Z_TYPE_P(zv) != IS_UNDEF) { replace_entry_str = zval_get_tmp_string(zv, &tmp_replace_entry_str); diff --git a/ext/standard/array.c b/ext/standard/array.c index dc99a703a05d0..8137bfcbd8d79 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -6462,11 +6462,7 @@ PHP_FUNCTION(array_combine) if (pos_values >= values->nNumUsed) { break; } - if (HT_IS_PACKED(values)) { - entry_values = &values->arPacked[pos_values]; - } else { - entry_values = &values->arData[pos_values].val; - } + entry_values = ZEND_HASH_ELEMENT(values, pos_values); if (Z_TYPE_P(entry_values) != IS_UNDEF) { if (Z_TYPE_P(entry_keys) == IS_LONG) { entry_values = zend_hash_index_update(Z_ARRVAL_P(return_value), From ff48182f76cbc92a1d57c29d0b7d0e02ed582789 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 3 Nov 2021 15:06:40 +0300 Subject: [PATCH 20/21] Use specialized packed iterator. (We checked for !HT_IS_CACHE above). --- ext/soap/php_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 1cd73ed792876..f61357128bfc1 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -828,7 +828,7 @@ int make_http_soap_request(zval *this_ptr, zend_string *key; has_cookies = 1; smart_str_append_const(&soap_headers, "Cookie: "); - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { + ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) { if (key && Z_TYPE_P(data) == IS_ARRAY) { zval *value; From 9bbaf671bba97c4a73aeaec1a076ce56a534970c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 3 Nov 2021 15:07:47 +0300 Subject: [PATCH 21/21] Use general hash/packed iteratr or HT_IS_CACHE check --- Zend/zend_API.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index cf643402722c5..36265ca9d4ab3 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1284,6 +1284,9 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */ zend_string *key; zval *value; + if (HT_IS_PACKED(properties)) { + return; + } EG(fake_scope) = Z_OBJCE_P(obj); ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, value) { if (key) { @@ -1558,7 +1561,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) zend_long h; zend_property_info *property_info; - ZEND_HASH_MAP_FOREACH_KEY_VAL(properties, h, key, prop) { + ZEND_HASH_FOREACH_KEY_VAL(properties, h, key, prop) { if (key) { if (ZSTR_VAL(key)[0] == '\0') { const char *class_name, *prop_name;