17b5ba8e6SKalle Sommer Nielsen/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5a6519d05SXinchen Hui   | Copyright (c) 1998-2018 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   +----------------------------------------------------------------------+
159afce019SZeev Suraski   | Authors: Andi Gutmans <andi@php.net>                                 |
169afce019SZeev Suraski   |          Zeev Suraski <zeev@php.net>                                 |
1758f88057SAndrei Zmievski   |          Andrei Zmievski <andrei@php.net>                            |
189afce019SZeev Suraski   |          Dmitry Stogov <dmitry@php.net>                              |
19573b4602SAndi Gutmans   +----------------------------------------------------------------------+
20573b4602SAndi Gutmans*/
21573b4602SAndi Gutmans
22b982307dSSascha Schumann#ifndef ZEND_API_H
23b982307dSSascha Schumann#define ZEND_API_H
24573b4602SAndi Gutmans
257080fa5bSAndi Gutmans#include "zend_modules.h"
26573b4602SAndi Gutmans#include "zend_list.h"
275dba4774SZeev Suraski#include "zend_operators.h"
285dba4774SZeev Suraski#include "zend_variables.h"
29df74f1dfSSascha Schumann#include "zend_execute.h"
30573b4602SAndi Gutmans
310450ab94SZeev Suraski
320450ab94SZeev SuraskiBEGIN_EXTERN_C()
33e9d126a7SAndi Gutmans
34f8bbafd6SZeev Suraskitypedef struct _zend_function_entry {
356c810b0dSDmitry Stogov	const char *fname;
36db4561bfSDmitry Stogov	zif_handler handler;
375dd427eaSDmitry Stogov	const struct _zend_internal_arg_info *arg_info;
386f9f0bf2SAnatol Belski	uint32_t num_args;
396f9f0bf2SAnatol Belski	uint32_t flags;
40f8bbafd6SZeev Suraski} zend_function_entry;
41f8bbafd6SZeev Suraski
42feb85801SDmitry Stogovtypedef struct _zend_fcall_info {
43feb85801SDmitry Stogov	size_t size;
44f4cfaf36SDmitry Stogov	zval function_name;
45f4cfaf36SDmitry Stogov	zval *retval;
46f4cfaf36SDmitry Stogov	zval *params;
47ea85451bSDmitry Stogov	zend_object *object;
48feb85801SDmitry Stogov	zend_bool no_separation;
495d5a7020SAnatol Belski	uint32_t param_count;
50feb85801SDmitry Stogov} zend_fcall_info;
51feb85801SDmitry Stogov
52feb85801SDmitry Stogovtypedef struct _zend_fcall_info_cache {
53feb85801SDmitry Stogov	zend_function *function_handler;
54feb85801SDmitry Stogov	zend_class_entry *calling_scope;
55feb85801SDmitry Stogov	zend_class_entry *called_scope;
56ea85451bSDmitry Stogov	zend_object *object;
57feb85801SDmitry Stogov} zend_fcall_info_cache;
58feb85801SDmitry Stogov
5986b36438SJelle Zijlstra#define ZEND_NS_NAME(ns, name)			ns "\\" name
60907fa665SDmitry Stogov
61f8bbafd6SZeev Suraski#define ZEND_FN(name) zif_##name
62637a4042SMarcus Boerger#define ZEND_MN(name) zim_##name
63f3aca3c8SDmitry Stogov#define ZEND_NAMED_FUNCTION(name)		void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
64f8bbafd6SZeev Suraski#define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(ZEND_FN(name))
65637a4042SMarcus Boerger#define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
66f8bbafd6SZeev Suraski
677c2a0157SBob 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 },
681c2512ddSMarcus Boerger
697c2a0157SBob 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 },
701e19ee87SHannes Magnusson#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
711e19ee87SHannes Magnusson
721c2512ddSMarcus Boerger#define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_FENTRY(zend_name, name, arg_info, 0)
731c2512ddSMarcus Boerger#define ZEND_FE(name, arg_info)						ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
74941b0651SMarcus Boerger#define ZEND_DEP_FE(name, arg_info)                 ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
75cec053f7SMarcus Boerger#define ZEND_FALIAS(name, alias, arg_info)			ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
76941b0651SMarcus Boerger#define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
77637a4042SMarcus Boerger#define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
78637a4042SMarcus Boerger#define ZEND_ME(classname, name, arg_info, flags)	ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
791c2512ddSMarcus Boerger#define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
8033cdc9edSMarcus Boerger#define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
81637a4042SMarcus Boerger                                                    ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
82637a4042SMarcus Boerger#define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
83f8bbafd6SZeev Suraski
84907fa665SDmitry 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)
85907fa665SDmitry Stogov
86907fa665SDmitry 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)
87907fa665SDmitry Stogov#define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
88907fa665SDmitry Stogov
892d5695cbSSara Golemon#define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
90907fa665SDmitry Stogov#define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
91907fa665SDmitry Stogov#define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
92907fa665SDmitry Stogov#define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
93907fa665SDmitry Stogov#define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
94907fa665SDmitry Stogov
95f1f2a649SFelipe Pena#define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
96f1f2a649SFelipe Pena
97141d1ba9SDmitry Stogov#define ZEND_ARG_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 0},
98141d1ba9SDmitry Stogov#define ZEND_ARG_PASS_INFO(pass_by_ref)                              { NULL,  0, pass_by_ref, 0},
99141d1ba9SDmitry 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 },
100141d1ba9SDmitry Stogov#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null)           { #name, ZEND_TYPE_ENCODE(IS_ARRAY, allow_null), pass_by_ref, 0 },
101141d1ba9SDmitry Stogov#define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null)        { #name, ZEND_TYPE_ENCODE(IS_CALLABLE, allow_null), pass_by_ref, 0 },
102141d1ba9SDmitry 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 },
103ab2489faSBogdan Padalko#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 1 },
104ab2489faSBogdan 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 },
105ab2489faSBogdan 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 },
1060d7a6388SNikita Popov
10766e5dc5bSRichard Fussenegger#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
108a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
10966e5dc5bSRichard Fussenegger		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, 0 },
11066e5dc5bSRichard Fussenegger
111141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
11266e5dc5bSRichard Fussenegger	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, 0, -1, class_name, allow_null)
113141d1ba9SDmitry Stogov
114141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
115141d1ba9SDmitry Stogov	static const zend_internal_arg_info name[] = { \
116141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE(type, allow_null), return_reference, 0 },
117141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
118141d1ba9SDmitry Stogov	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
119bff4c47fSReeze Xia
1200d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
121a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
122141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, 0 },
1230d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO(name, _unused)	\
1240d7a6388SNikita Popov	ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
125f8bbafd6SZeev Suraski#define ZEND_END_ARG_INFO()		};
126342c6e0bSZeev Suraski
1278b6f848cSAndi Gutmans/* Name macros */
1288b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
1298b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
1308b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
1318b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
1326535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
1338b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_N(module)			zm_info_##module
134ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
135ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
136342c6e0bSZeev Suraski
1378b6f848cSAndi Gutmans/* Declaration macros */
1388b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_D(module)		int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
1398b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_D(module)		int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
1408b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_D(module)		int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
1418b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_D(module)	int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
1426535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
1438b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_D(module)			void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
144bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
145bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
146342c6e0bSZeev Suraski
1470b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
148cb71ac03SHartmut Holzgraefe    BEGIN_EXTERN_C()\
149cb71ac03SHartmut Holzgraefe	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
150cb71ac03SHartmut Holzgraefe    END_EXTERN_C()
1510d21940dSZeev Suraski
1520d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
1530d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
1540d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
1550d21940dSZeev Suraski	} zend_##module_name##_globals;
1560d21940dSZeev Suraski
1570d21940dSZeev Suraski#ifdef ZTS
1580d21940dSZeev Suraski
1590d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
16002af513cSAndi Gutmans	ts_rsrc_id module_name##_globals_id;
16102af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
16202af513cSAndi Gutmans	extern ts_rsrc_id module_name##_globals_id;
1630d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1642c254ba7SZeev Suraski	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
16543cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
166c9a538cdSAnatol Belski#if ZEND_ENABLE_STATIC_TSRMLS_CACHE
167c9a538cdSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
168c9a538cdSAnatol Belski#else
169ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
170c9a538cdSAnatol Belski#endif
1710d21940dSZeev Suraski
1720d21940dSZeev Suraski#else
1730d21940dSZeev Suraski
1740d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
17502af513cSAndi Gutmans	zend_##module_name##_globals module_name##_globals;
17602af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
17702af513cSAndi Gutmans	extern zend_##module_name##_globals module_name##_globals;
1780d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1790d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
18043cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
181ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
1820d21940dSZeev Suraski
1830d21940dSZeev Suraski#endif
1840d21940dSZeev Suraski
185b4892511SJani Taskinen#define INIT_CLASS_ENTRY(class_container, class_name, functions) \
1866e77a60aSDmitry Stogov	INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
187741b8161SZeev Suraski
188b4892511SJani Taskinen#define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
189741b8161SZeev Suraski	{															\
1907d4e18b0SDmitry Stogov		memset(&class_container, 0, sizeof(zend_class_entry)); \
191272f5a17SDmitry Stogov		class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
1927d4e18b0SDmitry Stogov		class_container.info.internal.builtin_functions = functions;	\
19303a1fcabSXinchen Hui	}
19403a1fcabSXinchen Hui
1956e77a60aSDmitry Stogov#define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
19603a1fcabSXinchen Hui	{															\
1972eccd95cSAndi Gutmans		class_container.constructor = NULL;						\
19873b159e0SAndi Gutmans		class_container.destructor = NULL;						\
19929ea3da2SAndi Gutmans		class_container.clone = NULL;							\
200637a4042SMarcus Boerger		class_container.serialize = NULL;						\
201637a4042SMarcus Boerger		class_container.unserialize = NULL;						\
202637a4042SMarcus Boerger		class_container.create_object = NULL;					\
20372d0454bSDmitry Stogov		class_container.get_static_method = NULL;				\
2046e77a60aSDmitry Stogov		class_container.__call = NULL;							\
205b4892511SJani Taskinen		class_container.__callstatic = NULL;					\
206637a4042SMarcus Boerger		class_container.__tostring = NULL;						\
2076e77a60aSDmitry Stogov		class_container.__get = NULL;							\
2086e77a60aSDmitry Stogov		class_container.__set = NULL;							\
2096e77a60aSDmitry Stogov		class_container.__unset = NULL;							\
2106e77a60aSDmitry Stogov		class_container.__isset = NULL;							\
2116e77a60aSDmitry Stogov		class_container.__debugInfo = NULL;						\
21210b484e6SNikita Popov		class_container.serialize_func = NULL;					\
21310b484e6SNikita Popov		class_container.unserialize_func = NULL;				\
214637a4042SMarcus Boerger		class_container.parent = NULL;							\
215637a4042SMarcus Boerger		class_container.num_interfaces = 0;						\
216fdb6077fSFelipe Pena		class_container.traits = NULL;							\
217fdb6077fSFelipe Pena		class_container.num_traits = 0;							\
218fdb6077fSFelipe Pena		class_container.trait_aliases = NULL;					\
219fdb6077fSFelipe Pena		class_container.trait_precedences = NULL;				\
220637a4042SMarcus Boerger		class_container.interfaces = NULL;						\
221637a4042SMarcus Boerger		class_container.get_iterator = NULL;					\
2227d4e18b0SDmitry Stogov		class_container.iterator_funcs_ptr = NULL;				\
223f2df6a4aSDmitry Stogov		class_container.info.internal.module = NULL;			\
224f2df6a4aSDmitry Stogov		class_container.info.internal.builtin_functions = functions;	\
225741b8161SZeev Suraski	}
226741b8161SZeev Suraski
227345e0255SDmitry Stogov
228907fa665SDmitry Stogov#define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
229907fa665SDmitry Stogov	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
230907fa665SDmitry Stogov
2318768ab94SDmitry Stogov#ifdef ZTS
232f23e8576SDmitry 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])
2338768ab94SDmitry Stogov#else
234c5237d82SDmitry Stogov#	define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
2358768ab94SDmitry Stogov#endif
2368768ab94SDmitry Stogov
237b4892511SJani Taskinen#define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
238b4892511SJani Taskinen
239c96a6b44SAnatol BelskiZEND_API int zend_next_free_module(void);
240573b4602SAndi Gutmans
2411727c6a2SHartmut HolzgraefeBEGIN_EXTERN_C()
242bdeb220fSAnatol BelskiZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array);
24311e5d2f2SZeev Suraski
244e39f3f3fSMarcus Boerger/* internal function to efficiently copy parameters when executing __call() */
245bdeb220fSAnatol BelskiZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
246e39f3f3fSMarcus Boerger
24795dbe1d0SBob Weinand#define zend_get_parameters_array(ht, param_count, argument_array) \
248bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
24995dbe1d0SBob Weinand#define zend_get_parameters_array_ex(param_count, argument_array) \
250bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
25195dbe1d0SBob Weinand#define zend_parse_parameters_none() \
2527e329a82SDmitry Stogov	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_error())
2530affe1e7SKalle Sommer Nielsen#define zend_parse_parameters_none_throw() \
2547e329a82SDmitry Stogov	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_exception())
25558f88057SAndrei Zmievski
25658f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
25758f88057SAndrei Zmievski
25835f9b90bSDmitry Stogov#define ZEND_PARSE_PARAMS_QUIET (1<<1)
259122d7596SNikita Popov#define ZEND_PARSE_PARAMS_THROW (1<<2)
260bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
261bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
262122d7596SNikita PopovZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...);
263cf7384aaSFelipe PenaZEND_API char *zend_zval_type_name(const zval *arg);
264f00d1c72SDmitry StogovZEND_API zend_string *zend_zval_get_type(const zval *arg);
26558f88057SAndrei Zmievski
266bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
267bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...);
268c4528f82SHarald Radi
269bdeb220fSAnatol BelskiZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...);
27013f1d53bSGustavo André dos Santos Lopes
271b5255495SZeev Suraski/* End of parameter parsing API -- andrei */
27239f9487eSAndi Gutmans
273bdeb220fSAnatol BelskiZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
274bdeb220fSAnatol BelskiZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
275bdeb220fSAnatol BelskiZEND_API int zend_startup_module(zend_module_entry *module_entry);
276bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
277bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
278bdeb220fSAnatol BelskiZEND_API int zend_startup_module_ex(zend_module_entry *module);
279bdeb220fSAnatol BelskiZEND_API int zend_startup_modules(void);
280bdeb220fSAnatol BelskiZEND_API void zend_collect_module_handlers(void);
2811a1178a6SDmitry StogovZEND_API void zend_destroy_modules(void);
282bdeb220fSAnatol BelskiZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type);
283eb0e6946SAndi Gutmans
284bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
285bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
286bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
287bdeb220fSAnatol BelskiZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
288eb0e6946SAndi Gutmans
2898e01026bSDmitry StogovZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, int persistent);
290907fa665SDmitry Stogov
2912bf8b427SDmitry Stogov#define zend_register_class_alias(name, ce) \
2922bf8b427SDmitry Stogov	zend_register_class_alias_ex(name, sizeof(name)-1, ce, 1)
2932bf8b427SDmitry Stogov#define zend_register_ns_class_alias(ns, name, ce) \
2942bf8b427SDmitry Stogov	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
295907fa665SDmitry Stogov
296bdeb220fSAnatol BelskiZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
297bdeb220fSAnatol BelskiZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
298573b4602SAndi Gutmans
29971af54e5SDmitry StogovZEND_API ZEND_COLD void zend_wrong_param_count(void);
300c81db6bcSDmitry Stogov
301c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
302c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_NO_ACCESS   (1<<1)
30353e52606SMarcus Boerger#define IS_CALLABLE_CHECK_IS_STATIC   (1<<2)
304af05ce0aSDmitry Stogov#define IS_CALLABLE_CHECK_SILENT      (1<<3)
305c81db6bcSDmitry Stogov
3060cd997d7SMarcus Boerger#define IS_CALLABLE_STRICT  (IS_CALLABLE_CHECK_IS_STATIC)
3070cd997d7SMarcus Boerger
308ee8e75aaSNikita PopovZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
309ee8e75aaSNikita PopovZEND_API zend_string *zend_get_callable_name(zval *callable);
310b204b3abSAnatol 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);
311b204b3abSAnatol BelskiZEND_API zend_bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
312bdeb220fSAnatol BelskiZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name);
3136c810b0dSDmitry StogovZEND_API const char *zend_get_module_version(const char *module_name);
314cf7384aaSFelipe PenaZEND_API int zend_get_module_started(const char *module_name);
315bdeb220fSAnatol BelskiZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
316bdeb220fSAnatol BelskiZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
317bdeb220fSAnatol BelskiZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
318bdeb220fSAnatol BelskiZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
319bdeb220fSAnatol BelskiZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
320bdeb220fSAnatol BelskiZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
321bdeb220fSAnatol BelskiZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
322bdeb220fSAnatol 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);
323bdeb220fSAnatol Belski
324a75c1950SDmitry StogovZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
325bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
326bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
327bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
328bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value);
329bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
330bdeb220fSAnatol 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);
331bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
332bdeb220fSAnatol Belski
333ea09a9faSDmitry StogovZEND_API int zend_update_class_constants(zend_class_entry *class_type);
334ea09a9faSDmitry Stogov
33570c86732SDmitry StogovZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value);
336bdeb220fSAnatol BelskiZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value);
337bdeb220fSAnatol BelskiZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
338bdeb220fSAnatol BelskiZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
339bdeb220fSAnatol BelskiZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
340bdeb220fSAnatol BelskiZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value);
341bdeb220fSAnatol BelskiZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value);
342bdeb220fSAnatol BelskiZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value);
343bdeb220fSAnatol 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);
344f42cbd74SStanislav MalyshevZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
345bdeb220fSAnatol Belski
3467ac06d66SNikita PopovZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
347bdeb220fSAnatol BelskiZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
348bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
349bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
350bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
351bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
352bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
353bdeb220fSAnatol 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);
354bdeb220fSAnatol Belski
3557b94b958SDmitry StogovZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv);
3563e31838dSDmitry StogovZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv);
357bdeb220fSAnatol Belski
358813b6fc9SNikita PopovZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, zend_bool silent);
359bdeb220fSAnatol BelskiZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent);
360248345d9SDmitry Stogov
3619dd24c6dSAntony DovgalZEND_API char *zend_get_type_by_const(int type);
3626ac6cb10SHarald Radi
3637abfaac9SDmitry Stogov#define getThis()							((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
364cf5920e8SNikita Popov#define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
365741b8161SZeev Suraski
3668be4266fSAnthony Ferrara#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
367579e7fa4SAnthony Ferrara#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
36811384ba7SDmitry Stogov#define ARG_COUNT(dummy)					EX_NUM_ARGS()
36911384ba7SDmitry Stogov#define ZEND_NUM_ARGS()						EX_NUM_ARGS()
370579e7fa4SAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
3718be4266fSAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ zend_wrong_param_count(); return ret; }
372573b4602SAndi Gutmans
37380bdd19eSZeev Suraski#ifndef ZEND_WIN32
374573b4602SAndi Gutmans#define DLEXPORT
375573b4602SAndi Gutmans#endif
376573b4602SAndi Gutmans
37744e0b79aSDmitry Stogov#define array_init(arg)				ZVAL_ARR((arg), zend_new_array(0))
37844e0b79aSDmitry Stogov#define array_init_size(arg, size)	ZVAL_ARR((arg), zend_new_array(size))
3798361c0a9SDmitry StogovZEND_API int object_init(zval *arg);
380ebd1f5afSDmitry StogovZEND_API int object_init_ex(zval *arg, zend_class_entry *ce);
381ebd1f5afSDmitry StogovZEND_API int object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
382c5237d82SDmitry StogovZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
383bdeb220fSAnatol BelskiZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
384bdeb220fSAnatol BelskiZEND_API void object_properties_load(zend_object *object, HashTable *properties);
3856847fefaSThies C. Arntzen
386bdeb220fSAnatol BelskiZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
387047a574eSMarcus Boerger
388f2279224SAnatol BelskiZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
389f2279224SAnatol BelskiZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
390f2279224SAnatol BelskiZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b);
391f2279224SAnatol BelskiZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
392f2279224SAnatol BelskiZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
393f2279224SAnatol BelskiZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
394eb6614e4SJakub ZelenkaZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
395eb6614e4SJakub ZelenkaZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
396f2279224SAnatol BelskiZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
397f2279224SAnatol Belski
398f2279224SAnatol Belski#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
399f2279224SAnatol Belski#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
400f2279224SAnatol Belski#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
401f2279224SAnatol Belski#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
402f2279224SAnatol Belski#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
403f2279224SAnatol Belski#define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
404f2279224SAnatol Belski#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
405f2279224SAnatol Belski#define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
406f2279224SAnatol Belski#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
4076847fefaSThies C. Arntzen
4082d48d734SGabriel Caruso/* unset() functions are only supported for legacy modules and null() functions should be used */
409f2279224SAnatol Belski#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
4100611acb9SAndi Gutmans#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
4110611acb9SAndi Gutmans#define add_next_index_unset(__arg) add_next_index_null(__arg)
4120611acb9SAndi Gutmans#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
4130611acb9SAndi Gutmans
414c3e3c98eSAnatol BelskiZEND_API int add_index_long(zval *arg, zend_ulong idx, zend_long n);
415c3e3c98eSAnatol BelskiZEND_API int add_index_null(zval *arg, zend_ulong idx);
416c3e3c98eSAnatol BelskiZEND_API int add_index_bool(zval *arg, zend_ulong idx, int b);
417c3e3c98eSAnatol BelskiZEND_API int add_index_resource(zval *arg, zend_ulong idx, zend_resource *r);
418c3e3c98eSAnatol BelskiZEND_API int add_index_double(zval *arg, zend_ulong idx, double d);
419c3e3c98eSAnatol BelskiZEND_API int add_index_str(zval *arg, zend_ulong idx, zend_string *str);
420c3e3c98eSAnatol BelskiZEND_API int add_index_string(zval *arg, zend_ulong idx, const char *str);
421d6faac2cSAnatol BelskiZEND_API int add_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
422c3e3c98eSAnatol BelskiZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value);
423c3e3c98eSAnatol Belski
424c3e3c98eSAnatol BelskiZEND_API int add_next_index_long(zval *arg, zend_long n);
4250611acb9SAndi GutmansZEND_API int add_next_index_null(zval *arg);
4266847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
427f4cfaf36SDmitry StogovZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
428573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
429f4cfaf36SDmitry StogovZEND_API int add_next_index_str(zval *arg, zend_string *str);
430050d7e38SDmitry StogovZEND_API int add_next_index_string(zval *arg, const char *str);
431d6faac2cSAnatol BelskiZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length);
432ef95a346SAndi GutmansZEND_API int add_next_index_zval(zval *arg, zval *value);
433ef95a346SAndi Gutmans
434b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint32_t key_len, const char *str);
435b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint32_t key_len, const char *str, size_t length);
436ef95a346SAndi Gutmans
437050d7e38SDmitry Stogov#define add_get_assoc_string(__arg, __key, __str) add_get_assoc_string_ex(__arg, __key, strlen(__key), __str)
438050d7e38SDmitry Stogov#define add_get_assoc_stringl(__arg, __key, __str, __length) add_get_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
439573b4602SAndi Gutmans
440c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_long(zval *arg, zend_ulong idx, zend_long l);
441c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_double(zval *arg, zend_ulong idx, double d);
442c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str);
443c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_string(zval *arg, zend_ulong idx, const char *str);
444d6faac2cSAnatol BelskiZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
445573b4602SAndi Gutmans
446bdeb220fSAnatol BelskiZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value);
447fcc6611dSNikita Popov
448bdeb220fSAnatol BelskiZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
449bdeb220fSAnatol BelskiZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len);
450bdeb220fSAnatol BelskiZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
451bdeb220fSAnatol BelskiZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
452bdeb220fSAnatol BelskiZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
453bdeb220fSAnatol BelskiZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
454bdeb220fSAnatol BelskiZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
455bdeb220fSAnatol BelskiZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
456bdeb220fSAnatol BelskiZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
457f2279224SAnatol Belski
458bdeb220fSAnatol Belski#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
459bdeb220fSAnatol Belski#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
460bdeb220fSAnatol Belski#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
461bdeb220fSAnatol Belski#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
462bdeb220fSAnatol Belski#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
463bdeb220fSAnatol Belski#define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
464bdeb220fSAnatol Belski#define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
465bdeb220fSAnatol Belski#define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
466bdeb220fSAnatol Belski#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
467ef95a346SAndi Gutmans
46892b4013eSZeev Suraski
469f0a2e8ebSDmitry StogovZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);
470c67c166fSDmitry Stogov
471f0a2e8ebSDmitry Stogov#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
472f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)
473c67c166fSDmitry Stogov#define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \
474f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)
47592b4013eSZeev Suraski
476f87d4530SNuno LopesZEND_API extern const zend_fcall_info empty_fcall_info;
477f87d4530SNuno LopesZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
47892b4013eSZeev Suraski
47964c353abSMarcus Boerger/** Build zend_call_info/cache from a zval*
48064c353abSMarcus Boerger *
481a17e4187SJoe Watkins * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
48264c353abSMarcus Boerger * In order to pass parameters the following members need to be set:
48364c353abSMarcus Boerger * fci->param_count = 0;
48464c353abSMarcus Boerger * fci->params = NULL;
485b4892511SJani Taskinen * The callable_name argument may be NULL.
486e8a8acdfSMarcus Boerger * Set check_flags to IS_CALLABLE_STRICT for every new usage!
487b4892511SJani Taskinen */
488b204b3abSAnatol 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);
489b4892511SJani Taskinen
49004145dc2SVeres Lajos/** Clear arguments connected with zend_fcall_info *fci
491b4892511SJani Taskinen * If free_mem is not zero then the params array gets free'd as well
492b4892511SJani Taskinen */
493b4892511SJani TaskinenZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
494b4892511SJani Taskinen
495b4892511SJani Taskinen/** Save current arguments from zend_fcall_info *fci
496b4892511SJani Taskinen * params array will be set to NULL
497b4892511SJani Taskinen */
498f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
499b4892511SJani Taskinen
500b4892511SJani Taskinen/** Free arguments connected with zend_fcall_info *fci andset back saved ones.
50164c353abSMarcus Boerger */
502f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
50364c353abSMarcus Boerger
50464c353abSMarcus Boerger/** Set or clear the arguments in the zend_call_info struct taking care of
50564c353abSMarcus Boerger * refcount. If args is NULL and arguments are set then those are cleared.
50664c353abSMarcus Boerger */
507bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args);
508bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
50964c353abSMarcus Boerger
510b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
511b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
512b4892511SJani Taskinen * a variable amount of zval** arguments.
513b4892511SJani Taskinen */
514bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv);
515b4892511SJani Taskinen
516b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
517b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
518b4892511SJani Taskinen * a variable amount of zval** arguments.
519b4892511SJani Taskinen */
520bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv);
521b4892511SJani Taskinen
522b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
523b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
524b4892511SJani Taskinen * a variable amount of zval** arguments.
525b4892511SJani Taskinen */
526bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...);
527b4892511SJani Taskinen
52864c353abSMarcus Boerger/** Call a function using information created by zend_fcall_info_init()/args().
52904145dc2SVeres Lajos * If args is given then those replace the argument info in fci is temporarily.
53064c353abSMarcus Boerger */
531bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
53264c353abSMarcus Boerger
533bdeb220fSAnatol BelskiZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
53492b4013eSZeev Suraski
535cf7384aaSFelipe PenaZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
536f962a35dSAndrei Zmievski
537bdeb220fSAnatol BelskiZEND_API int zend_delete_global_variable(zend_string *name);
538453b49edSDmitry Stogov
539bdeb220fSAnatol BelskiZEND_API zend_array *zend_rebuild_symbol_table(void);
540ea2e1bb1SDmitry StogovZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
541ea2e1bb1SDmitry StogovZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
542bdeb220fSAnatol BelskiZEND_API int zend_set_local_var(zend_string *name, zval *value, int force);
543bdeb220fSAnatol BelskiZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force);
54491f59403SNikita PopovZEND_API int zend_forbid_dynamic_call(const char *func_name);
5452ecf4bb0SDmitry Stogov
546f4cfaf36SDmitry StogovZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
547f4cfaf36SDmitry StogovZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
5487dce0194SXinchen Hui
54902be73b5SKalle Sommer NielsenZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
550927d53fdSKalle Sommer Nielsen
55172692e9aSAaron PiotrowskiZEND_API zend_bool zend_is_iterable(zval *iterable);
55272692e9aSAaron Piotrowski
553d0ee2a82SGabriel CarusoZEND_API zend_bool zend_is_countable(zval *countable);
554d0ee2a82SGabriel Caruso
5554f6c95d1SZeev Suraski#define add_method(arg, key, method)	add_assoc_function((arg), (key), (method))
556573b4602SAndi Gutmans
557a35c61afSAndrei ZmievskiZEND_API ZEND_FUNCTION(display_disabled_function);
558a700180fSHarald RadiZEND_API ZEND_FUNCTION(display_disabled_class);
5591727c6a2SHartmut HolzgraefeEND_EXTERN_C()
560a35c61afSAndrei Zmievski
561bcddfd47SThies C. Arntzen#if ZEND_DEBUG
562050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING(str) \
5634a2e40bbSDmitry Stogov	if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", ZSTR_VAL(str)); }
564050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING_REL(str) \
5654a2e40bbSDmitry 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); }
566bcddfd47SThies C. Arntzen#else
567bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z)
56843ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z)
569bcddfd47SThies C. Arntzen#endif
570bcddfd47SThies C. Arntzen
571c3e3c98eSAnatol Belski#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
57214331620SDmitry Stogov#define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
57332b5f8a1SFelipe Pena
574f4cfaf36SDmitry Stogov#define ZVAL_STRINGL(z, s, l) do {				\
575c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
576453b49edSDmitry Stogov	} while (0)
577bcddfd47SThies C. Arntzen
578f4cfaf36SDmitry Stogov#define ZVAL_STRING(z, s) do {					\
579f4cfaf36SDmitry Stogov		const char *_s = (s);					\
580a0fe8e5aSDmitry Stogov		ZVAL_STRINGL(z, _s, strlen(_s));		\
581453b49edSDmitry Stogov	} while (0)
582bcddfd47SThies C. Arntzen
583f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_STRING(z) do {				\
5844bd22cf1SDmitry Stogov		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
585453b49edSDmitry Stogov	} while (0)
586453b49edSDmitry Stogov
587f4cfaf36SDmitry Stogov#define ZVAL_PSTRINGL(z, s, l) do {				\
588c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
589453b49edSDmitry Stogov	} while (0)
590453b49edSDmitry Stogov
591f4cfaf36SDmitry Stogov#define ZVAL_PSTRING(z, s) do {					\
592f4cfaf36SDmitry Stogov		const char *_s = (s);					\
593a0fe8e5aSDmitry Stogov		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
594f4cfaf36SDmitry Stogov	} while (0)
595f4cfaf36SDmitry Stogov
596f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_PSTRING(z) do {				\
5970e425121SDmitry Stogov		ZVAL_PSTRINGL(z, "", 0);				\
598453b49edSDmitry Stogov	} while (0)
599af22085cSThies C. Arntzen
600d18b9698SNikita Popov#define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
601d18b9698SNikita Popov		zval *__z = (z);						\
602d18b9698SNikita Popov		zval *__zv = (zv);						\
603bfdaf6e8SDmitry Stogov		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
6048e10e8f9SDmitry Stogov			if (copy && !dtor) {				\
6058e10e8f9SDmitry Stogov				ZVAL_COPY(__z, __zv);			\
6068e10e8f9SDmitry Stogov			} else {							\
6078e10e8f9SDmitry Stogov				ZVAL_COPY_VALUE(__z, __zv);		\
6088e10e8f9SDmitry Stogov			}									\
6098e10e8f9SDmitry Stogov		} else {								\
6108e10e8f9SDmitry Stogov			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
6118e10e8f9SDmitry Stogov			if (dtor || !copy) {				\
6128e10e8f9SDmitry Stogov				zval_ptr_dtor(__zv);			\
613d90ebc65SDmitry Stogov			}									\
6148e10e8f9SDmitry Stogov		}										\
615d18b9698SNikita Popov	} while (0)
616c7d27ad9SMarcus Boerger
6174f6c95d1SZeev Suraski#define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
618bcddfd47SThies C. Arntzen#define RETVAL_NULL() 					ZVAL_NULL(return_value)
619c3e3c98eSAnatol Belski#define RETVAL_LONG(l) 					ZVAL_LONG(return_value, l)
6204f6c95d1SZeev Suraski#define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value, d)
621f4cfaf36SDmitry Stogov#define RETVAL_STR(s)			 		ZVAL_STR(return_value, s)
62286336856SDmitry Stogov#define RETVAL_INTERNED_STR(s)	 		ZVAL_INTERNED_STR(return_value, s)
62376cc99feSDmitry Stogov#define RETVAL_NEW_STR(s)		 		ZVAL_NEW_STR(return_value, s)
62486336856SDmitry Stogov#define RETVAL_STR_COPY(s)		 		ZVAL_STR_COPY(return_value, s)
625f4cfaf36SDmitry Stogov#define RETVAL_STRING(s)		 		ZVAL_STRING(return_value, s)
626f4cfaf36SDmitry Stogov#define RETVAL_STRINGL(s, l)		 	ZVAL_STRINGL(return_value, s, l)
627bcddfd47SThies C. Arntzen#define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
628398256e5SDmitry Stogov#define RETVAL_RES(r)			 		ZVAL_RES(return_value, r)
6291f28da02SJin Hu#define RETVAL_ARR(r)			 		ZVAL_ARR(return_value, r)
6302402d6cbSXinchen Hui#define RETVAL_OBJ(r)			 		ZVAL_OBJ(return_value, r)
631c7d27ad9SMarcus Boerger#define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
632b5b61767SXinchen Hui#define RETVAL_FALSE  					ZVAL_FALSE(return_value)
633b5b61767SXinchen Hui#define RETVAL_TRUE   					ZVAL_TRUE(return_value)
634bcddfd47SThies C. Arntzen
635bcddfd47SThies C. Arntzen#define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
636bcddfd47SThies C. Arntzen#define RETURN_NULL() 					{ RETVAL_NULL(); return;}
637c3e3c98eSAnatol Belski#define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
638bcddfd47SThies C. Arntzen#define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
639f4cfaf36SDmitry Stogov#define RETURN_STR(s) 					{ RETVAL_STR(s); return; }
64086336856SDmitry Stogov#define RETURN_INTERNED_STR(s)			{ RETVAL_INTERNED_STR(s); return; }
64176cc99feSDmitry Stogov#define RETURN_NEW_STR(s)				{ RETVAL_NEW_STR(s); return; }
64286336856SDmitry Stogov#define RETURN_STR_COPY(s)				{ RETVAL_STR_COPY(s); return; }
643f4cfaf36SDmitry Stogov#define RETURN_STRING(s) 				{ RETVAL_STRING(s); return; }
644f4cfaf36SDmitry Stogov#define RETURN_STRINGL(s, l) 			{ RETVAL_STRINGL(s, l); return; }
645bcddfd47SThies C. Arntzen#define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
646398256e5SDmitry Stogov#define RETURN_RES(r) 					{ RETVAL_RES(r); return; }
6471f28da02SJin Hu#define RETURN_ARR(r) 					{ RETVAL_ARR(r); return; }
6482402d6cbSXinchen Hui#define RETURN_OBJ(r) 					{ RETVAL_OBJ(r); return; }
649c7d27ad9SMarcus Boerger#define RETURN_ZVAL(zv, copy, dtor)		{ RETVAL_ZVAL(zv, copy, dtor); return; }
650bcddfd47SThies C. Arntzen#define RETURN_FALSE  					{ RETVAL_FALSE; return; }
651bcddfd47SThies C. Arntzen#define RETURN_TRUE   					{ RETVAL_TRUE; return; }
6521f985edeSZeev Suraski
653bdeb220fSAnatol 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)))
654068ec75fSXinchen Hui#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
65506a18f16SAndi Gutmans
6568b6f848cSAndi Gutmans/* For compatibility */
6578b6f848cSAndi Gutmans#define ZEND_MINIT			ZEND_MODULE_STARTUP_N
6588b6f848cSAndi Gutmans#define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
6598b6f848cSAndi Gutmans#define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
6608b6f848cSAndi Gutmans#define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
6618b6f848cSAndi Gutmans#define ZEND_MINFO			ZEND_MODULE_INFO_N
662bdeb220fSAnatol Belski#define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
663bdeb220fSAnatol Belski#define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
6648b6f848cSAndi Gutmans
6658b6f848cSAndi Gutmans#define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
666f5c59863SStanislav Malyshev#define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
667f5c59863SStanislav Malyshev#define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
668f5c59863SStanislav Malyshev#define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
669f5c59863SStanislav Malyshev#define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
670ada4e506SDmitry Stogov#define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
671ada4e506SDmitry Stogov#define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
6728b6f848cSAndi Gutmans
67327f38798SDmitry Stogov/* Fast parameter parsing API */
67427f38798SDmitry Stogov
675d690014bSAndrea Faulds/* Fast ZPP is always enabled now; this define is left in for compatibility
676d690014bSAndrea Faulds * with any existing conditional compilation blocks.
67727f38798SDmitry Stogov */
67827f38798SDmitry Stogov#define FAST_ZPP 1
67927f38798SDmitry Stogov
68027f38798SDmitry Stogov#define Z_EXPECTED_TYPES(_) \
681ce1d69a1SGabriel Caruso	_(Z_EXPECTED_LONG,		"int") \
682fef879a2SGabriel Caruso	_(Z_EXPECTED_BOOL,		"bool") \
68327f38798SDmitry Stogov	_(Z_EXPECTED_STRING,	"string") \
68427f38798SDmitry Stogov	_(Z_EXPECTED_ARRAY,		"array") \
68527f38798SDmitry Stogov	_(Z_EXPECTED_FUNC,		"valid callback") \
68627f38798SDmitry Stogov	_(Z_EXPECTED_RESOURCE,	"resource") \
68727f38798SDmitry Stogov	_(Z_EXPECTED_PATH,		"a valid path") \
68827f38798SDmitry Stogov	_(Z_EXPECTED_OBJECT,	"object") \
689e5eb9530SAndrea Faulds	_(Z_EXPECTED_DOUBLE,	"float")
69027f38798SDmitry Stogov
69127f38798SDmitry Stogov#define Z_EXPECTED_TYPE_ENUM(id, str) id,
69227f38798SDmitry Stogov#define Z_EXPECTED_TYPE_STR(id, str)  str,
69327f38798SDmitry Stogov
69427f38798SDmitry Stogovtypedef enum _zend_expected_type {
69527f38798SDmitry Stogov	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
69627f38798SDmitry Stogov	Z_EXPECTED_LAST
69727f38798SDmitry Stogov} zend_expected_type;
69827f38798SDmitry Stogov
6997e329a82SDmitry StogovZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_error(void);
7007e329a82SDmitry StogovZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_exception(void);
7017e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args);
7027e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_exception(int min_num_args, int max_num_args);
7037e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
7047e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_exception(int num, zend_expected_type expected_type, zval *arg);
7057e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, char *name, zval *arg);
7067e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_exception(int num, char *name, zval *arg);
7077e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error);
7087e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_deprecated(int num, char *error);
7097e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_exception(int num, char *error);
71027f38798SDmitry Stogov
7110ae305e6SDmitry Stogov#define ZPP_ERROR_OK             0
7120ae305e6SDmitry Stogov#define ZPP_ERROR_FAILURE        1
7130ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CALLBACK 2
7140ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CLASS    3
7150ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_ARG      4
7160ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_COUNT    5
7170ae305e6SDmitry Stogov
71827f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
71935f9b90bSDmitry Stogov		const int _flags = (flags); \
72027f38798SDmitry Stogov		int _min_num_args = (min_num_args); \
72127f38798SDmitry Stogov		int _max_num_args = (max_num_args); \
72211384ba7SDmitry Stogov		int _num_args = EX_NUM_ARGS(); \
72327f38798SDmitry Stogov		int _i; \
7240ae305e6SDmitry Stogov		zval *_real_arg, *_arg = NULL; \
725e88e83d3SSara Golemon		zend_expected_type _expected_type = Z_EXPECTED_LONG; \
7260ae305e6SDmitry Stogov		char *_error = NULL; \
72727f38798SDmitry Stogov		zend_bool _dummy; \
7280ae305e6SDmitry Stogov		zend_bool _optional = 0; \
729cce2e33cSNikita Popov		int error_code = ZPP_ERROR_OK; \
73027f38798SDmitry Stogov		((void)_i); \
73127f38798SDmitry Stogov		((void)_real_arg); \
73227f38798SDmitry Stogov		((void)_arg); \
73327f38798SDmitry Stogov		((void)_expected_type); \
73427f38798SDmitry Stogov		((void)_error); \
73527f38798SDmitry Stogov		((void)_dummy); \
7360ae305e6SDmitry Stogov		((void)_optional); \
7370ae305e6SDmitry Stogov		\
7380ae305e6SDmitry Stogov		do { \
7390ae305e6SDmitry Stogov			if (UNEXPECTED(_num_args < _min_num_args) || \
7400ae305e6SDmitry Stogov			    (UNEXPECTED(_num_args > _max_num_args) && \
7410ae305e6SDmitry Stogov			     EXPECTED(_max_num_args >= 0))) { \
7420ae305e6SDmitry Stogov				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
7437e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7447e329a82SDmitry Stogov						zend_wrong_parameters_count_exception(_min_num_args, _max_num_args); \
7457e329a82SDmitry Stogov					} else { \
7467e329a82SDmitry Stogov						zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
7477e329a82SDmitry Stogov					} \
7480ae305e6SDmitry Stogov				} \
749cce2e33cSNikita Popov				error_code = ZPP_ERROR_FAILURE; \
7500ae305e6SDmitry Stogov				break; \
75127f38798SDmitry Stogov			} \
7520ae305e6SDmitry Stogov			_i = 0; \
753bd9a2346SDmitry Stogov			_real_arg = ZEND_CALL_ARG(execute_data, 0);
75427f38798SDmitry Stogov
75527f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
75627f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
75727f38798SDmitry Stogov
7587e329a82SDmitry Stogov#define ZEND_PARSE_PARAMETERS_NONE() do { \
7597e329a82SDmitry Stogov		if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
7607e329a82SDmitry Stogov			zend_wrong_parameters_none_error(); \
761ea7a3c32SDmitry Stogov			return; \
7627e329a82SDmitry Stogov		} \
7637e329a82SDmitry Stogov	} while (0)
76467be32ceSKalle Sommer Nielsen
76527f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END_EX(failure) \
7660ae305e6SDmitry Stogov		} while (0); \
767cce2e33cSNikita Popov		if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
76827f38798SDmitry Stogov			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
769cce2e33cSNikita Popov				if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
7707e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7717e329a82SDmitry Stogov						zend_wrong_callback_exception(_i, _error); \
7727e329a82SDmitry Stogov					} else { \
7737e329a82SDmitry Stogov						zend_wrong_callback_error(_i, _error); \
7747e329a82SDmitry Stogov					} \
775cce2e33cSNikita Popov				} else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
7767e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7777e329a82SDmitry Stogov						zend_wrong_parameter_class_exception(_i, _error, _arg); \
7787e329a82SDmitry Stogov					} else { \
7797e329a82SDmitry Stogov						zend_wrong_parameter_class_error(_i, _error, _arg); \
7807e329a82SDmitry Stogov					} \
781cce2e33cSNikita Popov				} else if (error_code == ZPP_ERROR_WRONG_ARG) { \
7827e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7837e329a82SDmitry Stogov						zend_wrong_parameter_type_exception(_i, _expected_type, _arg); \
7847e329a82SDmitry Stogov					} else { \
7857e329a82SDmitry Stogov						zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
7867e329a82SDmitry Stogov					} \
7870ae305e6SDmitry Stogov				} \
78827f38798SDmitry Stogov			} \
78927f38798SDmitry Stogov			failure; \
79027f38798SDmitry Stogov		} \
79127f38798SDmitry Stogov	} while (0)
79227f38798SDmitry Stogov
79327f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END() \
79427f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END_EX(return)
79527f38798SDmitry Stogov
796ace9fe53SDmitry Stogov#define Z_PARAM_PROLOGUE(deref, separate) \
7970ae305e6SDmitry Stogov	++_i; \
798a861019bSRemi Collet	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
799a861019bSRemi Collet	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
8000ae305e6SDmitry Stogov	if (_optional) { \
8010ae305e6SDmitry Stogov		if (UNEXPECTED(_i >_num_args)) break; \
8020ae305e6SDmitry Stogov	} \
80327f38798SDmitry Stogov	_real_arg++; \
80427f38798SDmitry Stogov	_arg = _real_arg; \
805ace9fe53SDmitry Stogov	if (deref) { \
806ace9fe53SDmitry Stogov		ZVAL_DEREF(_arg); \
807ace9fe53SDmitry Stogov	} \
80827f38798SDmitry Stogov	if (separate) { \
80927f38798SDmitry Stogov		SEPARATE_ZVAL_NOREF(_arg); \
81027f38798SDmitry Stogov	}
81127f38798SDmitry Stogov
81227f38798SDmitry Stogov/* old "|" */
8130ae305e6SDmitry Stogov#define Z_PARAM_OPTIONAL \
8140ae305e6SDmitry Stogov	_optional = 1;
81527f38798SDmitry Stogov
81627f38798SDmitry Stogov/* old "a" */
817ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
818ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
81941e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
82027f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
821cce2e33cSNikita Popov			error_code = ZPP_ERROR_WRONG_ARG; \
8220ae305e6SDmitry Stogov			break; \
8230ae305e6SDmitry Stogov		}
82427f38798SDmitry Stogov
825ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
826ace9fe53SDmitry Stogov	Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
827ace9fe53SDmitry Stogov
82827f38798SDmitry Stogov#define Z_PARAM_ARRAY(dest) \
82927f38798SDmitry Stogov	Z_PARAM_ARRAY_EX(dest, 0, 0)
83027f38798SDmitry Stogov
83127f38798SDmitry Stogov/* old "A" */
832ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
833ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
83441e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
83527f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
836cce2e33cSNikita Popov			error_code = ZPP_ERROR_WRONG_ARG; \
8370ae305e6SDmitry Stogov			break; \
8380ae305e6SDmitry Stogov		}
83927f38798SDmitry Stogov
840ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
841ace9fe53SDmitry Stogov	Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
842ace9fe53SDmitry Stogov
843a595b0f7SThomas Punt#define Z_PARAM_ARRAY_OR_OBJECT(dest) \
84427f38798SDmitry Stogov	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
84527f38798SDmitry Stogov
84627f38798SDmitry Stogov/* old "b" */
847ace9fe53SDmitry Stogov#define Z_PARAM_BOOL_EX2(dest, is_null, check_null, deref, separate) \
848ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
84935f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \
85027f38798SDmitry Stogov			_expected_type = Z_EXPECTED_BOOL; \
851cce2e33cSNikita Popov			error_code = ZPP_ERROR_WRONG_ARG; \
8520ae305e6SDmitry Stogov			break; \
8530ae305e6SDmitry Stogov		}
85427f38798SDmitry Stogov
855ace9fe53SDmitry Stogov#define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
856ace9fe53SDmitry Stogov	Z_PARAM_BOOL_EX2(dest, is_null, check_null, separate, separate)
857ace9fe53SDmitry Stogov
85827f38798SDmitry Stogov#define Z_PARAM_BOOL(dest) \
85927f38798SDmitry Stogov	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
86027f38798SDmitry Stogov
86127f38798SDmitry Stogov/* old "C" */
862ace9fe53SDmitry Stogov#define Z_PARAM_CLASS_EX2(dest, check_null, deref, separate) \
863ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
86435f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
865cce2e33cSNikita Popov			error_code = ZPP_ERROR_FAILURE; \
8660ae305e6SDmitry Stogov			break; \
8670ae305e6SDmitry Stogov		}
86827f38798SDmitry Stogov
869ace9fe53SDmitry Stogov#define Z_PARAM_CLASS_EX(dest, check_null, separate) \
870ace9fe53SDmitry Stogov	Z_PARAM_CLASS_EX2(dest, check_null, separate, separate)
871ace9fe53SDmitry Stogov
87227f38798SDmitry Stogov#define Z_PARAM_CLASS(dest) \
87327f38798SDmitry Stogov	Z_PARAM_CLASS_EX(dest, 0, 0)
87427f38798SDmitry Stogov
87527f38798SDmitry Stogov/* old "d" */
876ace9fe53SDmitry Stogov#define Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, deref, separate) \
877ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
87835f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \
87927f38798SDmitry Stogov			_expected_type = Z_EXPECTED_DOUBLE; \
880cce2e33cSNikita Popov			error_code = ZPP_ERROR_WRONG_ARG; \
8810ae305e6SDmitry Stogov			break; \
8820ae305e6SDmitry Stogov		}
88327f38798SDmitry Stogov
884ace9fe53SDmitry Stogov#define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
885ace9fe53SDmitry Stogov	Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, separate, separate)
886ace9fe53SDmitry Stogov
88727f38798SDmitry Stogov#define Z_PARAM_DOUBLE(dest) \
88827f38798SDmitry Stogov	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
88927f38798SDmitry Stogov
89027f38798SDmitry Stogov/* old "f" */
891ace9fe53SDmitry Stogov#define Z_PARAM_FUNC_EX2(dest_fci, dest_fcc, check_null, deref, separate) \
892ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
89341e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
89427f38798SDmitry Stogov			if (!_error) { \
89527f38798SDmitry Stogov				_expected_type = Z_EXPECTED_FUNC; \
896cce2e33cSNikita Popov				error_code = ZPP_ERROR_WRONG_ARG; \
8970ae305e6SDmitry Stogov				break; \
89827f38798SDmitry Stogov			} else { \
899cce2e33cSNikita Popov				error_code = ZPP_ERROR_WRONG_CALLBACK; \
900