Skip to content

Commit c7637ed

Browse files
MaxKellermanndevnexen
authored andcommitted
Zend/zend_type_code: remove hard-coded integer values and
remove unused macro ZEND_SAME_FAKE_TYPE Zend/zend_variables: add _Static_assert on the size zend_rc_dtor_func _Static_assert is C11, but has been supported since GCC 4.6. Also removing the comment about keeping those values in sync with `zend_variables.c` which was obsoleted by commit 0460420 (designated initializers). Closes GH-10714.
1 parent 3db3243 commit c7637ed

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

Zend/zend_type_code.h

+35-30
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,48 @@
1818
#define ZEND_TYPE_CODE_H
1919

2020
enum {
21-
/* Regular data types: Must be in sync with zend_variables.c. */
22-
IS_UNDEF = 0,
23-
IS_NULL = 1,
24-
IS_FALSE = 2,
25-
IS_TRUE = 3,
26-
IS_LONG = 4,
27-
IS_DOUBLE = 5,
28-
IS_STRING = 6,
29-
IS_ARRAY = 7,
30-
IS_OBJECT = 8,
31-
IS_RESOURCE = 9,
32-
IS_REFERENCE = 10,
33-
IS_CONSTANT_AST = 11, /* Constant expressions */
21+
/* Regular data types */
22+
IS_UNDEF,
23+
IS_NULL,
24+
IS_FALSE,
25+
IS_TRUE,
26+
IS_LONG,
27+
IS_DOUBLE,
28+
IS_STRING,
29+
IS_ARRAY,
30+
IS_OBJECT,
31+
IS_RESOURCE,
32+
IS_REFERENCE,
33+
IS_CONSTANT_AST, /* Constant expressions */
34+
35+
/**
36+
* One after the largest regular data type; used internally
37+
* for overlapping ranges below.
38+
*/
39+
_IS_REGULAR_END,
3440

3541
/* Fake types used only for type hinting.
3642
* These are allowed to overlap with the types below. */
37-
IS_CALLABLE = 12,
38-
IS_ITERABLE = 13,
39-
IS_VOID = 14,
40-
IS_STATIC = 15,
41-
IS_MIXED = 16,
42-
IS_NEVER = 17,
43+
IS_CALLABLE = _IS_REGULAR_END,
44+
IS_ITERABLE,
45+
IS_VOID,
46+
IS_STATIC,
47+
IS_MIXED,
48+
IS_NEVER,
49+
50+
_IS_FAKE_END,
4351

4452
/* internal types */
45-
IS_INDIRECT = 12,
46-
IS_PTR = 13,
47-
IS_ALIAS_PTR = 14,
48-
_IS_ERROR = 15,
53+
IS_INDIRECT = _IS_REGULAR_END,
54+
IS_PTR,
55+
IS_ALIAS_PTR,
56+
_IS_ERROR,
57+
58+
_IS_INTERNAL_END,
4959

5060
/* used for casts */
51-
_IS_BOOL = 18,
52-
_IS_NUMBER = 19,
61+
_IS_BOOL = _IS_FAKE_END > _IS_INTERNAL_END ? _IS_FAKE_END : _IS_INTERNAL_END,
62+
_IS_NUMBER,
5363
};
5464

55-
#define ZEND_SAME_FAKE_TYPE(faketype, realtype) ( \
56-
(faketype) == (realtype) \
57-
|| ((faketype) == _IS_BOOL && ((realtype) == IS_TRUE || (realtype) == IS_FALSE)) \
58-
)
59-
6065
#endif /* ZEND_TYPE_CODE_H */

Zend/zend_variables.c

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ static const zend_rc_dtor_func_t zend_rc_dtor_func[] = {
5151
[IS_CONSTANT_AST] = (zend_rc_dtor_func_t)zend_ast_ref_destroy
5252
};
5353

54+
#if ZEND_GCC_VERSION >= 4006 || defined(__clang__)
55+
_Static_assert(sizeof(zend_rc_dtor_func) / sizeof(zend_rc_dtor_func[0]) == _IS_REGULAR_END,
56+
"zend_rc_dtor_func has the wrong size");
57+
#endif
58+
5459
ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p)
5560
{
5661
ZEND_ASSERT(GC_TYPE(p) <= IS_CONSTANT_AST);

0 commit comments

Comments
 (0)