zend_API.h revision eb6614e4
17b5ba8e6SKalle Sommer Nielsen/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
59e29f841SSammy Kaye Powers   | Copyright (c) 1998-2017 Zend Technologies Ltd. (http://www.zend.com) |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
7d863d52aSSebastian Bergmann   | This source file is subject to version 2.00 of the Zend license,     |
8b4892511SJani Taskinen   | that is bundled with this package in the file LICENSE, and is        |
9f68c7ff2SJames Cox   | available through the world-wide-web at the following url:           |
10d863d52aSSebastian Bergmann   | http://www.zend.com/license/2_00.txt.                                |
11b5b11177SZeev Suraski   | If you did not receive a copy of the Zend license and are unable to  |
12b5b11177SZeev Suraski   | obtain it through the world-wide-web, please send a note to          |
13b5b11177SZeev Suraski   | license@zend.com so we can mail you a copy immediately.              |
14573b4602SAndi Gutmans   +----------------------------------------------------------------------+
15573b4602SAndi Gutmans   | Authors: Andi Gutmans <andi@zend.com>                                |
16573b4602SAndi Gutmans   |          Zeev Suraski <zeev@zend.com>                                |
1758f88057SAndrei Zmievski   |          Andrei Zmievski <andrei@php.net>                            |
1837f0c6b5SDmitry Stogov   |          Dmitry Stogov <dmitry@zend.com>                             |
19573b4602SAndi Gutmans   +----------------------------------------------------------------------+
20573b4602SAndi Gutmans*/
21573b4602SAndi Gutmans
22333406bdSfoobar/* $Id$ */
23b5b11177SZeev Suraski
24b982307dSSascha Schumann#ifndef ZEND_API_H
25b982307dSSascha Schumann#define ZEND_API_H
26573b4602SAndi Gutmans
277080fa5bSAndi Gutmans#include "zend_modules.h"
28573b4602SAndi Gutmans#include "zend_list.h"
295dba4774SZeev Suraski#include "zend_operators.h"
305dba4774SZeev Suraski#include "zend_variables.h"
31df74f1dfSSascha Schumann#include "zend_execute.h"
32573b4602SAndi Gutmans
330450ab94SZeev Suraski
340450ab94SZeev SuraskiBEGIN_EXTERN_C()
35e9d126a7SAndi Gutmans
36f8bbafd6SZeev Suraskitypedef struct _zend_function_entry {
376c810b0dSDmitry Stogov	const char *fname;
38f8bbafd6SZeev Suraski	void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
395dd427eaSDmitry Stogov	const struct _zend_internal_arg_info *arg_info;
406f9f0bf2SAnatol Belski	uint32_t num_args;
416f9f0bf2SAnatol Belski	uint32_t flags;
42f8bbafd6SZeev Suraski} zend_function_entry;
43f8bbafd6SZeev Suraski
44feb85801SDmitry Stogovtypedef struct _zend_fcall_info {
45feb85801SDmitry Stogov	size_t size;
46f4cfaf36SDmitry Stogov	zval function_name;
47f4cfaf36SDmitry Stogov	zval *retval;
48f4cfaf36SDmitry Stogov	zval *params;
49ea85451bSDmitry Stogov	zend_object *object;
50feb85801SDmitry Stogov	zend_bool no_separation;
515d5a7020SAnatol Belski	uint32_t param_count;
52feb85801SDmitry Stogov} zend_fcall_info;
53feb85801SDmitry Stogov
54feb85801SDmitry Stogovtypedef struct _zend_fcall_info_cache {
55feb85801SDmitry Stogov	zend_bool initialized;
56feb85801SDmitry Stogov	zend_function *function_handler;
57feb85801SDmitry Stogov	zend_class_entry *calling_scope;
58feb85801SDmitry Stogov	zend_class_entry *called_scope;
59ea85451bSDmitry Stogov	zend_object *object;
60feb85801SDmitry Stogov} zend_fcall_info_cache;
61feb85801SDmitry Stogov
6286b36438SJelle Zijlstra#define ZEND_NS_NAME(ns, name)			ns "\\" name
63907fa665SDmitry Stogov
64f8bbafd6SZeev Suraski#define ZEND_FN(name) zif_##name
65637a4042SMarcus Boerger#define ZEND_MN(name) zim_##name
66f8bbafd6SZeev Suraski#define ZEND_NAMED_FUNCTION(name)		void name(INTERNAL_FUNCTION_PARAMETERS)
67f8bbafd6SZeev Suraski#define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(ZEND_FN(name))
68637a4042SMarcus Boerger#define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
69f8bbafd6SZeev Suraski
707c2a0157SBob Weinand#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 },
711c2512ddSMarcus Boerger
727c2a0157SBob Weinand#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 },
731e19ee87SHannes Magnusson#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
741e19ee87SHannes Magnusson
751c2512ddSMarcus Boerger#define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_FENTRY(zend_name, name, arg_info, 0)
761c2512ddSMarcus Boerger#define ZEND_FE(name, arg_info)						ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
77941b0651SMarcus Boerger#define ZEND_DEP_FE(name, arg_info)                 ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
78cec053f7SMarcus Boerger#define ZEND_FALIAS(name, alias, arg_info)			ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
79941b0651SMarcus Boerger#define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
80637a4042SMarcus Boerger#define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
81637a4042SMarcus Boerger#define ZEND_ME(classname, name, arg_info, flags)	ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
821c2512ddSMarcus Boerger#define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
8333cdc9edSMarcus Boerger#define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
84637a4042SMarcus Boerger                                                    ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
85637a4042SMarcus Boerger#define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
86f8bbafd6SZeev Suraski
87907fa665SDmitry Stogov#define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags)		ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
88907fa665SDmitry Stogov
89907fa665SDmitry Stogov#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)
90907fa665SDmitry Stogov#define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
91907fa665SDmitry Stogov
922d5695cbSSara Golemon#define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
93907fa665SDmitry Stogov#define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
94907fa665SDmitry Stogov#define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
95907fa665SDmitry Stogov#define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
96907fa665SDmitry Stogov#define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
97907fa665SDmitry Stogov
98f1f2a649SFelipe Pena#define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
99f1f2a649SFelipe Pena
100141d1ba9SDmitry Stogov#define ZEND_ARG_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 0},
101141d1ba9SDmitry Stogov#define ZEND_ARG_PASS_INFO(pass_by_ref)                              { NULL,  0, pass_by_ref, 0},
102141d1ba9SDmitry Stogov#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 },
103141d1ba9SDmitry Stogov#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null)           { #name, ZEND_TYPE_ENCODE(IS_ARRAY, allow_null), pass_by_ref, 0 },
104141d1ba9SDmitry Stogov#define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null)        { #name, ZEND_TYPE_ENCODE(IS_CALLABLE, allow_null), pass_by_ref, 0 },
105141d1ba9SDmitry Stogov#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 },
106ab2489faSBogdan Padalko#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 1 },
107ab2489faSBogdan Padalko#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 },
108ab2489faSBogdan Padalko#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 },
1090d7a6388SNikita Popov
110bff4c47fSReeze Xia
111141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, classname, allow_null) \
112a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
113141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), return_reference, 0 },
114141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
115141d1ba9SDmitry Stogov	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, class_name, allow_null)
116141d1ba9SDmitry Stogov
117141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
118141d1ba9SDmitry Stogov	static const zend_internal_arg_info name[] = { \
119141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE(type, allow_null), return_reference, 0 },
120141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
121141d1ba9SDmitry Stogov	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
122bff4c47fSReeze Xia
1230d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
124a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
125141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, 0 },
1260d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO(name, _unused)	\
1270d7a6388SNikita Popov	ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
128f8bbafd6SZeev Suraski#define ZEND_END_ARG_INFO()		};
129342c6e0bSZeev Suraski
1308b6f848cSAndi Gutmans/* Name macros */
1318b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
1328b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
1338b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
1348b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
1356535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
1368b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_N(module)			zm_info_##module
137ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
138ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
139342c6e0bSZeev Suraski
1408b6f848cSAndi Gutmans/* Declaration macros */
1418b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_D(module)		int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
1428b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_D(module)		int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
1438b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_D(module)		int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
1448b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_D(module)	int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
1456535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
1468b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_D(module)			void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
147bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
148bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
149342c6e0bSZeev Suraski
1500b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
151cb71ac03SHartmut Holzgraefe    BEGIN_EXTERN_C()\
152cb71ac03SHartmut Holzgraefe	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
153cb71ac03SHartmut Holzgraefe    END_EXTERN_C()
1540d21940dSZeev Suraski
1550d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
1560d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
1570d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
1580d21940dSZeev Suraski	} zend_##module_name##_globals;
1590d21940dSZeev Suraski
1600d21940dSZeev Suraski#ifdef ZTS
1610d21940dSZeev Suraski
1620d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
16302af513cSAndi Gutmans	ts_rsrc_id module_name##_globals_id;
16402af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
16502af513cSAndi Gutmans	extern ts_rsrc_id module_name##_globals_id;
1660d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1672c254ba7SZeev Suraski	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
16843cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
169c9a538cdSAnatol Belski#if ZEND_ENABLE_STATIC_TSRMLS_CACHE
170c9a538cdSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
171c9a538cdSAnatol Belski#else
172ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
173c9a538cdSAnatol Belski#endif
1740d21940dSZeev Suraski
1750d21940dSZeev Suraski#else
1760d21940dSZeev Suraski
1770d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
17802af513cSAndi Gutmans	zend_##module_name##_globals module_name##_globals;
17902af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
18002af513cSAndi Gutmans	extern zend_##module_name##_globals module_name##_globals;
1810d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1820d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
18343cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
184ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
1850d21940dSZeev Suraski
1860d21940dSZeev Suraski#endif
1870d21940dSZeev Suraski
188b4892511SJani Taskinen#define INIT_CLASS_ENTRY(class_container, class_name, functions) \
189b4892511SJani Taskinen	INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, NULL, NULL, NULL)
190741b8161SZeev Suraski
191b4892511SJani Taskinen#define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
192b4892511SJani Taskinen	INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, NULL, NULL, NULL, NULL, NULL)
193b4892511SJani Taskinen
194b4892511SJani Taskinen#define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
195741b8161SZeev Suraski	{															\
196f4cfaf36SDmitry Stogov		zend_string *cl_name;									\
197c3e3c98eSAnatol Belski		cl_name = zend_string_init(class_name, class_name_len, 1);		\
198bdeb220fSAnatol Belski		class_container.name = zend_new_interned_string(cl_name);	\
19903a1fcabSXinchen Hui		INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
20003a1fcabSXinchen Hui	}
20103a1fcabSXinchen Hui
20203a1fcabSXinchen Hui#define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
20303a1fcabSXinchen Hui	{															\
2042eccd95cSAndi Gutmans		class_container.constructor = NULL;						\
20573b159e0SAndi Gutmans		class_container.destructor = NULL;						\
20629ea3da2SAndi Gutmans		class_container.clone = NULL;							\
207637a4042SMarcus Boerger		class_container.serialize = NULL;						\
208637a4042SMarcus Boerger		class_container.unserialize = NULL;						\
209637a4042SMarcus Boerger		class_container.create_object = NULL;					\
2103c62b3b5SMarcus Boerger		class_container.interface_gets_implemented = NULL;		\
21172d0454bSDmitry Stogov		class_container.get_static_method = NULL;				\
212637a4042SMarcus Boerger		class_container.__call = handle_fcall;					\
213b4892511SJani Taskinen		class_container.__callstatic = NULL;					\
214637a4042SMarcus Boerger		class_container.__tostring = NULL;						\
215637a4042SMarcus Boerger		class_container.__get = handle_propget;					\
216637a4042SMarcus Boerger		class_container.__set = handle_propset;					\
217637a4042SMarcus Boerger		class_container.__unset = handle_propunset;				\
218637a4042SMarcus Boerger		class_container.__isset = handle_propisset;				\
2191e752ce9SSara Golemon		class_container.__debugInfo = NULL;					\
220637a4042SMarcus Boerger		class_container.serialize_func = NULL;					\
221637a4042SMarcus Boerger		class_container.unserialize_func = NULL;				\
222637a4042SMarcus Boerger		class_container.serialize = NULL;						\
223637a4042SMarcus Boerger		class_container.unserialize = NULL;						\
224637a4042SMarcus Boerger		class_container.parent = NULL;							\
225637a4042SMarcus Boerger		class_container.num_interfaces = 0;						\
226fdb6077fSFelipe Pena		class_container.traits = NULL;							\
227fdb6077fSFelipe Pena		class_container.num_traits = 0;							\
228fdb6077fSFelipe Pena		class_container.trait_aliases = NULL;					\
229fdb6077fSFelipe Pena		class_container.trait_precedences = NULL;				\
230637a4042SMarcus Boerger		class_container.interfaces = NULL;						\
231637a4042SMarcus Boerger		class_container.get_iterator = NULL;					\
232637a4042SMarcus Boerger		class_container.iterator_funcs.funcs = NULL;			\
233f2df6a4aSDmitry Stogov		class_container.info.internal.module = NULL;			\
234f2df6a4aSDmitry Stogov		class_container.info.internal.builtin_functions = functions;	\
235741b8161SZeev Suraski	}
236741b8161SZeev Suraski
237345e0255SDmitry Stogov#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
238b4892511SJani Taskinen	INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL)
239345e0255SDmitry Stogov
240907fa665SDmitry Stogov#define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
241907fa665SDmitry Stogov	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
242907fa665SDmitry Stogov#define INIT_OVERLOADED_NS_CLASS_ENTRY_EX(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
243907fa665SDmitry Stogov	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)
244907fa665SDmitry Stogov#define INIT_OVERLOADED_NS_CLASS_ENTRY(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset) \
245907fa665SDmitry Stogov	INIT_OVERLOADED_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions, handle_fcall, handle_propget, handle_propset)
246907fa665SDmitry Stogov
2478768ab94SDmitry Stogov#ifdef ZTS
248f23e8576SDmitry Stogov#	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])
2498768ab94SDmitry Stogov#else
250c5237d82SDmitry Stogov#	define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
2518768ab94SDmitry Stogov#endif
2528768ab94SDmitry Stogov
253b4892511SJani Taskinen#define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
254b4892511SJani Taskinen
255c96a6b44SAnatol BelskiZEND_API int zend_next_free_module(void);
256573b4602SAndi Gutmans
2571727c6a2SHartmut HolzgraefeBEGIN_EXTERN_C()
258f77e6a44SZeev SuraskiZEND_API int zend_get_parameters(int ht, int param_count, ...);
259e59bfcffSStanislav MalyshevZEND_API ZEND_ATTRIBUTE_DEPRECATED int zend_get_parameters_ex(int param_count, ...);
260bdeb220fSAnatol BelskiZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array);
26111e5d2f2SZeev Suraski
262e39f3f3fSMarcus Boerger/* internal function to efficiently copy parameters when executing __call() */
263bdeb220fSAnatol BelskiZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
264e39f3f3fSMarcus Boerger
26595dbe1d0SBob Weinand#define zend_get_parameters_array(ht, param_count, argument_array) \
266bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
26795dbe1d0SBob Weinand#define zend_get_parameters_array_ex(param_count, argument_array) \
268bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
26995dbe1d0SBob Weinand#define zend_parse_parameters_none() \
27095dbe1d0SBob Weinand	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_parse_parameters(ZEND_NUM_ARGS(), ""))
2710affe1e7SKalle Sommer Nielsen#define zend_parse_parameters_none_throw() \
2720affe1e7SKalle Sommer Nielsen	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_parse_parameters_throw(ZEND_NUM_ARGS(), ""))
27358f88057SAndrei Zmievski
27458f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
27558f88057SAndrei Zmievski
27635f9b90bSDmitry Stogov#define ZEND_PARSE_PARAMS_QUIET (1<<1)
277122d7596SNikita Popov#define ZEND_PARSE_PARAMS_THROW (1<<2)
278bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
279bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
280122d7596SNikita PopovZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...);
281cf7384aaSFelipe PenaZEND_API char *zend_zval_type_name(const zval *arg);
282f00d1c72SDmitry StogovZEND_API zend_string *zend_zval_get_type(const zval *arg);
28358f88057SAndrei Zmievski
284bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
285bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...);
286c4528f82SHarald Radi
287bdeb220fSAnatol BelskiZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...);
28813f1d53bSGustavo André dos Santos Lopes
289b5255495SZeev Suraski/* End of parameter parsing API -- andrei */
29039f9487eSAndi Gutmans
291bdeb220fSAnatol BelskiZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
292bdeb220fSAnatol BelskiZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
293bdeb220fSAnatol BelskiZEND_API int zend_startup_module(zend_module_entry *module_entry);
294bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
295bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
296bdeb220fSAnatol BelskiZEND_API int zend_startup_module_ex(zend_module_entry *module);
297bdeb220fSAnatol BelskiZEND_API int zend_startup_modules(void);
298bdeb220fSAnatol BelskiZEND_API void zend_collect_module_handlers(void);
2991a1178a6SDmitry StogovZEND_API void zend_destroy_modules(void);
300bdeb220fSAnatol BelskiZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type);
301eb0e6946SAndi Gutmans
302bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
303bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
304bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
305bdeb220fSAnatol BelskiZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
306eb0e6946SAndi Gutmans
307bdeb220fSAnatol BelskiZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce);
308907fa665SDmitry Stogov
309907fa665SDmitry Stogov#define zend_register_class_alias(name, ce) \
310bdeb220fSAnatol Belski	zend_register_class_alias_ex(name, sizeof(name)-1, ce)
311907fa665SDmitry Stogov#define zend_register_ns_class_alias(ns, name, ce) \
312bdeb220fSAnatol Belski	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce)
313907fa665SDmitry Stogov
314bdeb220fSAnatol BelskiZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
315bdeb220fSAnatol BelskiZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
316573b4602SAndi Gutmans
31771af54e5SDmitry StogovZEND_API ZEND_COLD void zend_wrong_param_count(void);
318c81db6bcSDmitry Stogov
319c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
320c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_NO_ACCESS   (1<<1)
32153e52606SMarcus Boerger#define IS_CALLABLE_CHECK_IS_STATIC   (1<<2)
322af05ce0aSDmitry Stogov#define IS_CALLABLE_CHECK_SILENT      (1<<3)
323c81db6bcSDmitry Stogov
3240cd997d7SMarcus Boerger#define IS_CALLABLE_STRICT  (IS_CALLABLE_CHECK_IS_STATIC)
3250cd997d7SMarcus Boerger
326b204b3abSAnatol BelskiZEND_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);
327b204b3abSAnatol BelskiZEND_API zend_bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
328bdeb220fSAnatol BelskiZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name);
3296c810b0dSDmitry StogovZEND_API const char *zend_get_module_version(const char *module_name);
330cf7384aaSFelipe PenaZEND_API int zend_get_module_started(const char *module_name);
331bdeb220fSAnatol BelskiZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
332bdeb220fSAnatol BelskiZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
333bdeb220fSAnatol BelskiZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
334bdeb220fSAnatol BelskiZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
335bdeb220fSAnatol BelskiZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
336bdeb220fSAnatol BelskiZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
337bdeb220fSAnatol BelskiZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
338bdeb220fSAnatol BelskiZEND_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);
339bdeb220fSAnatol Belski
340a75c1950SDmitry StogovZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
341bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
342bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
343bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
344bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value);
345bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
346bdeb220fSAnatol BelskiZEND_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);
347bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
348bdeb220fSAnatol Belski
349ea09a9faSDmitry StogovZEND_API int zend_update_class_constants(zend_class_entry *class_type);
350ea09a9faSDmitry Stogov
35170c86732SDmitry StogovZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value);
352bdeb220fSAnatol BelskiZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value);
353bdeb220fSAnatol BelskiZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
354bdeb220fSAnatol BelskiZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
355bdeb220fSAnatol BelskiZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
356bdeb220fSAnatol BelskiZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value);
357bdeb220fSAnatol BelskiZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value);
358bdeb220fSAnatol BelskiZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value);
359bdeb220fSAnatol BelskiZEND_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);
360f42cbd74SStanislav MalyshevZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
361bdeb220fSAnatol Belski
362bdeb220fSAnatol BelskiZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
363bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
364bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
365bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
366bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
367bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
368bdeb220fSAnatol BelskiZEND_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);
369bdeb220fSAnatol Belski
3707b94b958SDmitry StogovZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv);
3713e31838dSDmitry StogovZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv);
372bdeb220fSAnatol Belski
373bdeb220fSAnatol BelskiZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent);
374248345d9SDmitry Stogov
3759dd24c6dSAntony DovgalZEND_API char *zend_get_type_by_const(int type);
3766ac6cb10SHarald Radi
3777abfaac9SDmitry Stogov#define getThis()							((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
378cf5920e8SNikita Popov#define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
379741b8161SZeev Suraski
3808be4266fSAnthony Ferrara#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
381579e7fa4SAnthony Ferrara#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
38211384ba7SDmitry Stogov#define ARG_COUNT(dummy)					EX_NUM_ARGS()
38311384ba7SDmitry Stogov#define ZEND_NUM_ARGS()						EX_NUM_ARGS()
384579e7fa4SAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
3858be4266fSAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ zend_wrong_param_count(); return ret; }
386573b4602SAndi Gutmans
38780bdd19eSZeev Suraski#ifndef ZEND_WIN32
388573b4602SAndi Gutmans#define DLEXPORT
389573b4602SAndi Gutmans#endif
390573b4602SAndi Gutmans
3917da75d81SMatt Wilmas#define array_init(arg)			_array_init((arg), 0 ZEND_FILE_LINE_CC)
3927da75d81SMatt Wilmas#define array_init_size(arg, size) _array_init((arg), (size) ZEND_FILE_LINE_CC)
393bdeb220fSAnatol Belski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
394bdeb220fSAnatol Belski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
395bdeb220fSAnatol Belski#define object_and_properties_init(arg, ce, properties)	_object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC)
39607fdc1c7SAnatol BelskiZEND_API int _array_init(zval *arg, uint32_t size ZEND_FILE_LINE_DC);
397bdeb220fSAnatol BelskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
398bdeb220fSAnatol BelskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
399bdeb220fSAnatol BelskiZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC);
400c5237d82SDmitry StogovZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
401bdeb220fSAnatol BelskiZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
402bdeb220fSAnatol BelskiZEND_API void object_properties_load(zend_object *object, HashTable *properties);
4036847fefaSThies C. Arntzen
404bdeb220fSAnatol BelskiZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
405047a574eSMarcus Boerger
406f2279224SAnatol BelskiZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
407f2279224SAnatol BelskiZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
408f2279224SAnatol BelskiZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b);
409f2279224SAnatol BelskiZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
410f2279224SAnatol BelskiZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
411f2279224SAnatol BelskiZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
412eb6614e4SJakub ZelenkaZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
413eb6614e4SJakub ZelenkaZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
414f2279224SAnatol BelskiZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
415f2279224SAnatol Belski
416f2279224SAnatol Belski#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
417f2279224SAnatol Belski#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
418f2279224SAnatol Belski#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
419f2279224SAnatol Belski#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
420f2279224SAnatol Belski#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
421f2279224SAnatol Belski#define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
422f2279224SAnatol Belski#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
423f2279224SAnatol Belski#define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
424f2279224SAnatol Belski#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
4256847fefaSThies C. Arntzen
4260611acb9SAndi Gutmans/* unset() functions are only suported for legacy modules and null() functions should be used */
427f2279224SAnatol Belski#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
4280611acb9SAndi Gutmans#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
4290611acb9SAndi Gutmans#define add_next_index_unset(__arg) add_next_index_null(__arg)
4300611acb9SAndi Gutmans#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
4310611acb9SAndi Gutmans
432c3e3c98eSAnatol BelskiZEND_API int add_index_long(zval *arg, zend_ulong idx, zend_long n);
433c3e3c98eSAnatol BelskiZEND_API int add_index_null(zval *arg, zend_ulong idx);
434c3e3c98eSAnatol BelskiZEND_API int add_index_bool(zval *arg, zend_ulong idx, int b);
435c3e3c98eSAnatol BelskiZEND_API int add_index_resource(zval *arg, zend_ulong idx, zend_resource *r);
436c3e3c98eSAnatol BelskiZEND_API int add_index_double(zval *arg, zend_ulong idx, double d);
437c3e3c98eSAnatol BelskiZEND_API int add_index_str(zval *arg, zend_ulong idx, zend_string *str);
438c3e3c98eSAnatol BelskiZEND_API int add_index_string(zval *arg, zend_ulong idx, const char *str);
439d6faac2cSAnatol BelskiZEND_API int add_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
440c3e3c98eSAnatol BelskiZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value);
441c3e3c98eSAnatol Belski
442c3e3c98eSAnatol BelskiZEND_API int add_next_index_long(zval *arg, zend_long n);
4430611acb9SAndi GutmansZEND_API int add_next_index_null(zval *arg);
4446847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
445f4cfaf36SDmitry StogovZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
446573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
447f4cfaf36SDmitry StogovZEND_API int add_next_index_str(zval *arg, zend_string *str);
448050d7e38SDmitry StogovZEND_API int add_next_index_string(zval *arg, const char *str);
449d6faac2cSAnatol BelskiZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length);
450ef95a346SAndi GutmansZEND_API int add_next_index_zval(zval *arg, zval *value);
451ef95a346SAndi Gutmans
452b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint32_t key_len, const char *str);
453b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint32_t key_len, const char *str, size_t length);
454ef95a346SAndi Gutmans
455050d7e38SDmitry Stogov#define add_get_assoc_string(__arg, __key, __str) add_get_assoc_string_ex(__arg, __key, strlen(__key), __str)
456050d7e38SDmitry Stogov#define add_get_assoc_stringl(__arg, __key, __str, __length) add_get_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
457573b4602SAndi Gutmans
458c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_long(zval *arg, zend_ulong idx, zend_long l);
459c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_double(zval *arg, zend_ulong idx, double d);
460c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str);
461c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_string(zval *arg, zend_ulong idx, const char *str);
462d6faac2cSAnatol BelskiZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
463573b4602SAndi Gutmans
464bdeb220fSAnatol BelskiZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value);
465fcc6611dSNikita Popov
466bdeb220fSAnatol BelskiZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
467bdeb220fSAnatol BelskiZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len);
468bdeb220fSAnatol BelskiZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
469bdeb220fSAnatol BelskiZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
470bdeb220fSAnatol BelskiZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
471bdeb220fSAnatol BelskiZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
472bdeb220fSAnatol BelskiZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
473bdeb220fSAnatol BelskiZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
474bdeb220fSAnatol BelskiZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
475f2279224SAnatol Belski
476bdeb220fSAnatol Belski#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
477bdeb220fSAnatol Belski#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
478bdeb220fSAnatol Belski#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
479bdeb220fSAnatol Belski#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
480bdeb220fSAnatol Belski#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
481bdeb220fSAnatol Belski#define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
482bdeb220fSAnatol Belski#define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
483bdeb220fSAnatol Belski#define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
484bdeb220fSAnatol Belski#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
485ef95a346SAndi Gutmans
48692b4013eSZeev Suraski
487f0a2e8ebSDmitry StogovZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);
488c67c166fSDmitry Stogov
489f0a2e8ebSDmitry Stogov#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
490f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)
491c67c166fSDmitry Stogov#define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \
492f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)
49392b4013eSZeev Suraski
494f87d4530SNuno LopesZEND_API extern const zend_fcall_info empty_fcall_info;
495f87d4530SNuno LopesZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
49692b4013eSZeev Suraski
49764c353abSMarcus Boerger/** Build zend_call_info/cache from a zval*
49864c353abSMarcus Boerger *
499a17e4187SJoe Watkins * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
50064c353abSMarcus Boerger * In order to pass parameters the following members need to be set:
50164c353abSMarcus Boerger * fci->param_count = 0;
50264c353abSMarcus Boerger * fci->params = NULL;
503b4892511SJani Taskinen * The callable_name argument may be NULL.
504e8a8acdfSMarcus Boerger * Set check_flags to IS_CALLABLE_STRICT for every new usage!
505b4892511SJani Taskinen */
506b204b3abSAnatol BelskiZEND_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);
507b4892511SJani Taskinen
50804145dc2SVeres Lajos/** Clear arguments connected with zend_fcall_info *fci
509b4892511SJani Taskinen * If free_mem is not zero then the params array gets free'd as well
510b4892511SJani Taskinen */
511b4892511SJani TaskinenZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
512b4892511SJani Taskinen
513b4892511SJani Taskinen/** Save current arguments from zend_fcall_info *fci
514b4892511SJani Taskinen * params array will be set to NULL
515b4892511SJani Taskinen */
516f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
517b4892511SJani Taskinen
518b4892511SJani Taskinen/** Free arguments connected with zend_fcall_info *fci andset back saved ones.
51964c353abSMarcus Boerger */
520f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
52164c353abSMarcus Boerger
52264c353abSMarcus Boerger/** Set or clear the arguments in the zend_call_info struct taking care of
52364c353abSMarcus Boerger * refcount. If args is NULL and arguments are set then those are cleared.
52464c353abSMarcus Boerger */
525bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args);
526bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
52764c353abSMarcus Boerger
528b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
529b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
530b4892511SJani Taskinen * a variable amount of zval** arguments.
531b4892511SJani Taskinen */
532bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv);
533b4892511SJani Taskinen
534b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
535b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
536b4892511SJani Taskinen * a variable amount of zval** arguments.
537b4892511SJani Taskinen */
538bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv);
539b4892511SJani Taskinen
540b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
541b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
542b4892511SJani Taskinen * a variable amount of zval** arguments.
543b4892511SJani Taskinen */
544bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...);
545b4892511SJani Taskinen
54664c353abSMarcus Boerger/** Call a function using information created by zend_fcall_info_init()/args().
54704145dc2SVeres Lajos * If args is given then those replace the argument info in fci is temporarily.
54864c353abSMarcus Boerger */
549bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
55064c353abSMarcus Boerger
551bdeb220fSAnatol BelskiZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
55292b4013eSZeev Suraski
553cf7384aaSFelipe PenaZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
554f962a35dSAndrei Zmievski
555bdeb220fSAnatol BelskiZEND_API int zend_delete_global_variable(zend_string *name);
556453b49edSDmitry Stogov
557bdeb220fSAnatol BelskiZEND_API zend_array *zend_rebuild_symbol_table(void);
558ea2e1bb1SDmitry StogovZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
559ea2e1bb1SDmitry StogovZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
560bdeb220fSAnatol BelskiZEND_API int zend_set_local_var(zend_string *name, zval *value, int force);
561bdeb220fSAnatol BelskiZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force);
56291f59403SNikita PopovZEND_API int zend_forbid_dynamic_call(const char *func_name);
5632ecf4bb0SDmitry Stogov
564f4cfaf36SDmitry StogovZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
565f4cfaf36SDmitry StogovZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
5667dce0194SXinchen Hui
56702be73b5SKalle Sommer NielsenZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
568927d53fdSKalle Sommer Nielsen
56972692e9aSAaron PiotrowskiZEND_API zend_bool zend_is_iterable(zval *iterable);
57072692e9aSAaron Piotrowski
5714f6c95d1SZeev Suraski#define add_method(arg, key, method)	add_assoc_function((arg), (key), (method))
572573b4602SAndi Gutmans
573a35c61afSAndrei ZmievskiZEND_API ZEND_FUNCTION(display_disabled_function);
574a700180fSHarald RadiZEND_API ZEND_FUNCTION(display_disabled_class);
5751727c6a2SHartmut HolzgraefeEND_EXTERN_C()
576a35c61afSAndrei Zmievski
577bcddfd47SThies C. Arntzen#if ZEND_DEBUG
578050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING(str) \
5794a2e40bbSDmitry Stogov	if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", ZSTR_VAL(str)); }
580050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING_REL(str) \
5814a2e40bbSDmitry Stogov	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); }
582bcddfd47SThies C. Arntzen#else
583bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z)
58443ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z)
585bcddfd47SThies C. Arntzen#endif
586bcddfd47SThies C. Arntzen
587c3e3c98eSAnatol Belski#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
58814331620SDmitry Stogov#define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
58932b5f8a1SFelipe Pena
590f4cfaf36SDmitry Stogov#define ZVAL_STRINGL(z, s, l) do {				\
591c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
592453b49edSDmitry Stogov	} while (0)
593bcddfd47SThies C. Arntzen
594f4cfaf36SDmitry Stogov#define ZVAL_STRING(z, s) do {					\
595f4cfaf36SDmitry Stogov		const char *_s = (s);					\
596a0fe8e5aSDmitry Stogov		ZVAL_STRINGL(z, _s, strlen(_s));		\
597453b49edSDmitry Stogov	} while (0)
598bcddfd47SThies C. Arntzen
599f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_STRING(z) do {				\
6004bd22cf1SDmitry Stogov		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
601453b49edSDmitry Stogov	} while (0)
602453b49edSDmitry Stogov
603f4cfaf36SDmitry Stogov#define ZVAL_PSTRINGL(z, s, l) do {				\
604c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
605453b49edSDmitry Stogov	} while (0)
606453b49edSDmitry Stogov
607f4cfaf36SDmitry Stogov#define ZVAL_PSTRING(z, s) do {					\
608f4cfaf36SDmitry Stogov		const char *_s = (s);					\
609a0fe8e5aSDmitry Stogov		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
610f4cfaf36SDmitry Stogov	} while (0)
611f4cfaf36SDmitry Stogov
612f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_PSTRING(z) do {				\
6130e425121SDmitry Stogov		ZVAL_PSTRINGL(z, "", 0);				\
614453b49edSDmitry Stogov	} while (0)
615af22085cSThies C. Arntzen
616d18b9698SNikita Popov#define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
617d18b9698SNikita Popov		zval *__z = (z);						\
618d18b9698SNikita Popov		zval *__zv = (zv);						\
619bfdaf6e8SDmitry Stogov		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
6208e10e8f9SDmitry Stogov			if (copy && !dtor) {				\
6218e10e8f9SDmitry Stogov				ZVAL_COPY(__z, __zv);			\
6228e10e8f9SDmitry Stogov			} else {							\
6238e10e8f9SDmitry Stogov				ZVAL_COPY_VALUE(__z, __zv);		\
6248e10e8f9SDmitry Stogov			}									\
6258e10e8f9SDmitry Stogov		} else {								\
6268e10e8f9SDmitry Stogov			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
6278e10e8f9SDmitry Stogov			if (dtor || !copy) {				\
6288e10e8f9SDmitry Stogov				zval_ptr_dtor(__zv);			\
629d90ebc65SDmitry Stogov			}									\
6308e10e8f9SDmitry Stogov		}										\
631d18b9698SNikita Popov	} while (0)
632c7d27ad9SMarcus Boerger
6334f6c95d1SZeev Suraski#define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
634bcddfd47SThies C. Arntzen#define RETVAL_NULL() 					ZVAL_NULL(return_value)
635c3e3c98eSAnatol Belski#define RETVAL_LONG(l) 					ZVAL_LONG(return_value, l)
6364f6c95d1SZeev Suraski#define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value, d)
637f4cfaf36SDmitry Stogov#define RETVAL_STR(s)			 		ZVAL_STR(return_value, s)
63886336856SDmitry Stogov#define RETVAL_INTERNED_STR(s)	 		ZVAL_INTERNED_STR(return_value, s)
63976cc99feSDmitry Stogov#define RETVAL_NEW_STR(s)		 		ZVAL_NEW_STR(return_value, s)
64086336856SDmitry Stogov#define RETVAL_STR_COPY(s)		 		ZVAL_STR_COPY(return_value, s)
641f4cfaf36SDmitry Stogov#define RETVAL_STRING(s)		 		ZVAL_STRING(return_value, s)
642f4cfaf36SDmitry Stogov#define RETVAL_STRINGL(s, l)		 	ZVAL_STRINGL(return_value, s, l)
643bcddfd47SThies C. Arntzen#define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
644398256e5SDmitry Stogov#define RETVAL_RES(r)			 		ZVAL_RES(return_value, r)
6451f28da02SJin Hu#define RETVAL_ARR(r)			 		ZVAL_ARR(return_value, r)
6462402d6cbSXinchen Hui#define RETVAL_OBJ(r)			 		ZVAL_OBJ(return_value, r)
647c7d27ad9SMarcus Boerger#define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
648b5b61767SXinchen Hui#define RETVAL_FALSE  					ZVAL_FALSE(return_value)
649b5b61767SXinchen Hui#define RETVAL_TRUE   					ZVAL_TRUE(return_value)
650bcddfd47SThies C. Arntzen
651bcddfd47SThies C. Arntzen#define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
652bcddfd47SThies C. Arntzen#define RETURN_NULL() 					{ RETVAL_NULL(); return;}
653c3e3c98eSAnatol Belski#define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
654bcddfd47SThies C. Arntzen#define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
655f4cfaf36SDmitry Stogov#define RETURN_STR(s) 					{ RETVAL_STR(s); return; }
65686336856SDmitry Stogov#define RETURN_INTERNED_STR(s)			{ RETVAL_INTERNED_STR(s); return; }
65776cc99feSDmitry Stogov#define RETURN_NEW_STR(s)				{ RETVAL_NEW_STR(s); return; }
65886336856SDmitry Stogov#define RETURN_STR_COPY(s)				{ RETVAL_STR_COPY(s); return; }
659f4cfaf36SDmitry Stogov#define RETURN_STRING(s) 				{ RETVAL_STRING(s); return; }
660f4cfaf36SDmitry Stogov#define RETURN_STRINGL(s, l) 			{ RETVAL_STRINGL(s, l); return; }
661bcddfd47SThies C. Arntzen#define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
662398256e5SDmitry Stogov#define RETURN_RES(r) 					{ RETVAL_RES(r); return; }
6631f28da02SJin Hu#define RETURN_ARR(r) 					{ RETVAL_ARR(r); return; }
6642402d6cbSXinchen Hui#define RETURN_OBJ(r) 					{ RETVAL_OBJ(r); return; }
665c7d27ad9SMarcus Boerger#define RETURN_ZVAL(zv, copy, dtor)		{ RETVAL_ZVAL(zv, copy, dtor); return; }
666bcddfd47SThies C. Arntzen#define RETURN_FALSE  					{ RETVAL_FALSE; return; }
667bcddfd47SThies C. Arntzen#define RETURN_TRUE   					{ RETVAL_TRUE; return; }
6681f985edeSZeev Suraski
669bdeb220fSAnatol Belski#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)))
670068ec75fSXinchen Hui#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
67106a18f16SAndi Gutmans
6728b6f848cSAndi Gutmans/* For compatibility */
6738b6f848cSAndi Gutmans#define ZEND_MINIT			ZEND_MODULE_STARTUP_N
6748b6f848cSAndi Gutmans#define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
6758b6f848cSAndi Gutmans#define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
6768b6f848cSAndi Gutmans#define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
6778b6f848cSAndi Gutmans#define ZEND_MINFO			ZEND_MODULE_INFO_N
678bdeb220fSAnatol Belski#define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
679bdeb220fSAnatol Belski#define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
6808b6f848cSAndi Gutmans
6818b6f848cSAndi Gutmans#define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
682f5c59863SStanislav Malyshev#define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
683f5c59863SStanislav Malyshev#define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
684f5c59863SStanislav Malyshev#define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
685f5c59863SStanislav Malyshev#define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
686ada4e506SDmitry Stogov#define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
687ada4e506SDmitry Stogov#define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
6888b6f848cSAndi Gutmans
68927f38798SDmitry Stogov/* Fast parameter parsing API */
69027f38798SDmitry Stogov
691d690014bSAndrea Faulds/* Fast ZPP is always enabled now; this define is left in for compatibility
692d690014bSAndrea Faulds * with any existing conditional compilation blocks.
69327f38798SDmitry Stogov */
69427f38798SDmitry Stogov#define FAST_ZPP 1
69527f38798SDmitry Stogov
69627f38798SDmitry Stogov#define Z_EXPECTED_TYPES(_) \
697e5eb9530SAndrea Faulds	_(Z_EXPECTED_LONG,		"integer") \
69827f38798SDmitry Stogov	_(Z_EXPECTED_BOOL,		"boolean") \
69927f38798SDmitry Stogov	_(Z_EXPECTED_STRING,	"string") \
70027f38798SDmitry Stogov	_(Z_EXPECTED_ARRAY,		"array") \
70127f38798SDmitry Stogov	_(Z_EXPECTED_FUNC,		"valid callback") \
70227f38798SDmitry Stogov	_(Z_EXPECTED_RESOURCE,	"resource") \
70327f38798SDmitry Stogov	_(Z_EXPECTED_PATH,		"a valid path") \
70427f38798SDmitry Stogov	_(Z_EXPECTED_OBJECT,	"object") \
705e5eb9530SAndrea Faulds	_(Z_EXPECTED_DOUBLE,	"float")
70627f38798SDmitry Stogov
70727f38798SDmitry Stogov#define Z_EXPECTED_TYPE_ENUM(id, str) id,
70827f38798SDmitry Stogov#define Z_EXPECTED_TYPE_STR(id, str)  str,
70927f38798SDmitry Stogov
71027f38798SDmitry Stogovtypedef enum _zend_expected_type {
71127f38798SDmitry Stogov	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
71227f38798SDmitry Stogov	Z_EXPECTED_LAST
71327f38798SDmitry Stogov} zend_expected_type;
71427f38798SDmitry Stogov
71552db03b3SSara GolemonZEND_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);
71652db03b3SSara GolemonZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(zend_bool throw_, int num, zend_expected_type expected_type, zval *arg);
71752db03b3SSara GolemonZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(zend_bool throw_, int num, char *name, zval *arg);
71852db03b3SSara GolemonZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(zend_bool throw_, int severity, int num, char *error);
71927f38798SDmitry Stogov
7200ae305e6SDmitry Stogov#define ZPP_ERROR_OK             0
7210ae305e6SDmitry Stogov#define ZPP_ERROR_FAILURE        1
7220ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CALLBACK 2
7230ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CLASS    3
7240ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_ARG      4
7250ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_COUNT    5
7260ae305e6SDmitry Stogov
72727f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
72835f9b90bSDmitry Stogov		const int _flags = (flags); \
72927f38798SDmitry Stogov		int _min_num_args = (min_num_args); \
73027f38798SDmitry Stogov		int _max_num_args = (max_num_args); \
73111384ba7SDmitry Stogov		int _num_args = EX_NUM_ARGS(); \
73227f38798SDmitry Stogov		int _i; \
7330ae305e6SDmitry Stogov		zval *_real_arg, *_arg = NULL; \
7340ae305e6SDmitry Stogov		zend_expected_type _expected_type = IS_UNDEF; \
7350ae305e6SDmitry Stogov		char *_error = NULL; \
73627f38798SDmitry Stogov		zend_bool _dummy; \
7370ae305e6SDmitry Stogov		zend_bool _optional = 0; \
7380ae305e6SDmitry Stogov		int error_code = ZPP_ERROR_OK; \
73927f38798SDmitry Stogov		((void)_i); \
74027f38798SDmitry Stogov		((void)_real_arg); \
74127f38798SDmitry Stogov		((void)_arg); \
74227f38798SDmitry Stogov		((void)_expected_type); \
74327f38798SDmitry Stogov		((void)_error); \
74427f38798SDmitry Stogov		((void)_dummy); \
7450ae305e6SDmitry Stogov		((void)_optional); \
7460ae305e6SDmitry Stogov		\
7470ae305e6SDmitry Stogov		do { \
7480ae305e6SDmitry Stogov			if (UNEXPECTED(_num_args < _min_num_args) || \
7490ae305e6SDmitry Stogov			    (UNEXPECTED(_num_args > _max_num_args) && \
7500ae305e6SDmitry Stogov			     EXPECTED(_max_num_args >= 0))) { \
7510ae305e6SDmitry Stogov				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
75252db03b3SSara Golemon					zend_wrong_parameters_count_error(_flags & ZEND_PARSE_PARAMS_THROW, _num_args, _min_num_args, _max_num_args); \
7530ae305e6SDmitry Stogov				} \
7540ae305e6SDmitry Stogov				error_code = ZPP_ERROR_FAILURE; \
7550ae305e6SDmitry Stogov				break; \
75627f38798SDmitry Stogov			} \
7570ae305e6SDmitry Stogov			_i = 0; \
758bd9a2346SDmitry Stogov			_real_arg = ZEND_CALL_ARG(execute_data, 0);
75927f38798SDmitry Stogov
76027f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
76127f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
76227f38798SDmitry Stogov
76327f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END_EX(failure) \
7640ae305e6SDmitry Stogov		} while (0); \
7650ae305e6SDmitry Stogov		if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
76627f38798SDmitry Stogov			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
7670ae305e6SDmitry Stogov				if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
76852db03b3SSara Golemon					zend_wrong_callback_error(_flags & ZEND_PARSE_PARAMS_THROW, E_WARNING, _i, _error); \
7690ae305e6SDmitry Stogov				} else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
77052db03b3SSara Golemon					zend_wrong_parameter_class_error(_flags & ZEND_PARSE_PARAMS_THROW, _i, _error, _arg); \
7710ae305e6SDmitry Stogov				} else if (error_code == ZPP_ERROR_WRONG_ARG) { \
77252db03b3SSara Golemon					zend_wrong_parameter_type_error(_flags & ZEND_PARSE_PARAMS_THROW, _i, _expected_type, _arg); \
7730ae305e6SDmitry Stogov				} \
77427f38798SDmitry Stogov			} \
77527f38798SDmitry Stogov			failure; \
77627f38798SDmitry Stogov		} \
77727f38798SDmitry Stogov	} while (0)
77827f38798SDmitry Stogov
77927f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END() \
78027f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END_EX(return)
78127f38798SDmitry Stogov
78227f38798SDmitry Stogov#define Z_PARAM_PROLOGUE(separate) \
7830ae305e6SDmitry Stogov	++_i; \
784a861019bSRemi Collet	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
785a861019bSRemi Collet	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
7860ae305e6SDmitry Stogov	if (_optional) { \
7870ae305e6SDmitry Stogov		if (UNEXPECTED(_i >_num_args)) break; \
7880ae305e6SDmitry Stogov	} \
78927f38798SDmitry Stogov	_real_arg++; \
79027f38798SDmitry Stogov	_arg = _real_arg; \
79127f38798SDmitry Stogov	ZVAL_DEREF(_arg); \
79227f38798SDmitry Stogov	if (separate) { \
79327f38798SDmitry Stogov		SEPARATE_ZVAL_NOREF(_arg); \
79427f38798SDmitry Stogov	}
79527f38798SDmitry Stogov
79627f38798SDmitry Stogov/* old "|" */
7970ae305e6SDmitry Stogov#define Z_PARAM_OPTIONAL \
7980ae305e6SDmitry Stogov	_optional = 1;
79927f38798SDmitry Stogov
80027f38798SDmitry Stogov/* old "a" */
8010ae305e6SDmitry Stogov#define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
80227f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
80341e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
80427f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8050ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8060ae305e6SDmitry Stogov			break; \
8070ae305e6SDmitry Stogov		}
80827f38798SDmitry Stogov
80927f38798SDmitry Stogov#define Z_PARAM_ARRAY(dest) \
81027f38798SDmitry Stogov	Z_PARAM_ARRAY_EX(dest, 0, 0)
81127f38798SDmitry Stogov
81227f38798SDmitry Stogov/* old "A" */
8130ae305e6SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
81427f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
81541e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
81627f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8170ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8180ae305e6SDmitry Stogov			break; \
8190ae305e6SDmitry Stogov		}
82027f38798SDmitry Stogov
82127f38798SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT(dest, check_null, separate) \
82227f38798SDmitry Stogov	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
82327f38798SDmitry Stogov
82427f38798SDmitry Stogov/* old "b" */
8250ae305e6SDmitry Stogov#define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
82627f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
82735f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \
82827f38798SDmitry Stogov			_expected_type = Z_EXPECTED_BOOL; \
8290ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8300ae305e6SDmitry Stogov			break; \
8310ae305e6SDmitry Stogov		}
83227f38798SDmitry Stogov
83327f38798SDmitry Stogov#define Z_PARAM_BOOL(dest) \
83427f38798SDmitry Stogov	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
83527f38798SDmitry Stogov
83627f38798SDmitry Stogov/* old "C" */
8370ae305e6SDmitry Stogov#define Z_PARAM_CLASS_EX(dest, check_null, separate) \
83827f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
83935f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
8400ae305e6SDmitry Stogov			error_code = ZPP_ERROR_FAILURE; \
8410ae305e6SDmitry Stogov			break; \
8420ae305e6SDmitry Stogov		}
84327f38798SDmitry Stogov
84427f38798SDmitry Stogov#define Z_PARAM_CLASS(dest) \
84527f38798SDmitry Stogov	Z_PARAM_CLASS_EX(dest, 0, 0)
84627f38798SDmitry Stogov
84727f38798SDmitry Stogov/* old "d" */
8480ae305e6SDmitry Stogov#define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
84927f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
85035f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \
85127f38798SDmitry Stogov			_expected_type = Z_EXPECTED_DOUBLE; \
8520ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8530ae305e6SDmitry Stogov			break; \
8540ae305e6SDmitry Stogov		}
85527f38798SDmitry Stogov
85627f38798SDmitry Stogov#define Z_PARAM_DOUBLE(dest) \
85727f38798SDmitry Stogov	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
85827f38798SDmitry Stogov
85927f38798SDmitry Stogov/* old "f" */
8600ae305e6SDmitry Stogov#define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, separate) \
86127f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
86241e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
86327f38798SDmitry Stogov			if (!_error) { \
86427f38798SDmitry Stogov				_expected_type = Z_EXPECTED_FUNC; \
8650ae305e6SDmitry Stogov				error_code = ZPP_ERROR_WRONG_ARG; \
8660ae305e6SDmitry Stogov				break; \
86727f38798SDmitry Stogov			} else { \
8680ae305e6SDmitry Stogov				error_code = ZPP_ERROR_WRONG_CALLBACK; \
8690ae305e6SDmitry Stogov				break; \
87027f38798SDmitry Stogov			} \
8710ae305e6SDmitry Stogov		} else if (UNEXPECTED(_error != NULL)) { \
87252db03b3SSara Golemon			zend_wrong_callback_error(_flags & ZEND_PARSE_PARAMS_THROW, E_DEPRECATED, _i, _error); \
8730ae305e6SDmitry Stogov		}
87427f38798SDmitry Stogov
87527f38798SDmitry Stogov#define Z_PARAM_FUNC(dest_fci, dest_fcc) \
87627f38798SDmitry Stogov	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
87727f38798SDmitry Stogov
87827f38798SDmitry Stogov/* old "h" */
8790ae305e6SDmitry Stogov#define Z_PARAM_ARRAY_HT_EX(dest, check_null, separate) \
88027f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
88142184397SDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
88227f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8830ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8840ae305e6SDmitry Stogov			break; \
8850ae305e6SDmitry Stogov		}
88627f38798SDmitry Stogov
88727f38798SDmitry Stogov#define Z_PARAM_ARRAY_HT(dest) \
88827f38798SDmitry Stogov	Z_PARAM_ARRAY_HT_EX(dest, 0, 0)
88927f38798SDmitry Stogov
89027f38798SDmitry Stogov/* old "H" */
8910ae305e6SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_HT_EX(dest, check_null, separate) \
89227f38798SDmitry Stogov		Z_PARAM_PROLOGUE(separate); \
89342184397SDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 1, separate))) { \
89427f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8950ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8960ae305e6SDmitry Stogov			break; \
8970ae305e6SDmitry Stogov		}
89827f38798SDmitry Stogov
89927f38798SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_HT(dest) \
900