Skip to content

Commit 275ec6f

Browse files
authored
Zend: make zend_copy_parameters_array() private (php#20265)
And slightly refactor implementation.
1 parent bac62bf commit 275ec6f

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

UPGRADING.INTERNALS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ PHP 8.6 INTERNALS UPGRADE NOTES
3434
printf family.
3535
. The zval_dtor() alias of zval_ptr_dtor_nogc() has been removed.
3636
Call zval_ptr_dtor_nogc() directly instead.
37+
. The internal zend_copy_parameters_array() function is no longer exposed.
3738

3839
========================
3940
2. Build system changes

Zend/zend_API.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,6 @@ ZEND_API zend_result zend_get_parameters_array_ex(uint32_t param_count, zval *ar
7676
}
7777
/* }}} */
7878

79-
ZEND_API zend_result zend_copy_parameters_array(uint32_t param_count, zval *argument_array) /* {{{ */
80-
{
81-
zval *param_ptr;
82-
uint32_t arg_count;
83-
84-
param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
85-
arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
86-
87-
if (param_count>arg_count) {
88-
return FAILURE;
89-
}
90-
91-
while (param_count-->0) {
92-
Z_TRY_ADDREF_P(param_ptr);
93-
zend_hash_next_index_insert_new(Z_ARRVAL_P(argument_array), param_ptr);
94-
param_ptr++;
95-
}
96-
97-
return SUCCESS;
98-
}
99-
/* }}} */
100-
10179
ZEND_API ZEND_COLD void zend_wrong_param_count(void) /* {{{ */
10280
{
10381
const char *space;

Zend/zend_API.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ ZEND_API void zend_set_dl_use_deepbind(bool use_deepbind);
347347

348348
ZEND_API zend_result zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);
349349

350-
/* internal function to efficiently copy parameters when executing __call() */
351-
ZEND_API zend_result zend_copy_parameters_array(uint32_t param_count, zval *argument_array);
352-
353350
#define zend_get_parameters_array(ht, param_count, argument_array) \
354351
zend_get_parameters_array_ex(param_count, argument_array)
355352
#define zend_parse_parameters_none() \

Zend/zend_closures.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ ZEND_METHOD(Closure, bindTo)
287287
do_closure_bind(return_value, ZEND_THIS, newthis, scope_obj, scope_str);
288288
}
289289

290+
static void zend_copy_parameters_array(const uint32_t param_count, HashTable *argument_array) /* {{{ */
291+
{
292+
zval *param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
293+
294+
ZEND_ASSERT(param_count <= ZEND_CALL_NUM_ARGS(EG(current_execute_data)));
295+
296+
for (uint32_t i = 0; i < param_count; i++) {
297+
Z_TRY_ADDREF_P(param_ptr);
298+
zend_hash_next_index_insert_new(argument_array, param_ptr);
299+
param_ptr++;
300+
}
301+
}
302+
290303
static ZEND_NAMED_FUNCTION(zend_closure_call_magic) /* {{{ */ {
291304
zend_fcall_info fci;
292305
zend_fcall_info_cache fcc;
@@ -310,14 +323,14 @@ static ZEND_NAMED_FUNCTION(zend_closure_call_magic) /* {{{ */ {
310323
array_init_size(&fci.params[1], ZEND_NUM_ARGS() + zend_hash_num_elements(EX(extra_named_params)));
311324
/* Avoid conversion from packed to mixed later. */
312325
zend_hash_real_init_mixed(Z_ARRVAL(fci.params[1]));
313-
zend_copy_parameters_array(ZEND_NUM_ARGS(), &fci.params[1]);
326+
zend_copy_parameters_array(ZEND_NUM_ARGS(), Z_ARRVAL(fci.params[1]));
314327
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EX(extra_named_params), name, named_param_zval) {
315328
Z_TRY_ADDREF_P(named_param_zval);
316329
zend_hash_add_new(Z_ARRVAL(fci.params[1]), name, named_param_zval);
317330
} ZEND_HASH_FOREACH_END();
318331
} else if (ZEND_NUM_ARGS()) {
319332
array_init_size(&fci.params[1], ZEND_NUM_ARGS());
320-
zend_copy_parameters_array(ZEND_NUM_ARGS(), &fci.params[1]);
333+
zend_copy_parameters_array(ZEND_NUM_ARGS(), Z_ARRVAL(fci.params[1]));
321334
} else {
322335
ZVAL_EMPTY_ARRAY(&fci.params[1]);
323336
}

0 commit comments

Comments
 (0)