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