Skip to content

Commit 4f3eccf

Browse files
committed
Use consistent types
uint32_t type for argument count size_t for length of char* zend_bool for a zval bool arg Closes GH-5845
1 parent 4896337 commit 4f3eccf

File tree

3 files changed

+68
-68
lines changed

3 files changed

+68
-68
lines changed

UPGRADING.INTERNALS

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ PHP 8.0 INTERNALS UPGRADE NOTES
153153
- zend_declare_property*()
154154
- zend_startup_modules()
155155
- zend_wrong_parameters_none_error()
156+
- zend_fcall_info_argp()
157+
- zend_fcall_info_argv()
158+
- zend_fcall_info_argn()
159+
2. Argument int to uint32_t in Zend Engine 4.0:
160+
- _zend_get_parameters_array_ex()
161+
- zend_copy_parameters_array()
162+
- zend_fcall_info_args_save()
163+
- zend_fcall_info_args_restore()
164+
- zend_fcall_info_argp()
165+
- zend_fcall_info_argv()
166+
- zend_fcall_info_argn()
167+
- zend_wrong_parameter*()
168+
- zend_wrong_callback_error()
169+
- zend_parse_arg_class()
170+
3. Argument int to zend_bool in Zend Engine 4.0:
171+
- add_next_index_bool()
172+
4. Argument int to size_t in Zend Engine 4.0:
173+
- zend_set_hash_symbol()
156174

157175
========================
158176
2. Build system changes

Zend/zend_API.c

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ static zend_module_entry **module_post_deactivate_handlers;
4242

4343
static zend_class_entry **class_cleanup_handlers;
4444

45-
ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array) /* {{{ */
45+
ZEND_API int _zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array) /* {{{ */
4646
{
4747
zval *param_ptr;
48-
int arg_count;
48+
uint32_t arg_count;
4949

5050
param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
5151
arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
@@ -64,10 +64,10 @@ ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array
6464
}
6565
/* }}} */
6666

67-
ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array) /* {{{ */
67+
ZEND_API int zend_copy_parameters_array(uint32_t param_count, zval *argument_array) /* {{{ */
6868
{
6969
zval *param_ptr;
70-
int arg_count;
70+
uint32_t arg_count;
7171

7272
param_ptr = ZEND_CALL_ARG(EG(current_execute_data), 1);
7373
arg_count = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
@@ -195,9 +195,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void) /*
195195
}
196196
/* }}} */
197197

198-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args) /* {{{ */
198+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args) /* {{{ */
199199
{
200-
int num_args = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
200+
uint32_t num_args = ZEND_CALL_NUM_ARGS(EG(current_execute_data));
201201
zend_function *active_function = EG(current_execute_data)->func;
202202
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
203203

@@ -213,7 +213,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_
213213
}
214214
/* }}} */
215215

216-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, int num, char *name, zend_expected_type expected_type, zval *arg) /* {{{ */
216+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, zval *arg) /* {{{ */
217217
{
218218
switch (error_code) {
219219
case ZPP_ERROR_WRONG_CALLBACK:
@@ -240,7 +240,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code,
240240
}
241241
/* }}} */
242242

243-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg) /* {{{ */
243+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, zval *arg) /* {{{ */
244244
{
245245
static const char * const expected_error[] = {
246246
Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_STR)
@@ -255,7 +255,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, z
255255
}
256256
/* }}} */
257257

258-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, const char *name, zval *arg) /* {{{ */
258+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, zval *arg) /* {{{ */
259259
{
260260
if (EG(exception)) {
261261
return;
@@ -265,7 +265,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num,
265265
}
266266
/* }}} */
267267

268-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(int num, const char *name, zval *arg) /* {{{ */
268+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, zval *arg) /* {{{ */
269269
{
270270
if (EG(exception)) {
271271
return;
@@ -275,7 +275,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(i
275275
}
276276
/* }}} */
277277

278-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error(int num, const char *name, zval *arg) /* {{{ */
278+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error(uint32_t num, const char *name, zval *arg) /* {{{ */
279279
{
280280
if (EG(exception)) {
281281
return;
@@ -285,7 +285,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error
285285
}
286286
/* }}} */
287287

288-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error(int num, const char *name, zval *arg) /* {{{ */
288+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error(uint32_t num, const char *name, zval *arg) /* {{{ */
289289
{
290290
if (EG(exception)) {
291291
return;
@@ -295,7 +295,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_nu
295295
}
296296
/* }}} */
297297

298-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error) /* {{{ */
298+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error) /* {{{ */
299299
{
300300
if (EG(exception)) {
301301
return;
@@ -358,7 +358,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
358358
}
359359
/* }}} */
360360

361-
ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null) /* {{{ */
361+
ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, int check_null) /* {{{ */
362362
{
363363
zend_class_entry *ce_base = *pce;
364364

@@ -1570,7 +1570,7 @@ ZEND_API int add_next_index_null(zval *arg) /* {{{ */
15701570
}
15711571
/* }}} */
15721572

1573-
ZEND_API int add_next_index_bool(zval *arg, int b) /* {{{ */
1573+
ZEND_API int add_next_index_bool(zval *arg, zend_bool b) /* {{{ */
15741574
{
15751575
zval tmp;
15761576

@@ -2711,7 +2711,7 @@ ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zen
27112711
}
27122712
/* }}} */
27132713

2714-
ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...) /* {{{ */
2714+
ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, size_t name_length, zend_bool is_ref, int num_symbol_tables, ...) /* {{{ */
27152715
{
27162716
HashTable *symbol_table;
27172717
va_list symbol_table_list;
@@ -3365,7 +3365,7 @@ ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem) /*
33653365
}
33663366
/* }}} */
33673367

