Browse Source

Drop redundant casting code from ext/filter

pull/865/merge
Nikita Popov 12 years ago
parent
commit
1577ac146f
  1. 15
      ext/filter/filter.c
  2. 11
      ext/filter/filter_private.h
  3. 2
      ext/filter/logical_filters.c

15
ext/filter/filter.c

@ -582,9 +582,7 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args,
char *charset = NULL;
if (filter_args && Z_TYPE_P(filter_args) != IS_ARRAY) {
zend_long lval;
PHP_FILTER_GET_LONG_OPT(filter_args, lval);
zend_long lval = zval_get_long(filter_args);
if (filter != -1) { /* handler for array apply */
/* filter_args is the filter_flags */
@ -598,11 +596,11 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args,
}
} else if (filter_args) {
if ((option = zend_hash_str_find(HASH_OF(filter_args), "filter", sizeof("filter") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter);
filter = zval_get_long(option);
}
if ((option = zend_hash_str_find(HASH_OF(filter_args), "flags", sizeof("flags") - 1)) != NULL) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
filter_flags = zval_get_long(option);
if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) {
filter_flags |= FILTER_REQUIRE_SCALAR;
@ -662,7 +660,6 @@ static void php_filter_call(zval *filtered, zend_long filter, zval *filter_args,
static void php_filter_array_handler(zval *input, zval *op, zval *return_value, zend_bool add_empty TSRMLS_DC) /* {{{ */
{
zend_ulong index;
zend_string *arg_key;
zval *tmp, *arg_elm;
@ -677,7 +674,7 @@ static void php_filter_array_handler(zval *input, zval *op, zval *return_value,
} else if (Z_TYPE_P(op) == IS_ARRAY) {
array_init(return_value);
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(op), index, arg_key, arg_elm) {
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(op), arg_key, arg_elm) {
if (arg_key == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric keys are not allowed in the definition array");
zval_ptr_dtor(return_value);
@ -733,7 +730,7 @@ PHP_FUNCTION(filter_input)
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) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
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 &&
@ -810,7 +807,7 @@ PHP_FUNCTION(filter_input_array)
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) {
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
filter_flags = zval_get_long(option);
}
}

11
ext/filter/filter_private.h

@ -117,17 +117,6 @@
} \
}
#define PHP_FILTER_GET_LONG_OPT(zv, opt) { \
if (Z_TYPE_P(zv) != IS_LONG) { \
zval ___tmp; \
ZVAL_DUP(&___tmp, zv); \
convert_to_long(&___tmp); \
opt = Z_LVAL(___tmp); \
} else { \
opt = Z_LVAL_P(zv); \
} \
}
#endif /* FILTER_PRIVATE_H */
/*

2
ext/filter/logical_filters.c

@ -41,7 +41,7 @@
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) { \
PHP_FILTER_GET_LONG_OPT(option_val, var_name); \
var_name = zval_get_long(option_val); \
var_name##_set = 1; \
} \
}

Loading…
Cancel
Save