Skip to content

Commit 575f0ca

Browse files
committed
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.
1 parent 8993422 commit 575f0ca

File tree

5 files changed

+24
-43
lines changed

5 files changed

+24
-43
lines changed

ext/mysqli/mysqli.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,11 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
749749
MYSQL_RES *result;
750750
zval *mysql_result;
751751
zend_long fetchtype;
752-
zval *ctor_params = NULL;
752+
HashTable *ctor_params = NULL;
753753
zend_class_entry *ce = NULL;
754754

755755
if (into_object) {
756-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ca", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
756+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|Ch", &mysql_result, mysqli_result_class_entry, &ce, &ctor_params) == FAILURE) {
757757
RETURN_THROWS();
758758
}
759759
if (ce == NULL) {
@@ -810,13 +810,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
810810
fci.retval = &retval;
811811
fci.params = NULL;
812812
fci.param_count = 0;
813-
fci.named_params = NULL;
814-
815-
if (ctor_params) {
816-
if (zend_fcall_info_args(&fci, ctor_params) == FAILURE) {
817-
ZEND_UNREACHABLE();
818-
}
819-
}
813+
fci.named_params = ctor_params;
820814

821815
fcc.function_handler = ce->constructor;
822816
fcc.called_scope = Z_OBJCE_P(return_value);
@@ -827,8 +821,8 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
827821
} else {
828822
zval_ptr_dtor(&retval);
829823
}
830-
zend_fcall_info_args_clear(&fci, 1);
831-
} else if (ctor_params && zend_hash_num_elements(Z_ARRVAL_P(ctor_params)) > 0) {
824+
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
825+
/* TODO Convert this to a ValueError */
832826
zend_argument_error(zend_ce_exception, ERROR_ARG_POS(3),
833827
"must be empty when the specified class (%s) does not have a constructor",
834828
ZSTR_VAL(ce->name)

ext/pgsql/pgsql.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,11 +1756,11 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
17561756
zend_long row;
17571757
bool row_is_null = 1;
17581758
char *field_name;
1759-
zval *ctor_params = NULL;
1759+
HashTable *ctor_params = NULL;
17601760
zend_class_entry *ce = NULL;
17611761

17621762
if (into_object) {
1763-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!Ca", &result, pgsql_result_ce, &row, &row_is_null, &ce, &ctor_params) == FAILURE) {
1763+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l!Ch", &result, pgsql_result_ce, &row, &row_is_null, &ce, &ctor_params) == FAILURE) {
17641764
RETURN_THROWS();
17651765
}
17661766
if (!ce) {
@@ -1853,13 +1853,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
18531853
fci.retval = &retval;
18541854
fci.params = NULL;
18551855
fci.param_count = 0;
1856-
fci.named_params = NULL;
1857-
1858-
if (ctor_params) {
1859-
if (zend_fcall_info_args(&fci, ctor_params) == FAILURE) {
1860-
ZEND_UNREACHABLE();
1861-
}
1862-
}
1856+
fci.named_params = ctor_params;
18631857

18641858
fcc.function_handler = ce->constructor;
18651859
fcc.called_scope = Z_OBJCE_P(return_value);
@@ -1870,10 +1864,8 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
18701864
} else {
18711865
zval_ptr_dtor(&retval);
18721866
}
1873-
if (fci.params) {
1874-
efree(fci.params);
1875-
}
1876-
} else if (ctor_params && zend_hash_num_elements(Z_ARRVAL_P(ctor_params)) > 0) {
1867+
} else if (ctor_params && zend_hash_num_elements(ctor_params) > 0) {
1868+
/* TODO Convert this to a ValueError */
18771869
zend_argument_error(zend_ce_exception, 3,
18781870
"must be empty when the specified class (%s) does not have a constructor",
18791871
ZSTR_VAL(ce->name)

ext/spl/spl_iterators.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,7 +3208,6 @@ PHP_FUNCTION(iterator_count)
32083208

32093209
typedef struct {
32103210
zval *obj;
3211-
zval *args;
32123211
zend_long count;
32133212
zend_fcall_info fci;
32143213
zend_fcall_info_cache fcc;
@@ -3235,19 +3234,16 @@ PHP_FUNCTION(iterator_apply)
32353234
{
32363235
spl_iterator_apply_info apply_info;
32373236

3238-
apply_info.args = NULL;
3239-
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) {
3237+
/* The HashTable is used to determine positional arguments */
3238+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of|h!", &apply_info.obj, zend_ce_traversable,
3239+
&apply_info.fci, &apply_info.fcc, &apply_info.fci.named_params) == FAILURE) {
32403240
RETURN_THROWS();
32413241
}
32423242

32433243
apply_info.count = 0;
3244-
zend_fcall_info_args(&apply_info.fci, apply_info.args);
32453244
if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == FAILURE) {
3246-
zend_fcall_info_args(&apply_info.fci, NULL);
32473245
return;
32483246
}
3249-
3250-
zend_fcall_info_args(&apply_info.fci, NULL);
32513247
RETURN_LONG(apply_info.count);
32523248
}
32533249
/* }}} */

ext/standard/basic_functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,18 +1566,20 @@ PHP_FUNCTION(forward_static_call)
15661566
/* {{{ Call a static method which is the first parameter with the arguments contained in array */
15671567
PHP_FUNCTION(forward_static_call_array)
15681568
{
1569-
zval *params, retval;
1569+
zval retval;
1570+
HashTable *params;
15701571
zend_fcall_info fci;
15711572
zend_fcall_info_cache fci_cache;
15721573
zend_class_entry *called_scope;
15731574

15741575
ZEND_PARSE_PARAMETERS_START(2, 2)
15751576
Z_PARAM_FUNC(fci, fci_cache)
1576-
Z_PARAM_ARRAY(params)
1577+
Z_PARAM_ARRAY_HT(params)
15771578
ZEND_PARSE_PARAMETERS_END();
15781579

1579-
zend_fcall_info_args(&fci, params);
15801580
fci.retval = &retval;
1581+
/* Add positional arguments */
1582+
fci.named_params = params;
15811583

15821584
called_scope = zend_get_called_scope(execute_data);
15831585
if (called_scope && fci_cache.calling_scope &&
@@ -1591,8 +1593,6 @@ PHP_FUNCTION(forward_static_call_array)
15911593
}
15921594
ZVAL_COPY_VALUE(return_value, &retval);
15931595
}
1594-
1595-
zend_fcall_info_args_clear(&fci, 1);
15961596
}
15971597
/* }}} */
15981598

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
114114

115115
ZVAL_STRINGL(&fci.function_name, lc_name, name->len);
116116
fci.size = sizeof(zend_fcall_info);
117-
//???fci.symbol_table = zend_rebuild_symbol_table();
118117
fci.object = NULL;
119118
fci.retval = &fretval;
119+
fci.param_count = 0;
120+
fci.params = NULL;
121+
fci.named_params = NULL;
120122

123+
zval params;
121124
if (name->next) {
122-
zval params;
123125
phpdbg_param_t *next = name->next;
124126

125127
array_init(&params);
@@ -170,11 +172,8 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
170172

171173
next = next->next;
172174
}
173-
174-
zend_fcall_info_args(&fci, &params);
175-
} else {
176-
fci.params = NULL;
177-
fci.param_count = 0;
175+
/* Add positional arguments */
176+
fci.named_params = Z_ARRVAL(params);
178177
}
179178

180179
phpdbg_activate_err_buf(0);

0 commit comments

Comments
 (0)