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