xref: /PHP-7.3/Zend/zend_API.h (revision cce2e33c)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@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 
31 
32 BEGIN_EXTERN_C()
33 
34 typedef struct _zend_function_entry {
35 	const char *fname;
36 	zif_handler handler;
37 	const struct _zend_internal_arg_info *arg_info;
38 	uint32_t num_args;
39 	uint32_t flags;
40 } zend_function_entry;
41 
42 typedef struct _zend_fcall_info {
43 	size_t size;
44 	zval function_name;
45 	zval *retval;
46 	zval *params;
47 	zend_object *object;
48 	zend_bool no_separation;
49 	uint32_t param_count;
50 } zend_fcall_info;
51 
52 typedef struct _zend_fcall_info_cache {
53 	zend_function *function_handler;
54 	zend_class_entry *calling_scope;
55 	zend_class_entry *called_scope;
56 	zend_object *object;
57 } zend_fcall_info_cache;
58 
59 #define ZEND_NS_NAME(ns, name)			ns "\\" name
60 
61 #define ZEND_FN(name) zif_##name
62 #define ZEND_MN(name) zim_##name
63 #define ZEND_NAMED_FUNCTION(name)		void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
64 #define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(ZEND_FN(name))
65 #define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
66 
67 #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 },
68 
69 #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 },
70 #define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
71 
72 #define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_FENTRY(zend_name, name, arg_info, 0)
73 #define ZEND_FE(name, arg_info)						ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
74 #define ZEND_DEP_FE(name, arg_info)                 ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
75 #define ZEND_FALIAS(name, alias, arg_info)			ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
76 #define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
77 #define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
78 #define ZEND_ME(classname, name, arg_info, flags)	ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
79 #define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
80 #define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
81                                                     ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
82 #define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
83 
84 #define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags)		ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
85 
86 #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)
87 #define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
88 
89 #define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
90 #define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
91 #define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
92 #define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
93 #define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
94 
95 #define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
96 
97 #define ZEND_ARG_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 0},
98 #define ZEND_ARG_PASS_INFO(pass_by_ref)                              { NULL,  0, pass_by_ref, 0},
99 #define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null)  { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, 0 },
100 #define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null)           { #name, ZEND_TYPE_ENCODE(IS_ARRAY, allow_null), pass_by_ref, 0 },
101 #define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null)        { #name, ZEND_TYPE_ENCODE(IS_CALLABLE, allow_null), pass_by_ref, 0 },
102 #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE(type_hint, allow_null), pass_by_ref, 0 },
103 #define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 1 },
104 #define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE(type_hint, allow_null), pass_by_ref, 1 },
105 #define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, classname, allow_null)  { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, 1 },
106 
107 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
108 	static const zend_internal_arg_info name[] = { \
109 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, 0 },
110 
111 #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
112 	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, 0, -1, class_name, allow_null)
113 
114 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
115 	static const zend_internal_arg_info name[] = { \
116 		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE(type, allow_null), return_reference, 0 },
117 #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
118 	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
119 
120 #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
121 	static const zend_internal_arg_info name[] = { \
122 		{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, 0 },
123 #define ZEND_BEGIN_ARG_INFO(name, _unused)	\
124 	ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
125 #define ZEND_END_ARG_INFO()		};
126 
127 /* Name macros */
128 #define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
129 #define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
130 #define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
131 #define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
132 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
133 #define ZEND_MODULE_INFO_N(module)			zm_info_##module
134 #define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
135 #define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
136 
137 /* Declaration macros */
138 #define ZEND_MODULE_STARTUP_D(module)		int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
139 #define ZEND_MODULE_SHUTDOWN_D(module)		int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
140 #define ZEND_MODULE_ACTIVATE_D(module)		int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
141 #define ZEND_MODULE_DEACTIVATE_D(module)	int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
142 #define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
143 #define ZEND_MODULE_INFO_D(module)			void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
144 #define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
145 #define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
146 
147 #define ZEND_GET_MODULE(name) \
148     BEGIN_EXTERN_C()\
149 	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
150     END_EXTERN_C()
151 
152 #define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
153 	typedef struct _zend_##module_name##_globals {
154 #define ZEND_END_MODULE_GLOBALS(module_name)		\
155 	} zend_##module_name##_globals;
156 
157 #ifdef ZTS
158 
159 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
160 	ts_rsrc_id module_name##_globals_id;
161 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
162 	extern ts_rsrc_id module_name##_globals_id;
163 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
164 	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
165 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
166 #if ZEND_ENABLE_STATIC_TSRMLS_CACHE
167 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
168 #else
169 #define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
170 #endif
171 
172 #else
173 
174 #define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
175 	zend_##module_name##_globals module_name##_globals;
176 #define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
177 	extern zend_##module_name##_globals module_name##_globals;
178 #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
179 	globals_ctor(&module_name##_globals);
180 #define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
181 #define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
182 
183 #endif
184 
185 #define INIT_CLASS_ENTRY(class_container, class_name, functions) \
186 	INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
187 
188 #define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
189 	{															\
190 		memset(&class_container, 0, sizeof(zend_class_entry)); \
191 		class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
192 		class_container.info.internal.builtin_functions = functions;	\
193 	}
194 
195 #define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
196 	{															\
197 		class_container.constructor = NULL;						\
198 		class_container.destructor = NULL;						\
199 		class_container.clone = NULL;							\
200 		class_container.serialize = NULL;						\
201 		class_container.unserialize = NULL;						\
202 		class_container.create_object = NULL;					\
203 		class_container.get_static_method = NULL;				\
204 		class_container.__call = NULL;							\
205 		class_container.__callstatic = NULL;					\
206 		class_container.__tostring = NULL;						\
207 		class_container.__get = NULL;							\
208 		class_container.__set = NULL;							\
209 		class_container.__unset = NULL;							\
210 		class_container.__isset = NULL;							\
211 		class_container.__debugInfo = NULL;						\
212 		class_container.serialize_func = NULL;					\
213 		class_container.unserialize_func = NULL;				\
214 		class_container.parent = NULL;							\
215 		class_container.num_interfaces = 0;						\
216 		class_container.traits = NULL;							\
217 		class_container.num_traits = 0;							\
218 		class_container.trait_aliases = NULL;					\
219 		class_container.trait_precedences = NULL;				\
220 		class_container.interfaces = NULL;						\
221 		class_container.get_iterator = NULL;					\
222 		class_container.iterator_funcs_ptr = NULL;				\
223 		class_container.info.internal.module = NULL;			\
224 		class_container.info.internal.builtin_functions = functions;	\
225 	}
226 
227 
228 #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
229 	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
230 
231 #ifdef ZTS
232 #	define CE_STATIC_MEMBERS(ce) (((ce)->type==ZEND_USER_CLASS)?(ce)->static_members_table:CG(static_members_table)[(zend_intptr_t)(ce)->static_members_table])
233 #else
234 #	define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
235 #endif
236 
237 #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
238 
239 ZEND_API int zend_next_free_module(void);
240 
241 BEGIN_EXTERN_C()
242 ZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array);
243 
244 /* internal function to efficiently copy parameters when executing __call() */
245 ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
246 
247 #define zend_get_parameters_array(ht, param_count, argument_array) \
248 	_zend_get_parameters_array_ex(param_count, argument_array)
249 #define zend_get_parameters_array_ex(param_count, argument_array) \
250 	_zend_get_parameters_array_ex(param_count, argument_array)
251 #define zend_parse_parameters_none() \
252 	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_error())
253 #define zend_parse_parameters_none_throw() \
254 	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_exception())
255 
256 /* Parameter parsing API -- andrei */
257 
258 #define ZEND_PARSE_PARAMS_QUIET (1<<1)
259 #define ZEND_PARSE_PARAMS_THROW (1<<2)
260 ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
261 ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
262 ZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...);
263 ZEND_API char *zend_zval_type_name(const zval *arg);
264 ZEND_API zend_string *zend_zval_get_type(const zval *arg);
265 
266 ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
267 ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...);
268 
269 ZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...);
270 
271 /* End of parameter parsing API -- andrei */
272 
273 ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
274 ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
275 ZEND_API int zend_startup_module(zend_module_entry *module_entry);
276 ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
277 ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
278 ZEND_API int zend_startup_module_ex(zend_module_entry *module);
279 ZEND_API int zend_startup_modules(void);
280 ZEND_API void zend_collect_module_handlers(void);
281 ZEND_API void zend_destroy_modules(void);
282 ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type);
283 
284 ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
285 ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
286 ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
287 ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
288 
289 ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, int persistent);
290 
291 #define zend_register_class_alias(name, ce) \
292 	zend_register_class_alias_ex(name, sizeof(name)-1, ce, 1)
293 #define zend_register_ns_class_alias(ns, name, ce) \
294 	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
295 
296 ZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
297 ZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
298 
299 ZEND_API ZEND_COLD void zend_wrong_param_count(void);
300 
301 #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
302 #define IS_CALLABLE_CHECK_NO_ACCESS   (1<<1)
303 #define IS_CALLABLE_CHECK_IS_STATIC   (1<<2)
304 #define IS_CALLABLE_CHECK_SILENT      (1<<3)
305 
306 #define IS_CALLABLE_STRICT  (IS_CALLABLE_CHECK_IS_STATIC)
307 
308 ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
309 ZEND_API zend_string *zend_get_callable_name(zval *callable);
310 ZEND_API zend_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);
311 ZEND_API zend_bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
312 ZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name);
313 ZEND_API const char *zend_get_module_version(const char *module_name);
314 ZEND_API int zend_get_module_started(const char *module_name);
315 ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
316 ZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
317 ZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
318 ZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
319 ZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
320 ZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
321 ZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
322 ZEND_API int 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);
323 
324 ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
325 ZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
326 ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
327 ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
328 ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value);
329 ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
330 ZEND_API int zend_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length);
331 ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
332 
333 ZEND_API int zend_update_class_constants(zend_class_entry *class_type);
334 
335 ZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value);
336 ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value);
337 ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
338 ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
339 ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
340 ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value);
341 ZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value);
342 ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value);
343 ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_length);
344 ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
345 
346 ZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
347 ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
348 ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
349 ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
350 ZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
351 ZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
352 ZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
353 ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
354 
355 ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv);
356 ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv);
357 
358 ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, zend_bool silent);
359 ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent);
360 
361 ZEND_API char *zend_get_type_by_const(int type);
362 
363 #define getThis()							((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
364 #define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
365 
366 #define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
367 #define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
368 #define ARG_COUNT(dummy)					EX_NUM_ARGS()
369 #define ZEND_NUM_ARGS()						EX_NUM_ARGS()
370 #define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
371 #define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ zend_wrong_param_count(); return ret; }
372 
373 #ifndef ZEND_WIN32
374 #define DLEXPORT
375 #endif
376 
377 #define array_init(arg)				ZVAL_ARR((arg), zend_new_array(0))
378 #define array_init_size(arg, size)	ZVAL_ARR((arg), zend_new_array(size))
379 ZEND_API int object_init(zval *arg);
380 ZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
381 ZEND_API int object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
382 ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
383 ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
384 ZEND_API void object_properties_load(zend_object *object, HashTable *properties);
385 
386 ZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
387 
388 ZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
389 ZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
390 ZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b);
391 ZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
392 ZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
393 ZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
394 ZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
395 ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
396 ZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
397 
398 #define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
399 #define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
400 #define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
401 #define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
402 #define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
403 #define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
404 #define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
405 #define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
406 #define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
407 
408 /* unset() functions are only supported for legacy modules and null() functions should be used */
409 #define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
410 #define add_index_unset(__arg, __key) add_index_null(__arg, __key)
411 #define add_next_index_unset(__arg) add_next_index_null(__arg)
412 #define add_property_unset(__arg, __key) add_property_null(__arg, __key)
413 
414 ZEND_API int add_index_long(zval *arg, zend_ulong idx, zend_long n);
415 ZEND_API int add_index_null(zval *arg, zend_ulong idx);
416 ZEND_API int add_index_bool(zval *arg, zend_ulong idx, int b);
417 ZEND_API int add_index_resource(zval *arg, zend_ulong idx, zend_resource *r);
418 ZEND_API int add_index_double(zval *arg, zend_ulong idx, double d);
419 ZEND_API int add_index_str(zval *arg, zend_ulong idx, zend_string *str);
420 ZEND_API int add_index_string(zval *arg, zend_ulong idx, const char *str);
421 ZEND_API int add_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
422 ZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value);
423 
424 ZEND_API int add_next_index_long(zval *arg, zend_long n);
425 ZEND_API int add_next_index_null(zval *arg);
426 ZEND_API int add_next_index_bool(zval *arg, int b);
427 ZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
428 ZEND_API int add_next_index_double(zval *arg, double d);
429 ZEND_API int add_next_index_str(zval *arg, zend_string *str);
430 ZEND_API int add_next_index_string(zval *arg, const char *str);
431 ZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length);
432 ZEND_API int add_next_index_zval(zval *arg, zval *value);
433 
434 ZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint32_t key_len, const char *str);
435 ZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint32_t key_len, const char *str, size_t length);
436 
437 #define add_get_assoc_string(__arg, __key, __str) add_get_assoc_string_ex(__arg, __key, strlen(__key), __str)
438 #define add_get_assoc_stringl(__arg, __key, __str, __length) add_get_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
439 
440 ZEND_API zval *add_get_index_long(zval *arg, zend_ulong idx, zend_long l);
441 ZEND_API zval *add_get_index_double(zval *arg, zend_ulong idx, double d);
442 ZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str);
443 ZEND_API zval *add_get_index_string(zval *arg, zend_ulong idx, const char *str);
444 ZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
445 
446 ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value);
447 
448 ZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
449 ZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len);
450 ZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
451 ZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
452 ZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
453 ZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
454 ZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
455 ZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
456 ZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
457 
458 #define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
459 #define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
460 #define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
461 #define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
462 #define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
463 #define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
464 #define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
465 #define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
466 #define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
467 
468 
469 ZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);
470 
471 #define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
472 	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)
473 #define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \
474 	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)
475 
476 ZEND_API extern const zend_fcall_info empty_fcall_info;
477 ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
478 
479 /** Build zend_call_info/cache from a zval*
480  *
481  * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
482  * In order to pass parameters the following members need to be set:
483  * fci->param_count = 0;
484  * fci->params = NULL;
485  * The callable_name argument may be NULL.
486  * Set check_flags to IS_CALLABLE_STRICT for every new usage!
487  */
488 ZEND_API int 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);
489 
490 /** Clear arguments connected with zend_fcall_info *fci
491  * If free_mem is not zero then the params array gets free'd as well
492  */
493 ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
494 
495 /** Save current arguments from zend_fcall_info *fci
496  * params array will be set to NULL
497  */
498 ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
499 
500 /** Free arguments connected with zend_fcall_info *fci andset back saved ones.
501  */
502 ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
503 
504 /** Set or clear the arguments in the zend_call_info struct taking care of
505  * refcount. If args is NULL and arguments are set then those are cleared.
506  */
507 ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args);
508 ZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
509 
510 /** Set arguments in the zend_fcall_info struct taking care of refcount.
511  * If argc is 0 the arguments which are set will be cleared, else pass
512  * a variable amount of zval** arguments.
513  */
514 ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv);
515 
516 /** Set arguments in the zend_fcall_info struct taking care of refcount.
517  * If argc is 0 the arguments which are set will be cleared, else pass
518  * a variable amount of zval** arguments.
519  */
520 ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv);
521 
522 /** Set arguments in the zend_fcall_info struct taking care of refcount.
523  * If argc is 0 the arguments which are set will be cleared, else pass
524  * a variable amount of zval** arguments.
525  */
526 ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...);
527 
528 /** Call a function using information created by zend_fcall_info_init()/args().
529  * If args is given then those replace the argument info in fci is temporarily.
530  */
531 ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
532 
533 ZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
534 
535 ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
536 
537 ZEND_API int zend_delete_global_variable(zend_string *name);
538 
539 ZEND_API zend_array *zend_rebuild_symbol_table(void);
540 ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
541 ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
542 ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force);
543 ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force);
544 ZEND_API int zend_forbid_dynamic_call(const char *func_name);
545 
546 ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
547 ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
548 
549 ZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
550 
551 ZEND_API zend_bool zend_is_iterable(zval *iterable);
552 
553 ZEND_API zend_bool zend_is_countable(zval *countable);
554 
555 #define add_method(arg, key, method)	add_assoc_function((arg), (key), (method))
556 
557 ZEND_API ZEND_FUNCTION(display_disabled_function);
558 ZEND_API ZEND_FUNCTION(display_disabled_class);
559 END_EXTERN_C()
560 
561 #if ZEND_DEBUG
562 #define CHECK_ZVAL_STRING(str) \
563 	if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", ZSTR_VAL(str)); }
564 #define CHECK_ZVAL_STRING_REL(str) \
565 	if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", ZSTR_VAL(str) ZEND_FILE_LINE_RELAY_CC); }
566 #else
567 #define CHECK_ZVAL_STRING(z)
568 #define CHECK_ZVAL_STRING_REL(z)
569 #endif
570 
571 #define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
572 #define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
573 
574 #define ZVAL_STRINGL(z, s, l) do {				\
575 		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
576 	} while (0)
577 
578 #define ZVAL_STRING(z, s) do {					\
579 		const char *_s = (s);					\
580 		ZVAL_STRINGL(z, _s, strlen(_s));		\
581 	} while (0)
582 
583 #define ZVAL_EMPTY_STRING(z) do {				\
584 		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
585 	} while (0)
586 
587 #define ZVAL_PSTRINGL(z, s, l) do {				\
588 		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
589 	} while (0)
590 
591 #define ZVAL_PSTRING(z, s) do {					\
592 		const char *_s = (s);					\
593 		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
594 	} while (0)
595 
596 #define ZVAL_EMPTY_PSTRING(z) do {				\
597 		ZVAL_PSTRINGL(z, "", 0);				\
598 	} while (0)
599 
600 #define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
601 		zval *__z = (z);						\
602 		zval *__zv = (zv);						\
603 		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
604 			if (copy && !dtor) {				\
605 				ZVAL_COPY(__z, __zv);			\
606 			} else {							\
607 				ZVAL_COPY_VALUE(__z, __zv);		\
608 			}									\
609 		} else {								\
610 			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
611 			if (dtor || !copy) {				\
612 				zval_ptr_dtor(__zv);			\
613 			}									\
614 		}										\
615 	} while (0)
616 
617 #define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
618 #define RETVAL_NULL() 					ZVAL_NULL(return_value)
619 #define RETVAL_LONG(l) 					ZVAL_LONG(return_value, l)
620 #define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value, d)
621 #define RETVAL_STR(s)			 		ZVAL_STR(return_value, s)
622 #define RETVAL_INTERNED_STR(s)	 		ZVAL_INTERNED_STR(return_value, s)
623 #define RETVAL_NEW_STR(s)		 		ZVAL_NEW_STR(return_value, s)
624 #define RETVAL_STR_COPY(s)		 		ZVAL_STR_COPY(return_value, s)
625 #define RETVAL_STRING(s)		 		ZVAL_STRING(return_value, s)
626 #define RETVAL_STRINGL(s, l)		 	ZVAL_STRINGL(return_value, s, l)
627 #define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
628 #define RETVAL_RES(r)			 		ZVAL_RES(return_value, r)
629 #define RETVAL_ARR(r)			 		ZVAL_ARR(return_value, r)
630 #define RETVAL_OBJ(r)			 		ZVAL_OBJ(return_value, r)
631 #define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
632 #define RETVAL_FALSE  					ZVAL_FALSE(return_value)
633 #define RETVAL_TRUE   					ZVAL_TRUE(return_value)
634 
635 #define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
636 #define RETURN_NULL() 					{ RETVAL_NULL(); return;}
637 #define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
638 #define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
639 #define RETURN_STR(s) 					{ RETVAL_STR(s); return; }
640 #define RETURN_INTERNED_STR(s)			{ RETVAL_INTERNED_STR(s); return; }
641 #define RETURN_NEW_STR(s)				{ RETVAL_NEW_STR(s); return; }
642 #define RETURN_STR_COPY(s)				{ RETVAL_STR_COPY(s); return; }
643 #define RETURN_STRING(s) 				{ RETVAL_STRING(s); return; }
644 #define RETURN_STRINGL(s, l) 			{ RETVAL_STRINGL(s, l); return; }
645 #define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
646 #define RETURN_RES(r) 					{ RETVAL_RES(r); return; }
647 #define RETURN_ARR(r) 					{ RETVAL_ARR(r); return; }
648 #define RETURN_OBJ(r) 					{ RETVAL_OBJ(r); return; }
649 #define RETURN_ZVAL(zv, copy, dtor)		{ RETVAL_ZVAL(zv, copy, dtor); return; }
650 #define RETURN_FALSE  					{ RETVAL_FALSE; return; }
651 #define RETURN_TRUE   					{ RETVAL_TRUE; return; }
652 
653 #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((p)) : NULL)))
654 #define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
655 
656 /* For compatibility */
657 #define ZEND_MINIT			ZEND_MODULE_STARTUP_N
658 #define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
659 #define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
660 #define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
661 #define ZEND_MINFO			ZEND_MODULE_INFO_N
662 #define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
663 #define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
664 
665 #define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
666 #define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
667 #define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
668 #define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
669 #define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
670 #define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
671 #define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
672 
673 /* Fast parameter parsing API */
674 
675 /* Fast ZPP is always enabled now; this define is left in for compatibility
676  * with any existing conditional compilation blocks.
677  */
678 #define FAST_ZPP 1
679 
680 #define Z_EXPECTED_TYPES(_) \
681 	_(Z_EXPECTED_LONG,		"int") \
682 	_(Z_EXPECTED_BOOL,		"bool") \
683 	_(Z_EXPECTED_STRING,	"string") \
684 	_(Z_EXPECTED_ARRAY,		"array") \
685 	_(Z_EXPECTED_FUNC,		"valid callback") \
686 	_(Z_EXPECTED_RESOURCE,	"resource") \
687 	_(Z_EXPECTED_PATH,		"a valid path") \
688 	_(Z_EXPECTED_OBJECT,	"object") \
689 	_(Z_EXPECTED_DOUBLE,	"float")
690 
691 #define Z_EXPECTED_TYPE_ENUM(id, str) id,
692 #define Z_EXPECTED_TYPE_STR(id, str)  str,
693 
694 typedef enum _zend_expected_type {
695 	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
696 	Z_EXPECTED_LAST
697 } zend_expected_type;
698 
699 ZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_error(void);
700 ZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_exception(void);
701 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args);
702 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_exception(int min_num_args, int max_num_args);
703 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
704 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_exception(int num, zend_expected_type expected_type, zval *arg);
705 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, char *name, zval *arg);
706 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_exception(int num, char *name, zval *arg);
707 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error);
708 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_deprecated(int num, char *error);
709 ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_exception(int num, char *error);
710 
711 #define ZPP_ERROR_OK             0
712 #define ZPP_ERROR_FAILURE        1
713 #define ZPP_ERROR_WRONG_CALLBACK 2
714 #define ZPP_ERROR_WRONG_CLASS    3
715 #define ZPP_ERROR_WRONG_ARG      4
716 #define ZPP_ERROR_WRONG_COUNT    5
717 
718 #define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
719 		const int _flags = (flags); \
720 		int _min_num_args = (min_num_args); \
721 		int _max_num_args = (max_num_args); \
722 		int _num_args = EX_NUM_ARGS(); \
723 		int _i; \
724 		zval *_real_arg, *_arg = NULL; \
725 		zend_expected_type _expected_type = Z_EXPECTED_LONG; \
726 		char *_error = NULL; \
727 		zend_bool _dummy; \
728 		zend_bool _optional = 0; \
729 		int error_code = ZPP_ERROR_OK; \
730 		((void)_i); \
731 		((void)_real_arg); \
732 		((void)_arg); \
733 		((void)_expected_type); \
734 		((void)_error); \
735 		((void)_dummy); \
736 		((void)_optional); \
737 		\
738 		do { \
739 			if (UNEXPECTED(_num_args < _min_num_args) || \
740 			    (UNEXPECTED(_num_args > _max_num_args) && \
741 			     EXPECTED(_max_num_args >= 0))) { \
742 				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
743 					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
744 						zend_wrong_parameters_count_exception(_min_num_args, _max_num_args); \
745 					} else { \
746 						zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
747 					} \
748 				} \
749 				error_code = ZPP_ERROR_FAILURE; \
750 				break; \
751 			} \
752 			_i = 0; \
753 			_real_arg = ZEND_CALL_ARG(execute_data, 0);
754 
755 #define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
756 	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
757 
758 #define ZEND_PARSE_PARAMETERS_NONE() do { \
759 		if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
760 			zend_wrong_parameters_none_error(); \
761 			return; \
762 		} \
763 	} while (0)
764 
765 #define ZEND_PARSE_PARAMETERS_END_EX(failure) \
766 		} while (0); \
767 		if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
768 			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
769 				if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
770 					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
771 						zend_wrong_callback_exception(_i, _error); \
772 					} else { \
773 						zend_wrong_callback_error(_i, _error); \
774 					} \
775 				} else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
776 					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
777 						zend_wrong_parameter_class_exception(_i, _error, _arg); \
778 					} else { \
779 						zend_wrong_parameter_class_error(_i, _error, _arg); \
780 					} \
781 				} else if (error_code == ZPP_ERROR_WRONG_ARG) { \
782 					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
783 						zend_wrong_parameter_type_exception(_i, _expected_type, _arg); \
784 					} else { \
785 						zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
786 					} \
787 				} \
788 			} \
789 			failure; \
790 		} \
791 	} while (0)
792 
793 #define ZEND_PARSE_PARAMETERS_END() \
794 	ZEND_PARSE_PARAMETERS_END_EX(return)
795 
796 #define Z_PARAM_PROLOGUE(deref, separate) \
797 	++_i; \
798 	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
799 	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
800 	if (_optional) { \
801 		if (UNEXPECTED(_i >_num_args)) break; \
802 	} \
803 	_real_arg++; \
804 	_arg = _real_arg; \
805 	if (deref) { \
806 		ZVAL_DEREF(_arg); \
807 	} \
808 	if (separate) { \
809 		SEPARATE_ZVAL_NOREF(_arg); \
810 	}
811 
812 /* old "|" */
813 #define Z_PARAM_OPTIONAL \
814 	_optional = 1;
815 
816 /* old "a" */
817 #define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
818 		Z_PARAM_PROLOGUE(deref, separate); \
819 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
820 			_expected_type = Z_EXPECTED_ARRAY; \
821 			error_code = ZPP_ERROR_WRONG_ARG; \
822 			break; \
823 		}
824 
825 #define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
826 	Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
827 
828 #define Z_PARAM_ARRAY(dest) \
829 	Z_PARAM_ARRAY_EX(dest, 0, 0)
830 
831 /* old "A" */
832 #define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
833 		Z_PARAM_PROLOGUE(deref, separate); \
834 		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
835 			_expected_type = Z_EXPECTED_ARRAY; \
836 			error_code = ZPP_ERROR_WRONG_ARG; \
837 			break; \
838 		}
839 
840 #define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
841 	Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
842 
843 #define Z_PARAM_ARRAY_OR_OBJECT(dest) \
844 	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
845 
846 /* old "b" */
847 #define Z_PARAM_BOOL_EX2(dest, is_null, check_null, deref, separate) \
848 		Z_PARAM_PROLOGUE(deref, separate); \
849 		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \
850 			_expected_type = Z_EXPECTED_BOOL; \
851 			error_code = ZPP_ERROR_WRONG_ARG; \
852 			break; \
853 		}
854 
855 #define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
856 	Z_PARAM_BOOL_EX2(dest, is_null, check_null, separate, separate)
857 
858 #define Z_PARAM_BOOL(dest) \
859 	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
860 
861 /* old "C" */
862 #define Z_PARAM_CLASS_EX2(dest, check_null, deref, separate) \
863 		Z_PARAM_PROLOGUE(deref, separate); \
864 		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
865 			error_code = ZPP_ERROR_FAILURE; \
866 			break; \
867 		}
868 
869 #define Z_PARAM_CLASS_EX(dest, check_null, separate) \
870 	Z_PARAM_CLASS_EX2(dest, check_null, separate, separate)
871 
872 #define Z_PARAM_CLASS(dest) \
873 	Z_PARAM_CLASS_EX(dest, 0, 0)
874 
875 /* old "d" */
876 #define Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, deref, separate) \
877 		Z_PARAM_PROLOGUE(deref, separate); \
878 		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \
879 			_expected_type = Z_EXPECTED_DOUBLE; \
880 			error_code = ZPP_ERROR_WRONG_ARG; \
881 			break; \
882 		}
883 
884 #define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
885 	Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, separate, separate)
886 
887 #define Z_PARAM_DOUBLE(dest) \
888 	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
889 
890 /* old "f" */
891 #define Z_PARAM_FUNC_EX2(dest_fci, dest_fcc, check_null, deref, separate) \
892 		Z_PARAM_PROLOGUE(deref, separate); \
893 		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
894 			if (!_error) { \
895 				_expected_type = Z_EXPECTED_FUNC; \
896 				error_code = ZPP_ERROR_WRONG_ARG; \
897 				break; \
898 			} else { \
899 				error_code = ZPP_ERROR_WRONG_CALLBACK; \
900 				break; \
901 			} \
902 		} else if (UNEXPECTED(_error != NULL)) { \
903 			zend_wrong_callback_deprecated(_i, _error); \
904 		}
905 
906 #define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, separate) \
907 	Z_PARAM_FUNC_EX2(dest_fci, dest_fcc, check_null, separate, separate)
908 
909 #define Z_PARAM_FUNC(dest_fci, dest_fcc) \
910 	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
911 
912 /* old "h" */
913 #define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
914 		Z_PARAM_PROLOGUE(deref, separate); \
915 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
916 			_expected_type = Z_EXPECTED_ARRAY; \
917 			error_code = ZPP_ERROR_WRONG_ARG; \
918 			break; \
919 		}
920 
921 #define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
922 	Z_PARAM_ARRAY_HT_EX2(dest, check_null, separate, separate)
923 
924 #define Z_PARAM_ARRAY_HT(dest) \
925 	Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
926 
927 /* old "H" */
928 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, deref, separate) \
929 		Z_PARAM_PROLOGUE(deref, separate); \
930 		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 1, separate))) { \
931 			_expected_type = Z_EXPECTED_ARRAY; \
932 			error_code = ZPP_ERROR_WRONG_ARG; \
933 			break; \
934 		}
935 
936 #define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
937 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX2(dest, check_null, separate, separate)
938 
939 #define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
940 	Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, 0, 0)
941 
942 /* old "l" */
943 #define Z_PARAM_LONG_EX2(dest, is_null, check_null, deref, separate) \
944 		Z_PARAM_PROLOGUE(deref, separate); \
945 		if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 0))) { \
946 			_expected_type = Z_EXPECTED_LONG; \
947 			error_code = ZPP_ERROR_WRONG_ARG; \
948 			break; \
949 		}
950 
951 #define Z_PARAM_LONG_EX(dest, is_null, check_null, separate) \
952 	Z_PARAM_LONG_EX2(dest, is_null, check_null, separate, separate)
953 
954 #define Z_PARAM_LONG(dest) \
955 	Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
956 
957 /* old "L" */
958 #define Z_PARAM_STRICT_LONG_EX2(dest, is_null, check_null, deref, separate) \
959 		Z_PARAM_PROLOGUE(deref, separate); \
960 		if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, 1))) { \
961 			_expected_type = Z_EXPECTED_LONG; \
962 			error_code = ZPP_ERROR_WRONG_ARG; \
963 			break; \
964 		}
965 
966 #define Z_PARAM_STRICT_LONG_EX(dest, is_null, check_null, separate) \
967 	Z_PARAM_STRICT_LONG_EX2(dest, is_null, check_null, separate, separate)
968 
969 #define Z_PARAM_STRICT_LONG(dest) \
970 	Z_PARAM_STRICT_LONG_EX(dest, _dummy, 0, 0)
971 
972 /* old "o" */
973 #define Z_PARAM_OBJECT_EX2(dest, check_null, deref, separate) \
974 		Z_PARAM_PROLOGUE(deref, separate); \
975 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, NULL, check_null))) { \
976 			_expected_type = Z_EXPECTED_OBJECT; \
977 			error_code = ZPP_ERROR_WRONG_ARG; \
978 			break; \
979 		}
980 
981 #define Z_PARAM_OBJECT_EX(dest, check_null, separate) \
982 	Z_PARAM_OBJECT_EX2(dest, check_null, separate, separate)
983 
984 #define Z_PARAM_OBJECT(dest) \
985 	Z_PARAM_OBJECT_EX(dest, 0, 0)
986 
987 /* old "O" */
988 #define Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, deref, separate) \
989 		Z_PARAM_PROLOGUE(deref, separate); \
990 		if (UNEXPECTED(!zend_parse_arg_object(_arg, &dest, _ce, check_null))) { \
991 			if (_ce) { \
992 				_error = ZSTR_VAL((_ce)->name); \
993 				error_code = ZPP_ERROR_WRONG_CLASS; \
994 				break; \
995 			} else { \
996 				_expected_type = Z_EXPECTED_OBJECT; \
997 				error_code = ZPP_ERROR_WRONG_ARG; \
998 				break; \
999 			} \
1000 		}
1001 
1002 #define Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, check_null, separate) \
1003 	Z_PARAM_OBJECT_OF_CLASS_EX2(dest, _ce, check_null, separate, separate)
1004 
1005 #define Z_PARAM_OBJECT_OF_CLASS(dest, _ce) \
1006 	Z_PARAM_OBJECT_OF_CLASS_EX(dest, _ce, 0, 0)
1007 
1008 /* old "p" */
1009 #define Z_PARAM_PATH_EX2(dest, dest_len, check_null, deref, separate) \
1010 		Z_PARAM_PROLOGUE(deref, separate); \
1011 		if (UNEXPECTED(!zend_parse_arg_path(_arg, &dest, &dest_len, check_null))) { \
1012 			_expected_type = Z_EXPECTED_PATH; \
1013 			error_code = ZPP_ERROR_WRONG_ARG; \
1014 			break; \
1015 		}
1016 
1017 #define Z_PARAM_PATH_EX(dest, dest_len, check_null, separate) \
1018 	Z_PARAM_PATH_EX2(dest, dest_len, check_null, separate, separate)
1019 
1020 #define Z_PARAM_PATH(dest, dest_len) \
1021 	Z_PARAM_PATH_EX(dest, dest_len, 0, 0)
1022 
1023 /* old "P" */
1024 #define Z_PARAM_PATH_STR_EX2(dest, check_null, deref, separate) \
1025 		Z_PARAM_PROLOGUE(deref, separate); \
1026 		if (UNEXPECTED(!zend_parse_arg_path_str(_arg, &dest, check_null))) { \
1027 			_expected_type = Z_EXPECTED_PATH; \
1028 			error_code = ZPP_ERROR_WRONG_ARG; \
1029 			break; \
1030 		}
1031 
1032 #define Z_PARAM_PATH_STR_EX(dest, check_null, separate) \
1033 	Z_PARAM_PATH_STR_EX2(dest, check_null, separate, separate)
1034 
1035 #define Z_PARAM_PATH_STR(dest) \
1036 	Z_PARAM_PATH_STR_EX(dest, 0, 0)
1037 
1038 /* old "r" */
1039 #define Z_PARAM_RESOURCE_EX2(dest, check_null, deref, separate) \
1040 		Z_PARAM_PROLOGUE(deref, separate); \
1041 		if (UNEXPECTED(!zend_parse_arg_resource(_arg, &dest, check_null))) { \
1042 			_expected_type = Z_EXPECTED_RESOURCE; \
1043 			error_code = ZPP_ERROR_WRONG_ARG; \
1044 			break; \
1045 		}
1046 
1047 #define Z_PARAM_RESOURCE_EX(dest, check_null, separate) \
1048 	Z_PARAM_RESOURCE_EX2(dest, check_null, separate, separate)
1049 
1050 #define Z_PARAM_RESOURCE(dest) \
1051 	Z_PARAM_RESOURCE_EX(dest, 0, 0)
1052 
1053 /* old "s" */
1054 #define Z_PARAM_STRING_EX2(dest, dest_len, check_null, deref, separate) \
1055 		Z_PARAM_PROLOGUE(deref, separate); \
1056 		if (UNEXPECTED(!zend_parse_arg_string(_arg, &dest, &dest_len, check_null))) { \
1057 			_expected_type = Z_EXPECTED_STRING; \
1058 			error_code = ZPP_ERROR_WRONG_ARG; \
1059 			break; \
1060 		}
1061 
1062 #define Z_PARAM_STRING_EX(dest, dest_len, check_null, separate) \
1063 	Z_PARAM_STRING_EX2(dest, dest_len, check_null, separate, separate)
1064 
1065 #define Z_PARAM_STRING(dest, dest_len) \
1066 	Z_PARAM_STRING_EX(dest, dest_len, 0, 0)
1067 
1068 /* old "S" */
1069 #define Z_PARAM_STR_EX2(dest, check_null, deref, separate) \
1070 		Z_PARAM_PROLOGUE(deref, separate); \
1071 		if (UNEXPECTED(!zend_parse_arg_str(_arg, &dest, check_null))) { \
1072 			_expected_type = Z_EXPECTED_STRING; \
1073 			error_code = ZPP_ERROR_WRONG_ARG; \
1074 			break; \
1075 		}
1076 
1077 #define Z_PARAM_STR_EX(dest, check_null, separate) \
1078 	Z_PARAM_STR_EX2(dest, check_null, separate, separate)
1079 
1080 #define Z_PARAM_STR(dest) \
1081 	Z_PARAM_STR_EX(dest, 0, 0)
1082 
1083 /* old "z" */
1084 #define Z_PARAM_ZVAL_EX2(dest, check_null, deref, separate) \
1085 		Z_PARAM_PROLOGUE(deref, separate); \
1086 		zend_parse_arg_zval_deref(_arg, &dest, check_null);
1087 
1088 #define Z_PARAM_ZVAL_EX(dest, check_null, separate) \
1089 	Z_PARAM_ZVAL_EX2(dest, check_null, separate, separate)
1090 
1091 #define Z_PARAM_ZVAL(dest) \
1092 	Z_PARAM_ZVAL_EX(dest, 0, 0)
1093 
1094 /* old "z" (with dereference) */
1095 #define Z_PARAM_ZVAL_DEREF_EX(dest, check_null, separate) \
1096 		Z_PARAM_PROLOGUE(1, separate); \
1097 		zend_parse_arg_zval_deref(_arg, &dest, check_null);
1098 
1099 #define Z_PARAM_ZVAL_DEREF(dest) \
1100 	Z_PARAM_ZVAL_DEREF_EX(dest, 0, 0)
1101 
1102 /* old "+" and "*" */
1103 #define Z_PARAM_VARIADIC_EX(spec, dest, dest_num, post_varargs) do { \
1104 		int _num_varargs = _num_args - _i - (post_varargs); \
1105 		if (EXPECTED(_num_varargs > 0)) { \
1106 			dest = _real_arg + 1; \
1107 			dest_num = _num_varargs; \
1108 			_i += _num_varargs; \
1109 			_real_arg += _num_varargs; \
1110 		} else { \
1111 			dest = NULL; \
1112 			dest_num = 0; \
1113 		} \
1114 	} while (0);
1115 
1116 #define Z_PARAM_VARIADIC(spec, dest, dest_num) \
1117 	Z_PARAM_VARIADIC_EX(spec, dest, dest_num, 0)
1118 
1119 /* End of new parameter parsing API */
1120 
1121 /* Inlined implementations shared by new and old parameter parsing APIs */
1122 
1123 ZEND_API int ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, int num, int check_null);
1124 ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_slow(zval *arg, zend_bool *dest);
1125 ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, zend_bool *dest);
1126 ZEND_API int ZEND_FASTCALL zend_parse_arg_long_slow(zval *arg, zend_long *dest);
1127 ZEND_API int ZEND_FASTCALL zend_parse_arg_long_weak(zval *arg, zend_long *dest);
1128 ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_slow(zval *arg, zend_long *dest);
1129 ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_weak(zval *arg, zend_long *dest);
1130 ZEND_API int ZEND_FASTCALL zend_parse_arg_double_slow(zval *arg, double *dest);
1131 ZEND_API int ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest);
1132 ZEND_API int ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest);
1133 ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest);
1134 
zend_parse_arg_bool(zval * arg,zend_bool * dest,zend_bool * is_null,int check_null)1135 static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null)
1136 {
1137 	if (check_null) {
1138 		*is_null = 0;
1139 	}
1140 	if (EXPECTED(Z_TYPE_P(arg) == IS_TRUE)) {
1141 		*dest = 1;
1142 	} else if (EXPECTED(Z_TYPE_P(arg) == IS_FALSE)) {
1143 		*dest = 0;
1144 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1145 		*is_null = 1;
1146 		*dest = 0;
1147 	} else {
1148 		return zend_parse_arg_bool_slow(arg, dest);
1149 	}
1150 	return 1;
1151 }
1152 
zend_parse_arg_long(zval * arg,zend_long * dest,zend_bool * is_null,int check_null,int cap)1153 static zend_always_inline int zend_parse_arg_long(zval *arg, zend_long *dest, zend_bool *is_null, int check_null, int cap)
1154 {
1155 	if (check_null) {
1156 		*is_null = 0;
1157 	}
1158 	if (EXPECTED(Z_TYPE_P(arg) == IS_LONG)) {
1159 		*dest = Z_LVAL_P(arg);
1160 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1161 		*is_null = 1;
1162 		*dest = 0;
1163 	} else if (cap) {
1164 		return zend_parse_arg_long_cap_slow(arg, dest);
1165 	} else {
1166 		return zend_parse_arg_long_slow(arg, dest);
1167 	}
1168 	return 1;
1169 }
1170 
zend_parse_arg_double(zval * arg,double * dest,zend_bool * is_null,int check_null)1171 static zend_always_inline int zend_parse_arg_double(zval *arg, double *dest, zend_bool *is_null, int check_null)
1172 {
1173 	if (check_null) {
1174 		*is_null = 0;
1175 	}
1176 	if (EXPECTED(Z_TYPE_P(arg) == IS_DOUBLE)) {
1177 		*dest = Z_DVAL_P(arg);
1178 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1179 		*is_null = 1;
1180 		*dest = 0.0;
1181 	} else {
1182 		return zend_parse_arg_double_slow(arg, dest);
1183 	}
1184 	return 1;
1185 }
1186 
zend_parse_arg_str(zval * arg,zend_string ** dest,int check_null)1187 static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null)
1188 {
1189 	if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
1190 		*dest = Z_STR_P(arg);
1191 	} else if (check_null && Z_TYPE_P(arg) == IS_NULL) {
1192 		*dest = NULL;
1193 	} else {
1194 		return zend_parse_arg_str_slow(arg, dest);
1195 	}
1196 	return 1;
1197 }
1198 
zend_parse_arg_string(zval * arg,char ** dest,size_t * dest_len,int check_null)1199 static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size_t *dest_len, int check_null)
1200 {
1201 	zend_string *str;
1202 
1203 	if (!zend_parse_arg_str(arg, &str, check_null)) {
1204 		return 0;
1205 	}
1206 	if (check_null && UNEXPECTED(!str)) {
1207 		*dest = NULL;
1208 		*dest_len = 0;
1209 	} else {
1210 		*dest = ZSTR_VAL(str);
1211 		*dest_len = ZSTR_LEN(str);
1212 	}
1213 	return 1;
1214 }
1215 
zend_parse_arg_path_str(zval * arg,zend_string ** dest,int check_null)1216 static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null)
1217 {
1218 	if (!zend_parse_arg_str(arg, dest, check_null) ||
1219 	    (*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
1220 		return 0;
1221 	}
1222 	return 1;
1223 }
1224 
zend_parse_arg_path(zval * arg,char ** dest,size_t * dest_len,int check_null)1225 static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t *dest_len, int check_null)
1226 {
1227 	zend_string *str;
1228 
1229 	if (!zend_parse_arg_path_str(arg, &str, check_null)) {
1230 		return 0;
1231 	}
1232 	if (check_null && UNEXPECTED(!str)) {
1233 		*dest = NULL;
1234 		*dest_len = 0;
1235 	} else {
1236 		*dest = ZSTR_VAL(str);
1237 		*dest_len = ZSTR_LEN(str);
1238 	}
1239 	return 1;
1240 }
1241 
zend_parse_arg_array(zval * arg,zval ** dest,int check_null,int or_object)1242 static zend_always_inline int zend_parse_arg_array(zval *arg, zval **dest, int check_null, int or_object)
1243 {
1244 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY) ||
1245 		(or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT))) {
1246 		*dest = arg;
1247 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1248 		*dest = NULL;
1249 	} else {
1250 		return 0;
1251 	}
1252 	return 1;
1253 }
1254 
zend_parse_arg_array_ht(zval * arg,HashTable ** dest,int check_null,int or_object,int separate)1255 static zend_always_inline int zend_parse_arg_array_ht(zval *arg, HashTable **dest, int check_null, int or_object, int separate)
1256 {
1257 	if (EXPECTED(Z_TYPE_P(arg) == IS_ARRAY)) {
1258 		*dest = Z_ARRVAL_P(arg);
1259 	} else if (or_object && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1260 		if (separate
1261 		 && Z_OBJ_P(arg)->properties
1262 		 && UNEXPECTED(GC_REFCOUNT(Z_OBJ_P(arg)->properties) > 1)) {
1263 			if (EXPECTED(!(GC_FLAGS(Z_OBJ_P(arg)->properties) & IS_ARRAY_IMMUTABLE))) {
1264 				GC_DELREF(Z_OBJ_P(arg)->properties);
1265 			}
1266 			Z_OBJ_P(arg)->properties = zend_array_dup(Z_OBJ_P(arg)->properties);
1267 		}
1268 		*dest = Z_OBJ_HT_P(arg)->get_properties(arg);
1269 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1270 		*dest = NULL;
1271 	} else {
1272 		return 0;
1273 	}
1274 	return 1;
1275 }
1276 
zend_parse_arg_object(zval * arg,zval ** dest,zend_class_entry * ce,int check_null)1277 static zend_always_inline int zend_parse_arg_object(zval *arg, zval **dest, zend_class_entry *ce, int check_null)
1278 {
1279 	if (EXPECTED(Z_TYPE_P(arg) == IS_OBJECT) &&
1280 	    (!ce || EXPECTED(instanceof_function(Z_OBJCE_P(arg), ce) != 0))) {
1281 		*dest = arg;
1282 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1283 		*dest = NULL;
1284 	} else {
1285 		return 0;
1286 	}
1287 	return 1;
1288 }
1289 
zend_parse_arg_resource(zval * arg,zval ** dest,int check_null)1290 static zend_always_inline int zend_parse_arg_resource(zval *arg, zval **dest, int check_null)
1291 {
1292 	if (EXPECTED(Z_TYPE_P(arg) == IS_RESOURCE)) {
1293 		*dest = arg;
1294 	} else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1295 		*dest = NULL;
1296 	} else {
1297 		return 0;
1298 	}
1299 	return 1;
1300 }
1301 
zend_parse_arg_func(zval * arg,zend_fcall_info * dest_fci,zend_fcall_info_cache * dest_fcc,int check_null,char ** error)1302 static zend_always_inline int zend_parse_arg_func(zval *arg, zend_fcall_info *dest_fci, zend_fcall_info_cache *dest_fcc, int check_null, char **error)
1303 {
1304 	if (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
1305 		dest_fci->size = 0;
1306 		dest_fcc->function_handler = NULL;
1307 		*error = NULL;
1308 	} else if (UNEXPECTED(zend_fcall_info_init(arg, 0, dest_fci, dest_fcc, NULL, error) != SUCCESS)) {
1309 		return 0;
1310 	}
1311 	return 1;
1312 }
1313 
zend_parse_arg_zval(zval * arg,zval ** dest,int check_null)1314 static zend_always_inline void zend_parse_arg_zval(zval *arg, zval **dest, int check_null)
1315 {
1316 	*dest = (check_null &&
1317 	    (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) ||
1318 	     (UNEXPECTED(Z_ISREF_P(arg)) &&
1319 	      UNEXPECTED(Z_TYPE_P(Z_REFVAL_P(arg)) == IS_NULL)))) ? NULL : arg;
1320 }
1321 
zend_parse_arg_zval_deref(zval * arg,zval ** dest,int check_null)1322 static zend_always_inline void zend_parse_arg_zval_deref(zval *arg, zval **dest, int check_null)
1323 {
1324 	*dest = (check_null && UNEXPECTED(Z_TYPE_P(arg) == IS_NULL)) ? NULL : arg;
1325 }
1326 
1327 END_EXTERN_C()
1328 
1329 #endif /* ZEND_API_H */
1330 
1331 
1332 /*
1333  * Local variables:
1334  * tab-width: 4
1335  * c-basic-offset: 4
1336  * indent-tabs-mode: t
1337  * End:
1338  * vim600: sw=4 ts=4 fdm=marker
1339  * vim<600: sw=4 ts=4
1340  */
1341