Skip to content

Add zend_wrong_parameter_error to reduce the size of ZPP macro #5831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,33 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_
}
/* }}} */

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) /* {{{ */
{
switch (error_code) {
case ZPP_ERROR_WRONG_CALLBACK:
zend_wrong_callback_error(num, name);
break;
case ZPP_ERROR_WRONG_CLASS:
zend_wrong_parameter_class_error(num, name, arg);
break;
case ZPP_ERROR_WRONG_CLASS_OR_NULL:
zend_wrong_parameter_class_or_null_error(num, name, arg);
break;
case ZPP_ERROR_WRONG_ARG:
zend_wrong_parameter_type_error(num, expected_type, arg);
break;
case ZPP_ERROR_WRONG_STRING_OR_CLASS:
zend_wrong_parameter_string_or_class_error(num, name, arg);
break;
case ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL:
zend_wrong_parameter_string_or_class_or_null_error(num, name, arg);
break;
default:
ZEND_ASSERT(error_code != ZPP_ERROR_OK);
}
}
/* }}} */

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg) /* {{{ */
{
static const char * const expected_error[] = {
Expand Down
15 changes: 2 additions & 13 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ typedef enum _zend_expected_type {

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args);
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);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, const char *name, zval *arg);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(int num, const char *name, zval *arg);
Expand Down Expand Up @@ -1296,19 +1297,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
} while (0); \
if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
if (_error_code == ZPP_ERROR_WRONG_CALLBACK) { \
zend_wrong_callback_error(_i, _error); \
} else if (_error_code == ZPP_ERROR_WRONG_CLASS) { \
zend_wrong_parameter_class_error(_i, _error, _arg); \
} else if (_error_code == ZPP_ERROR_WRONG_CLASS_OR_NULL) { \
zend_wrong_parameter_class_or_null_error(_i, _error, _arg); \
} else if (_error_code == ZPP_ERROR_WRONG_ARG) { \
zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
} else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS) { \
zend_wrong_parameter_string_or_class_error(_i, _error, _arg); \
} else if (_error_code == ZPP_ERROR_WRONG_STRING_OR_CLASS_OR_NULL) { \
zend_wrong_parameter_string_or_class_or_null_error(_i, _error, _arg); \
} \
zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
} \
failure; \
} \
Expand Down