com php-src: Remove HASH_OF uses in ext/filter: ext /filter/filter.c ext/filter/logical_filters.c
| From: | Nikita Popov | Date: | Thu, 11 Oct 2018 11:04:08 +0000 |
| Subject: | com php-src: Remove HASH_OF uses in ext/filter: ext /filter/filter.c ext/filter/logical_filters.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-103437@lists.php.net to get a copy of this message | ||
Commit: bfaba83102e886de93aaec7d773ec3adfb2c943f
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 11 Oct 2018 12:30:49 +0200
Parents: 9bbf9967bd2ae5094e00fc6649d46f6082b44097
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bfaba83102e886de93aaec7d773ec3adfb2c943f
Log:
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.
Changed paths:
M ext/filter/filter.c
M ext/filter/logical_filters.c
Diff:
diff --git a/ext/filter/filter.c b/ext/filter/filter.c
index 7e2cee4..cc8e010 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 076d247..3dcbf21 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; \