diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2018-10-11 12:30:49 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2018-10-11 13:04:08 +0200 |
| commit | bfaba83102e886de93aaec7d773ec3adfb2c943f (patch) | |
| tree | 48a2b5212d77e76383961e44ba40d1a12be2de74 | |
| parent | 9bbf9967bd2ae5094e00fc6649d46f6082b44097 (diff) | |
| download | php-git-bfaba83102e886de93aaec7d773ec3adfb2c943f.tar.gz | |
Remove HASH_OF uses in ext/filter
It turns out that all of these places ultimately only accept arrays,
not objects, so we can use Z_ARRVAL_P everywhere.
Also add _deref in a few places where the hash lookup result is
directly type-checked.
| -rw-r--r-- | ext/filter/filter.c | 21 | ||||
| -rw-r--r-- | ext/filter/logical_filters.c | 6 |
2 files changed, 12 insertions, 15 deletions
diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 7e2cee4c9f..cc8e010e57 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -408,11 +408,11 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval filter_func.function(value, flags, options, charset); handle_default: - if (options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) && + if (options && Z_TYPE_P(options) == IS_ARRAY && ((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_P(value) == IS_NULL) || (!(flags & FILTER_NULL_ON_FAILURE) && Z_TYPE_P(value) == IS_FALSE))) { zval *tmp; - if ((tmp = zend_hash_str_find(HASH_OF(options), "default", sizeof("default") - 1)) != NULL) { + if ((tmp = zend_hash_str_find(Z_ARRVAL_P(options), "default", sizeof("default") - 1)) != NULL) { ZVAL_COPY(value, tmp); } } @@ -613,11 +613,11 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args, filter = lval; } } else if (filter_args) { - if ((option = zend_hash_str_find(HASH_OF(filter_args), "filter", sizeof("filter") - 1)) != NULL) { + if ((option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "filter", sizeof("filter") - 1)) != NULL) { filter = zval_get_long(option); } - if ((option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) { + if ((option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "flags", sizeof("flags") - 1)) != NULL) { filter_flags = zval_get_long(option); if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) { @@ -625,10 +625,7 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args, } } - if ((option = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL) { - /* avoid reference type */ - ZVAL_DEREF(option); - + if ((option = zend_hash_str_find_deref(Z_ARRVAL_P(filter_args), "options", sizeof("options") - 1)) != NULL) { if (filter != FILTER_CALLBACK) { if (Z_TYPE_P(option) == IS_ARRAY) { options = option; @@ -744,13 +741,13 @@ PHP_FUNCTION(filter_input) if (filter_args) { if (Z_TYPE_P(filter_args) == IS_LONG) { filter_flags = Z_LVAL_P(filter_args); - } else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) { + } else if (Z_TYPE_P(filter_args) == IS_ARRAY && (option = zend_hash_str_find(Z_ARRVAL_P(filter_args), "flags", sizeof("flags") - 1)) != NULL) { filter_flags = zval_get_long(option); } if (Z_TYPE_P(filter_args) == IS_ARRAY && - (opt = zend_hash_str_find(HASH_OF(filter_args), "options", sizeof("options") - 1)) != NULL && + (opt = zend_hash_str_find_deref(Z_ARRVAL_P(filter_args), "options", sizeof("options") - 1)) != NULL && Z_TYPE_P(opt) == IS_ARRAY && - (def = zend_hash_str_find(HASH_OF(opt), "default", sizeof("default") - 1)) != NULL) { + (def = zend_hash_str_find_deref(Z_ARRVAL_P(opt), "default", sizeof("default") - 1)) != NULL) { ZVAL_COPY(return_value, def); return; } @@ -821,7 +818,7 @@ PHP_FUNCTION(filter_input_array) if (op) { if (Z_TYPE_P(op) == IS_LONG) { filter_flags = Z_LVAL_P(op); - } else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(HASH_OF(op), "flags", sizeof("flags") - 1)) != NULL) { + } else if (Z_TYPE_P(op) == IS_ARRAY && (option = zend_hash_str_find(Z_ARRVAL_P(op), "flags", sizeof("flags") - 1)) != NULL) { filter_flags = zval_get_long(option); } } diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 076d247946..3dcbf21443 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -39,7 +39,7 @@ var_name = 0; \ var_name##_set = 0; \ if (option_array) { \ - if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ + if ((option_val = zend_hash_str_find(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ var_name = zval_get_long(option_val); \ var_name##_set = 1; \ } \ @@ -52,7 +52,7 @@ var_name##_set = 0; \ var_name##_len = 0; \ if (option_array) { \ - if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ + if ((option_val = zend_hash_str_find_deref(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ if (Z_TYPE_P(option_val) == IS_STRING) { \ var_name = Z_STRVAL_P(option_val); \ var_name##_len = Z_STRLEN_P(option_val); \ @@ -67,7 +67,7 @@ var_name = NULL; \ var_name##_set = 0; \ if (option_array) { \ - if ((option_val = zend_hash_str_find(HASH_OF(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ + if ((option_val = zend_hash_str_find_deref(Z_ARRVAL_P(option_array), option_name, sizeof(option_name) - 1)) != NULL) { \ if (Z_TYPE_P(option_val) == IS_STRING) { \ var_name = Z_STR_P(option_val); \ var_name##_set = 1; \ |
