From 40e5238a00ab172b3f64c2a4f13bcf721043575e Mon Sep 17 00:00:00 2001 From: twosee Date: Fri, 4 Sep 2020 22:43:02 +0800 Subject: [PATCH] Flesh out ZEND_HASH_REVERSE_FOREACH_* macros Closes GH-6080. --- Zend/zend_hash.h | 99 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index fb11c4a9e32..6d3398fd903 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -993,107 +993,146 @@ static zend_always_inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, ZEND_HASH_FOREACH(ht, 0); \ _bucket = _p; +#define ZEND_HASH_REVERSE_FOREACH_BUCKET(ht, _bucket) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _bucket = _p; + #define ZEND_HASH_FOREACH_VAL(ht, _val) \ ZEND_HASH_FOREACH(ht, 0); \ _val = _z; +#define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _val = _z; + #define ZEND_HASH_FOREACH_VAL_IND(ht, _val) \ ZEND_HASH_FOREACH(ht, 1); \ _val = _z; +#define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \ + ZEND_HASH_REVERSE_FOREACH(ht, 1); \ + _val = _z; + #define ZEND_HASH_FOREACH_PTR(ht, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ _ptr = Z_PTR_P(_z); +#define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _ptr = Z_PTR_P(_z); + #define ZEND_HASH_FOREACH_NUM_KEY(ht, _h) \ ZEND_HASH_FOREACH(ht, 0); \ _h = _p->h; +#define ZEND_HASH_REVERSE_FOREACH_NUM_KEY(ht, _h) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; + #define ZEND_HASH_FOREACH_STR_KEY(ht, _key) \ ZEND_HASH_FOREACH(ht, 0); \ _key = _p->key; +#define ZEND_HASH_REVERSE_FOREACH_STR_KEY(ht, _key) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _key = _p->key; + #define ZEND_HASH_FOREACH_KEY(ht, _h, _key) \ ZEND_HASH_FOREACH(ht, 0); \ _h = _p->h; \ _key = _p->key; +#define ZEND_HASH_REVERSE_FOREACH_KEY(ht, _h, _key) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; + #define ZEND_HASH_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ ZEND_HASH_FOREACH(ht, 0); \ _h = _p->h; \ _val = _z; +#define ZEND_HASH_REVERSE_FOREACH_NUM_KEY_VAL(ht, _h, _val) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _val = _z; + #define ZEND_HASH_FOREACH_STR_KEY_VAL(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ _key = _p->key; \ _val = _z; +#define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _key = _p->key; \ + _val = _z; + #define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) \ ZEND_HASH_FOREACH(ht, 0); \ _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 = _p->h; \ + _key = _p->key; \ + _val = _z; + #define ZEND_HASH_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ ZEND_HASH_FOREACH(ht, 1); \ _key = _p->key; \ _val = _z; +#define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL_IND(ht, _key, _val) \ + ZEND_HASH_REVERSE_FOREACH(ht, 1); \ + _key = _p->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; \ _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; \ + _val = _z; + #define ZEND_HASH_FOREACH_NUM_KEY_PTR(ht, _h, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ _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 = _p->h; \ + _ptr = Z_PTR_P(_z); + #define ZEND_HASH_FOREACH_STR_KEY_PTR(ht, _key, _ptr) \ ZEND_HASH_FOREACH(ht, 0); \ _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 = _p->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; \ _ptr = Z_PTR_P(_z); -#define ZEND_HASH_REVERSE_FOREACH_BUCKET(ht, _bucket) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _bucket = _p; - -#define ZEND_HASH_REVERSE_FOREACH_VAL(ht, _val) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _val = _z; - -#define ZEND_HASH_REVERSE_FOREACH_PTR(ht, _ptr) \ +#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); -#define ZEND_HASH_REVERSE_FOREACH_VAL_IND(ht, _val) \ - ZEND_HASH_REVERSE_FOREACH(ht, 1); \ - _val = _z; - -#define ZEND_HASH_REVERSE_FOREACH_STR_KEY_VAL(ht, _key, _val) \ - ZEND_HASH_REVERSE_FOREACH(ht, 0); \ - _key = _p->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; \ - _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; \ - _val = _z; - /* The following macros are useful to insert a sequence of new elements * of packed array. They may be used instead of series of * zend_hash_next_index_insert_new()