xref: /PHP-7.2/Zend/zend_variables.h (revision 7a7ec01a)
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    +----------------------------------------------------------------------+
19 */
20 
21 /* $Id$ */
22 
23 #ifndef ZEND_VARIABLES_H
24 #define ZEND_VARIABLES_H
25 
26 #include "zend_types.h"
27 #include "zend_gc.h"
28 
29 BEGIN_EXTERN_C()
30 
31 ZEND_API void ZEND_FASTCALL _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC);
32 ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC);
33 
34 #define zval_dtor_func(zv)         _zval_dtor_func(zv ZEND_FILE_LINE_CC)
35 #define zval_copy_ctor_func(zv)    _zval_copy_ctor_func(zv ZEND_FILE_LINE_CC)
36 
_zval_ptr_dtor_nogc(zval * zval_ptr ZEND_FILE_LINE_DC)37 static zend_always_inline void _zval_ptr_dtor_nogc(zval *zval_ptr ZEND_FILE_LINE_DC)
38 {
39 	if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
40 		_zval_dtor_func(Z_COUNTED_P(zval_ptr) ZEND_FILE_LINE_RELAY_CC);
41 	}
42 }
43 
i_zval_ptr_dtor(zval * zval_ptr ZEND_FILE_LINE_DC)44 static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC)
45 {
46 	if (Z_REFCOUNTED_P(zval_ptr)) {
47 		zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
48 		if (!--GC_REFCOUNT(ref)) {
49 			_zval_dtor_func(ref ZEND_FILE_LINE_RELAY_CC);
50 		} else {
51 			gc_check_possible_root(ref);
52 		}
53 	}
54 }
55 
_zval_copy_ctor(zval * zvalue ZEND_FILE_LINE_DC)56 static zend_always_inline void _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
57 {
58 	if (Z_REFCOUNTED_P(zvalue) || Z_COPYABLE_P(zvalue)) {
59 		if (Z_COPYABLE_P(zvalue)) {
60 			_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
61 		} else {
62 			Z_ADDREF_P(zvalue);
63 		}
64 	}
65 }
66 
_zval_opt_copy_ctor(zval * zvalue ZEND_FILE_LINE_DC)67 static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC)
68 {
69 	if (Z_OPT_REFCOUNTED_P(zvalue) || Z_OPT_COPYABLE_P(zvalue)) {
70 		if (Z_OPT_COPYABLE_P(zvalue)) {
71 			_zval_copy_ctor_func(zvalue ZEND_FILE_LINE_RELAY_CC);
72 		} else {
73 			Z_ADDREF_P(zvalue);
74 		}
75 	}
76 }
77 
78 ZEND_API size_t zend_print_variable(zval *var);
79 ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC);
80 ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC);
81 ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC);
82 ZEND_API void _zval_internal_ptr_dtor(zval *zvalue ZEND_FILE_LINE_DC);
83 ZEND_API void _zval_dtor_wrapper(zval *zvalue);
84 #define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
85 #define zval_opt_copy_ctor(zvalue) _zval_opt_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
86 #define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
87 #define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
88 #define zval_ptr_dtor_nogc(zval_ptr) _zval_ptr_dtor_nogc((zval_ptr) ZEND_FILE_LINE_CC)
89 #define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC)
90 #define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC)
91 #define zval_dtor_wrapper _zval_dtor_wrapper
92 
93 #if ZEND_DEBUG
94 ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr);
95 ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue);
96 ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zvalue);
97 #define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper
98 #define zval_internal_dtor_wrapper _zval_internal_dtor_wrapper
99 #define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor_wrapper
100 #else
101 #define zval_ptr_dtor_wrapper _zval_ptr_dtor
102 #define zval_internal_dtor_wrapper _zval_internal_dtor
103 #define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor
104 #endif
105 
106 ZEND_API void zval_add_ref(zval *p);
107 ZEND_API void zval_add_ref_unref(zval *p);
108 
109 END_EXTERN_C()
110 
111 #define ZVAL_DESTRUCTOR zval_dtor_wrapper
112 #define ZVAL_PTR_DTOR zval_ptr_dtor_wrapper
113 #define ZVAL_INTERNAL_DTOR zval_internal_dtor_wrapper
114 #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor_wrapper
115 
116 #endif
117 
118 /*
119  * Local variables:
120  * tab-width: 4
121  * c-basic-offset: 4
122  * indent-tabs-mode: t
123  * End:
124  * vim600: sw=4 ts=4 fdm=marker
125  * vim<600: sw=4 ts=4
126  */
127