1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 2.00 of the Zend license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.zend.com/license/2_00.txt. |
11 | If you did not receive a copy of the Zend license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@zend.com so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 | Dmitry Stogov <dmitry@zend.com> |
18 | Xinchen Hui <xinchen.h@zend.com> |
19 +----------------------------------------------------------------------+
20 */
21
22 /* $Id$ */
23
24 #ifndef ZEND_TYPES_H
25 #define ZEND_TYPES_H
26
27 #include "zend_portability.h"
28 #include "zend_long.h"
29
30 #ifdef WORDS_BIGENDIAN
31 # define ZEND_ENDIAN_LOHI(lo, hi) hi; lo;
32 # define ZEND_ENDIAN_LOHI_3(lo, mi, hi) hi; mi; lo;
33 # define ZEND_ENDIAN_LOHI_4(a, b, c, d) d; c; b; a;
34 # define ZEND_ENDIAN_LOHI_C(lo, hi) hi, lo
35 # define ZEND_ENDIAN_LOHI_C_3(lo, mi, hi) hi, mi, lo,
36 # define ZEND_ENDIAN_LOHI_C_4(a, b, c, d) d, c, b, a
37 #else
38 # define ZEND_ENDIAN_LOHI(lo, hi) lo; hi;
39 # define ZEND_ENDIAN_LOHI_3(lo, mi, hi) lo; mi; hi;
40 # define ZEND_ENDIAN_LOHI_4(a, b, c, d) a; b; c; d;
41 # define ZEND_ENDIAN_LOHI_C(lo, hi) lo, hi
42 # define ZEND_ENDIAN_LOHI_C_3(lo, mi, hi) lo, mi, hi,
43 # define ZEND_ENDIAN_LOHI_C_4(a, b, c, d) a, b, c, d
44 #endif
45
46 typedef unsigned char zend_bool;
47 typedef unsigned char zend_uchar;
48
49 typedef enum {
50 SUCCESS = 0,
51 FAILURE = -1, /* this MUST stay a negative number, or it may affect functions! */
52 } ZEND_RESULT_CODE;
53
54 #ifdef ZEND_ENABLE_ZVAL_LONG64
55 # ifdef ZEND_WIN32
56 # define ZEND_SIZE_MAX _UI64_MAX
57 # else
58 # define ZEND_SIZE_MAX SIZE_MAX
59 # endif
60 #else
61 # if defined(ZEND_WIN32)
62 # define ZEND_SIZE_MAX _UI32_MAX
63 # else
64 # define ZEND_SIZE_MAX SIZE_MAX
65 # endif
66 #endif
67
68 typedef intptr_t zend_intptr_t;
69 typedef uintptr_t zend_uintptr_t;
70
71 #ifdef ZTS
72 #define ZEND_TLS static TSRM_TLS
73 #define ZEND_EXT_TLS TSRM_TLS
74 #else
75 #define ZEND_TLS static
76 #define ZEND_EXT_TLS
77 #endif
78
79 typedef struct _zend_object_handlers zend_object_handlers;
80 typedef struct _zend_class_entry zend_class_entry;
81 typedef union _zend_function zend_function;
82 typedef struct _zend_execute_data zend_execute_data;
83
84 typedef struct _zval_struct zval;
85
86 typedef struct _zend_refcounted zend_refcounted;
87 typedef struct _zend_string zend_string;
88 typedef struct _zend_array zend_array;
89 typedef struct _zend_object zend_object;
90 typedef struct _zend_resource zend_resource;
91 typedef struct _zend_reference zend_reference;
92 typedef struct _zend_ast_ref zend_ast_ref;
93 typedef struct _zend_ast zend_ast;
94
95 typedef int (*compare_func_t)(const void *, const void *);
96 typedef void (*swap_func_t)(void *, void *);
97 typedef void (*sort_func_t)(void *, size_t, size_t, compare_func_t, swap_func_t);
98 typedef void (*dtor_func_t)(zval *pDest);
99 typedef void (*copy_ctor_func_t)(zval *pElement);
100
101 /*
102 * zend_type - is an abstraction layer to represent information about type hint.
103 * It shouldn't be used directly. Only through ZEND_TYPE_* macros.
104 *
105 * ZEND_TYPE_IS_SET() - checks if type-hint exists
106 * ZEND_TYPE_IS_CODE() - checks if type-hint refer to standard type
107 * ZEND_TYPE_IS_CLASS() - checks if type-hint refer to some class
108 *
109 * ZEND_TYPE_NAME() - returns referenced class name
110 * ZEND_TYPE_CE() - returns referenced class entry
111 * ZEND_TYPE_CODE() - returns standard type code (e.g. IS_LONG, _IS_BOOL)
112 *
113 * ZEND_TYPE_ALLOW_NULL() - checks if NULL is allowed
114 *
115 * ZEND_TYPE_ENCODE() and ZEND_TYPE_ENCODE_CLASS() should be used for
116 * construction.
117 */
118
119 typedef uintptr_t zend_type;
120
121 #define ZEND_TYPE_IS_SET(t) \
122 ((t) > Z_L(1))
123
124 #define ZEND_TYPE_IS_CODE(t) \
125 (((t) > Z_L(1)) && ((t) <= Z_L(0x1ff)))
126
127 #define ZEND_TYPE_IS_CLASS(t) \
128 ((t) > Z_L(0x1ff))
129
130 #define ZEND_TYPE_NAME(t) \
131 ((zend_string*)((t) & ~Z_L(0x3)))
132
133 #define ZEND_TYPE_CE(t) \
134 ((zend_class_entry*)((t) & ~Z_L(0x3)))
135
136 #define ZEND_TYPE_CODE(t) \
137 ((t) >> Z_L(1))
138
139 #define ZEND_TYPE_ALLOW_NULL(t) \
140 (((t) & Z_L(0x1)) != 0)
141
142 #define ZEND_TYPE_ENCODE(code, allow_null) \
143 (((code) << Z_L(1)) | ((allow_null) ? Z_L(0x1) : Z_L(0x0)))
144
145 #define ZEND_TYPE_ENCODE_CLASS(class_name, allow_null) \
146 (((uintptr_t)(class_name)) | ((allow_null) ? Z_L(0x1) : Z_L(0)))
147
148 #define ZEND_TYPE_ENCODE_CLASS_CONST_0(class_name) \
149 ((zend_type) class_name)
150 #define ZEND_TYPE_ENCODE_CLASS_CONST_1(class_name) \
151 ((zend_type) "?" class_name)
152 #define ZEND_TYPE_ENCODE_CLASS_CONST_Q2(macro, class_name) \
153 macro(class_name)
154 #define ZEND_TYPE_ENCODE_CLASS_CONST_Q1(allow_null, class_name) \
155 ZEND_TYPE_ENCODE_CLASS_CONST_Q2(ZEND_TYPE_ENCODE_CLASS_CONST_ ##allow_null, class_name)
156 #define ZEND_TYPE_ENCODE_CLASS_CONST(class_name, allow_null) \
157 ZEND_TYPE_ENCODE_CLASS_CONST_Q1(allow_null, class_name)
158
159 typedef union _zend_value {
160 zend_long lval; /* long value */
161 double dval; /* double value */
162 zend_refcounted *counted;
163 zend_string *str;
164 zend_array *arr;
165 zend_object *obj;
166 zend_resource *res;
167 zend_reference *ref;
168 zend_ast_ref *ast;
169 zval *zv;
170 void *ptr;
171 zend_class_entry *ce;
172 zend_function *func;
173 struct {
174 uint32_t w1;
175 uint32_t w2;
176 } ww;
177 } zend_value;
178
179 struct _zval_struct {
180 zend_value value; /* value */
181 union {
182 struct {
183 ZEND_ENDIAN_LOHI_4(
184 zend_uchar type, /* active type */
185 zend_uchar type_flags,
186 zend_uchar const_flags,
187 zend_uchar reserved) /* call info for EX(This) */
188 } v;
189 uint32_t type_info;
190 } u1;
191 union {
192 uint32_t next; /* hash collision chain */
193 uint32_t cache_slot; /* literal cache slot */
194 uint32_t lineno; /* line number (for ast nodes) */
195 uint32_t num_args; /* arguments number for EX(This) */
196 uint32_t fe_pos; /* foreach position */
197 uint32_t fe_iter_idx; /* foreach iterator index */
198 uint32_t access_flags; /* class constant access flags */
199 uint32_t property_guard; /* single property guard */
200 uint32_t extra; /* not further specified */
201 } u2;
202 };
203
204 typedef struct _zend_refcounted_h {
205 uint32_t refcount; /* reference counter 32-bit */
206 union {
207 struct {
208 ZEND_ENDIAN_LOHI_3(
209 zend_uchar type,
210 zend_uchar flags, /* used for strings & objects */
211 uint16_t gc_info) /* keeps GC root number (or 0) and color */
212 } v;
213 uint32_t type_info;
214 } u;
215 } zend_refcounted_h;
216
217 struct _zend_refcounted {
218 zend_refcounted_h gc;
219 };
220
221 struct _zend_string {
222 zend_refcounted_h gc;
223 zend_ulong h; /* hash value */
224 size_t len;
225 char val[1];
226 };
227
228 typedef struct _Bucket {
229 zval val;
230 zend_ulong h; /* hash value (or numeric index) */
231 zend_string *key; /* string key or NULL for numerics */
232 } Bucket;
233
234 typedef struct _zend_array HashTable;
235
236 struct _zend_array {
237 zend_refcounted_h gc;
238 union {
239 struct {
240 ZEND_ENDIAN_LOHI_4(
241 zend_uchar flags,
242 zend_uchar nApplyCount,
243 zend_uchar nIteratorsCount,
244 zend_uchar consistency)
245 } v;
246 uint32_t flags;
247 } u;
248 uint32_t nTableMask;
249 Bucket *arData;
250 uint32_t nNumUsed;
251 uint32_t nNumOfElements;
252 uint32_t nTableSize;
253 uint32_t nInternalPointer;
254 zend_long nNextFreeElement;
255 dtor_func_t pDestructor;
256 };
257
258 /*
259 * HashTable Data Layout
260 * =====================
261 *
262 * +=============================+
263 * | HT_HASH(ht, ht->nTableMask) |
264 * | ... |
265 * | HT_HASH(ht, -1) |
266 * +-----------------------------+
267 * ht->arData ---> | Bucket[0] |
268 * | ... |
269 * | Bucket[ht->nTableSize-1] |
270 * +=============================+
271 */
272
273 #define HT_INVALID_IDX ((uint32_t) -1)
274
275 #define HT_MIN_MASK ((uint32_t) -2)
276 #define HT_MIN_SIZE 8
277
278 #if SIZEOF_SIZE_T == 4
279 # define HT_MAX_SIZE 0x04000000 /* small enough to avoid overflow checks */
280 # define HT_HASH_TO_BUCKET_EX(data, idx) \
281 ((Bucket*)((char*)(data) + (idx)))
282 # define HT_IDX_TO_HASH(idx) \
283 ((idx) * sizeof(Bucket))
284 # define HT_HASH_TO_IDX(idx) \
285 ((idx) / sizeof(Bucket))
286 #elif SIZEOF_SIZE_T == 8
287 # define HT_MAX_SIZE 0x80000000
288 # define HT_HASH_TO_BUCKET_EX(data, idx) \
289 ((data) + (idx))
290 # define HT_IDX_TO_HASH(idx) \
291 (idx)
292 # define HT_HASH_TO_IDX(idx) \
293 (idx)
294 #else
295 # error "Unknown SIZEOF_SIZE_T"
296 #endif
297
298 #define HT_HASH_EX(data, idx) \
299 ((uint32_t*)(data))[(int32_t)(idx)]
300 #define HT_HASH(ht, idx) \
301 HT_HASH_EX((ht)->arData, idx)
302
303 #define HT_HASH_SIZE(nTableMask) \
304 (((size_t)(uint32_t)-(int32_t)(nTableMask)) * sizeof(uint32_t))
305 #define HT_DATA_SIZE(nTableSize) \
306 ((size_t)(nTableSize) * sizeof(Bucket))
307 #define HT_SIZE_EX(nTableSize, nTableMask) \
308 (HT_DATA_SIZE((nTableSize)) + HT_HASH_SIZE((nTableMask)))
309 #define HT_SIZE(ht) \
310 HT_SIZE_EX((ht)->nTableSize, (ht)->nTableMask)
311 #define HT_USED_SIZE(ht) \
312 (HT_HASH_SIZE((ht)->nTableMask) + ((size_t)(ht)->nNumUsed * sizeof(Bucket)))
313 #define HT_HASH_RESET(ht) \
314 memset(&HT_HASH(ht, (ht)->nTableMask), HT_INVALID_IDX, HT_HASH_SIZE((ht)->nTableMask))
315 #define HT_HASH_RESET_PACKED(ht) do { \
316 HT_HASH(ht, -2) = HT_INVALID_IDX; \
317 HT_HASH(ht, -1) = HT_INVALID_IDX; \
318 } while (0)
319 #define HT_HASH_TO_BUCKET(ht, idx) \
320 HT_HASH_TO_BUCKET_EX((ht)->arData, idx)
321
322 #define HT_SET_DATA_ADDR(ht, ptr) do { \
323 (ht)->arData = (Bucket*)(((char*)(ptr)) + HT_HASH_SIZE((ht)->nTableMask)); \
324 } while (0)
325 #define HT_GET_DATA_ADDR(ht) \
326 ((char*)((ht)->arData) - HT_HASH_SIZE((ht)->nTableMask))
327
328 typedef uint32_t HashPosition;
329
330 typedef struct _HashTableIterator {
331 HashTable *ht;
332 HashPosition pos;
333 } HashTableIterator;
334
335 struct _zend_object {
336 zend_refcounted_h gc;
337 uint32_t handle; // TODO: may be removed ???
338 zend_class_entry *ce;
339 const zend_object_handlers *handlers;
340 HashTable *properties;
341 zval properties_table[1];
342 };
343
344 struct _zend_resource {
345 zend_refcounted_h gc;
346 int handle; // TODO: may be removed ???
347 int type;
348 void *ptr;
349 };
350
351 struct _zend_reference {
352 zend_refcounted_h gc;
353 zval val;
354 };
355
356 struct _zend_ast_ref {
357 zend_refcounted_h gc;
358 zend_ast *ast;
359 };
360
361 /* regular data types */
362 #define IS_UNDEF 0
363 #define IS_NULL 1
364 #define IS_FALSE 2
365 #define IS_TRUE 3
366 #define IS_LONG 4
367 #define IS_DOUBLE 5
368 #define IS_STRING 6
369 #define IS_ARRAY 7
370 #define IS_OBJECT 8
371 #define IS_RESOURCE 9
372 #define IS_REFERENCE 10
373
374 /* constant expressions */
375 #define IS_CONSTANT 11
376 #define IS_CONSTANT_AST 12
377
378 /* fake types */
379 #define _IS_BOOL 13
380 #define IS_CALLABLE 14
381 #define IS_ITERABLE 19
382 #define IS_VOID 18
383
384 /* internal types */
385 #define IS_INDIRECT 15
386 #define IS_PTR 17
387 #define _IS_ERROR 20
388
zval_get_type(const zval * pz)389 static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
390 return pz->u1.v.type;
391 }
392
393 #define ZEND_SAME_FAKE_TYPE(faketype, realtype) ( \
394 (faketype) == (realtype) \
395 || ((faketype) == _IS_BOOL && ((realtype) == IS_TRUE || (realtype) == IS_FALSE)) \
396 )
397
398 /* we should never set just Z_TYPE, we should set Z_TYPE_INFO */
399 #define Z_TYPE(zval) zval_get_type(&(zval))
400 #define Z_TYPE_P(zval_p) Z_TYPE(*(zval_p))
401
402 #define Z_TYPE_FLAGS(zval) (zval).u1.v.type_flags
403 #define Z_TYPE_FLAGS_P(zval_p) Z_TYPE_FLAGS(*(zval_p))
404
405 #define Z_CONST_FLAGS(zval) (zval).u1.v.const_flags
406 #define Z_CONST_FLAGS_P(zval_p) Z_CONST_FLAGS(*(zval_p))
407
408 #define Z_TYPE_INFO(zval) (zval).u1.type_info
409 #define Z_TYPE_INFO_P(zval_p) Z_TYPE_INFO(*(zval_p))
410
411 #define Z_NEXT(zval) (zval).u2.next
412 #define Z_NEXT_P(zval_p) Z_NEXT(*(zval_p))
413
414 #define Z_CACHE_SLOT(zval) (zval).u2.cache_slot
415 #define Z_CACHE_SLOT_P(zval_p) Z_CACHE_SLOT(*(zval_p))
416
417 #define Z_FE_POS(zval) (zval).u2.fe_pos
418 #define Z_FE_POS_P(zval_p) Z_FE_POS(*(zval_p))
419
420 #define Z_FE_ITER(zval) (zval).u2.fe_iter_idx
421 #define Z_FE_ITER_P(zval_p) Z_FE_ITER(*(zval_p))
422
423 #define Z_ACCESS_FLAGS(zval) (zval).u2.access_flags
424 #define Z_ACCESS_FLAGS_P(zval_p) Z_ACCESS_FLAGS(*(zval_p))
425
426 #define Z_EXTRA(zval) (zval).u2.extra
427 #define Z_EXTRA_P(zval_p) Z_EXTRA(*(zval_p))
428
429 #define Z_COUNTED(zval) (zval).value.counted
430 #define Z_COUNTED_P(zval_p) Z_COUNTED(*(zval_p))
431
432 #define Z_TYPE_MASK 0xff
433
434 #define Z_TYPE_FLAGS_SHIFT 8
435 #define Z_CONST_FLAGS_SHIFT 16
436
437 #define GC_REFCOUNT(p) (p)->gc.refcount
438 #define GC_TYPE(p) (p)->gc.u.v.type
439 #define GC_FLAGS(p) (p)->gc.u.v.flags
440 #define GC_INFO(p) (p)->gc.u.v.gc_info
441 #define GC_TYPE_INFO(p) (p)->gc.u.type_info
442
443 #define Z_GC_TYPE(zval) GC_TYPE(Z_COUNTED(zval))
444 #define Z_GC_TYPE_P(zval_p) Z_GC_TYPE(*(zval_p))
445
446 #define Z_GC_FLAGS(zval) GC_FLAGS(Z_COUNTED(zval))
447 #define Z_GC_FLAGS_P(zval_p) Z_GC_FLAGS(*(zval_p))
448
449 #define Z_GC_INFO(zval) GC_INFO(Z_COUNTED(zval))
450 #define Z_GC_INFO_P(zval_p) Z_GC_INFO(*(zval_p))
451 #define Z_GC_TYPE_INFO(zval) GC_TYPE_INFO(Z_COUNTED(zval))
452 #define Z_GC_TYPE_INFO_P(zval_p) Z_GC_TYPE_INFO(*(zval_p))
453
454 #define GC_FLAGS_SHIFT 8
455 #define GC_INFO_SHIFT 16
456 #define GC_INFO_MASK 0xffff0000
457
458 /* zval.value->gc.u.v.flags */
459 #define GC_COLLECTABLE (1<<7)
460
461 #define GC_ARRAY (IS_ARRAY | (GC_COLLECTABLE << GC_FLAGS_SHIFT))
462 #define GC_OBJECT (IS_OBJECT | (GC_COLLECTABLE << GC_FLAGS_SHIFT))
463
464 /* zval.u1.v.type_flags */
465 #define IS_TYPE_CONSTANT (1<<0)
466 #define IS_TYPE_REFCOUNTED (1<<2)
467 #define IS_TYPE_COPYABLE (1<<4)
468
469 /* extended types */
470 #define IS_INTERNED_STRING_EX IS_STRING
471
472 #define IS_STRING_EX (IS_STRING | (( IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT))
473 #define IS_ARRAY_EX (IS_ARRAY | (( IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT))
474 #define IS_OBJECT_EX (IS_OBJECT | (( IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
475 #define IS_RESOURCE_EX (IS_RESOURCE | (( IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
476 #define IS_REFERENCE_EX (IS_REFERENCE | (( IS_TYPE_REFCOUNTED ) << Z_TYPE_FLAGS_SHIFT))
477
478 #define IS_CONSTANT_EX (IS_CONSTANT | ((IS_TYPE_CONSTANT | IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT))
479 #define IS_CONSTANT_AST_EX (IS_CONSTANT_AST | ((IS_TYPE_CONSTANT | IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT))
480
481 /* zval.u1.v.const_flags */
482 #define IS_CONSTANT_UNQUALIFIED 0x010
483 #define IS_CONSTANT_VISITED_MARK 0x020
484 #define IS_CONSTANT_CLASS 0x080 /* __CLASS__ in trait */
485 #define IS_CONSTANT_IN_NAMESPACE 0x100 /* used only in opline->extended_value */
486
487 #define IS_CONSTANT_VISITED(p) (Z_CONST_FLAGS_P(p) & IS_CONSTANT_VISITED_MARK)
488 #define MARK_CONSTANT_VISITED(p) Z_CONST_FLAGS_P(p) |= IS_CONSTANT_VISITED_MARK
489 #define RESET_CONSTANT_VISITED(p) Z_CONST_FLAGS_P(p) &= ~IS_CONSTANT_VISITED_MARK
490
491 /* string flags (zval.value->gc.u.flags) */
492 #define IS_STR_PERSISTENT (1<<0) /* allocated using malloc */
493 #define IS_STR_INTERNED (1<<1) /* interned string */
494 #define IS_STR_PERMANENT (1<<2) /* relives request boundary */
495
496 #define IS_STR_CONSTANT (1<<3) /* constant index */
497 #define IS_STR_CONSTANT_UNQUALIFIED (1<<4) /* the same as IS_CONSTANT_UNQUALIFIED */
498
499 /* array flags */
500 #define IS_ARRAY_IMMUTABLE (1<<1)
501
502 /* object flags (zval.value->gc.u.flags) */
503 #define IS_OBJ_APPLY_COUNT 0x07
504 #define IS_OBJ_DESTRUCTOR_CALLED (1<<3)
505 #define IS_OBJ_FREE_CALLED (1<<4)
506 #define IS_OBJ_USE_GUARDS (1<<5)
507 #define IS_OBJ_HAS_GUARDS (1<<6)
508
509 #define Z_OBJ_APPLY_COUNT(zval) \
510 (Z_GC_FLAGS(zval) & IS_OBJ_APPLY_COUNT)
511
512 #define Z_OBJ_INC_APPLY_COUNT(zval) do { \
513 Z_GC_FLAGS(zval) = \
514 (Z_GC_FLAGS(zval) & ~IS_OBJ_APPLY_COUNT) | \
515 ((Z_GC_FLAGS(zval) & IS_OBJ_APPLY_COUNT) + 1); \
516 } while (0)
517
518 #define Z_OBJ_DEC_APPLY_COUNT(zval) do { \
519 Z_GC_FLAGS(zval) = \
520 (Z_GC_FLAGS(zval) & ~IS_OBJ_APPLY_COUNT) | \
521 ((Z_GC_FLAGS(zval) & IS_OBJ_APPLY_COUNT) - 1); \
522 } while (0)
523
524 #define Z_OBJ_APPLY_COUNT_P(zv) Z_OBJ_APPLY_COUNT(*(zv))
525 #define Z_OBJ_INC_APPLY_COUNT_P(zv) Z_OBJ_INC_APPLY_COUNT(*(zv))
526 #define Z_OBJ_DEC_APPLY_COUNT_P(zv) Z_OBJ_DEC_APPLY_COUNT(*(zv))
527
528 /* All data types < IS_STRING have their constructor/destructors skipped */
529 #define Z_CONSTANT(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_CONSTANT) != 0)
530 #define Z_CONSTANT_P(zval_p) Z_CONSTANT(*(zval_p))
531
532 #define Z_REFCOUNTED(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_REFCOUNTED) != 0)
533 #define Z_REFCOUNTED_P(zval_p) Z_REFCOUNTED(*(zval_p))
534
535 #define Z_COPYABLE(zval) ((Z_TYPE_FLAGS(zval) & IS_TYPE_COPYABLE) != 0)
536 #define Z_COPYABLE_P(zval_p) Z_COPYABLE(*(zval_p))
537
538 /* deprecated: (IMMUTABLE is the same as COPYABLE && !REFCOUED) */
539 #define Z_IMMUTABLE(zval) ((Z_TYPE_FLAGS(zval) & (IS_TYPE_REFCOUNTED|IS_TYPE_COPYABLE)) == IS_TYPE_COPYABLE)
540 #define Z_IMMUTABLE_P(zval_p) Z_IMMUTABLE(*(zval_p))
541 #define Z_OPT_IMMUTABLE(zval) Z_IMMUTABLE(zval_p)
542 #define Z_OPT_IMMUTABLE_P(zval_p) Z_IMMUTABLE(*(zval_p))
543
544 /* the following Z_OPT_* macros make better code when Z_TYPE_INFO accessed before */
545 #define Z_OPT_TYPE(zval) (Z_TYPE_INFO(zval) & Z_TYPE_MASK)
546 #define Z_OPT_TYPE_P(zval_p) Z_OPT_TYPE(*(zval_p))
547
548 #define Z_OPT_CONSTANT(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_CONSTANT << Z_TYPE_FLAGS_SHIFT)) != 0)
549 #define Z_OPT_CONSTANT_P(zval_p) Z_OPT_CONSTANT(*(zval_p))
550
551 #define Z_OPT_REFCOUNTED(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) != 0)
552 #define Z_OPT_REFCOUNTED_P(zval_p) Z_OPT_REFCOUNTED(*(zval_p))
553
554 #define Z_OPT_COPYABLE(zval) ((Z_TYPE_INFO(zval) & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0)
555 #define Z_OPT_COPYABLE_P(zval_p) Z_OPT_COPYABLE(*(zval_p))
556
557 #define Z_OPT_ISREF(zval) (Z_OPT_TYPE(zval) == IS_REFERENCE)
558 #define Z_OPT_ISREF_P(zval_p) Z_OPT_ISREF(*(zval_p))
559
560 #define Z_ISREF(zval) (Z_TYPE(zval) == IS_REFERENCE)
561 #define Z_ISREF_P(zval_p) Z_ISREF(*(zval_p))
562
563 #define Z_ISUNDEF(zval) (Z_TYPE(zval) == IS_UNDEF)
564 #define Z_ISUNDEF_P(zval_p) Z_ISUNDEF(*(zval_p))
565
566 #define Z_ISNULL(zval) (Z_TYPE(zval) == IS_NULL)
567 #define Z_ISNULL_P(zval_p) Z_ISNULL(*(zval_p))
568
569 #define Z_ISERROR(zval) (Z_TYPE(zval) == _IS_ERROR)
570 #define Z_ISERROR_P(zval_p) Z_ISERROR(*(zval_p))
571
572 #define Z_LVAL(zval) (zval).value.lval
573 #define Z_LVAL_P(zval_p) Z_LVAL(*(zval_p))
574
575 #define Z_DVAL(zval) (zval).value.dval
576 #define Z_DVAL_P(zval_p) Z_DVAL(*(zval_p))
577
578 #define Z_STR(zval) (zval).value.str
579 #define Z_STR_P(zval_p) Z_STR(*(zval_p))
580
581 #define Z_STRVAL(zval) ZSTR_VAL(Z_STR(zval))
582 #define Z_STRVAL_P(zval_p) Z_STRVAL(*(zval_p))
583
584 #define Z_STRLEN(zval) ZSTR_LEN(Z_STR(zval))
585 #define Z_STRLEN_P(zval_p) Z_STRLEN(*(zval_p))
586
587 #define Z_STRHASH(zval) ZSTR_HASH(Z_STR(zval))
588 #define Z_STRHASH_P(zval_p) Z_STRHASH(*(zval_p))
589
590 #define Z_ARR(zval) (zval).value.arr
591 #define Z_ARR_P(zval_p) Z_ARR(*(zval_p))
592
593 #define Z_ARRVAL(zval) Z_ARR(zval)
594 #define Z_ARRVAL_P(zval_p) Z_ARRVAL(*(zval_p))
595
596 #define Z_OBJ(zval) (zval).value.obj
597 #define Z_OBJ_P(zval_p) Z_OBJ(*(zval_p))
598
599 #define Z_OBJ_HT(zval) Z_OBJ(zval)->handlers
600 #define Z_OBJ_HT_P(zval_p) Z_OBJ_HT(*(zval_p))
601
602 #define Z_OBJ_HANDLER(zval, hf) Z_OBJ_HT((zval))->hf
603 #define Z_OBJ_HANDLER_P(zv_p, hf) Z_OBJ_HANDLER(*(zv_p), hf)
604
605 #define Z_OBJ_HANDLE(zval) (Z_OBJ((zval)))->handle
606 #define Z_OBJ_HANDLE_P(zval_p) Z_OBJ_HANDLE(*(zval_p))
607
608 #define Z_OBJCE(zval) (Z_OBJ(zval)->ce)
609 #define Z_OBJCE_P(zval_p) Z_OBJCE(*(zval_p))
610
611 #define Z_OBJPROP(zval) Z_OBJ_HT((zval))->get_properties(&(zval))
612 #define Z_OBJPROP_P(zval_p) Z_OBJPROP(*(zval_p))
613
614 #define Z_OBJDEBUG(zval,tmp) (Z_OBJ_HANDLER((zval),get_debug_info)?Z_OBJ_HANDLER((zval),get_debug_info)(&(zval),&tmp):(tmp=0,Z_OBJ_HANDLER((zval),get_properties)?Z_OBJPROP(zval):NULL))
615 #define Z_OBJDEBUG_P(zval_p,tmp) Z_OBJDEBUG(*(zval_p), tmp)
616
617 #define Z_RES(zval) (zval).value.res
618 #define Z_RES_P(zval_p) Z_RES(*zval_p)
619
620 #define Z_RES_HANDLE(zval) Z_RES(zval)->handle
621 #define Z_RES_HANDLE_P(zval_p) Z_RES_HANDLE(*zval_p)
622
623 #define Z_RES_TYPE(zval) Z_RES(zval)->type
624 #define Z_RES_TYPE_P(zval_p) Z_RES_TYPE(*zval_p)
625
626 #define Z_RES_VAL(zval) Z_RES(zval)->ptr
627 #define Z_RES_VAL_P(zval_p) Z_RES_VAL(*zval_p)
628
629 #define Z_REF(zval) (zval).value.ref
630 #define Z_REF_P(zval_p) Z_REF(*(zval_p))
631
632 #define Z_REFVAL(zval) &Z_REF(zval)->val
633 #define Z_REFVAL_P(zval_p) Z_REFVAL(*(zval_p))
634
635 #define Z_AST(zval) (zval).value.ast
636 #define Z_AST_P(zval_p) Z_AST(*(zval_p))
637
638 #define Z_ASTVAL(zval) (zval).value.ast->ast
639 #define Z_ASTVAL_P(zval_p) Z_ASTVAL(*(zval_p))
640
641 #define Z_INDIRECT(zval) (zval).value.zv
642 #define Z_INDIRECT_P(zval_p) Z_INDIRECT(*(zval_p))
643
644 #define Z_CE(zval) (zval).value.ce
645 #define Z_CE_P(zval_p) Z_CE(*(zval_p))
646
647 #define Z_FUNC(zval) (zval).value.func
648 #define Z_FUNC_P(zval_p) Z_FUNC(*(zval_p))
649
650 #define Z_PTR(zval) (zval).value.ptr
651 #define Z_PTR_P(zval_p) Z_PTR(*(zval_p))
652
653 #define ZVAL_UNDEF(z) do { \
654 Z_TYPE_INFO_P(z) = IS_UNDEF; \
655 } while (0)
656
657 #define ZVAL_NULL(z) do { \
658 Z_TYPE_INFO_P(z) = IS_NULL; \
659 } while (0)
660
661 #define ZVAL_FALSE(z) do { \
662 Z_TYPE_INFO_P(z) = IS_FALSE; \
663 } while (0)
664
665 #define ZVAL_TRUE(z) do { \
666 Z_TYPE_INFO_P(z) = IS_TRUE; \
667 } while (0)
668
669 #define ZVAL_BOOL(z, b) do { \
670 Z_TYPE_INFO_P(z) = \
671 (b) ? IS_TRUE : IS_FALSE; \
672 } while (0)
673
674 #define ZVAL_LONG(z, l) { \
675 zval *__z = (z); \
676 Z_LVAL_P(__z) = l; \
677 Z_TYPE_INFO_P(__z) = IS_LONG; \
678 }
679
680 #define ZVAL_DOUBLE(z, d) { \
681 zval *__z = (z); \
682 Z_DVAL_P(__z) = d; \
683 Z_TYPE_INFO_P(__z) = IS_DOUBLE; \
684 }
685
686 #define ZVAL_STR(z, s) do { \
687 zval *__z = (z); \
688 zend_string *__s = (s); \
689 Z_STR_P(__z) = __s; \
690 /* interned strings support */ \
691 Z_TYPE_INFO_P(__z) = ZSTR_IS_INTERNED(__s) ? \
692 IS_INTERNED_STRING_EX : \
693 IS_STRING_EX; \
694 } while (0)
695
696 #define ZVAL_INTERNED_STR(z, s) do { \
697 zval *__z = (z); \
698 zend_string *__s = (s); \
699 Z_STR_P(__z) = __s; \
700 Z_TYPE_INFO_P(__z) = IS_INTERNED_STRING_EX; \
701 } while (0)
702
703 #define ZVAL_NEW_STR(z, s) do { \
704 zval *__z = (z); \
705 zend_string *__s = (s); \
706 Z_STR_P(__z) = __s; \
707 Z_TYPE_INFO_P(__z) = IS_STRING_EX; \
708 } while (0)
709
710 #define ZVAL_STR_COPY(z, s) do { \
711 zval *__z = (z); \
712 zend_string *__s = (s); \
713 Z_STR_P(__z) = __s; \
714 /* interned strings support */ \
715 if (ZSTR_IS_INTERNED(__s)) { \
716 Z_TYPE_INFO_P(__z) = IS_INTERNED_STRING_EX; \
717 } else { \
718 GC_REFCOUNT(__s)++; \
719 Z_TYPE_INFO_P(__z) = IS_STRING_EX; \
720 } \
721 } while (0)
722
723 #define ZVAL_ARR(z, a) do { \
724 zval *__z = (z); \
725 Z_ARR_P(__z) = (a); \
726 Z_TYPE_INFO_P(__z) = IS_ARRAY_EX; \
727 } while (0)
728
729 #define ZVAL_NEW_ARR(z) do { \
730 zval *__z = (z); \
731 zend_array *_arr = \
732 (zend_array *) emalloc(sizeof(zend_array)); \
733 Z_ARR_P(__z) = _arr; \
734 Z_TYPE_INFO_P(__z) = IS_ARRAY_EX; \
735 } while (0)
736
737 #define ZVAL_NEW_PERSISTENT_ARR(z) do { \
738 zval *__z = (z); \
739 zend_array *_arr = \
740 (zend_array *) malloc(sizeof(zend_array)); \
741 Z_ARR_P(__z) = _arr; \
742 Z_TYPE_INFO_P(__z) = IS_ARRAY_EX; \
743 } while (0)
744
745 #define ZVAL_OBJ(z, o) do { \
746 zval *__z = (z); \
747 Z_OBJ_P(__z) = (o); \
748 Z_TYPE_INFO_P(__z) = IS_OBJECT_EX; \
749 } while (0)
750
751 #define ZVAL_RES(z, r) do { \
752 zval *__z = (z); \
753 Z_RES_P(__z) = (r); \
754 Z_TYPE_INFO_P(__z) = IS_RESOURCE_EX; \
755 } while (0)
756
757 #define ZVAL_NEW_RES(z, h, p, t) do { \
758 zend_resource *_res = \
759 (zend_resource *) emalloc(sizeof(zend_resource)); \
760 zval *__z; \
761 GC_REFCOUNT(_res) = 1; \
762 GC_TYPE_INFO(_res) = IS_RESOURCE; \
763 _res->handle = (h); \
764 _res->type = (t); \
765 _res->ptr = (p); \
766 __z = (z); \
767 Z_RES_P(__z) = _res; \
768 Z_TYPE_INFO_P(__z) = IS_RESOURCE_EX; \
769 } while (0)
770
771 #define ZVAL_NEW_PERSISTENT_RES(z, h, p, t) do { \
772 zend_resource *_res = \
773 (zend_resource *) malloc(sizeof(zend_resource)); \
774 zval *__z; \
775 GC_REFCOUNT(_res) = 1; \
776 GC_TYPE_INFO(_res) = IS_RESOURCE; \
777 _res->handle = (h); \
778 _res->type = (t); \
779 _res->ptr = (p); \
780 __z = (z); \
781 Z_RES_P(__z) = _res; \
782 Z_TYPE_INFO_P(__z) = IS_RESOURCE_EX; \
783 } while (0)
784
785 #define ZVAL_REF(z, r) do { \
786 zval *__z = (z); \
787 Z_REF_P(__z) = (r); \
788 Z_TYPE_INFO_P(__z) = IS_REFERENCE_EX; \
789 } while (0)
790
791 #define ZVAL_NEW_EMPTY_REF(z) do { \
792 zend_reference *_ref = \
793 (zend_reference *) emalloc(sizeof(zend_reference)); \
794 GC_REFCOUNT(_ref) = 1; \
795 GC_TYPE_INFO(_ref) = IS_REFERENCE; \
796 Z_REF_P(z) = _ref; \
797 Z_TYPE_INFO_P(z) = IS_REFERENCE_EX; \
798 } while (0)
799
800 #define ZVAL_NEW_REF(z, r) do { \
801 zend_reference *_ref = \
802 (zend_reference *) emalloc(sizeof(zend_reference)); \
803 GC_REFCOUNT(_ref) = 1; \
804 GC_TYPE_INFO(_ref) = IS_REFERENCE; \
805 ZVAL_COPY_VALUE(&_ref->val, r); \
806 Z_REF_P(z) = _ref; \
807 Z_TYPE_INFO_P(z) = IS_REFERENCE_EX; \
808 } while (0)
809
810 #define ZVAL_NEW_PERSISTENT_REF(z, r) do { \
811 zend_reference *_ref = \
812 (zend_reference *) malloc(sizeof(zend_reference)); \
813 GC_REFCOUNT(_ref) = 1; \
814 GC_TYPE_INFO(_ref) = IS_REFERENCE; \
815 ZVAL_COPY_VALUE(&_ref->val, r); \
816 Z_REF_P(z) = _ref; \
817 Z_TYPE_INFO_P(z) = IS_REFERENCE_EX; \
818 } while (0)
819
820 #define ZVAL_NEW_AST(z, a) do { \
821 zval *__z = (z); \
822 zend_ast_ref *_ast = \
823 (zend_ast_ref *) emalloc(sizeof(zend_ast_ref)); \
824 GC_REFCOUNT(_ast) = 1; \
825 GC_TYPE_INFO(_ast) = IS_CONSTANT_AST; \
826 _ast->ast = (a); \
827 Z_AST_P(__z) = _ast; \
828 Z_TYPE_INFO_P(__z) = IS_CONSTANT_AST_EX; \
829 } while (0)
830
831 #define ZVAL_INDIRECT(z, v) do { \
832 Z_INDIRECT_P(z) = (v); \
833 Z_TYPE_INFO_P(z) = IS_INDIRECT; \
834 } while (0)
835
836 #define ZVAL_PTR(z, p) do { \
837 Z_PTR_P(z) = (p); \
838 Z_TYPE_INFO_P(z) = IS_PTR; \
839 } while (0)
840
841 #define ZVAL_FUNC(z, f) do { \
842 Z_FUNC_P(z) = (f); \
843 Z_TYPE_INFO_P(z) = IS_PTR; \
844 } while (0)
845
846 #define ZVAL_CE(z, c) do { \
847 Z_CE_P(z) = (c); \
848 Z_TYPE_INFO_P(z) = IS_PTR; \
849 } while (0)
850
851 #define ZVAL_ERROR(z) do { \
852 Z_TYPE_INFO_P(z) = _IS_ERROR; \
853 } while (0)
854
855 #define Z_REFCOUNT_P(pz) zval_refcount_p(pz)
856 #define Z_SET_REFCOUNT_P(pz, rc) zval_set_refcount_p(pz, rc)
857 #define Z_ADDREF_P(pz) zval_addref_p(pz)
858 #define Z_DELREF_P(pz) zval_delref_p(pz)
859
860 #define Z_REFCOUNT(z) Z_REFCOUNT_P(&(z))
861 #define Z_SET_REFCOUNT(z, rc) Z_SET_REFCOUNT_P(&(z), rc)
862 #define Z_ADDREF(z) Z_ADDREF_P(&(z))
863 #define Z_DELREF(z) Z_DELREF_P(&(z))
864
865 #define Z_TRY_ADDREF_P(pz) do { \
866 if (Z_REFCOUNTED_P((pz))) { \
867 Z_ADDREF_P((pz)); \
868 } \
869 } while (0)
870
871 #define Z_TRY_DELREF_P(pz) do { \
872 if (Z_REFCOUNTED_P((pz))) { \
873 Z_DELREF_P((pz)); \
874 } \
875 } while (0)
876
877 #define Z_TRY_ADDREF(z) Z_TRY_ADDREF_P(&(z))
878 #define Z_TRY_DELREF(z) Z_TRY_DELREF_P(&(z))
879
zval_refcount_p(zval * pz)880 static zend_always_inline uint32_t zval_refcount_p(zval* pz) {
881 ZEND_ASSERT(Z_REFCOUNTED_P(pz) || Z_COPYABLE_P(pz));
882 return GC_REFCOUNT(Z_COUNTED_P(pz));
883 }
884
zval_set_refcount_p(zval * pz,uint32_t rc)885 static zend_always_inline uint32_t zval_set_refcount_p(zval* pz, uint32_t rc) {
886 ZEND_ASSERT(Z_REFCOUNTED_P(pz));
887 return GC_REFCOUNT(Z_COUNTED_P(pz)) = rc;
888 }
889
zval_addref_p(zval * pz)890 static zend_always_inline uint32_t zval_addref_p(zval* pz) {
891 ZEND_ASSERT(Z_REFCOUNTED_P(pz));
892 return ++GC_REFCOUNT(Z_COUNTED_P(pz));
893 }
894
zval_delref_p(zval * pz)895 static zend_always_inline uint32_t zval_delref_p(zval* pz) {
896 ZEND_ASSERT(Z_REFCOUNTED_P(pz));
897 return --GC_REFCOUNT(Z_COUNTED_P(pz));
898 }
899
900 #if SIZEOF_SIZE_T == 4
901 # define ZVAL_COPY_VALUE_EX(z, v, gc, t) \
902 do { \
903 uint32_t _w2 = v->value.ww.w2; \
904 Z_COUNTED_P(z) = gc; \
905 z->value.ww.w2 = _w2; \
906 Z_TYPE_INFO_P(z) = t; \
907 } while (0)
908 #elif SIZEOF_SIZE_T == 8
909 # define ZVAL_COPY_VALUE_EX(z, v, gc, t) \
910 do { \
911 Z_COUNTED_P(z) = gc; \
912 Z_TYPE_INFO_P(z) = t; \
913 } while (0)
914 #else
915 # error "Unknown SIZEOF_SIZE_T"
916 #endif
917
918 #define ZVAL_COPY_VALUE(z, v) \
919 do { \
920 zval *_z1 = (z); \
921 const zval *_z2 = (v); \
922 zend_refcounted *_gc = Z_COUNTED_P(_z2); \
923 uint32_t _t = Z_TYPE_INFO_P(_z2); \
924 ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
925 } while (0)
926
927 #define ZVAL_COPY(z, v) \
928 do { \
929 zval *_z1 = (z); \
930 const zval *_z2 = (v); \
931 zend_refcounted *_gc = Z_COUNTED_P(_z2); \
932 uint32_t _t = Z_TYPE_INFO_P(_z2); \
933 ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
934 if ((_t & (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT)) != 0) { \
935 GC_REFCOUNT(_gc)++; \
936 } \
937 } while (0)
938
939 #define ZVAL_DUP(z, v) \
940 do { \
941 zval *_z1 = (z); \
942 const zval *_z2 = (v); \
943 zend_refcounted *_gc = Z_COUNTED_P(_z2); \
944 uint32_t _t = Z_TYPE_INFO_P(_z2); \
945 ZVAL_COPY_VALUE_EX(_z1, _z2, _gc, _t); \
946 if ((_t & ((IS_TYPE_REFCOUNTED|IS_TYPE_COPYABLE) << Z_TYPE_FLAGS_SHIFT)) != 0) { \
947 if ((_t & (IS_TYPE_COPYABLE << Z_TYPE_FLAGS_SHIFT)) != 0) { \
948 _zval_copy_ctor_func(_z1 ZEND_FILE_LINE_CC); \
949 } else { \
950 GC_REFCOUNT(_gc)++; \
951 } \
952 } \
953 } while (0)
954
955 #define ZVAL_DEREF(z) do { \
956 if (UNEXPECTED(Z_ISREF_P(z))) { \
957 (z) = Z_REFVAL_P(z); \
958 } \
959 } while (0)
960
961 #define ZVAL_OPT_DEREF(z) do { \
962 if (UNEXPECTED(Z_OPT_ISREF_P(z))) { \
963 (z) = Z_REFVAL_P(z); \
964 } \
965 } while (0)
966
967 #define ZVAL_MAKE_REF(zv) do { \
968 zval *__zv = (zv); \
969 if (!Z_ISREF_P(__zv)) { \
970 ZVAL_NEW_REF(__zv, __zv); \
971 } \
972 } while (0)
973
974 #define ZVAL_UNREF(z) do { \
975 zval *_z = (z); \
976 zend_reference *ref; \
977 ZEND_ASSERT(Z_ISREF_P(_z)); \
978 ref = Z_REF_P(_z); \
979 ZVAL_COPY_VALUE(_z, &ref->val); \
980 efree_size(ref, sizeof(zend_reference)); \
981 } while (0)
982
983 #define ZVAL_COPY_UNREF(z, v) do { \
984 zval *_z3 = (v); \
985 if (Z_OPT_REFCOUNTED_P(_z3)) { \
986 if (UNEXPECTED(Z_OPT_ISREF_P(_z3)) \
987 && UNEXPECTED(Z_REFCOUNT_P(_z3) == 1)) { \
988 ZVAL_UNREF(_z3); \
989 if (Z_OPT_REFCOUNTED_P(_z3)) { \
990 Z_ADDREF_P(_z3); \
991 } \
992 } else { \
993 Z_ADDREF_P(_z3); \
994 } \
995 } \
996 ZVAL_COPY_VALUE(z, _z3); \
997 } while (0)
998
999
1000 #define SEPARATE_STRING(zv) do { \
1001 zval *_zv = (zv); \
1002 if (Z_REFCOUNT_P(_zv) > 1) { \
1003 if (Z_REFCOUNTED_P(_zv)) { \
1004 Z_DELREF_P(_zv); \
1005 } \
1006 zval_copy_ctor_func(_zv); \
1007 } \
1008 } while (0)
1009
1010 #define SEPARATE_ARRAY(zv) do { \
1011 zval *_zv = (zv); \
1012 zend_array *_arr = Z_ARR_P(_zv); \
1013 if (UNEXPECTED(GC_REFCOUNT(_arr) > 1)) { \
1014 if (Z_REFCOUNTED_P(_zv)) { \
1015 GC_REFCOUNT(_arr)--; \
1016 } \
1017 ZVAL_ARR(_zv, zend_array_dup(_arr)); \
1018 } \
1019 } while (0)
1020
1021 #define SEPARATE_ZVAL_NOREF(zv) do { \
1022 zval *_zv = (zv); \
1023 ZEND_ASSERT(Z_TYPE_P(_zv) != IS_REFERENCE); \
1024 if (Z_COPYABLE_P(_zv)) { \
1025 if (Z_REFCOUNT_P(_zv) > 1) { \
1026 if (Z_REFCOUNTED_P(_zv)) { \
1027 Z_DELREF_P(_zv); \
1028 } \
1029 zval_copy_ctor_func(_zv); \
1030 } \
1031 } \
1032 } while (0)
1033
1034 #define SEPARATE_ZVAL(zv) do { \
1035 zval *_zv = (zv); \
1036 if (Z_REFCOUNTED_P(_zv) || \
1037 Z_COPYABLE_P(_zv)) { \
1038 if (Z_REFCOUNT_P(_zv) > 1) { \
1039 if (Z_COPYABLE_P(_zv)) { \
1040 if (Z_REFCOUNTED_P(_zv)) { \
1041 Z_DELREF_P(_zv); \
1042 } \
1043 zval_copy_ctor_func(_zv); \
1044 } else if (Z_ISREF_P(_zv)) { \
1045 Z_DELREF_P(_zv); \
1046 ZVAL_DUP(_zv, Z_REFVAL_P(_zv)); \
1047 } \
1048 } \
1049 } \
1050 } while (0)
1051
1052 #define SEPARATE_ZVAL_IF_NOT_REF(zv) do { \
1053 zval *_zv = (zv); \
1054 if (Z_COPYABLE_P(_zv)) { \
1055 if (Z_REFCOUNT_P(_zv) > 1) { \
1056 if (Z_REFCOUNTED_P(_zv)) { \
1057 Z_DELREF_P(_zv); \
1058 } \
1059 zval_copy_ctor_func(_zv); \
1060 } \
1061 } \
1062 } while (0)
1063
1064 #define SEPARATE_ARG_IF_REF(varptr) do { \
1065 ZVAL_DEREF(varptr); \
1066 if (Z_REFCOUNTED_P(varptr)) { \
1067 Z_ADDREF_P(varptr); \
1068 } \
1069 } while (0)
1070
1071 #endif /* ZEND_TYPES_H */
1072
1073 /*
1074 * Local variables:
1075 * tab-width: 4
1076 * c-basic-offset: 4
1077 * indent-tabs-mode: t
1078 * End:
1079 * vim600: sw=4 ts=4 fdm=marker
1080 * vim<600: sw=4 ts=4
1081 */
1082