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