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