Skip to content

Commit b284ba3

Browse files
twosenikic
authored andcommitted
Add zend_wrong_parameter_error to reduce the size of ZPP macro
Closes GH-5831.
1 parent bdcda50 commit b284ba3

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

Zend/zend_API.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ 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) /* {{{ */
217+
{
218+
switch (error_code) {
219+
case ZPP_ERROR_WRONG_CALLBACK:
220+
zend_wrong_callback_error(num, name);
221+
break;
222+
case ZPP_ERROR_WRONG_CLASS:
223+
zend_wrong_parameter_class_error(num, name, arg);
224+
break;
225+
case ZPP_ERROR_WRONG_CLASS_OR_NULL:
226+
zend_wrong_parameter_class_or_null_error(num, name, arg);
227+
break;
228+
case ZPP_ERROR_WRONG_ARG:
229+
zend_wrong_parameter_type_error(num, expected_type, arg);
230+
break;
231+
case ZPP_ERROR_WRONG_STRING_OR_CLASS:
232+
zend_wrong_parameter_string_or_class_error(num, name, arg);
233+
break;
234+
case ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL:
235+
zend_wrong_parameter_string_or_class_or_null_error(num, name, arg);
236+
break;
237+
default:
238+
ZEND_ASSERT(error_code != ZPP_ERROR_OK);
239+
}
240+
}
241+
/* }}} */
242+
216243
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg) /* {{{ */
217244
{
218245
static const char * const expected_error[] = {

Zend/zend_API.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ typedef enum _zend_expected_type {
12311231

12321232
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
12331233
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);
12341235
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
12351236
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, const char *name, zval *arg);
12361237
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(int num, const char *name, zval *arg);
@@ -1296,19 +1297,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
12961297
} while (0); \
12971298
if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
12981299
if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
1299-
if (_error_code == ZPP_ERROR_WRONG_CALLBACK) { \
1300-
zend_wrong_callback_error(_i, _error); \
1301-
} else if (_error_code == ZPP_ERROR_WRONG_CLASS) { \
1302-
zend_wrong_parameter_class_error(_i, _error, _arg); \
1303-
} else if (_error_code == ZPP_ERROR_WRONG_CLASS_OR_NULL) { \
1304-
zend_wrong_parameter_class_or_null_error(_i, _error, _arg); \
1305-
} else if (_error_code == ZPP_ERROR_WRONG_ARG) { \
1306-
zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
1307-
} else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS) { \
1308-
zend_wrong_parameter_string_or_class_error(_i, _error, _arg); \
1309-
} else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL) { \
1310-
zend_wrong_parameter_string_or_class_or_null_error(_i, _error, _arg); \
1311-
} \
1300+
zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
13121301
} \
13131302
failure; \
13141303
} \

0 commit comments

Comments
 (0)