xref: /PHP-8.1/Zend/zend_API.h (revision 717335ec)
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    |          Andrei Zmievski <andrei@php.net>                            |
18    |          Dmitry Stogov <dmitry@php.net>                              |
19    +----------------------------------------------------------------------+
20 */
21 
22 #ifndef ZEND_API_H
23 #define ZEND_API_H
24 
25 #include "zend_modules.h"
26 #include "zend_list.h"
27 #include "zend_operators.h"
28 #include "zend_variables.h"
29 #include "zend_execute.h"
30 #include "zend_type_info.h"
31 
32 
33 BEGIN_EXTERN_C()
34 
35 typedef struct _zend_function_entry {
36 	const char *fname;
37 	zif_handler handler;
38 	const struct _zend_internal_arg_info *arg_info;
39 	uint32_t num_args;
40 	uint32_t flags;
41 } zend_function_entry;
42 
43 typedef struct _zend_fcall_info {
44 	size_t size;
45 	zval function_name;
46 	zval *retval;
47 	zval *params;
48 	zend_object *object;
49 	uint32_t param_count;
50 	/* This hashtable can also contain positional arguments (with integer keys),
51 	 * which will be appended to the normal params[]. This makes it easier to
52 	 * integrate APIs like call_user_func_array(). The usual restriction that
53 	 * there may not be position arguments after named arguments applies. */
54 	HashTable *named_params;
55 } zend_fcall_info;
56 
57 typedef struct _zend_fcall_info_cache {
58 	zend_function *function_handler;
59 	zend_class_entry *calling_scope;
60 	zend_class_entry *called_scope;
61 	zend_object *object;
62 } zend_fcall_info_cache;
63 
64 #define ZEND_NS_NAME(ns, name)			ns "\\" name
65 
66 /* ZEND_FN/ZEND_MN are inlined below to prevent pre-scan macro expansion,
67  * which causes issues if the function name is also a macro name. */
68 #define ZEND_FN(name) zif_##name
69 #define ZEND_MN(name) zim_##name
70 
71 #define ZEND_NAMED_FUNCTION(name)		void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
72 #define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(zif_##name)
73 #define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(zim_##classname##_##name)
74 
75 #define ZEND_FENTRY(zend_name, name, arg_info, flags)	{ #zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
76 
77 #define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags)   { zend_name, name, arg_info, (uint32_t) (sizeof(arg_info)/sizeof(struct _zend_internal_arg_info)-1), flags },
78 
79 /* Same as ZEND_NAMED_FE */
80 #define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
81 
82 #define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
83 #define ZEND_FE(name, arg_info)						ZEND_RAW_FENTRY(#name, zif_##name, arg_info, 0)
84 #define ZEND_DEP_FE(name, arg_info)                 ZEND_RAW_FENTRY(#name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
85 #define ZEND_FALIAS(name, alias, arg_info)			ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
86 #define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_RAW_FENTRY(#name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
87 #define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
88 #define ZEND_ME(classname, name, arg_info, flags)	ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags)
89 #define ZEND_DEP_ME(classname, name, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##name, arg_info, flags | ZEND_ACC_DEPRECATED)
90 #define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_RAW_FENTRY(#name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
91 #define ZEND_ABSTRACT_ME_WITH_FLAGS(classname, name, arg_info, flags)	ZEND_RAW_FENTRY(#name, NULL, arg_info, flags)
92 #define ZEND_MALIAS(classname, name, alias, arg_info, flags) ZEND_RAW_FENTRY(#name, zim_##classname##_##alias, arg_info, flags)
93 #define ZEND_ME_MAPPING(name, func_name, arg_info, flags) ZEND_RAW_FENTRY(#name, zif_##func_name, arg_info, flags)
94 
95 #define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags)		ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
96 
97 #define ZEND_NS_RAW_FENTRY(ns, zend_name, name, arg_info, flags)	ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, zend_name), name, arg_info, flags)
98 
99 /* Same as ZEND_NS_NAMED_FE */
100 #define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
101 
102 #define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
103 #define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, 0)
104 #define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_RAW_FENTRY(ns, #name, zif_##name, arg_info, ZEND_ACC_DEPRECATED)
105 #define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, 0)
106 #define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_RAW_FENTRY(ns, #name, zif_##alias, arg_info, ZEND_ACC_DEPRECATED)
107 
108 #define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
109 
110 #define _ZEND_ARG_INFO_FLAGS(pass_by_ref, is_variadic, is_tentative) \
111 	(((pass_by_ref) << _ZEND_SEND_MODE_SHIFT) | ((is_variadic) ? _ZEND_IS_VARIADIC_BIT : 0) | ((is_tentative) ? _ZEND_IS_TENTATIVE_BIT : 0))
112 
113 /* Arginfo structures without type information */
114 #define ZEND_ARG_INFO(pass_by_ref, name) \
115 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
116 #define ZEND_ARG_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, default_value) \
117 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
118 #define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) \
119 	{ #name, ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
120 
121 /* Arginfo structures with simple type information */
122 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
123 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
124 #define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \
125 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
126 #define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
127 	{ #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
128 
129 /* Arginfo structures with complex type information */
130 #define ZEND_ARG_TYPE_MASK(pass_by_ref, name, type_mask, default_value) \
131 	{ #name, ZEND_TYPE_INIT_MASK(type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
132 #define ZEND_ARG_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask, default_value) \
133 	{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
134 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, class_name, type_mask) \
135 	{ #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
136 
137 /* Arginfo structures with object type information */
138 #define ZEND_ARG_OBJ_INFO(pass_by_ref, name, class_name, allow_null) \
139 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
140 #define ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, class_name, allow_null, default_value) \
141 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), default_value },
142 #define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, class_name, allow_null) \
143 	{ #name, ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), NULL },
144 
145 /* Legacy arginfo structures */
146 #define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) \
147 	{ #name, ZEND_TYPE_INIT_CODE(IS_ARRAY, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
148 #define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null) \
149 	{ #name, ZEND_TYPE_INIT_CODE(IS_CALLABLE, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
150 
151 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, is_tentative_return_type) \
152 	static const zend_internal_arg_info name[] = { \
153 		{ (const char*)(zend_uintptr_t)(required_num_args), \
154 			ZEND_TYPE_INIT_CLASS_CONST(#class_name, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
155 
156 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
157 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 0)
158 
159 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
160 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, return_reference, required_num_args, class_name, allow_null, 1)
161 
162 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
163 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX2(name, 0, -1, class_name, allow_null, 0)
164 
165 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, is_tentative_return_type) \
166 	static const zend_internal_arg_info name[] = { \
167 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_MASK(type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
168 
169 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
170 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 0)
171 
172 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(name, return_reference, required_num_args, type) \
173 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX2(name, return_reference, required_num_args, type, 1)
174 
175 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, is_tentative_return_type) \
176 	static const zend_internal_arg_info name[] = { \
177 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CLASS_CONST_MASK(#class_name, type | _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
178 
179 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
180 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 0)
181 
182 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(name, return_reference, required_num_args, class_name, type) \
183 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX2(name, return_reference, required_num_args, class_name, type, 1)
184 
185 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, is_tentative_return_type) \
186 	static const zend_internal_arg_info name[] = { \
187 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_CODE(type, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
188 
189 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
190 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 0)
191 
192 #define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
193 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 1)
194 
195 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
196 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, 0, -1, type, allow_null, 0)
197 
198 #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
199 	static const zend_internal_arg_info name[] = { \
200 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_INIT_NONE(_ZEND_ARG_INFO_FLAGS(return_reference, 0, 0)), NULL },
201 #define ZEND_BEGIN_ARG_INFO(name, _unused)	\
202 	ZEND_BEGIN_ARG_INFO_EX(name, {}, ZEND_RETURN_VALUE, -1)
203 #define ZEND_END_ARG_INFO()		};
204 
205 /* Name macros */
206 #define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
207 #define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
208 #define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
209 #define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
210 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
211 #define ZEND_MODULE_INFO_N(module)			zm_info_##module
212 #define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
213 #define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
214 
215 /* Declaration macros */
216 #define ZEND_MODULE_STARTUP_D(module)		zend_result ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
217 #define ZEND_MODULE_SHUTDOWN_D(module)		zend_result ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
218 #define ZEND_MODULE_ACTIVATE_D(module)		zend_result ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
219 #define ZEND_MODULE_DEACTIVATE_D(module)	zend_result ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
220 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	zend_result ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
221 #define ZEND_MODULE_INFO_D(module)			ZEND_COLD void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
222 #define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
223 #define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
224 
225 #define ZEND_GET_MODULE(name) \
226     BEGIN_EXTERN_C()\
227 	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
228     END_EXTERN_C()
229 
230 #define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
231 	typedef struct _zend_##module_name##_globals {
232 #define ZEND_END_MODULE_GLOBALS(module_name)		\
233 	} zend_##module_name##_globals;
234 
235 #ifdef ZTS
236 
237 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
238 	ts_rsrc_id module_name##_globals_id;
239 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
240 	extern ts_rsrc_id module_name##_globals_id;
241 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
242 	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
243 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
244 #ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
245 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
246 #else
247 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
248 #endif
249 
250 #else
251 
252 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
253 	zend_##module_name##_globals module_name##_globals;
254 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
255 	extern zend_##module_name##_globals module_name##_globals;
256 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
257 	globals_ctor(&module_name##_globals);
258 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
259 #define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
260 
261 #endif
262 
263 #define INIT_CLASS_ENTRY(class_container, class_name, functions) \
264 	INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
265 
266 #define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
267 	{															\
268 		memset(&class_container, 0, sizeof(zend_class_entry)); \
269 		class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
270 		class_container.info.internal.builtin_functions = functions;	\
271 	}
272 
273 #define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
274 	{															\
275 		class_container.constructor = NULL;						\
276 		class_container.destructor = NULL;						\
277 		class_container.clone = NULL;							\
278 		class_container.serialize = NULL;						\
279 		class_container.unserialize = NULL;						\
280 		class_container.create_object = NULL;					\
281 		class_container.get_static_method = NULL;				\
282 		class_container.__call = NULL;							\
283 		class_container.__callstatic = NULL;					\
284 		class_container.__tostring = NULL;						\
285 		class_container.__get = NULL;							\
286 		class_container.__set = NULL;							\
287 		class_container.__unset = NULL;							\
288 		class_container.__isset = NULL;							\
289 		class_container.__debugInfo = NULL;						\
290 		class_container.__serialize = NULL;						\
291 		class_container.__unserialize = NULL;					\
292 		class_container.parent = NULL;							\
293 		class_container.num_interfaces = 0;						\
294 		class_container.trait_names = NULL;						\
295 		class_container.num_traits = 0;							\
296 		class_container.trait_aliases = NULL;					\
297 		class_container.trait_precedences = NULL;				\
298 		class_container.interfaces = NULL;						\
299 		class_container.get_iterator = NULL;					\
300 		class_container.iterator_funcs_ptr = NULL;				\
301 		class_container.info.internal.module = NULL;			\
302 		class_container.info.internal.builtin_functions = functions;	\
303 	}
304 
305 
306 #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
307 	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
308 
309 #define CE_STATIC_MEMBERS(ce) \
310 	((zval*)ZEND_MAP_PTR_GET((ce)->static_members_table))
311 
312 #define CE_CONSTANTS_TABLE(ce) \
313 	zend_class_constants_table(ce)
314 
315 #define CE_DEFAULT_PROPERTIES_TABLE(ce) \
316 	zend_class_default_properties_table(ce)
317 
318 #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
319 
320 ZEND_API int zend_next_free_module(void);
321 
322 BEGIN_EXTERN_C()
323 ZEND_API zend_result _zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array);
324 
325 /* internal function to efficiently copy parameters when executing __call() */
326 ZEND_API zend_result zend_copy_parameters_array(uint32_t param_count, zval *argument_array);
327 
328 #define zend_get_parameters_array(ht, param_count, argument_array) \
329 	_zend_get_parameters_array_ex(param_count, argument_array)
330 #define zend_get_parameters_array_ex(param_count, argument_array) \
331 	_zend_get_parameters_array_ex(param_count, argument_array)
332 #define zend_parse_parameters_none() \
333 	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : (zend_wrong_parameters_none_error(), FAILURE))
334 #define zend_parse_parameters_none_throw() \
335 	zend_parse_parameters_none()
336 
337 /* Parameter parsing API -- andrei */
338 
339 #define ZEND_PARSE_PARAMS_THROW 0 /* No longer used, zpp always uses exceptions */
340 #define ZEND_PARSE_PARAMS_QUIET (1<<1)
341 ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec, ...);
342 ZEND_API zend_result zend_parse_parameters_ex(int flags, uint32_t num_args, const char *type_spec, ...);
343 /* NOTE: This must have at least one value in __VA_ARGS__ for the expression to be valid */
344 #define zend_parse_parameters_throw(num_args, ...) \
345 	zend_parse_parameters(num_args, __VA_ARGS__)
346 ZEND_API const char *zend_zval_type_name(const zval *arg);
347 ZEND_API zend_string *zend_zval_get_legacy_type(const zval *arg);
348 
349 ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
350 ZEND_API zend_result zend_parse_method_parameters_ex(int flags, uint32_t num_args, zval *this_ptr, const char *type_spec, ...);
351 
352 ZEND_API zend_result zend_parse_parameter(int flags, uint32_t arg_num, zval *arg, const char *spec, ...);
353 
354 /* End of parameter parsing API -- andrei */
355 
356 ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
357 ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
358 ZEND_API zend_result zend_startup_module(zend_module_entry *module_entry);
359 ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
360 ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
361 ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module);
362 ZEND_API void zend_startup_modules(void);
363 ZEND_API void zend_collect_module_handlers(void);
364 ZEND_API void zend_destroy_modules(void);
365 ZEND_API void zend_check_magic_method_implementation(
366 		const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
367 ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, zend_string *lcname);
368 
369 ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
370 ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
371 ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
372 ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
373 
374 ZEND_API zend_result zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, bool persistent);
375 
376 #define zend_register_class_alias(name, ce) \
377 	zend_register_class_alias_ex(name, sizeof(name)-1, ce, 1)
378 #define zend_register_ns_class_alias(ns, name, ce) \
379 	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
380 
381 ZEND_API void zend_disable_functions(const char *function_list);
382 ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length);
383 
384 ZEND_API ZEND_COLD void zend_wrong_param_count(void);
385 
386 #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
387 #define IS_CALLABLE_CHECK_SILENT      (1<<3)
388 
389 ZEND_API void zend_release_fcall_info_cache(zend_fcall_info_cache *fcc);
390 ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
391 ZEND_API zend_string *zend_get_callable_name(zval *callable);
392 ZEND_API bool zend_is_callable_at_frame(
393 		zval *callable, zend_object *object, zend_execute_data *frame,
394 		uint32_t check_flags, zend_fcall_info_cache *fcc, char **error);
395 ZEND_API bool zend_is_callable_ex(zval *callable, zend_object *object, uint32_t check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error);
396 ZEND_API bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
397 ZEND_API bool zend_make_callable(zval *callable, zend_string **callable_name);
398 ZEND_API const char *zend_get_module_version(const char *module_name);
399 ZEND_API int zend_get_module_started(const char *module_name);
400 
401 ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type);
402 
403 ZEND_API void zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
404 ZEND_API void zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
405 ZEND_API void zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
406 ZEND_API void zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
407 ZEND_API void zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
408 ZEND_API void zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
409 ZEND_API void zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
410 ZEND_API void zend_declare_property_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_len, int access_type);
411 
412 ZEND_API zend_class_constant *zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
413 ZEND_API void zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
414 ZEND_API void zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
415 ZEND_API void zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
416 ZEND_API void zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, bool value);
417 ZEND_API void zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
418 ZEND_API void zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length);
419 ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
420 
421 ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type);
422 ZEND_API HashTable *zend_separate_class_constants_table(zend_class_entry *class_type);
423 
zend_class_constants_table(zend_class_entry * ce)424 static zend_always_inline HashTable *zend_class_constants_table(zend_class_entry *ce) {
425 	if ((ce->ce_flags & ZEND_ACC_HAS_AST_CONSTANTS) && ZEND_MAP_PTR(ce->mutable_data)) {
426 		zend_class_mutable_data *mutable_data =
427 			(zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
428 		if (mutable_data && mutable_data->constants_table) {
429 			return mutable_data->constants_table;
430 		} else {
431 			return zend_separate_class_constants_table(ce);
432 		}
433 	} else {
434 		return &ce->constants_table;
435 	}
436 }
437 
zend_class_default_properties_table(zend_class_entry * ce)438 static zend_always_inline zval *zend_class_default_properties_table(zend_class_entry *ce) {
439 	if ((ce->ce_flags & ZEND_ACC_HAS_AST_PROPERTIES) && ZEND_MAP_PTR(ce->mutable_data)) {
440 		zend_class_mutable_data *mutable_data =
441 			(zend_class_mutable_data*)ZEND_MAP_PTR_GET_IMM(ce->mutable_data);
442 		return mutable_data->default_properties_table;
443 	} else {
444 		return ce->default_properties_table;
445 	}
446 }
447 
448 ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value);
449 ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
450 ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
451 ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
452 ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
453 ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value);
454 ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value);
455 ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
456 ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length);
457 ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
458 
459 ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
460 ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
461 ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
462 ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
463 ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
464 ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
465 ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
466 ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
467 
468 ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv);
469 ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv);
470 
471 ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, bool silent);
472 ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, bool silent);
473 
474 ZEND_API const char *zend_get_type_by_const(int type);
475 
476 #define ZEND_THIS                           (&EX(This))
477 
478 #define getThis()							((Z_TYPE_P(ZEND_THIS) == IS_OBJECT) ? ZEND_THIS : NULL)
479 #define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
480 
481 #define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
482 #define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
483 #define ZEND_NUM_ARGS()						EX_NUM_ARGS()
484 #define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
485 #define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ zend_wrong_param_count(); return ret; }
486 
487 #ifndef ZEND_WIN32
488 #define DLEXPORT
489 #endif
490 
491 #define array_init(arg)				ZVAL_ARR((arg), zend_new_array(0))
492 #define array_init_size(arg, size)	ZVAL_ARR((arg), zend_new_array(size))
493 ZEND_API void object_init(zval *arg);
494 ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
495 ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
496 ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
497 ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
498 ZEND_API void object_properties_load(zend_object *object, HashTable *properties);
499 
500 ZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
501 
502 ZEND_API void add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
503 ZEND_API void add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
504 ZEND_API void add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, bool b);
505 ZEND_API void add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
506 ZEND_API void add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
507 ZEND_API void add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
508 ZEND_API void add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
509 ZEND_API void add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
510 ZEND_API void add_assoc_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
511 ZEND_API void add_assoc_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
512 ZEND_API void add_assoc_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
513 ZEND_API void add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
514 
515 #define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
516 #define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
517 #define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
518 #define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
519 #define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
520 #define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
521 #define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
522 #define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
523 #define add_assoc_array(__arg, __key, __arr) add_assoc_array_ex(__arg, __key, strlen(__key), __arr)
524 #define add_assoc_object(__arg, __key, __obj) add_assoc_object_ex(__arg, __key, strlen(__key), __obj)
525 #define add_assoc_reference(__arg, __key, __ref) add_assoc_object_ex(__arg, __key, strlen(__key), __ref)
526 #define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
527 
528 ZEND_API void add_index_long(zval *arg, zend_ulong index, zend_long n);
529 ZEND_API void add_index_null(zval *arg, zend_ulong index);
530 ZEND_API void add_index_bool(zval *arg, zend_ulong index, bool b);
531 ZEND_API void add_index_resource(zval *arg, zend_ulong index, zend_resource *r);
532 ZEND_API void add_index_double(zval *arg, zend_ulong index, double d);
533 ZEND_API void add_index_str(zval *arg, zend_ulong index, zend_string *str);
534 ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str);
535 ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length);
536 ZEND_API void add_index_array(zval *arg, zend_ulong index, zend_array *arr);
537 ZEND_API void add_index_object(zval *arg, zend_ulong index, zend_object *obj);
538 ZEND_API void add_index_reference(zval *arg, zend_ulong index, zend_reference *ref);
539 
add_index_zval(zval * arg,zend_ulong index,zval * value)540 static zend_always_inline zend_result add_index_zval(zval *arg, zend_ulong index, zval *value)
541 {
542 	return zend_hash_index_update(Z_ARRVAL_P(arg), index, value) ? SUCCESS : FAILURE;
543 }
544 
545 ZEND_API zend_result add_next_index_long(zval *arg, zend_long n);
546 ZEND_API zend_result add_next_index_null(zval *arg);
547 ZEND_API zend_result add_next_index_bool(zval *arg, bool b);
548 ZEND_API zend_result add_next_index_resource(zval *arg, zend_resource *r);
549 ZEND_API zend_result add_next_index_double(zval *arg, double d);
550 ZEND_API zend_result add_next_index_str(zval *arg, zend_string *str);
551 ZEND_API zend_result add_next_index_string(zval *arg, const char *str);
552 ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length);
553 ZEND_API zend_result add_next_index_array(zval *arg, zend_array *arr);
554 ZEND_API zend_result add_next_index_object(zval *arg, zend_object *obj);
555 ZEND_API zend_result add_next_index_reference(zval *arg, zend_reference *ref);
556 
add_next_index_zval(zval * arg,zval * value)557 static zend_always_inline zend_result add_next_index_zval(zval *arg, zval *value)
558 {
559 	return zend_hash_next_index_insert(Z_ARRVAL_P(arg), value) ? SUCCESS : FAILURE;
560 }
561 
562 ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value);
563 
564 ZEND_API void add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
565 ZEND_API void add_property_null_ex(zval *arg, const char *key, size_t key_len);
566 ZEND_API void add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
567 ZEND_API void add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
568 ZEND_API void add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
569 ZEND_API void add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
570 ZEND_API void add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
571 ZEND_API void add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
572 ZEND_API void add_property_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr);
573 ZEND_API void add_property_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj);
574 ZEND_API void add_property_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref);
575 ZEND_API void add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
576 
577 #define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
578 #define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
579 #define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
580 #define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
581 #define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
582 #define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
583 #define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
584 #define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
585 #define add_property_array(__arg, __key, __arr) add_property_array_ex(__arg, __key, strlen(__key), __arr)
586 #define add_property_object(__arg, __key, __obj) add_property_object_ex(__arg, __key, strlen(__key), __obj)
587 #define add_property_reference(__arg, __key, __ref) add_property_reference_ex(__arg, __key, strlen(__key), __ref)
588 #define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
589 
590 
591 ZEND_API zend_result _call_user_function_impl(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], HashTable *named_params);
592 
593 #define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
594 	_call_user_function_impl(object, function_name, retval_ptr, param_count, params, NULL)
595 
596 #define call_user_function_named(function_table, object, function_name, retval_ptr, param_count, params, named_params) \
597 	_call_user_function_impl(object, function_name, retval_ptr, param_count, params, named_params)
598 
599 ZEND_API extern const zend_fcall_info empty_fcall_info;
600 ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
601 
602 /** Build zend_call_info/cache from a zval*
603  *
604  * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
605  * In order to pass parameters the following members need to be set:
606  * fci->param_count = 0;
607  * fci->params = NULL;
608  * The callable_name argument may be NULL.
609  */
610 ZEND_API zend_result zend_fcall_info_init(zval *callable, uint32_t check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_string **callable_name, char **error);
611 
612 /** Clear arguments connected with zend_fcall_info *fci
613  * If free_mem is not zero then the params array gets free'd as well
614  */
615 ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, bool free_mem);
616 
617 /** Save current arguments from zend_fcall_info *fci
618  * params array will be set to NULL
619  */
620 ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, uint32_t *param_count, zval **params);
621 
622 /** Free arguments connected with zend_fcall_info *fci and set back saved ones.
623  */
624 ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, uint32_t param_count, zval *params);
625 
626 /** Set or clear the arguments in the zend_call_info struct taking care of
627  * refcount. If args is NULL and arguments are set then those are cleared.
628  */
629 ZEND_API zend_result zend_fcall_info_args(zend_fcall_info *fci, zval *args);
630 ZEND_API zend_result zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
631 
632 /** Set arguments in the zend_fcall_info struct taking care of refcount.
633  * If argc is 0 the arguments which are set will be cleared, else pass
634  * a variable amount of zval** arguments.
635  */
636 ZEND_API void zend_fcall_info_argp(zend_fcall_info *fci, uint32_t argc, zval *argv);
637 
638 /** Set arguments in the zend_fcall_info struct taking care of refcount.
639  * If argc is 0 the arguments which are set will be cleared, else pass
640  * a variable amount of zval** arguments.
641  */
642 ZEND_API void zend_fcall_info_argv(zend_fcall_info *fci, uint32_t argc, va_list *argv);
643 
644 /** Set arguments in the zend_fcall_info struct taking care of refcount.
645  * If argc is 0 the arguments which are set will be cleared, else pass
646  * a variable amount of zval** arguments.
647  */
648 ZEND_API void zend_fcall_info_argn(zend_fcall_info *fci, uint32_t argc, ...);
649 
650 /** Call a function using information created by zend_fcall_info_init()/args().
651  * If args is given then those replace the argument info in fci is temporarily.
652  */
653 ZEND_API zend_result zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
654 
655 ZEND_API zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
656 
657 /* Call the provided zend_function with the given params.
658  * If retval_ptr is NULL, the return value is discarded.
659  * If object is NULL, this must be a free function or static call.
660  * called_scope must be provided for instance and static method calls. */
661 ZEND_API void zend_call_known_function(
662 		zend_function *fn, zend_object *object, zend_class_entry *called_scope, zval *retval_ptr,
663 		uint32_t param_count, zval *params, HashTable *named_params);
664 
665 /* Call the provided zend_function instance method on an object. */
zend_call_known_instance_method(zend_function * fn,zend_object * object,zval * retval_ptr,uint32_t param_count,zval * params)666 static zend_always_inline void zend_call_known_instance_method(
667 		zend_function *fn, zend_object *object, zval *retval_ptr,
668 		uint32_t param_count, zval *params)
669 {
670 	zend_call_known_function(fn, object, object->ce, retval_ptr, param_count, params, NULL);
671 }
672 
zend_call_known_instance_method_with_0_params(zend_function * fn,zend_object * object,zval * retval_ptr)673 static zend_always_inline void zend_call_known_instance_method_with_0_params(
674 		zend_function *fn, zend_object *object, zval *retval_ptr)
675 {
676 	zend_call_known_instance_method(fn, object, retval_ptr, 0, NULL);
677 }
678 
zend_call_known_instance_method_with_1_params(zend_function * fn,zend_object * object,zval * retval_ptr,zval * param)679 static zend_always_inline void zend_call_known_instance_method_with_1_params(
680 		zend_function *fn, zend_object *object, zval *retval_ptr, zval *param)
681 {
682 	zend_call_known_instance_method(fn, object, retval_ptr, 1, param);
683 }
684 
685 ZEND_API void zend_call_known_instance_method_with_2_params(
686 		zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2);
687 
688 ZEND_API zend_result zend_set_hash_symbol(zval *symbol, const char *name, size_t name_length, bool is_ref, int num_symbol_tables, ...);
689 
690 ZEND_API zend_result zend_delete_global_variable(zend_string *name);
691 
692 ZEND_API zend_array *zend_rebuild_symbol_table(void);
693 ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
694 ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
695 ZEND_API zend_result zend_set_local_var(zend_string *name, zval *value, bool force);
696 ZEND_API zend_result zend_set_local_var_str(const char *name, size_t len, zval *value, bool force);
697 
zend_forbid_dynamic_call(const char * func_name)698 static zend_always_inline zend_result zend_forbid_dynamic_call(const char *func_name)
699 {
700 	zend_execute_data *ex = EG(current_execute_data);
701 	ZEND_ASSERT(ex != NULL && ex->func != NULL);
702 
703 	if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) {
704 		zend_throw_error(NULL, "Cannot call %s dynamically", func_name);
705 		return FAILURE;
706 	}
707 
708 	return SUCCESS;
709 }
710 
711 ZEND_API ZEND_COLD const char *zend_get_object_type(const zend_class_entry *ce);
712 
713 ZEND_API bool zend_is_iterable(zval *iterable);
714 
715 ZEND_API bool zend_is_countable(zval *countable);
716 
717 ZEND_API zend_result zend_get_default_from_internal_arg_info(
718 		zval *default_value_zval, zend_internal_arg_info *arg_info);
719 
720 END_EXTERN_C()
721 
722 #if ZEND_DEBUG
723 #define CHECK_ZVAL_STRING(str) \
724 	ZEND_ASSERT(ZSTR_VAL(str)[ZSTR_LEN(str)] == '\0' && "String is not null-terminated");
725 #else
726 #define CHECK_ZVAL_STRING(z)
727 #endif
728 
729 #define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
730 #define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
731 
732 #define ZVAL_STRINGL(z, s, l) do {				\
733 		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
734 	} while (0)
735 
736 #define ZVAL_STRING(z, s) do {					\
737 		const char *_s = (s);					\
738 		ZVAL_STRINGL(z, _s, strlen(_s));		\
739 	} while (0)
740 
741 #define ZVAL_EMPTY_STRING(z) do {				\
742 		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
743 	} while (0)
744 
745 #define ZVAL_PSTRINGL(z, s, l) do {				\
746 		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
747 	} while (0)
748 
749 #define ZVAL_PSTRING(z, s) do {					\
750 		const char *_s = (s);					\
751 		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
752 	} while (0)
753 
754 #define ZVAL_EMPTY_PSTRING(z) do {				\
755 		ZVAL_PSTRINGL(z, "", 0);				\
756 	} while (0)
757 
758 #define ZVAL_CHAR(z, c)  do {		            \
759 		char _c = (c);                          \
760 		ZVAL_INTERNED_STR(z, ZSTR_CHAR((zend_uchar) _c));	\
761 	} while (0)
762 
763 #define ZVAL_STRINGL_FAST(z, s, l) do {			\
764 		ZVAL_STR(z, zend_string_init_fast(s, l));	\
765 	} while (0)
766 
767 #define ZVAL_STRING_FAST(z, s) do {				\
768 		const char *_s = (s);					\
769 		ZVAL_STRINGL_FAST(z, _s, strlen(_s));	\
770 	} while (0)
771 
772 #define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
773 		zval *__z = (z);						\
774 		zval *__zv = (zv);						\
775 		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
776 			if (copy && !dtor) {				\
777 				ZVAL_COPY(__z, __zv);			\
778 			} else {							\
779 				ZVAL_COPY_VALUE(__z, __zv);		\
780 			}									\
781 		} else {								\
782 			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
783 			if (dtor || !copy) {				\
784 				zval_ptr_dtor(__zv);			\
785 			}									\
786 		}										\
787 	} while (0)
788 
789 #define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
790 #define RETVAL_NULL()					ZVAL_NULL(return_value)
791 #define RETVAL_LONG(l)					ZVAL_LONG(return_value, l)
792 #define RETVAL_DOUBLE(d)				ZVAL_DOUBLE(return_value, d)
793 #define RETVAL_STR(s)					ZVAL_STR(return_value, s)
794 #define RETVAL_INTERNED_STR(s)			ZVAL_INTERNED_STR(return_value, s)
795 #define RETVAL_NEW_STR(s)				ZVAL_NEW_STR(return_value, s)
796 #define RETVAL_STR_COPY(s)				ZVAL_STR_COPY(return_value, s)
797 #define RETVAL_STRING(s)				ZVAL_STRING(return_value, s)
798 #define RETVAL_STRINGL(s, l)			ZVAL_STRINGL(return_value, s, l)
799 #define RETVAL_STRING_FAST(s)			ZVAL_STRING_FAST(return_value, s)
800 #define RETVAL_STRINGL_FAST(s, l)		ZVAL_STRINGL_FAST(return_value, s, l)
801 #define RETVAL_EMPTY_STRING()			ZVAL_EMPTY_STRING(return_value)
802 #define RETVAL_CHAR(c)		            ZVAL_CHAR(return_value, c)
803 #define RETVAL_RES(r)					ZVAL_RES(return_value, r)
804 #define RETVAL_ARR(r)					ZVAL_ARR(return_value, r)
805 #define RETVAL_EMPTY_ARRAY()			ZVAL_EMPTY_ARRAY(return_value)
806 #define RETVAL_OBJ(r)					ZVAL_OBJ(return_value, r)
807 #define RETVAL_OBJ_COPY(r)				ZVAL_OBJ_COPY(return_value, r)
808 #define RETVAL_COPY(zv)					ZVAL_COPY(return_value, zv)
809 #define RETVAL_COPY_VALUE(zv)			ZVAL_COPY_VALUE(return_value, zv)
810 #define RETVAL_COPY_DEREF(zv)			ZVAL_COPY_DEREF(return_value, zv)
811 #define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
812 #define RETVAL_FALSE					ZVAL_FALSE(return_value)
813 #define RETVAL_TRUE						ZVAL_TRUE(return_value)
814 
815 #define RETURN_BOOL(b)					do { RETVAL_BOOL(b); return; } while (0)
816 #define RETURN_NULL()					do { RETVAL_NULL(); return;} while (0)
817 #define RETURN_LONG(l)					do { RETVAL_LONG(l); return; } while (0)
818 #define RETURN_DOUBLE(d)				do { RETVAL_DOUBLE(d); return; } while (0)
819 #define RETURN_STR(s) 					do { RETVAL_STR(s); return; } while (0)
820 #define RETURN_INTERNED_STR(s)			do { RETVAL_INTERNED_STR(s); return; } while (0)
821 #define RETURN_NEW_STR(s)				do { RETVAL_NEW_STR(s); return; } while (0)
822 #define RETURN_STR_COPY(s)				do { RETVAL_STR_COPY(s); return; } while (0)
823 #define RETURN_STRING(s) 				do { RETVAL_STRING(s); return; } while (0)
824 #define RETURN_STRINGL(s, l) 			do { RETVAL_STRINGL(s, l); return; } while (0)
825 #define RETURN_STRING_FAST(s) 			do { RETVAL_STRING_FAST(s); return; } while (0)
826 #define RETURN_STRINGL_FAST(s, l)		do { RETVAL_STRINGL_FAST(s, l); return; } while (0)
827 #define RETURN_EMPTY_STRING() 			do { RETVAL_EMPTY_STRING(); return; } while (0)
828 #define RETURN_CHAR(c)		            do { RETVAL_CHAR(c); return; } while (0)
829 #define RETURN_RES(r)					do { RETVAL_RES(r); return; } while (0)
830 #define RETURN_ARR(r)					do { RETVAL_ARR(r); return; } while (0)
831 #define RETURN_EMPTY_ARRAY()			do { RETVAL_EMPTY_ARRAY(); return; } while (0)
832 #define RETURN_OBJ(r)					do { RETVAL_OBJ(r); return; } while (0)
833 #define RETURN_OBJ_COPY(r)				do { RETVAL_OBJ_COPY(r); return; } while (0)
834 #define RETURN_COPY(zv)					do { RETVAL_COPY(zv); return; } while (0)
835 #define RETURN_COPY_VALUE(zv)			do { RETVAL_COPY_VALUE(zv); return; } while (0)
836 #define RETURN_COPY_DEREF(zv)			do { RETVAL_COPY_DEREF(zv); return; } while (0)
837 #define RETURN_ZVAL(zv, copy, dtor)		do { RETVAL_ZVAL(zv, copy, dtor); return; } while (0)
838 #define RETURN_FALSE					do { RETVAL_FALSE; return; } while (0)
839 #define RETURN_TRUE						do { RETVAL_TRUE; return; } while (0)
840 #define RETURN_THROWS()					do { ZEND_ASSERT(EG(exception)); (void) return_value; return; } while (0)
841 
842 #define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties(Z_OBJ_P(p)) : NULL)))
843 #define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
844 
845 /* For compatibility */
846 #define ZEND_MINIT			ZEND_MODULE_STARTUP_N
847 #define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
848 #define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
849 #define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
850 #define ZEND_MINFO			ZEND_MODULE_INFO_N
851 #define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
852 #define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
853 
854 #define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
855 #define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
856 #define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
857 #define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
858 #define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
859 #define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
860 #define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
861 
862 /* May modify arg in-place. Will free arg in failure case (and take ownership in success case).
863  * Prefer using the ZEND_TRY_ASSIGN_* macros over these APIs. */
864 ZEND_API zend_result zend_try_assign_typed_ref_ex(zend_reference *ref, zval *zv, bool strict);
865 ZEND_API zend_result zend_try_assign_typed_ref(zend_reference *ref, zval *zv);
866 
867 ZEND_API zend_result zend_try_assign_typed_ref_null(zend_reference *ref);
868 ZEND_API zend_result zend_try_assign_typed_ref_bool(zend_reference *ref, bool val);
869 ZEND_API zend_result zend_try_assign_typed_ref_long(zend_reference *ref, zend_long lval);
870 ZEND_API zend_result zend_try_assign_typed_ref_double(zend_reference *ref, double dval);
871 ZEND_API zend_result zend_try_assign_typed_ref_empty_string(zend_reference *ref);
872 ZEND_API zend_result zend_try_assign_typed_ref_str(zend_reference *ref, zend_string *str);
873 ZEND_API zend_result zend_try_assign_typed_ref_string(zend_reference *ref, const char *string);
874 ZEND_API zend_result zend_try_assign_typed_ref_stringl(zend_reference *ref, const char *string, size_t len);
875 ZEND_API zend_result zend_try_assign_typed_ref_arr(zend_reference *ref, zend_array *arr);
876 ZEND_API zend_result zend_try_assign_typed_ref_res(zend_reference *ref, zend_resource *res);
877 ZEND_API zend_result zend_try_assign_typed_ref_zval(zend_reference *ref, zval *zv);
878 ZEND_API zend_result zend_try_assign_typed_ref_zval_ex(zend_reference *ref, zval *zv, bool strict);
879 
880 #define _ZEND_TRY_ASSIGN_NULL(zv, is_ref) do { \
881 	zval *_zv = zv; \
882 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
883 		zend_reference *ref = Z_REF_P(_zv); \
884 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
885 			zend_try_assign_typed_ref_null(ref); \
886 			break; \
887 		} \
888 		_zv = &ref->val; \
889 	} \
890 	zval_ptr_dtor(_zv); \
891 	ZVAL_NULL(_zv); \
892 } while (0)
893 
894 #define ZEND_TRY_ASSIGN_NULL(zv) \
895 	_ZEND_TRY_ASSIGN_NULL(zv, 0)
896 
897 #define ZEND_TRY_ASSIGN_REF_NULL(zv) do { \
898 	ZEND_ASSERT(Z_ISREF_P(zv)); \
899 	_ZEND_TRY_ASSIGN_NULL(zv, 1); \
900 } while (0)
901 
902 #define _ZEND_TRY_ASSIGN_FALSE(zv, is_ref) do { \
903 	zval *_zv = zv; \
904 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
905 		zend_reference *ref = Z_REF_P(_zv); \
906 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
907 			zend_try_assign_typed_ref_bool(ref, 0); \
908 			break; \
909 		} \
910 		_zv = &ref->val; \
911 	} \
912 	zval_ptr_dtor(_zv); \
913 	ZVAL_FALSE(_zv); \
914 } while (0)
915 
916 #define ZEND_TRY_ASSIGN_FALSE(zv) \
917 	_ZEND_TRY_ASSIGN_FALSE(zv, 0)
918 
919 #define ZEND_TRY_ASSIGN_REF_FALSE(zv) do { \
920 	ZEND_ASSERT(Z_ISREF_P(zv)); \
921 	_ZEND_TRY_ASSIGN_FALSE(zv, 1); \
922 } while (0)
923 
924 #define _ZEND_TRY_ASSIGN_TRUE(zv, is_ref) do { \
925 	zval *_zv = zv; \
926 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
927 		zend_reference *ref = Z_REF_P(_zv); \
928 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
929 			zend_try_assign_typed_ref_bool(ref, 1); \
930 			break; \
931 		} \
932 		_zv = &ref->val; \
933 	} \
934 	zval_ptr_dtor(_zv); \
935 	ZVAL_TRUE(_zv); \
936 } while (0)
937 
938 #define ZEND_TRY_ASSIGN_TRUE(zv) \
939 	_ZEND_TRY_ASSIGN_TRUE(zv, 0)
940 
941 #define ZEND_TRY_ASSIGN_REF_TRUE(zv) do { \
942 	ZEND_ASSERT(Z_ISREF_P(zv)); \
943 	_ZEND_TRY_ASSIGN_TRUE(zv, 1); \
944 } while (0)
945 
946 #define _ZEND_TRY_ASSIGN_BOOL(zv, bval, is_ref) do { \
947 	zval *_zv = zv; \
948 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
949 		zend_reference *ref = Z_REF_P(_zv); \
950 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
951 			zend_try_assign_typed_ref_bool(ref, 1); \
952 			break; \
953 		} \
954 		_zv = &ref->val; \
955 	} \
956 	zval_ptr_dtor(_zv); \
957 	ZVAL_BOOL(_zv, bval); \
958 } while (0)
959 
960 #define ZEND_TRY_ASSIGN_BOOL(zv, bval) \
961 	_ZEND_TRY_ASSIGN_BOOL(zv, bval, 0)
962 
963 #define ZEND_TRY_ASSIGN_REF_BOOL(zv, bval) do { \
964 	ZEND_ASSERT(Z_ISREF_P(zv)); \
965 	_ZEND_TRY_ASSIGN_BOOL(zv, bval, 1); \
966 } while (0)
967 
968 #define _ZEND_TRY_ASSIGN_LONG(zv, lval, is_ref) do { \
969 	zval *_zv = zv; \
970 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
971 		zend_reference *ref = Z_REF_P(_zv); \
972 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
973 			zend_try_assign_typed_ref_long(ref, lval); \
974 			break; \
975 		} \
976 		_zv = &ref->val; \
977 	} \
978 	zval_ptr_dtor(_zv); \
979 	ZVAL_LONG(_zv, lval); \
980 } while (0)
981 
982 #define ZEND_TRY_ASSIGN_LONG(zv, lval) \
983 	_ZEND_TRY_ASSIGN_LONG(zv, lval, 0)
984 
985 #define ZEND_TRY_ASSIGN_REF_LONG(zv, lval) do { \
986 	ZEND_ASSERT(Z_ISREF_P(zv)); \
987 	_ZEND_TRY_ASSIGN_LONG(zv, lval, 1); \
988 } while (0)
989 
990 #define _ZEND_TRY_ASSIGN_DOUBLE(zv, dval, is_ref) do { \
991 	zval *_zv = zv; \
992 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
993 		zend_reference *ref = Z_REF_P(_zv); \
994 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
995 			zend_try_assign_typed_ref_double(ref, dval); \
996 			break; \
997 		} \
998 		_zv = &ref->val; \
999 	} \
1000 	zval_ptr_dtor(_zv); \
1001 	ZVAL_DOUBLE(_zv, dval); \
1002 } while (0)
1003 
1004 #define ZEND_TRY_ASSIGN_DOUBLE(zv, dval) \
1005 	_ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 0)
1006 
1007 #define ZEND_TRY_ASSIGN_REF_DOUBLE(zv, dval) do { \
1008 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1009 	_ZEND_TRY_ASSIGN_DOUBLE(zv, dval, 1); \
1010 } while (0)
1011 
1012 #define _ZEND_TRY_ASSIGN_EMPTY_STRING(zv, is_ref) do { \
1013 	zval *_zv = zv; \
1014 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1015 		zend_reference *ref = Z_REF_P(_zv); \
1016 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1017 			zend_try_assign_typed_ref_empty_string(ref); \
1018 			break; \
1019 		} \
1020 		_zv = &ref->val; \
1021 	} \
1022 	zval_ptr_dtor(_zv); \
1023 	ZVAL_EMPTY_STRING(_zv); \
1024 } while (0)
1025 
1026 #define ZEND_TRY_ASSIGN_EMPTY_STRING(zv) \
1027 	_ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 0)
1028 
1029 #define ZEND_TRY_ASSIGN_REF_EMPTY_STRING(zv) do { \
1030 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1031 	_ZEND_TRY_ASSIGN_EMPTY_STRING(zv, 1); \
1032 } while (0)
1033 
1034 #define _ZEND_TRY_ASSIGN_STR(zv, str, is_ref) do { \
1035 	zval *_zv = zv; \
1036 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1037 		zend_reference *ref = Z_REF_P(_zv); \
1038 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1039 			zend_try_assign_typed_ref_str(ref, str); \
1040 			break; \
1041 		} \
1042 		_zv = &ref->val; \
1043 	} \
1044 	zval_ptr_dtor(_zv); \
1045 	ZVAL_STR(_zv, str); \
1046 } while (0)
1047 
1048 #define ZEND_TRY_ASSIGN_STR(zv, str) \
1049 	_ZEND_TRY_ASSIGN_STR(zv, str, 0)
1050 
1051 #define ZEND_TRY_ASSIGN_REF_STR(zv, str) do { \
1052 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1053 	_ZEND_TRY_ASSIGN_STR(zv, str, 1); \
1054 } while (0)
1055 
1056 #define _ZEND_TRY_ASSIGN_NEW_STR(zv, str, is_str) do { \
1057 	zval *_zv = zv; \
1058 	if (is_str || UNEXPECTED(Z_ISREF_P(_zv))) { \
1059 		zend_reference *ref = Z_REF_P(_zv); \
1060 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1061 			zend_try_assign_typed_ref_str(ref, str); \
1062 			break; \
1063 		} \
1064 		_zv = &ref->val; \
1065 	} \
1066 	zval_ptr_dtor(_zv); \
1067 	ZVAL_NEW_STR(_zv, str); \
1068 } while (0)
1069 
1070 #define ZEND_TRY_ASSIGN_NEW_STR(zv, str) \
1071 	_ZEND_TRY_ASSIGN_NEW_STR(zv, str, 0)
1072 
1073 #define ZEND_TRY_ASSIGN_REF_NEW_STR(zv, str) do { \
1074 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1075 	_ZEND_TRY_ASSIGN_NEW_STR(zv, str, 1); \
1076 } while (0)
1077 
1078 #define _ZEND_TRY_ASSIGN_STRING(zv, string, is_ref) do { \
1079 	zval *_zv = zv; \
1080 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1081 		zend_reference *ref = Z_REF_P(_zv); \
1082 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1083 			zend_try_assign_typed_ref_string(ref, string); \
1084 			break; \
1085 		} \
1086 		_zv = &ref->val; \
1087 	} \
1088 	zval_ptr_dtor(_zv); \
1089 	ZVAL_STRING(_zv, string); \
1090 } while (0)
1091 
1092 #define ZEND_TRY_ASSIGN_STRING(zv, string) \
1093 	_ZEND_TRY_ASSIGN_STRING(zv, string, 0)
1094 
1095 #define ZEND_TRY_ASSIGN_REF_STRING(zv, string) do { \
1096 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1097 	_ZEND_TRY_ASSIGN_STRING(zv, string, 1); \
1098 } while (0)
1099 
1100 #define _ZEND_TRY_ASSIGN_STRINGL(zv, string, len, is_ref) do { \
1101 	zval *_zv = zv; \
1102 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1103 		zend_reference *ref = Z_REF_P(_zv); \
1104 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1105 			zend_try_assign_typed_ref_stringl(ref, string, len); \
1106 			break; \
1107 		} \
1108 		_zv = &ref->val; \
1109 	} \
1110 	zval_ptr_dtor(_zv); \
1111 	ZVAL_STRINGL(_zv, string, len); \
1112 } while (0)
1113 
1114 #define ZEND_TRY_ASSIGN_STRINGL(zv, string, len) \
1115 	_ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 0)
1116 
1117 #define ZEND_TRY_ASSIGN_REF_STRINGL(zv, string, len) do { \
1118 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1119 	_ZEND_TRY_ASSIGN_STRINGL(zv, string, len, 1); \
1120 } while (0)
1121 
1122 #define _ZEND_TRY_ASSIGN_ARR(zv, arr, is_ref) do { \
1123 	zval *_zv = zv; \
1124 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1125 		zend_reference *ref = Z_REF_P(_zv); \
1126 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1127 			zend_try_assign_typed_ref_arr(ref, arr); \
1128 			break; \
1129 		} \
1130 		_zv = &ref->val; \
1131 	} \
1132 	zval_ptr_dtor(_zv); \
1133 	ZVAL_ARR(_zv, arr); \
1134 } while (0)
1135 
1136 #define ZEND_TRY_ASSIGN_ARR(zv, arr) \
1137 	_ZEND_TRY_ASSIGN_ARR(zv, arr, 0)
1138 
1139 #define ZEND_TRY_ASSIGN_REF_ARR(zv, arr) do { \
1140 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1141 	_ZEND_TRY_ASSIGN_ARR(zv, arr, 1); \
1142 } while (0)
1143 
1144 #define _ZEND_TRY_ASSIGN_RES(zv, res, is_ref) do { \
1145 	zval *_zv = zv; \
1146 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1147 		zend_reference *ref = Z_REF_P(_zv); \
1148 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1149 			zend_try_assign_typed_ref_res(ref, res); \
1150 			break; \
1151 		} \
1152 		_zv = &ref->val; \
1153 	} \
1154 	zval_ptr_dtor(_zv); \
1155 	ZVAL_RES(_zv, res); \
1156 } while (0)
1157 
1158 #define ZEND_TRY_ASSIGN_RES(zv, res) \
1159 	_ZEND_TRY_ASSIGN_RES(zv, res, 0)
1160 
1161 #define ZEND_TRY_ASSIGN_REF_RES(zv, res) do { \
1162 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1163 	_ZEND_TRY_ASSIGN_RES(zv, res, 1); \
1164 } while (0)
1165 
1166 #define _ZEND_TRY_ASSIGN_TMP(zv, other_zv, is_ref) do { \
1167 	zval *_zv = zv; \
1168 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1169 		zend_reference *ref = Z_REF_P(_zv); \
1170 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1171 			zend_try_assign_typed_ref(ref, other_zv); \
1172 			break; \
1173 		} \
1174 		_zv = &ref->val; \
1175 	} \
1176 	zval_ptr_dtor(_zv); \
1177 	ZVAL_COPY_VALUE(_zv, other_zv); \
1178 } while (0)
1179 
1180 #define ZEND_TRY_ASSIGN_TMP(zv, other_zv) \
1181 	_ZEND_TRY_ASSIGN_TMP(zv, other_zv, 0)
1182 
1183 #define ZEND_TRY_ASSIGN_REF_TMP(zv, other_zv) do { \
1184 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1185 	_ZEND_TRY_ASSIGN_TMP(zv, other_zv, 1); \
1186 } while (0)
1187 
1188 #define _ZEND_TRY_ASSIGN_VALUE(zv, other_zv, is_ref) do { \
1189 	zval *_zv = zv; \
1190 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1191 		zend_reference *ref = Z_REF_P(_zv); \
1192 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1193 			zend_try_assign_typed_ref_zval(ref, other_zv); \
1194 			break; \
1195 		} \
1196 		_zv = &ref->val; \
1197 	} \
1198 	zval_ptr_dtor(_zv); \
1199 	ZVAL_COPY_VALUE(_zv, other_zv); \
1200 } while (0)
1201 
1202 #define ZEND_TRY_ASSIGN_VALUE(zv, other_zv) \
1203 	_ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 0)
1204 
1205 #define ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv) do { \
1206 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1207 	_ZEND_TRY_ASSIGN_VALUE(zv, other_zv, 1); \
1208 } while (0)
1209 
1210 #define ZEND_TRY_ASSIGN_COPY(zv, other_zv) do { \
1211 	Z_TRY_ADDREF_P(other_zv); \
1212 	ZEND_TRY_ASSIGN_VALUE(zv, other_zv); \
1213 } while (0)
1214 
1215 #define ZEND_TRY_ASSIGN_REF_COPY(zv, other_zv) do { \
1216 	Z_TRY_ADDREF_P(other_zv); \
1217 	ZEND_TRY_ASSIGN_REF_VALUE(zv, other_zv); \
1218 } while (0)
1219 
1220 #define _ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, is_ref) do { \
1221 	zval *_zv = zv; \
1222 	if (is_ref || UNEXPECTED(Z_ISREF_P(_zv))) { \
1223 		zend_reference *ref = Z_REF_P(_zv); \
1224 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) { \
1225 			zend_try_assign_typed_ref_zval_ex(ref, other_zv, strict); \
1226 			break; \
1227 		} \
1228 		_zv = &ref->val; \
1229 	} \
1230 	zval_ptr_dtor(_zv); \
1231 	ZVAL_COPY_VALUE(_zv, other_zv); \
1232 } while (0)
1233 
1234 #define ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict) \
1235 	_ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 0)
1236 
1237 #define ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict) do { \
1238 	ZEND_ASSERT(Z_ISREF_P(zv)); \
1239 	_ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict, 1); \
1240 } while (0)
1241 
1242 #define ZEND_TRY_ASSIGN_COPY_EX(zv, other_zv, strict) do { \
1243 	Z_TRY_ADDREF_P(other_zv); \
1244 	ZEND_TRY_ASSIGN_VALUE_EX(zv, other_zv, strict); \
1245 } while (0)
1246 
1247 #define ZEND_TRY_ASSIGN_REF_COPY_EX(zv, other_zv, strict) do { \
1248 	Z_TRY_ADDREF_P(other_zv); \
1249 	ZEND_TRY_ASSIGN_REF_VALUE_EX(zv, other_zv, strict); \
1250 } while (0)
1251 
1252 /* Initializes a reference to an empty array and returns dereferenced zval,
1253  * or NULL if the initialization failed. */
zend_try_array_init_size(zval * zv,uint32_t size)1254 static zend_always_inline zval *zend_try_array_init_size(zval *zv, uint32_t size)
1255 {
1256 	zend_array *arr = zend_new_array(size);
1257 
1258 	if (EXPECTED(Z_ISREF_P(zv))) {
1259 		zend_reference *ref = Z_REF_P(zv);
1260 		if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(ref))) {
1261 			if (zend_try_assign_typed_ref_arr(ref, arr) == FAILURE) {
1262 				return NULL;
1263 			}
1264 			return &ref->val;
1265 		}
1266 		zv = &ref->val;
1267 	}
1268 	zval_ptr_dtor(zv);
1269 	ZVAL_ARR(zv, arr);
1270 	return zv;
1271 }
1272 
zend_try_array_init(zval * zv)1273 static zend_always_inline zval *zend_try_array_init(zval *zv)
1274 {
1275 	return zend_try_array_init_size(zv, 0);
1276 }
1277 
1278 /* Fast parameter parsing API */
1279 
1280 /* Fast ZPP is always enabled now; this define is left in for compatibility
1281  * with any existing conditional compilation blocks.
1282  */
1283 #define FAST_ZPP 1
1284 
1285 #define Z_EXPECTED_TYPES(_) \
1286 	_(Z_EXPECTED_LONG,				"of type int") \
1287 	_(Z_EXPECTED_LONG_OR_NULL,		"of type ?int") \
1288 	_(Z_EXPECTED_BOOL,				"of type bool") \
1289 	_(Z_EXPECTED_BOOL_OR_NULL,		"of type ?bool") \
1290 	_(Z_EXPECTED_STRING,			"of type string") \
1291 	_(Z_EXPECTED_STRING_OR_NULL,	"of type ?string") \
1292 	_(Z_EXPECTED_ARRAY,				"of type array") \
1293 	_(Z_EXPECTED_ARRAY_OR_NULL,		"of type ?array") \
1294 	_(Z_EXPECTED_ARRAY_OR_LONG,		"of type array|int") \
1295 	_(Z_EXPECTED_ARRAY_OR_LONG_OR_NULL, "of type array|int|null") \
1296 	_(Z_EXPECTED_ITERABLE,				"of type iterable") \
1297 	_(Z_EXPECTED_ITERABLE_OR_NULL,		"of type ?iterable") \
1298 	_(Z_EXPECTED_FUNC,				"a valid callback") \
1299 	_(Z_EXPECTED_FUNC_OR_NULL,		"a valid callback or null") \
1300 	_(Z_EXPECTED_RESOURCE,			"of type resource") \
1301 	_(Z_EXPECTED_RESOURCE_OR_NULL,	"of type resource or null") \
1302 	_(Z_EXPECTED_PATH,				"of type string") \
1303 	_(Z_EXPECTED_PATH_OR_NULL,		"of type ?string") \
1304 	_(Z_EXPECTED_OBJECT,			"of type object") \
1305 	_(Z_EXPECTED_OBJECT_OR_NULL,	"of type ?object") \
1306 	_(Z_EXPECTED_DOUBLE,			"of type float") \
1307 	_(Z_EXPECTED_DOUBLE_OR_NULL,	"of type ?float") \
1308 	_(Z_EXPECTED_NUMBER,			"of type int|float") \
1309 	_(Z_EXPECTED_NUMBER_OR_NULL,	"of type int|float|null") \
1310 	_(Z_EXPECTED_ARRAY_OR_STRING,	"of type array|string") \
1311 	_(Z_EXPECTED_ARRAY_OR_STRING_OR_NULL, "of type array|string|null") \
1312 	_(Z_EXPECTED_STRING_OR_LONG,	"of type string|int") \
1313 	_(Z_EXPECTED_STRING_OR_LONG_OR_NULL, "of type string|int|null") \
1314 	_(Z_EXPECTED_OBJECT_OR_CLASS_NAME,	"an object or a valid class name") \
1315 	_(Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL, "an object, a valid class name, or null") \
1316 	_(Z_EXPECTED_OBJECT_OR_STRING,	"of type object|string") \
1317 	_(Z_EXPECTED_OBJECT_OR_STRING_OR_NULL, "of type object|string|null") \
1318 
1319 #define Z_EXPECTED_TYPE
1320 
1321 #define Z_EXPECTED_TYPE_ENUM(id, str) id,
1322 #define Z_EXPECTED_TYPE_STR(id, str)  str,
1323 
1324 typedef enum _zend_expected_type {
1325 	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
1326 	Z_EXPECTED_LAST
1327 } zend_expected_type;
1328 
1329 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void);
1330 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t min_num_args, uint32_t max_num_args);
1331 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_error(int error_code, uint32_t num, char *name, zend_expected_type expected_type, zval *arg);
1332 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(uint32_t num, zend_expected_type expected_type, zval *arg);
1333 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(uint32_t num, const char *name, zval *arg);
1334 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_null_error(uint32_t num, const char *name, zval *arg);
1335 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_error(uint32_t num, const char *name, zval *arg);
1336 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_long_or_null_error(uint32_t num, const char *name, zval *arg);
1337 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_error(uint32_t num, const char *name, zval *arg);
1338 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_or_string_or_null_error(uint32_t num, const char *name, zval *arg);
1339 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(uint32_t num, char *error);
1340 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_or_null_error(uint32_t num, char *error);
1341 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_unexpected_extra_named_error(void);
1342 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_entry *error_ce, uint32_t arg_num, const char *format, va_list va);
1343 ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
1344 ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
1345 ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format, ...);
1346 
1347 #define ZPP_ERROR_OK                            0
1348 #define ZPP_ERROR_FAILURE                       1
1349 #define ZPP_ERROR_WRONG_CALLBACK                2
1350 #define ZPP_ERROR_WRONG_CLASS                   3
1351 #define ZPP_ERROR_WRONG_CLASS_OR_NULL           4
1352 #define ZPP_ERROR_WRONG_CLASS_OR_STRING         5
1353 #define ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL 6
1354 #define ZPP_ERROR_WRONG_CLASS_OR_LONG           7
1355 #define ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL   8
1356 #define ZPP_ERROR_WRONG_ARG                     9
1357 #define ZPP_ERROR_WRONG_COUNT                   10
1358 #define ZPP_ERROR_UNEXPECTED_EXTRA_NAMED        11
1359 #define ZPP_ERROR_WRONG_CALLBACK_OR_NULL        12
1360 
1361 #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
1362 		const int _flags = (flags); \
1363 		uint32_t _min_num_args = (min_num_args); \
1364 		uint32_t _max_num_args = (uint32_t) (max_num_args); \
1365 		uint32_t _num_args = EX_NUM_ARGS(); \
1366 		uint32_t _i = 0; \
1367 		zval *_real_arg, *_arg = NULL; \
1368 		zend_expected_type _expected_type = Z_EXPECTED_LONG; \
1369 		char *_error = NULL; \
1370 		bool _dummy = 0; \
1371 		bool _optional = 0; \
1372 		int _error_code = ZPP_ERROR_OK; \
1373 		((void)_i); \
1374 		((void)_real_arg); \
1375 		((void)_arg); \
1376 		((void)_expected_type); \
1377 		((void)_error); \
1378 		((void)_optional); \
1379 		((void)_dummy); \
1380 		\
1381 		do { \
1382 			if (UNEXPECTED(_num_args < _min_num_args) || \
1383 			    UNEXPECTED(_num_args > _max_num_args)) { \
1384 				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
1385 					zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
1386 				} \
1387 				_error_code = ZPP_ERROR_FAILURE; \
1388 				break; \
1389 			} \
1390 			_real_arg = ZEND_CALL_ARG(execute_data, 0);
1391 
1392 #define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
1393 	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
1394 
1395 #define ZEND_PARSE_PARAMETERS_NONE() do { \
1396 		if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
1397 			zend_wrong_parameters_none_error(); \
1398 			return; \
1399 		} \
1400 	} while (0)
1401 
1402 #define ZEND_PARSE_PARAMETERS_END_EX(failure) \
1403 			ZEND_ASSERT(_i == _max_num_args || _max_num_args == (uint32_t) -1); \
1404 		} while (0); \
1405 		if (UNEXPECTED(_error_code != ZPP_ERROR_OK)) { \
1406 			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
1407 				zend_wrong_parameter_error(_error_code, _i, _error, _expected_type, _arg); \
1408 			} \
1409 			failure; \
1410 		} \
1411 	} while (0)
1412 
1413 #define ZEND_PARSE_PARAMETERS_END() \
1414 	ZEND_PARSE_PARAMETERS_END_EX(return)
1415 
1416 #define Z_PARAM_PROLOGUE(deref, separate) \
1417 	++_i; \
1418 	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
1419 	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
1420 	if (_optional) { \
1421 		if (UNEXPECTED(_i >_num_args)) break; \
1422 	} \
1423 	_real_arg++; \
1424 	_arg = _real_arg; \
1425 	if (deref) { \
1426 		if (EXPECTED(Z_ISREF_P(_arg))) { \
1427 			_arg = Z_REFVAL_P(_arg); \
1428 		} \
1429 	} \
1430 	if (separate) { \
1431 		SEPARATE_ZVAL_NOREF(_arg); \
1432 	}
1433 
1434 /* old "|" */
1435 #define Z_PARAM_OPTIONAL \
1436 	_optional = 1;
1437 
1438 /* old "a" */
1439 #define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
1440 		Z_PARAM_PROLOGUE(deref, separate); \
1441 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
1442 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1443 			_error_code = ZPP_ERROR_WRONG_ARG; \
1444 			break; \
1445 		}
1446 
1447 #define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
1448 	Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
1449 
1450 #define Z_PARAM_ARRAY(dest) \
1451 	Z_PARAM_ARRAY_EX(dest, 0, 0)
1452 
1453 #define Z_PARAM_ARRAY_OR_NULL(dest) \
1454 	Z_PARAM_ARRAY_EX(dest, 1, 0)
1455 
1456 /* old "A" */
1457 #define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
1458 		Z_PARAM_PROLOGUE(deref, separate); \
1459 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
1460 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1461 			_error_code = ZPP_ERROR_WRONG_ARG; \
1462 			break; \
1463 		}
1464 
1465 #define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
1466 	Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
1467 
1468 #define Z_PARAM_ARRAY_OR_OBJECT(dest) \
1469 	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
1470 
1471 #define Z_PARAM_ITERABLE_EX(dest, check_null) \
1472 	Z_PARAM_PROLOGUE(0, 0); \
1473 	if (UNEXPECTED(!zend_parse_arg_iterable(_arg, &dest, check_null))) { \
1474 		_expected_type = check_null ? Z_EXPECTED_ITERABLE_OR_NULL : Z_EXPECTED_ITERABLE; \
1475 		_error_code = ZPP_ERROR_WRONG_ARG; \
1476 		break; \
1477 	}
1478 
1479 #define Z_PARAM_ITERABLE(dest) \
1480 	Z_PARAM_ITERABLE_EX(dest, 0)
1481 
1482 #define Z_PARAM_ITERABLE_OR_NULL(dest) \
1483 	Z_PARAM_ITERABLE_EX(dest, 1)
1484 
1485 /* old "b" */
1486 #define Z_PARAM_BOOL_EX(dest, is_null, check_null, deref) \
1487 		Z_PARAM_PROLOGUE(deref, 0); \
1488 		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null, _i))) { \
1489 			_expected_type = check_null ? Z_EXPECTED_BOOL_OR_NULL : Z_EXPECTED_BOOL; \
1490 			_error_code = ZPP_ERROR_WRONG_ARG; \
1491 			break; \
1492 		}
1493 
1494 #define Z_PARAM_BOOL(dest) \
1495 	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
1496 
1497 #define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
1498 	Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
1499 
1500 /* old "C" */
1501 #define Z_PARAM_CLASS_EX(dest, check_null, deref) \
1502 		Z_PARAM_PROLOGUE(deref, 0); \
1503 		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
1504 			_error_code = ZPP_ERROR_FAILURE; \
1505 			break; \
1506 		}
1507 
1508 #define Z_PARAM_CLASS(dest) \
1509 	Z_PARAM_CLASS_EX(dest, 0, 0)
1510 
1511 #define Z_PARAM_CLASS_OR_NULL(dest) \
1512 	Z_PARAM_CLASS_EX(dest, 1, 0)
1513 
1514 #define Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, allow_null) \
1515 	Z_PARAM_PROLOGUE(0, 0); \
1516 	if (UNEXPECTED(!zend_parse_arg_obj_or_class_name(_arg, &dest, allow_null))) { \
1517 		_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_CLASS_NAME_OR_NULL : Z_EXPECTED_OBJECT_OR_CLASS_NAME; \
1518 		_error_code = ZPP_ERROR_WRONG_ARG; \
1519 		break; \
1520 	}
1521 
1522 #define Z_PARAM_OBJ_OR_CLASS_NAME(dest) \
1523 	Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 0);
1524 
1525 #define Z_PARAM_OBJ_OR_CLASS_NAME_OR_NULL(dest) \
1526 	Z_PARAM_OBJ_OR_CLASS_NAME_EX(dest, 1);
1527 
1528 #define Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, allow_null) \
1529 	Z_PARAM_PROLOGUE(0, 0); \
1530 	if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, NULL, &destination_string, allow_null, _i))) { \
1531 		_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
1532 		_error_code = ZPP_ERROR_WRONG_ARG; \
1533 		break; \
1534 	}
1535 
1536 #define Z_PARAM_OBJ_OR_STR(destination_object, destination_string) \
1537 	Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 0);
1538 
1539 #define Z_PARAM_OBJ_OR_STR_OR_NULL(destination_object, destination_string) \
1540 	Z_PARAM_OBJ_OR_STR_EX(destination_object, destination_string, 1);
1541 
1542 #define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null) \
1543 	Z_PARAM_PROLOGUE(0, 0); \
1544 	if (UNEXPECTED(!zend_parse_arg_obj_or_str(_arg, &destination_object, base_ce, &destination_string, allow_null, _i))) { \
1545 		if (base_ce) { \
1546 			_error = ZSTR_VAL((base_ce)->name); \
1547 			_error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_STRING_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_STRING; \
1548 			break; \
1549 		} else { \
1550 			_expected_type = allow_null ? Z_EXPECTED_OBJECT_OR_STRING_OR_NULL : Z_EXPECTED_OBJECT_OR_STRING; \
1551 			_error_code = ZPP_ERROR_WRONG_ARG; \
1552 			break; \
1553 		} \
1554 	}
1555 
1556 #define Z_PARAM_OBJ_OF_CLASS_OR_STR(destination_object, base_ce, destination_string) \
1557 	Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 0);
1558 
1559 #define Z_PARAM_OBJ_OF_CLASS_OR_STR_OR_NULL(destination_object, base_ce, destination_string) \
1560 	Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, 1);
1561 
1562 /* old "d" */
1563 #define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, deref) \
1564 		Z_PARAM_PROLOGUE(deref, 0); \
1565 		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null, _i))) { \
1566 			_expected_type = check_null ? Z_EXPECTED_DOUBLE_OR_NULL : Z_EXPECTED_DOUBLE; \
1567 			_error_code = ZPP_ERROR_WRONG_ARG; \
1568 			break; \
1569 		}
1570 
1571 #define Z_PARAM_DOUBLE(dest) \
1572 	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
1573 
1574 #define Z_PARAM_DOUBLE_OR_NULL(dest, is_null) \
1575 	Z_PARAM_DOUBLE_EX(dest, is_null, 1, 0)
1576 
1577 /* old "f" */
1578 #define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, deref) \
1579 		Z_PARAM_PROLOGUE(deref, 0); \
1580 		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
1581 			if (!_error) { \
1582 				_expected_type = check_null ? Z_EXPECTED_FUNC_OR_NULL : Z_EXPECTED_FUNC; \
1583 				_error_code = ZPP_ERROR_WRONG_ARG; \
1584 			} else { \
1585 				_error_code = check_null ? ZPP_ERROR_WRONG_CALLBACK_OR_NULL : ZPP_ERROR_WRONG_CALLBACK; \
1586 			} \
1587 			break; \
1588 		} \
1589 
1590 #define Z_PARAM_FUNC(dest_fci, dest_fcc) \
1591 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
1592 
1593 #define Z_PARAM_FUNC_OR_NULL(dest_fci, dest_fcc) \
1594 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0)
1595 
1596 /* old "h" */
1597 #define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
1598 		Z_PARAM_PROLOGUE(deref, separate); \
1599 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
1600 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1601 			_error_code = ZPP_ERROR_WRONG_ARG; \
1602 			break; \
1603 		}
1604 
1605 #define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
1606 	Z_PARAM_ARRAY_HT_EX2(dest, check_null, separate, separate)
1607 
1608 #define Z_PARAM_ARRAY_HT(dest) \
1609 	Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
1610 
1611 #define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
1612 	Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
1613 
1614 #define Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, allow_null) \
1615 	Z_PARAM_PROLOGUE(0, 0); \
1616 	if (UNEXPECTED(!zend_parse_arg_array_ht_or_long(_arg, &dest_ht, &dest_long, &is_null, allow_null, _i))) { \
1617 		_expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_LONG_OR_NULL : Z_EXPECTED_ARRAY_OR_LONG; \
1618 		_error_code = ZPP_ERROR_WRONG_ARG; \
1619 		break; \
1620 	}
1621 
1622 #define Z_PARAM_ARRAY_HT_OR_LONG(dest_ht, dest_long) \
1623 	Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, _dummy, 0)
1624 
1625 #define Z_PARAM_ARRAY_HT_OR_LONG_OR_NULL(dest_ht, dest_long, is_null) \
1626 	Z_PARAM_ARRAY_HT_OR_LONG_EX(dest_ht, dest_long, is_null, 1)
1627 
1628 /* old "H" */
1629 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
1630 		Z_PARAM_PROLOGUE(deref, separate); \
1631 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 1, separate))) { \
1632 			_expected_type = check_null ? Z_EXPECTED_ARRAY_OR_NULL : Z_EXPECTED_ARRAY; \
1633 			_error_code = ZPP_ERROR_WRONG_ARG; \
1634 			break; \
1635 		}
1636 
1637 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
1638 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, separate, separate)
1639 
1640 #define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
1641 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, 0, 0)
1642 
1643 /* old "l" */
1644 #define Z_PARAM_LONG_EX(dest, is_null, check_null, deref) \
1645 		Z_PARAM_PROLOGUE(deref, 0); \
1646 		if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, _i))) { \
1647 			_expected_type = check_null ? Z_EXPECTED_LONG_OR_NULL : Z_EXPECTED_LONG; \
1648 			_error_code = ZPP_ERROR_WRONG_ARG; \
1649 			break; \
1650 		}
1651 
1652 #define Z_PARAM_LONG(dest) \
1653 	Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
1654 
1655 #define Z_PARAM_LONG_OR_NULL(dest, is_null) \
1656 	Z_PARAM_LONG_EX(dest, is_null, 1, 0)
1657 
1658 /* old "n" */
1659 #define Z_PARAM_NUMBER_EX(dest, check_null) \
1660 	Z_PARAM_PROLOGUE(0, 0); \
1661 	if (UNEXPECTED(!zend_parse_arg_number(_arg, &dest, check_null, _i))) { \
1662 		_expected_type = check_null ? Z_EXPECTED_NUMBER_OR_NULL : Z_EXPECTED_NUMBER; \
1663 		_error_code = ZPP_ERROR_WRONG_ARG; \
1664 		break; \
1665 	}
1666 
1667 #define Z_PARAM_NUMBER_OR_NULL(dest) \
1668 	Z_PARAM_NUMBER_EX(dest, 1)
1669 
1670 #define Z_PARAM_NUMBER(dest) \
1671 	Z_PARAM_NUMBER_EX(dest, 0)
1672 
1673 /* old "o" */
1674 #define Z_PARAM_OBJECT_EX(dest, check_null, deref) \
1675 		Z_PARAM_PROLOGUE(deref, 0); \
1676 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, NULL, check_null))) { \
1677 			_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1678 			_error_code = ZPP_ERROR_WRONG_ARG; \
1679 			break; \
1680 		}
1681 
1682 #define Z_PARAM_OBJECT(dest) \
1683 	Z_PARAM_OBJECT_EX(dest, 0, 0)
1684 
1685 #define Z_PARAM_OBJECT_OR_NULL(dest) \
1686 	Z_PARAM_OBJECT_EX(dest, 1, 0)
1687 
1688 /* The same as Z_PARAM_OBJECT_EX except that dest is a zend_object rather than a zval */
1689 #define Z_PARAM_OBJ_EX(dest, check_null, deref) \
1690 		Z_PARAM_PROLOGUE(deref, 0); \
1691 		if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, NULL, check_null))) { \
1692 			_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1693 			_error_code = ZPP_ERROR_WRONG_ARG; \
1694 			break; \
1695 		}
1696 
1697 #define Z_PARAM_OBJ(dest) \
1698 	Z_PARAM_OBJ_EX(dest, 0, 0)
1699 
1700 #define Z_PARAM_OBJ_OR_NULL(dest) \
1701 	Z_PARAM_OBJ_EX(dest, 1, 0)
1702 
1703 /* old "O" */
1704 #define Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, check_null, deref) \
1705 		Z_PARAM_PROLOGUE(deref, 0); \
1706 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, _ce, check_null))) { \
1707 			if (_ce) { \
1708 				_error = ZSTR_VAL((_ce)->name); \
1709 				_error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
1710 				break; \
1711 			} else { \
1712 				_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1713 				_error_code = ZPP_ERROR_WRONG_ARG; \
1714 				break; \
1715 			} \
1716 		}
1717 
1718 #define Z_PARAM_OBJECT_OF_CLASS(dest, _ce) \
1719 	Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 0, 0)
1720 
1721 #define Z_PARAM_OBJECT_OF_CLASS_OR_NULL(dest, _ce) \
1722 	Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 1, 0)
1723 
1724 /* The same as Z_PARAM_OBJECT_OF_CLASS_EX except that dest is a zend_object rather than a zval */
1725 #define Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, check_null, deref) \
1726 		Z_PARAM_PROLOGUE(deref, 0); \
1727 		if (UNEXPECTED(!zend_parse_arg_obj(_arg, &dest, _ce, check_null))) { \
1728 			if (_ce) { \
1729 				_error = ZSTR_VAL((_ce)->name); \
1730 				_error_code = check_null ? ZPP_ERROR_WRONG_CLASS_OR_NULL : ZPP_ERROR_WRONG_CLASS; \
1731 				break; \
1732 			} else { \
1733 				_expected_type = check_null ? Z_EXPECTED_OBJECT_OR_NULL : Z_EXPECTED_OBJECT; \
1734 				_error_code = ZPP_ERROR_WRONG_ARG; \
1735 				break; \
1736 			} \
1737 		}
1738 
1739 #define Z_PARAM_OBJ_OF_CLASS(dest, _ce) \
1740 	Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 0, 0)
1741 
1742 #define Z_PARAM_OBJ_OF_CLASS_OR_NULL(dest, _ce) \
1743 	Z_PARAM_OBJ_OF_CLASS_EX(dest, _ce, 1, 0)
1744 
1745 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, allow_null) \
1746 		Z_PARAM_PROLOGUE(0, 0); \
1747 		if (UNEXPECTED(!zend_parse_arg_obj_or_long(_arg, &dest_obj, _ce, &dest_long, &is_null, allow_null, _i))) { \
1748 			_error = ZSTR_VAL((_ce)->name); \
1749 			_error_code = allow_null ? ZPP_ERROR_WRONG_CLASS_OR_LONG_OR_NULL : ZPP_ERROR_WRONG_CLASS_OR_LONG; \
1750 			break; \
1751 		}
1752 
1753 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG(dest_obj, _ce, dest_long) \
1754 	Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, _dummy, 0)
1755 
1756 #define Z_PARAM_OBJ_OF_CLASS_OR_LONG_OR_NULL(dest_obj, _ce, dest_long, is_null) \
1757 	Z_PARAM_OBJ_OF_CLASS_OR_LONG_EX(dest_obj, _ce, dest_long, is_null, 1)
1758 
1759 /* old "p" */
1760 #define Z_PARAM_PATH_EX(dest, dest_len, check_null, deref) \
1761 		Z_PARAM_PROLOGUE(deref, 0); \
1762 		if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null, _i))) { \
1763 			_expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
1764 			_error_code = ZPP_ERROR_WRONG_ARG; \
1765 			break; \
1766 		}
1767 
1768 #define Z_PARAM_PATH(dest, dest_len) \
1769 	Z_PARAM_PATH_EX(dest, dest_len, 0, 0)
1770 
1771 #define Z_PARAM_PATH_OR_NULL(dest, dest_len) \
1772 	Z_PARAM_PATH_EX(dest, dest_len, 1, 0)
1773 
1774 /* old "P" */
1775 #define Z_PARAM_PATH_STR_EX(dest, check_null, deref) \
1776 		Z_PARAM_PROLOGUE(deref, 0); \
1777 		if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null, _i))) { \
1778 			_expected_type = check_null ? Z_EXPECTED_PATH_OR_NULL : Z_EXPECTED_PATH; \
1779 			_error_code = ZPP_ERROR_WRONG_ARG; \
1780 			break; \
1781 		}
1782 
1783 #define Z_PARAM_PATH_STR(dest) \
1784 	Z_PARAM_PATH_STR_EX(dest, 0, 0)
1785 
1786 #define Z_PARAM_PATH_STR_OR_NULL(dest) \
1787 	Z_PARAM_PATH_STR_EX(dest, 1, 0)
1788 
1789 /* old "r" */
1790 #define Z_PARAM_RESOURCE_EX(dest, check_null, deref) \
1791 		Z_PARAM_PROLOGUE(deref, 0); \
1792 		if (UNEXPECTED(!zend_parse_arg_resource(_arg, &dest, check_null))) { \
1793 			_expected_type = check_null ? Z_EXPECTED_RESOURCE_OR_NULL : Z_EXPECTED_RESOURCE; \
1794 			_error_code = ZPP_ERROR_WRONG_ARG; \
1795 			break; \
1796 		}
1797 
1798 #define Z_PARAM_RESOURCE(dest) \
1799 	Z_PARAM_RESOURCE_EX(dest, 0, 0)
1800 
1801 #define Z_PARAM_RESOURCE_OR_NULL(dest) \
1802 	Z_PARAM_RESOURCE_EX(dest, 1, 0)
1803 
1804 /* old "s" */
1805 #define Z_PARAM_STRING_EX(dest, dest_len, check_null, deref) \
1806 		Z_PARAM_PROLOGUE(deref, 0); \
1807 		if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null, _i))) { \
1808 			_expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
1809 			_error_code = ZPP_ERROR_WRONG_ARG; \
1810 			break; \
1811 		}
1812 
1813 #define Z_PARAM_STRING(dest, dest_len) \
1814 	Z_PARAM_STRING_EX(dest, dest_len, 0, 0)
1815 
1816 #define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
1817 	Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
1818 
1819 /* old "S" */
1820 #define Z_PARAM_STR_EX(dest, check_null, deref) \
1821 		Z_PARAM_PROLOGUE(deref, 0); \
1822 		if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null, _i))) { \
1823 			_expected_type = check_null ? Z_EXPECTED_STRING_OR_NULL : Z_EXPECTED_STRING; \
1824 			_error_code = ZPP_ERROR_WRONG_ARG; \
1825 			break; \
1826 		}
1827 
1828 #define Z_PARAM_STR(dest) \
1829 	Z_PARAM_STR_EX(dest, 0, 0)
1830 
1831 #define Z_PARAM_STR_OR_NULL(dest) \
1832 	Z_PARAM_STR_EX(dest, 1, 0)
1833 
1834 /* old "z" */
1835 #define Z_PARAM_ZVAL_EX2(dest, check_null, deref, separate) \
1836 		Z_PARAM_PROLOGUE(deref, separate); \
1837 		zend_parse_arg_zval_deref(_arg, &dest, check_null);
1838 
1839 #define Z_PARAM_ZVAL_EX(dest, check_null, separate) \
1840 	Z_PARAM_ZVAL_EX2(dest, check_null, separate, separate)
1841 
1842 #define Z_PARAM_ZVAL(dest) \
1843 	Z_PARAM_ZVAL_EX(dest, 0, 0)
1844 
1845 #define Z_PARAM_ZVAL_OR_NULL(dest) \
1846 	Z_PARAM_ZVAL_EX(dest, 1, 0)
1847 
1848 /* old "+" and "*" */
1849 #define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
1850 		uint32_t _num_varargs = _num_args - _i - (post_varargs); \
1851 		if (EXPECTED(_num_varargs > 0)) { \
1852 			dest = _real_arg + 1; \
1853 			dest_num = _num_varargs; \
1854 			_i += _num_varargs; \
1855 			_real_arg += _num_varargs; \
1856 		} else { \
1857 			dest = NULL; \
1858 			dest_num = 0; \
1859 		} \
1860 		if (UNEXPECTED(ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)) { \
1861 			_error_code = ZPP_ERROR_UNEXPECTED_EXTRA_NAMED; \
1862 			break; \
1863 		} \
1864 	} while (0);
1865 
1866 #define Z_PARAM_VARIADIC(spec, dest, dest_num) \
1867 	Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0)
1868 
1869 #define Z_PARAM_VARIADIC_WITH_NAMED(dest, dest_num, dest_named) do { \
1870 		int _num_varargs = _num_args - _i; \
1871 		if (EXPECTED(_num_varargs > 0)) { \
1872 			dest = _real_arg + 1; \
1873 			dest_num = _num_varargs; \
1874 		} else { \
1875 			dest = NULL; \
1876 			dest_num = 0; \
1877 		} \
1878 		if (ZEND_CALL_INFO(execute_data) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { \
1879 			dest_named = execute_data->extra_named_params; \
1880 		} else { \
1881 			dest_named = NULL; \
1882 		} \
1883 	} while (0);
1884 
1885 #define Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, allow_null) \
1886 	Z_PARAM_PROLOGUE(0, 0); \
1887 	if (UNEXPECTED(!zend_parse_arg_array_ht_or_str(_arg, &dest_ht, &dest_str, allow_null, _i))) { \
1888 		_expected_type = allow_null ? Z_EXPECTED_ARRAY_OR_STRING_OR_NULL : Z_EXPECTED_ARRAY_OR_STRING; \
1889 		_error_code = ZPP_ERROR_WRONG_ARG; \
1890 		break; \
1891 	}
1892 
1893 #define Z_PARAM_ARRAY_HT_OR_STR(dest_ht, dest_str) \
1894 	Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 0);
1895 
1896 #define Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(dest_ht, dest_str) \
1897 	Z_PARAM_ARRAY_HT_OR_STR_EX(dest_ht, dest_str, 1);
1898 
1899 #define Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, allow_null) \
1900 	Z_PARAM_PROLOGUE(0, 0); \
1901 	if (UNEXPECTED(!zend_parse_arg_str_or_long(_arg, &dest_str, &dest_long, &is_null, allow_null, _i))) { \
1902 		_expected_type = allow_null ? Z_EXPECTED_STRING_OR_LONG_OR_NULL : Z_EXPECTED_STRING_OR_LONG; \
1903 		_error_code = ZPP_ERROR_WRONG_ARG; \
1904 		break; \
1905 	}
1906 
1907 #define Z_PARAM_STR_OR_LONG(dest_str, dest_long) \
1908 	Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, _dummy, 0);
1909 
1910 #define Z_PARAM_STR_OR_LONG_OR_NULL(dest_str, dest_long, is_null) \
1911 	Z_PARAM_STR_OR_LONG_EX(dest_str, dest_long, is_null, 1);
1912 
1913 /* End of new parameter parsing API */
1914 
1915 /* Inlined implementations shared by new and old parameter parsing APIs */
1916 
1917 ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, bool check_null);
1918 ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, bool *dest, uint32_t arg_num);
1919 ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest, uint32_t arg_num);
1920 ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest, uint32_t arg_num);
1921 ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest, uint32_t arg_num);
1922 ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest, uint32_t arg_num);
1923 ZEND_API bool ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest, uint32_t arg_num);
1924 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest, uint32_t arg_num);
1925 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest, uint32_t arg_num);
1926 ZEND_API bool ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest, uint32_t arg_num);
1927 ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_or_long_slow(zval *arg, zend_string **dest_str, zend_long *dest_long, uint32_t arg_num);
1928 
zend_parse_arg_bool(zval * arg,bool * dest,bool * is_null,bool check_null,uint32_t arg_num)1929 static zend_always_inline bool zend_parse_arg_bool(zval *arg, bool *dest, bool *is_null, bool check_null, uint32_t arg_num)
1930 {
1931 	if (check_null) {
1932 		*is_null = 0;
1933 	}
1934 	if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
1935 		*dest = 1;
1936 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_FALSE)) {
1937 		*dest = 0;
1938 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1939 		*is_null = 1;
1940 		*dest = 0;
1941 	} else {
1942 		return zend_parse_arg_bool_slow(arg, dest, arg_num);
1943 	}
1944 	return 1;
1945 }
1946 
zend_parse_arg_long(zval * arg,zend_long * dest,bool * is_null,bool check_null,uint32_t arg_num)1947 static zend_always_inline bool zend_parse_arg_long(zval *arg, zend_long *dest, bool *is_null, bool check_null, uint32_t arg_num)
1948 {
1949 	if (check_null) {
1950 		*is_null = 0;
1951 	}
1952 	if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
1953 		*dest = Z_LVAL_P(arg);
1954 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1955 		*is_null = 1;
1956 		*dest = 0;
1957 	} else {
1958 		return zend_parse_arg_long_slow(arg, dest, arg_num);
1959 	}
1960 	return 1;
1961 }
1962 
zend_parse_arg_double(zval * arg,double * dest,bool * is_null,bool check_null,uint32_t arg_num)1963 static zend_always_inline bool zend_parse_arg_double(zval *arg, double *dest, bool *is_null, bool check_null, uint32_t arg_num)
1964 {
1965 	if (check_null) {
1966 		*is_null = 0;
1967 	}
1968 	if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
1969 		*dest = Z_DVAL_P(arg);
1970 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1971 		*is_null = 1;
1972 		*dest = 0.0;
1973 	} else {
1974 		return zend_parse_arg_double_slow(arg, dest, arg_num);
1975 	}
1976 	return 1;
1977 }
1978 
zend_parse_arg_number(zval * arg,zval ** dest,bool check_null,uint32_t arg_num)1979 static zend_always_inline bool zend_parse_arg_number(zval *arg, zval **dest, bool check_null, uint32_t arg_num)
1980 {
1981 	if (EXPECTED(Z_TYPE_P(arg) == IS_LONG || Z_TYPE_P(arg) == IS_DOUBLE)) {
1982 		*dest = arg;
1983 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1984 		*dest = NULL;
1985 	} else {
1986 		return zend_parse_arg_number_slow(arg, dest, arg_num);
1987 	}
1988 	return 1;
1989 }
1990 
zend_parse_arg_str(zval * arg,zend_string ** dest,bool check_null,uint32_t arg_num)1991 static zend_always_inline bool zend_parse_arg_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
1992 {
1993 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
1994 		*dest = Z_STR_P(arg);
1995 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1996 		*dest = NULL;
1997 	} else {
1998 		return zend_parse_arg_str_slow(arg, dest, arg_num);
1999 	}
2000 	return 1;
2001 }
2002 
zend_parse_arg_string(zval * arg,char ** dest,size_t * dest_len,bool check_null,uint32_t arg_num)2003 static zend_always_inline bool zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
2004 {
2005 	zend_string *str;
2006 
2007 	if (!zend_parse_arg_str(arg, &str, check_null, arg_num)) {
2008 		return 0;
2009 	}
2010 	if (check_null && UNEXPECTED(!str)) {
2011 		*dest = NULL;
2012 		*dest_len = 0;
2013 	} else {
2014 		*dest = ZSTR_VAL(str);
2015 		*dest_len = ZSTR_LEN(str);
2016 	}
2017 	return 1;
2018 }
2019 
zend_parse_arg_path_str(zval * arg,zend_string ** dest,bool check_null,uint32_t arg_num)2020 static zend_always_inline bool zend_parse_arg_path_str(zval *arg, zend_string **dest, bool check_null, uint32_t arg_num)
2021 {
2022 	if (!zend_parse_arg_str(arg, dest, check_null, arg_num) ||
2023 	    (*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
2024 		return 0;
2025 	}
2026 	return 1;
2027 }
2028 
zend_parse_arg_path(zval * arg,char ** dest,size_t * dest_len,bool check_null,uint32_t arg_num)2029 static zend_always_inline bool zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, bool check_null, uint32_t arg_num)
2030 {
2031 	zend_string *str;
2032 
2033 	if (!zend_parse_arg_path_str(arg, &str, check_null, arg_num)) {
2034 		return 0;
2035 	}
2036 	if (check_null && UNEXPECTED(!str)) {
2037 		*dest = NULL;
2038 		*dest_len = 0;
2039 	} else {
2040 		*dest = ZSTR_VAL(str);
2041 		*dest_len = ZSTR_LEN(str);
2042 	}
2043 	return 1;
2044 }
2045 
zend_parse_arg_iterable(zval * arg,zval ** dest,bool check_null)2046 static zend_always_inline bool zend_parse_arg_iterable(zval *arg, zval **dest, bool check_null)
2047 {
2048 	if (EXPECTED(zend_is_iterable(arg))) {
2049 		*dest = arg;
2050 		return 1;
2051 	}
2052 
2053 	if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2054 		*dest = NULL;
2055 		return 1;
2056 	}
2057 
2058 	return 0;
2059 }
2060 
zend_parse_arg_array(zval * arg,zval ** dest,bool check_null,bool or_object)2061 static zend_always_inline bool zend_parse_arg_array(zval *arg, zval **dest, bool check_null, bool or_object)
2062 {
2063 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) ||
2064 		(or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) {
2065 		*dest = arg;
2066 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2067 		*dest = NULL;
2068 	} else {
2069 		return 0;
2070 	}
2071 	return 1;
2072 }
2073 
zend_parse_arg_array_ht(zval * arg,HashTable ** dest,bool check_null,bool or_object,bool separate)2074 static zend_always_inline bool zend_parse_arg_array_ht(zval *arg, HashTable **dest, bool check_null, bool or_object, bool separate)
2075 {
2076 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2077 		*dest = Z_ARRVAL_P(arg);
2078 	} else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2079 		zend_object *zobj = Z_OBJ_P(arg);
2080 		if (separate
2081 		 && zobj->properties
2082 		 && UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
2083 			if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
2084 				GC_DELREF(zobj->properties);
2085 			}
2086 			zobj->properties = zend_array_dup(zobj->properties);
2087 		}
2088 		*dest = zobj->handlers->get_properties(zobj);
2089 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2090 		*dest = NULL;
2091 	} else {
2092 		return 0;
2093 	}
2094 	return 1;
2095 }
2096 
zend_parse_arg_array_ht_or_long(zval * arg,HashTable ** dest_ht,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2097 static zend_always_inline bool zend_parse_arg_array_ht_or_long(
2098 	zval *arg, HashTable **dest_ht, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
2099 ) {
2100 	if (allow_null) {
2101 		*is_null = 0;
2102 	}
2103 
2104 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2105 		*dest_ht = Z_ARRVAL_P(arg);
2106 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2107 		*dest_ht = NULL;
2108 		*dest_long = Z_LVAL_P(arg);
2109 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2110 		*dest_ht = NULL;
2111 		*is_null = 1;
2112 	} else {
2113 		*dest_ht = NULL;
2114 		return zend_parse_arg_long_slow(arg, dest_long, arg_num);
2115 	}
2116 
2117 	return 1;
2118 }
2119 
zend_parse_arg_object(zval * arg,zval ** dest,zend_class_entry * ce,bool check_null)2120 static zend_always_inline bool zend_parse_arg_object(zval *arg, zval **dest, zend_class_entry *ce, bool check_null)
2121 {
2122 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
2123 	    (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
2124 		*dest = arg;
2125 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2126 		*dest = NULL;
2127 	} else {
2128 		return 0;
2129 	}
2130 	return 1;
2131 }
2132 
zend_parse_arg_obj(zval * arg,zend_object ** dest,zend_class_entry * ce,bool check_null)2133 static zend_always_inline bool zend_parse_arg_obj(zval *arg, zend_object **dest, zend_class_entry *ce, bool check_null)
2134 {
2135 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
2136 	    (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
2137 		*dest = Z_OBJ_P(arg);
2138 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2139 		*dest = NULL;
2140 	} else {
2141 		return 0;
2142 	}
2143 	return 1;
2144 }
2145 
zend_parse_arg_obj_or_long(zval * arg,zend_object ** dest_obj,zend_class_entry * ce,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2146 static zend_always_inline bool zend_parse_arg_obj_or_long(
2147 	zval *arg, zend_object **dest_obj, zend_class_entry *ce, zend_long *dest_long, bool *is_null, bool allow_null, uint32_t arg_num
2148 ) {
2149 	if (allow_null) {
2150 		*is_null = 0;
2151 	}
2152 
2153 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) && EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0)) {
2154 		*dest_obj = Z_OBJ_P(arg);
2155 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2156 		*dest_obj = NULL;
2157 		*dest_long = Z_LVAL_P(arg);
2158 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2159 		*dest_obj = NULL;
2160 		*is_null = 1;
2161 	} else {
2162 		*dest_obj = NULL;
2163 		return zend_parse_arg_long_slow(arg, dest_long, arg_num);
2164 	}
2165 
2166 	return 1;
2167 }
2168 
zend_parse_arg_resource(zval * arg,zval ** dest,bool check_null)2169 static zend_always_inline bool zend_parse_arg_resource(zval *arg, zval **dest, bool check_null)
2170 {
2171 	if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
2172 		*dest = arg;
2173 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2174 		*dest = NULL;
2175 	} else {
2176 		return 0;
2177 	}
2178 	return 1;
2179 }
2180 
zend_parse_arg_func(zval * arg,zend_fcall_info * dest_fci,zend_fcall_info_cache * dest_fcc,bool check_null,char ** error)2181 static zend_always_inline bool zend_parse_arg_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, bool check_null, char **error)
2182 {
2183 	if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2184 		dest_fci->size = 0;
2185 		dest_fcc->function_handler = NULL;
2186 		*error = NULL;
2187 	} else if (UNEXPECTED(zend_fcall_info_init(arg, 0, dest_fci, dest_fcc, NULL, error) != SUCCESS)) {
2188 		return 0;
2189 	}
2190 	/* Release call trampolines: The function may not get called, in which case
2191 	 * the trampoline will leak. Force it to be refetched during
2192 	 * zend_call_function instead. */
2193 	zend_release_fcall_info_cache(dest_fcc);
2194 	return 1;
2195 }
2196 
zend_parse_arg_zval(zval * arg,zval ** dest,bool check_null)2197 static zend_always_inline void zend_parse_arg_zval(zval *arg, zval **dest, bool check_null)
2198 {
2199 	*dest = (check_null &&
2200 	    (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) ||
2201 	     (UNEXPECTED(Z_ISREF_P(arg)) &&
2202 	      UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg;
2203 }
2204 
zend_parse_arg_zval_deref(zval * arg,zval ** dest,bool check_null)2205 static zend_always_inline void zend_parse_arg_zval_deref(zval *arg, zval **dest, bool check_null)
2206 {
2207 	*dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg;
2208 }
2209 
zend_parse_arg_array_ht_or_str(zval * arg,HashTable ** dest_ht,zend_string ** dest_str,bool allow_null,uint32_t arg_num)2210 static zend_always_inline bool zend_parse_arg_array_ht_or_str(
2211 		zval *arg, HashTable **dest_ht, zend_string **dest_str, bool allow_null, uint32_t arg_num)
2212 {
2213 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2214 		*dest_ht = NULL;
2215 		*dest_str = Z_STR_P(arg);
2216 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
2217 		*dest_ht = Z_ARRVAL_P(arg);
2218 		*dest_str = NULL;
2219 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2220 		*dest_ht = NULL;
2221 		*dest_str = NULL;
2222 	} else {
2223 		*dest_ht = NULL;
2224 		return zend_parse_arg_str_slow(arg, dest_str, arg_num);
2225 	}
2226 	return 1;
2227 }
2228 
zend_parse_arg_str_or_long(zval * arg,zend_string ** dest_str,zend_long * dest_long,bool * is_null,bool allow_null,uint32_t arg_num)2229 static zend_always_inline bool zend_parse_arg_str_or_long(zval *arg, zend_string **dest_str, zend_long *dest_long,
2230 	bool *is_null, bool allow_null, uint32_t arg_num)
2231 {
2232 	if (allow_null) {
2233 		*is_null = 0;
2234 	}
2235 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2236 		*dest_str = Z_STR_P(arg);
2237 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
2238 		*dest_str = NULL;
2239 		*dest_long = Z_LVAL_P(arg);
2240 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2241 		*dest_str = NULL;
2242 		*is_null = 1;
2243 	} else {
2244 		return zend_parse_arg_str_or_long_slow(arg, dest_str, dest_long, arg_num);
2245 	}
2246 	return 1;
2247 }
2248 
zend_parse_arg_obj_or_class_name(zval * arg,zend_class_entry ** destination,bool allow_null)2249 static zend_always_inline bool zend_parse_arg_obj_or_class_name(
2250 	zval *arg, zend_class_entry **destination, bool allow_null
2251 ) {
2252 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
2253 		*destination = zend_lookup_class(Z_STR_P(arg));
2254 
2255 		return *destination != NULL;
2256 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2257 		*destination = Z_OBJ_P(arg)->ce;
2258 	} else if (allow_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
2259 		*destination = NULL;
2260 	} else {
2261 		return 0;
2262 	}
2263 
2264 	return 1;
2265 }
2266 
zend_parse_arg_obj_or_str(zval * arg,zend_object ** destination_object,zend_class_entry * base_ce,zend_string ** destination_string,bool allow_null,uint32_t arg_num)2267 static zend_always_inline bool zend_parse_arg_obj_or_str(
2268 	zval *arg, zend_object **destination_object, zend_class_entry *base_ce, zend_string **destination_string, bool allow_null, uint32_t arg_num
2269 ) {
2270 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
2271 		if (!base_ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), base_ce))) {
2272 			*destination_object = Z_OBJ_P(arg);
2273 			*destination_string = NULL;
2274 			return 1;
2275 		}
2276 	}
2277 
2278 	*destination_object = NULL;
2279 	return zend_parse_arg_str(arg, destination_string, allow_null, arg_num);
2280 }
2281 
2282 END_EXTERN_C()
2283 
2284 #endif /* ZEND_API_H */
2285