Skip to content

Commit e19ff85

Browse files
committed
Zend: use C enum for ZPP error states
1 parent 41b4d43 commit e19ff85

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
@@ -1580,9 +1580,25 @@ typedef enum _zend_expected_type {
15801580
Z_EXPECTED_LAST
15811581
} zend_expected_type;
15821582

1583+
C23_ENUM(zpp_error, uint8_t) {
1584+
ZPP_ERROR_OK = 0,
1585+
ZPP_ERROR_FAILURE = 1,
1586+
ZPP_ERROR_WRONG_CALLBACK = 2,
1587+
ZPP_ERROR_WRONG_CLASS = 3,
1588+
ZPP_ERROR_WRONG_CLASS_OR_NULL = 4,
1589+
ZPP_ERROR_WRONG_CLASS_OR_STRING = 5,
1590+
ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL = 6,
1591+
ZPP_ERROR_WRONG_CLASS_OR_LONG = 7,
1592+
ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL = 8,
1593+
ZPP_ERROR_WRONG_ARG = 9,
1594+
ZPP_ERROR_WRONG_COUNT = 10,
1595+
ZPP_ERROR_UNEXPECTED_EXTRA_NAMED = 11,
1596+
ZPP_ERROR_WRONG_CALLBACK_OR_NULL = 12
1597+
};
1598+
15831599
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
15841600
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
1585-
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);
1601+
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);
15861602
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, const zval *arg);
15871603
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, const zval *arg);
15881604
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);
16041620
ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, const zend_class_entry *old_ce);
16051621
ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, const zend_class_entry *old_ce);
16061622

1607-
#define ZPP_ERROR_OK 0
1608-
#define ZPP_ERROR_FAILURE 1
1609-
#define ZPP_ERROR_WRONG_CALLBACK 2
1610-
#define ZPP_ERROR_WRONG_CLASS 3
1611-
#define ZPP_ERROR_WRONG_CLASS_OR_NULL 4
1612-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING 5
1613-
#define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
1614-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG 7
1615-
#define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL 8
1616-
#define ZPP_ERROR_WRONG_ARG 9
1617-
#define ZPP_ERROR_WRONG_COUNT 10
1618-
#define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED 11
1619-
#define ZPP_ERROR_WRONG_CALLBACK_OR_NULL 12
1620-
16211623
#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
16221624
const int _flags = (flags); \
16231625
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
16291631
char *_error = NULL; \
16301632
bool _dummy = 0; \
16311633
bool _optional = 0; \
1632-
int _error_code = ZPP_ERROR_OK; \
1634+
zpp_error _error_code = ZPP_ERROR_OK; \
16331635
((void)_i); \
16341636
((void)_real_arg); \
16351637
((void)_arg); \

0 commit comments

Comments
 (0)