Remove most usages of zend_fcall_info_args()

This reallocates the PHP array when one can just use the named_params fields to pass the positional arguments instead.

Only usage of zend_fcall_info_args(_ex) remains in PDO.
This commit is contained in:
George Peter Banyard 2022-10-11 14:40:13 +01:00
parent 3641f824fd
commit 66661ae682
No known key found for this signature in database
GPG Key ID: 3306078E3194AEBD
5 changed files with 24 additions and 43 deletions

View File

@ -749,11 +749,11 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
MYSQL_RES *result;
zval *mysql_result;
zend_long fetchtype;
zval *ctor_params = NULL;
HashTable *ctor_params = NULL;
zend_class_entry *ce = NULL;
if (into_object) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ca", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ch", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
RETURN_THROWS();
}
if (ce == NULL) {
@ -810,13 +810,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
fci.retval = &retval;
fci.params = NULL;
fci.param_count = 0;
fci.named_params = NULL;
if (ctor_params) {
if (zend_fcall_info_args(&fci, ctor_params) == FAILURE) {
ZEND_UNREACHABLE();
}
}
fci.named_params = ctor_params;
fcc.function_handler = ce->constructor;
fcc.called_scope = Z_OBJCE_P(return_value);
@ -827,8 +821,8 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
} else {
zval_ptr_dtor(&retval);
}
zend_fcall_info_args_clear(&fci, 1);
} else if (ctor_params && zend_hash_num_elements(Z_ARRVAL_P(ctor_params)) > 0) {
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
/* TODO Convert this to a ValueError */
zend_argument_error(zend_ce_exception, ERROR_ARG_POS(3),
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)

View File

@ -1756,11 +1756,11 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
zend_long row;
bool row_is_null = 1;
char *field_name;
zval *ctor_params = NULL;
HashTable *ctor_params = NULL;
zend_class_entry *ce = NULL;
if (into_object) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!Ca", &result, pgsql_result_ce, &row, &row_is_null, &ce, &ctor_params) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!Ch", &result, pgsql_result_ce, &row, &row_is_null, &ce, &ctor_params) == FAILURE) {
RETURN_THROWS();
}
if (!ce) {
@ -1853,13 +1853,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
fci.retval = &retval;
fci.params = NULL;
fci.param_count = 0;
fci.named_params = NULL;
if (ctor_params) {
if (zend_fcall_info_args(&fci, ctor_params) == FAILURE) {
ZEND_UNREACHABLE();
}
}
fci.named_params = ctor_params;
fcc.function_handler = ce->constructor;
fcc.called_scope = Z_OBJCE_P(return_value);
@ -1870,10 +1864,8 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
} else {
zval_ptr_dtor(&retval);
}
if (fci.params) {
efree(fci.params);
}
} else if (ctor_params && zend_hash_num_elements(Z_ARRVAL_P(ctor_params)) > 0) {
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
/* TODO Convert this to a ValueError */
zend_argument_error(zend_ce_exception, 3,
"must be empty when the specified class (%s) does not have a constructor",
ZSTR_VAL(ce->name)

View File

@ -3208,7 +3208,6 @@ PHP_FUNCTION(iterator_count)
typedef struct {
zval *obj;
zval *args;
zend_long count;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
@ -3233,19 +3232,16 @@ PHP_FUNCTION(iterator_apply)
{
spl_iterator_apply_info apply_info;
apply_info.args = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of|a!", &apply_info.obj, zend_ce_traversable, &apply_info.fci, &apply_info.fcc, &apply_info.args) == FAILURE) {
/* The HashTable is used to determine positional arguments */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of|h!", &apply_info.obj, zend_ce_traversable,
&apply_info.fci, &apply_info.fcc, &apply_info.fci.named_params) == FAILURE) {
RETURN_THROWS();
}
apply_info.count = 0;
zend_fcall_info_args(&apply_info.fci, apply_info.args);
if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == FAILURE) {
zend_fcall_info_args(&apply_info.fci, NULL);
return;
}
zend_fcall_info_args(&apply_info.fci, NULL);
RETURN_LONG(apply_info.count);
}
/* }}} */

View File

@ -1566,18 +1566,20 @@ PHP_FUNCTION(forward_static_call)
/* {{{ Call a static method which is the first parameter with the arguments contained in array */
PHP_FUNCTION(forward_static_call_array)
{
zval *params, retval;
zval retval;
HashTable *params;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
zend_class_entry *called_scope;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_FUNC(fci, fci_cache)
Z_PARAM_ARRAY(params)
Z_PARAM_ARRAY_HT(params)
ZEND_PARSE_PARAMETERS_END();
zend_fcall_info_args(&fci, params);
fci.retval = &retval;
/* Add positional arguments */
fci.named_params = params;
called_scope = zend_get_called_scope(execute_data);
if (called_scope && fci_cache.calling_scope &&
@ -1591,8 +1593,6 @@ PHP_FUNCTION(forward_static_call_array)
}
ZVAL_COPY_VALUE(return_value, &retval);
}
zend_fcall_info_args_clear(&fci, 1);
}
/* }}} */

View File

@ -114,12 +114,14 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
ZVAL_STRINGL(&fci.function_name, lc_name, name->len);
fci.size = sizeof(zend_fcall_info);
//???fci.symbol_table = zend_rebuild_symbol_table();
fci.object = NULL;
fci.retval = &fretval;
fci.param_count = 0;
fci.params = NULL;
fci.named_params = NULL;
zval params;
if (name->next) {
zval params;
phpdbg_param_t *next = name->next;
array_init(&params);
@ -170,11 +172,8 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
next = next->next;
}
zend_fcall_info_args(&fci, &params);
} else {
fci.params = NULL;
fci.param_count = 0;
/* Add positional arguments */
fci.named_params = Z_ARRVAL(params);
}
phpdbg_activate_err_buf(0);