3368-
ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params) /* {{{ */
3368+
ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, uint32_t *param_count, zval **params) /* {{{ */
33693369
{
33703370
*param_count = fci->param_count;
33713371
*params = fci->params;
@@ -3374,7 +3374,7 @@ ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count,
33743374
}
33753375
/* }}} */
33763376

3377-
ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params) /* {{{ */
3377+
ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, uint32_t param_count, zval *params) /* {{{ */
33783378
{
33793379
zend_fcall_info_args_clear(fci, 1);
33803380
fci->param_count = param_count;
@@ -3421,71 +3421,53 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args) /* {{{ */
34213421
}
34223422
/* }}} */
34233423

3424-
ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv) /* {{{ */
3424+
ZEND_API void zend_fcall_info_argp(zend_fcall_info *fci, uint32_t argc, zval *argv) /* {{{ */
34253425
{
3426-
int i;
3427-
3428-
if (argc < 0) {
3429-
return FAILURE;
3430-
}
3431-
34323426
zend_fcall_info_args_clear(fci, !argc);
34333427

34343428
if (argc) {
34353429
fci->param_count = argc;
34363430
fci->params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
34373431

3438-
for (i = 0; i < argc; ++i) {
3432+
for (uint32_t i = 0; i < argc; ++i) {
34393433
ZVAL_COPY(&fci->params[i], &argv[i]);
34403434
}
34413435
}
3442-
3443-
return SUCCESS;
34443436
}
34453437
/* }}} */
34463438

3447-
ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv) /* {{{ */
3439+
ZEND_API void zend_fcall_info_argv(zend_fcall_info *fci, uint32_t argc, va_list *argv) /* {{{ */
34483440
{
3449-
int i;
3450-
zval *arg;
3451-
3452-
if (argc < 0) {
3453-
return FAILURE;
3454-
}
3455-
34563441
zend_fcall_info_args_clear(fci, !argc);
34573442

34583443
if (argc) {
3444+
zval *arg;
34593445
fci->param_count = argc;
34603446
fci->params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
34613447

3462-
for (i = 0; i < argc; ++i) {
3448+
for (uint32_t i = 0; i < argc; ++i) {
34633449
arg = va_arg(*argv, zval *);
34643450
ZVAL_COPY(&fci->params[i], arg);
34653451
}
34663452
}
3467-
3468-
return SUCCESS;
34693453
}
34703454
/* }}} */
34713455

3472-
ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...) /* {{{ */
3456+
ZEND_API void zend_fcall_info_argn(zend_fcall_info *fci, uint32_t argc, ...) /* {{{ */
34733457
{
3474-
int ret;
34753458
va_list argv;
34763459

34773460
va_start(argv, argc);
3478-
ret = zend_fcall_info_argv(fci, argc, &argv);
3461+
zend_fcall_info_argv(fci, argc, &argv);
34793462
va_end(argv);
3480-
3481-
return ret;
34823463
}
34833464
/* }}} */
34843465

34853466
ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval_ptr, zval *args) /* {{{ */
34863467
{
34873468
zval retval, *org_params = NULL;
3488-
int result, org_count = 0;
3469+
uint32_t org_count = 0;
3470+
int result;
34893471

34903472
fci->retval = retval_ptr ? retval_ptr : &retval;
34913473
if (args) {

Zend/zend_API.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ typedef struct _zend_fcall_info_cache {
276276
ZEND_API int zend_next_free_module(void);
277277

278278
BEGIN_EXTERN_C()
279-
ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array);
279+
ZEND_API int _zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);
280280

281281
/* internal function to efficiently copy parameters when executing __call() */
282-
ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
282+
ZEND_API int zend_copy_parameters_array(uint32_t param_count, zval *argument_array);
283283

284284
#define zend_get_parameters_array(ht, param_count, argument_array) \
285285
_zend_get_parameters_array_ex(param_count, argument_array)
@@ -462,7 +462,7 @@ static zend_always_inline int add_index_zval(zval *arg, zend_ulong index, zval *
462462

463463
ZEND_API int add_next_index_long(zval *arg, zend_long n);
464464
ZEND_API int add_next_index_null(zval *arg);
465-
ZEND_API int add_next_index_bool(zval *arg, int b);
465+
ZEND_API int add_next_index_bool(zval *arg, zend_bool b);
466466
ZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
467467
ZEND_API int add_next_index_double(zval *arg, double d);
468468
ZEND_API int add_next_index_str(zval *arg, zend_string *str);
@@ -523,11 +523,11 @@ ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
523523
/** Save current arguments from zend_fcall_info *fci
524524
* params array will be set to NULL
525525
*/
526-
ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
526+
ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, uint32_t *param_count, zval **params);
527527

528528
/** Free arguments connected with zend_fcall_info *fci andset back saved ones.
529529
*/
530-
ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
530+
ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, uint32_t param_count, zval *params);
531531

