From ca27eb3a31a147b208c300a82d9807377091c902 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 2 Aug 2026 20:19:06 +0100 Subject: [PATCH 1/2] Zend: use C enum for ZPP error states --- Zend/zend_API.c | 6 ++++-- Zend/zend_API.h | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 517c5894e1d0..82c9ace00951 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -225,7 +225,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t } /* }}} */ -ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, const zval *arg) /* {{{ */ +ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(zpp_error error_code, uint32_t num, char *name, zend_expected_type expected_type, const zval *arg) /* {{{ */ { switch (error_code) { case ZPP_ERROR_WRONG_CALLBACK: @@ -261,7 +261,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, case ZPP_ERROR_FAILURE: ZEND_ASSERT(EG(exception) && "Should have produced an error already"); break; - default: ZEND_UNREACHABLE(); + case ZPP_ERROR_OK: + case ZPP_ERROR_WRONG_COUNT: + ZEND_UNREACHABLE(); } } /* }}} */ diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 622e90da59b2..86db88b724f2 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1580,9 +1580,25 @@ typedef enum _zend_expected_type { Z_EXPECTED_LAST } zend_expected_type; +C23_ENUM(zpp_error, uint8_t) { + ZPP_ERROR_OK, + ZPP_ERROR_FAILURE, + ZPP_ERROR_WRONG_CALLBACK, + ZPP_ERROR_WRONG_CLASS, + ZPP_ERROR_WRONG_CLASS_OR_NULL, + ZPP_ERROR_WRONG_CLASS_OR_STRING, + ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL, + ZPP_ERROR_WRONG_CLASS_OR_LONG, + ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL, + ZPP_ERROR_WRONG_ARG, + ZPP_ERROR_WRONG_COUNT, + ZPP_ERROR_UNEXPECTED_EXTRA_NAMED, + ZPP_ERROR_WRONG_CALLBACK_OR_NULL, +}; + 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(uint32_t min_num_args, uint32_t max_num_args); -ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, const zval *arg); +ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(zpp_error error_code, uint32_t num, char *name, zend_expected_type expected_type, const zval *arg); ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, const zval *arg); ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, const zval *arg); ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, const zval *arg); @@ -1604,20 +1620,6 @@ ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num); ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, const zend_class_entry *old_ce); ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, const zend_class_entry *old_ce); -#define ZPP_ERROR_OK 0 -#define ZPP_ERROR_FAILURE 1 -#define ZPP_ERROR_WRONG_CALLBACK 2 -#define ZPP_ERROR_WRONG_CLASS 3 -#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4 -#define ZPP_ERROR_WRONG_CLASS_OR_STRING 5 -#define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6 -#define ZPP_ERROR_WRONG_CLASS_OR_LONG 7 -#define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 8 -#define ZPP_ERROR_WRONG_ARG 9 -#define ZPP_ERROR_WRONG_COUNT 10 -#define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11 -#define ZPP_ERROR_WRONG_CALLBACK_OR_NULL 12 - #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \ const int _flags = (flags); \ uint32_t _min_num_args = (min_num_args); \ @@ -1629,7 +1631,7 @@ ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string char *_error = NULL; \ bool _dummy = 0; \ bool _optional = 0; \ - int _error_code = ZPP_ERROR_OK; \ + zpp_error _error_code = ZPP_ERROR_OK; \ ((void)_i); \ ((void)_real_arg); \ ((void)_arg); \ From c900464bc12e9f15f2a51c50af7140b0de88e739 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 2 Aug 2026 20:25:27 +0100 Subject: [PATCH 2/2] Zend: Remove ZPP_ERROR_WRONG_COUNT case As it is unused, the relevant error is handled before and _error_code is assigned ZPP_ERROR_FAILURE. --- Zend/zend_API.c | 1 - Zend/zend_API.h | 1 - 2 files changed, 2 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 82c9ace00951..edb9902f6484 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -262,7 +262,6 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(zpp_error error ZEND_ASSERT(EG(exception) && "Should have produced an error already"); break; case ZPP_ERROR_OK: - case ZPP_ERROR_WRONG_COUNT: ZEND_UNREACHABLE(); } } diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 86db88b724f2..51091c903d17 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1591,7 +1591,6 @@ C23_ENUM(zpp_error, uint8_t) { ZPP_ERROR_WRONG_CLASS_OR_LONG, ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL, ZPP_ERROR_WRONG_ARG, - ZPP_ERROR_WRONG_COUNT, ZPP_ERROR_UNEXPECTED_EXTRA_NAMED, ZPP_ERROR_WRONG_CALLBACK_OR_NULL, };