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