532532
/** Set or clear the arguments in the zend_call_info struct taking care of
533533
* refcount. If args is NULL and arguments are set then those are cleared.
@@ -539,19 +539,19 @@ ZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func,
539539
* If argc is 0 the arguments which are set will be cleared, else pass
540540
* a variable amount of zval** arguments.
541541
*/
542-
ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv);
542+
ZEND_API void zend_fcall_info_argp(zend_fcall_info *fci, uint32_t argc, zval *argv);
543543

544544
/** Set arguments in the zend_fcall_info struct taking care of refcount.
545545
* If argc is 0 the arguments which are set will be cleared, else pass
546546
* a variable amount of zval** arguments.
547547
*/
548-
ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv);
548+
ZEND_API void zend_fcall_info_argv(zend_fcall_info *fci, uint32_t argc, va_list *argv);
549549

550550
/** Set arguments in the zend_fcall_info struct taking care of refcount.
551551
* If argc is 0 the arguments which are set will be cleared, else pass
552552
* a variable amount of zval** arguments.
553553
*/
554-
ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...);
554+
ZEND_API void zend_fcall_info_argn(zend_fcall_info *fci, uint32_t argc, ...);
555555

556556
/** Call a function using information created by zend_fcall_info_init()/args().
557557
* If args is given then those replace the argument info in fci is temporarily.
@@ -591,7 +591,7 @@ static zend_always_inline void zend_call_known_instance_method_with_1_params(
591591
ZEND_API void zend_call_known_instance_method_with_2_params(
592592
zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2);
593593

594-
ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
594+
ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, size_t name_length, zend_bool is_ref, int num_symbol_tables, ...);
595595

596596
ZEND_API int zend_delete_global_variable(zend_string *name);
597597

@@ -1230,14 +1230,14 @@ typedef enum _zend_expected_type {
12301230
} zend_expected_type;
12311231

12321232
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
1233-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args);
1234-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, int num, char *name, zend_expected_type expected_type, zval *arg);
1235-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
1236-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, const char *name, zval *arg);
1237-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(int num, const char *name, zval *arg);
1238-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error(int num, const char *name, zval *arg);
1239-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error(int num, const char *name, zval *arg);
1240-
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error);
1233+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
1234+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, zval *arg);
1235+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, zval *arg);
1236+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, zval *arg);
1237+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, zval *arg);
1238+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_error(uint32_t num, const char *name, zval *arg);
1239+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_string_or_class_or_null_error(uint32_t num, const char *name, zval *arg);
1240+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error);
12411241
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
12421242
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_type_error(uint32_t arg_num, const char *format, ...);
12431243
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num, const char *format, ...);
@@ -1254,10 +1254,10 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
12541254

12551255
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
12561256
const int _flags = (flags); \
1257-
int _min_num_args = (min_num_args); \
1258-
int _max_num_args = (max_num_args); \
1259-
int _num_args = EX_NUM_ARGS(); \
1260-
int _i = 0; \
1257+
uint32_t _min_num_args = (min_num_args); \
1258+
int _max_num_args = (max_num_args); /* TODO uint32_t */ \
1259+
uint32_t _num_args = EX_NUM_ARGS(); \
1260+
uint32_t _i = 0; \
12611261
zval *_real_arg, *_arg = NULL; \
12621262
zend_expected_type _expected_type = Z_EXPECTED_LONG; \
12631263
char *_error = NULL; \
@@ -1683,7 +1683,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
16831683

16841684
/* old "+" and "*" */
16851685
#define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
1686-
int _num_varargs = _num_args - _i - (post_varargs); \
1686+
uint32_t _num_varargs = _num_args - _i - (post_varargs); \
16871687
if (EXPECTED(_num_varargs > 0)) { \
16881688
dest = _real_arg + 1; \
16891689
dest_num = _num_varargs; \
@@ -1730,7 +1730,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
17301730

17311731
/* Inlined implementations shared by new and old parameter parsing APIs */
17321732

1733-
ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null);
1733+
ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, int check_null);
17341734
ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, zend_bool *dest);
17351735
ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, zend_bool *dest);
17361736
ZEND_API int ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest);

0 commit comments

Comments
 (0)