xref: /PHP-7.4/Zend/zend_variables.h (revision 92ac598a)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 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@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    |          Dmitry Stogov <dmitry@php.net>                              |
18    +----------------------------------------------------------------------+
19 */
20 
21 #ifndef ZEND_VARIABLES_H
22 #define ZEND_VARIABLES_H
23 
24 #include "zend_types.h"
25 #include "zend_gc.h"
26 
27 BEGIN_EXTERN_C()
28 
29 ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p);
30 ZEND_API void ZEND_FASTCALL zval_copy_ctor_func(zval *zvalue);
31 
zval_ptr_dtor_nogc(zval * zval_ptr)32 static zend_always_inline void zval_ptr_dtor_nogc(zval *zval_ptr)
33 {
34 	if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
35 		rc_dtor_func(Z_COUNTED_P(zval_ptr));
36 	}
37 }
38 
i_zval_ptr_dtor(zval * zval_ptr)39 static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr)
40 {
41 	if (Z_REFCOUNTED_P(zval_ptr)) {
42 		zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
43 		if (!GC_DELREF(ref)) {
44 			rc_dtor_func(ref);
45 		} else {
46 			gc_check_possible_root(ref);
47 		}
48 	}
49 }
50 
zval_copy_ctor(zval * zvalue)51 static zend_always_inline void zval_copy_ctor(zval *zvalue)
52 {
53 	if (Z_TYPE_P(zvalue) == IS_ARRAY) {
54 		ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
55 	} else if (Z_REFCOUNTED_P(zvalue)) {
56 		Z_ADDREF_P(zvalue);
57 	}
58 }
59 
zval_opt_copy_ctor(zval * zvalue)60 static zend_always_inline void zval_opt_copy_ctor(zval *zvalue)
61 {
62 	if (Z_OPT_TYPE_P(zvalue) == IS_ARRAY) {
63 		ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
64 	} else if (Z_OPT_REFCOUNTED_P(zvalue)) {
65 		Z_ADDREF_P(zvalue);
66 	}
67 }
68 
zval_ptr_dtor_str(zval * zval_ptr)69 static zend_always_inline void zval_ptr_dtor_str(zval *zval_ptr)
70 {
71 	if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
72 		ZEND_ASSERT(Z_TYPE_P(zval_ptr) == IS_STRING);
73 		ZEND_ASSERT(!ZSTR_IS_INTERNED(Z_STR_P(zval_ptr)));
74 		ZEND_ASSERT(!(GC_FLAGS(Z_STR_P(zval_ptr)) & IS_STR_PERSISTENT));
75 		efree(Z_STR_P(zval_ptr));
76 	}
77 }
78 
79 ZEND_API void zval_ptr_dtor(zval *zval_ptr);
80 ZEND_API void zval_internal_ptr_dtor(zval *zvalue);
81 
82 /* Kept for compatibility */
83 #define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
84 #define zval_internal_dtor(zvalue) zval_internal_ptr_dtor(zvalue)
85 #define zval_dtor_func rc_dtor_func
86 #define zval_ptr_dtor_wrapper zval_ptr_dtor
87 #define zval_internal_ptr_dtor_wrapper zval_internal_ptr_dtor
88 
89 ZEND_API void zval_add_ref(zval *p);
90 
91 END_EXTERN_C()
92 
93 #define ZVAL_PTR_DTOR zval_ptr_dtor
94 #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor
95 
96 #endif
97