Skip to content

Commit 1e4920c

Browse files
committed
Renumber zval types, clarify allowed overlap
Make it clear that types used for type declarations can overlap with the rest, and can also overlap in MAY_BE space. This makes things more robust against the addition of new primitive types.
1 parent da48d25 commit 1e4920c

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

.gdbinit

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,31 +255,22 @@ define ____printzv_contents
255255
printf "CONSTANT_AST"
256256
end
257257
if $type == 12
258-
printf "CALLABLE"
259-
end
260-
if $type == 13
261-
printf "ITERABLE"
262-
end
263-
if $type == 14
264-
printf "VOID"
265-
end
266-
if $type == 15
267258
printf "indirect: "
268259
____printzv $zvalue->value.zv $arg1
269260
end
270-
if $type == 16
261+
if $type == 13
271262
printf "pointer: %p", $zvalue->value.ptr
272263
end
273-
if $type == 17
264+
if $type == 15
274265
printf "_ERROR"
275266
end
276-
if $type == 18
267+
if $type == 16
277268
printf "_BOOL"
278269
end
279-
if $type == 19
270+
if $type == 17
280271
printf "_NUMBER"
281272
end
282-
if $type > 19
273+
if $type > 17
283274
printf "unknown type %d", $type
284275
end
285276
printf "\n"

Zend/zend_type_info.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
#define MAY_BE_ANY (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)
3636
#define MAY_BE_REF (1 << IS_REFERENCE) /* may be reference */
3737

38-
/* These are used in zend_type, but not for type inference. */
38+
/* These are used in zend_type, but not for type inference.
39+
* They are allowed to overlap with types used during inference. */
3940
#define MAY_BE_CALLABLE (1 << IS_CALLABLE)
4041
#define MAY_BE_ITERABLE (1 << IS_ITERABLE)
4142
#define MAY_BE_VOID (1 << IS_VOID)
4243

43-
#define MAY_BE_ARRAY_SHIFT (IS_VOID)
44+
#define MAY_BE_ARRAY_SHIFT (IS_REFERENCE)
4445

4546
#define MAY_BE_ARRAY_OF_NULL (MAY_BE_NULL << MAY_BE_ARRAY_SHIFT)
4647
#define MAY_BE_ARRAY_OF_FALSE (MAY_BE_FALSE << MAY_BE_ARRAY_SHIFT)
@@ -54,11 +55,10 @@
5455
#define MAY_BE_ARRAY_OF_ANY (MAY_BE_ANY << MAY_BE_ARRAY_SHIFT)
5556
#define MAY_BE_ARRAY_OF_REF (MAY_BE_REF << MAY_BE_ARRAY_SHIFT)
5657

57-
#define MAY_BE_ARRAY_KEY_LONG (1<<25)
58-
#define MAY_BE_ARRAY_KEY_STRING (1<<26)
58+
#define MAY_BE_ARRAY_KEY_LONG (1<<21)
59+
#define MAY_BE_ARRAY_KEY_STRING (1<<22)
5960
#define MAY_BE_ARRAY_KEY_ANY (MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_KEY_STRING)
6061

61-
/* Bit 27 unused */
62-
#define MAY_BE_CLASS (1<<28)
62+
#define MAY_BE_CLASS (1<<23)
6363

6464
#endif /* ZEND_TYPE_INFO_H */

Zend/zend_types.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ typedef struct {
137137

138138
#define _ZEND_TYPE_EXTRA_FLAGS_SHIFT 24
139139
#define _ZEND_TYPE_MASK ((1u << 24) - 1)
140-
#define _ZEND_TYPE_MAY_BE_MASK ((1u << (IS_VOID+1)) - 1)
141140
/* Only one of these bits may be set. */
142141
#define _ZEND_TYPE_NAME_BIT (1u << 23)
143142
#define _ZEND_TYPE_CE_BIT (1u << 22)
144143
#define _ZEND_TYPE_LIST_BIT (1u << 21)
145144
#define _ZEND_TYPE_KIND_MASK (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_CE_BIT|_ZEND_TYPE_NAME_BIT)
146145
/* Whether the type list is arena allocated */
147146
#define _ZEND_TYPE_ARENA_BIT (1u << 20)
147+
/* Type mask excluding the flags above. */
148+
#define _ZEND_TYPE_MAY_BE_MASK ((1u << 20) - 1)
148149
/* Must have same value as MAY_BE_NULL */
149150
#define _ZEND_TYPE_NULLABLE_BIT 0x2
150151

@@ -533,20 +534,21 @@ struct _zend_ast_ref {
533534
#define IS_REFERENCE 10
534535
#define IS_CONSTANT_AST 11 /* Constant expressions */
535536

536-
/* Fake types used only for type hinting. IS_VOID should be the last. */
537+
/* Fake types used only for type hinting.
538+
* These are allowed to overlap with the types below. */
537539
#define IS_CALLABLE 12
538540
#define IS_ITERABLE 13
539541
#define IS_VOID 14
540542

541543
/* internal types */
542-
#define IS_INDIRECT 15
543-
#define IS_PTR 16
544-
#define IS_ALIAS_PTR 17
545-
#define _IS_ERROR 17
544+
#define IS_INDIRECT 12
545+
#define IS_PTR 13
546+
#define IS_ALIAS_PTR 14
547+
#define _IS_ERROR 15
546548

547549
/* used for casts */
548-
#define _IS_BOOL 18
549-
#define _IS_NUMBER 19
550+
#define _IS_BOOL 16
551+
#define _IS_NUMBER 17
550552

551553
static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
552554
return pz->u1.v.type;

0 commit comments

Comments
 (0)