Skip to content

Commit add8d54

Browse files
committed
Zend: use C enum for ZPP error states
1 parent 395b298 commit add8d54

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

Zend/zend_API.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t
225225
}
226226
/* }}} */
227227

228-
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) /* {{{ */
228+
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) /* {{{ */
229229
{
230230
switch (error_code) {
231231
case ZPP_ERROR_WRONG_CALLBACK:
@@ -261,7 +261,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code,
261261
case ZPP_ERROR_FAILURE:
262262
ZEND_ASSERT(EG(exception) && "Should have produced an error already");
263263
break;
264-
default: ZEND_UNREACHABLE();
264+
case ZPP_ERROR_OK:
265+
case ZPP_ERROR_WRONG_COUNT:
266+
ZEND_UNREACHABLE();
265267
}
266268
}
267269
/* }}} */

Zend/zend_API.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,9 +1588,25 @@ typedef enum _zend_expected_type {
15881588
Z_EXPECTED_LAST
15891589
} zend_expected_type;
15901590

1591+
C23_ENUM(zpp_error, uint8_t) {
1592+
ZPP_ERROR_OK,
1593+
ZPP_ERROR_FAILURE,
1594+
ZPP_ERROR_WRONG_CALLBACK,
1595+
ZPP_ERROR_WRONG_CLASS,
1596+
ZPP_ERROR_WRONG_CLASS_OR_NULL,
1597+
ZPP_ERROR_WRONG_CLASS_OR_STRING,
1598+
ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL,
1599+
ZPP_ERROR_WRONG_CLASS_OR_LONG,
1600+
ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL,
1601+
ZPP_ERROR_WRONG_ARG,
1602+
ZPP_ERROR_WRONG_COUNT,
1603+
ZPP_ERROR_UNEXPECTED_EXTRA_NAMED,
1604+
ZPP_ERROR_WRONG_CALLBACK_OR_NULL,
1605+
};
1606+
15911607
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
15921608
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
1593-
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);
1609+
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);
15941610
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, const zval *arg);
15951611
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, const zval *arg);
15961612
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, const zval *arg);
@@ -1612,20 +1628,6 @@ ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num);
16121628
ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, const zend_class_entry *old_ce);
16131629
ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, const zend_class_entry *old_ce);
16141630

1615-
#define ZPP_ERROR_OK 0
1616-
#define ZPP_ERROR_FAILURE 1
1617-
#define ZPP_ERROR_WRONG_CALLBACK 2
1618-
#define ZPP_ERROR_WRONG_CLASS 3
1619-
#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1620-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING 5
1621-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
1622-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG 7
1623-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 8
1624-
#define ZPP_ERROR_WRONG_ARG 9
1625-
#define ZPP_ERROR_WRONG_COUNT 10
1626-
#define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11
1627-
#define ZPP_ERROR_WRONG_CALLBACK_OR_NULL 12
1628-
16291631
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
16301632
const int _flags = (flags); \
16311633
uint32_t _min_num_args = (min_num_args); \
@@ -1637,7 +1639,7 @@ ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string
16371639
char *_error = NULL; \
16381640
bool _dummy = 0; \
16391641
bool _optional = 0; \
1640-
int _error_code = ZPP_ERROR_OK; \
1642+
zpp_error _error_code = ZPP_ERROR_OK; \
16411643
((void)_i); \
16421644
((void)_real_arg); \
16431645
((void)_arg); \

0 commit comments

Comments
 (0)