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