zend_API.h revision 813b6fc9
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   +----------------------------------------------------------------------+
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;
38db4561bfSDmitry Stogov	zif_handler handler;
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_function *function_handler;
56feb85801SDmitry Stogov	zend_class_entry *calling_scope;
57feb85801SDmitry Stogov	zend_class_entry *called_scope;
58ea85451bSDmitry Stogov	zend_object *object;
59feb85801SDmitry Stogov} zend_fcall_info_cache;
60feb85801SDmitry Stogov
6186b36438SJelle Zijlstra#define ZEND_NS_NAME(ns, name)			ns "\\" name
62907fa665SDmitry Stogov
63f8bbafd6SZeev Suraski#define ZEND_FN(name) zif_##name
64637a4042SMarcus Boerger#define ZEND_MN(name) zim_##name
65f3aca3c8SDmitry Stogov#define ZEND_NAMED_FUNCTION(name)		void ZEND_FASTCALL name(INTERNAL_FUNCTION_PARAMETERS)
66f8bbafd6SZeev Suraski#define ZEND_FUNCTION(name)				ZEND_NAMED_FUNCTION(ZEND_FN(name))
67637a4042SMarcus Boerger#define ZEND_METHOD(classname, name)	ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
68f8bbafd6SZeev Suraski
697c2a0157SBob 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 },
701c2512ddSMarcus Boerger
717c2a0157SBob 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 },
721e19ee87SHannes Magnusson#define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
731e19ee87SHannes Magnusson
741c2512ddSMarcus Boerger#define ZEND_NAMED_FE(zend_name, name, arg_info)	ZEND_FENTRY(zend_name, name, arg_info, 0)
751c2512ddSMarcus Boerger#define ZEND_FE(name, arg_info)						ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
76941b0651SMarcus Boerger#define ZEND_DEP_FE(name, arg_info)                 ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
77cec053f7SMarcus Boerger#define ZEND_FALIAS(name, alias, arg_info)			ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
78941b0651SMarcus Boerger#define ZEND_DEP_FALIAS(name, alias, arg_info)		ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
79637a4042SMarcus Boerger#define ZEND_NAMED_ME(zend_name, name, arg_info, flags)	ZEND_FENTRY(zend_name, name, arg_info, flags)
80637a4042SMarcus Boerger#define ZEND_ME(classname, name, arg_info, flags)	ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
811c2512ddSMarcus Boerger#define ZEND_ABSTRACT_ME(classname, name, arg_info)	ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
8233cdc9edSMarcus Boerger#define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
83637a4042SMarcus Boerger                                                    ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
84637a4042SMarcus Boerger#define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
85f8bbafd6SZeev Suraski
86907fa665SDmitry 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)
87907fa665SDmitry Stogov
88907fa665SDmitry 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)
89907fa665SDmitry Stogov#define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info)			ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
90907fa665SDmitry Stogov
912d5695cbSSara Golemon#define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info)	ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
92907fa665SDmitry Stogov#define ZEND_NS_FE(ns, name, arg_info)					ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
93907fa665SDmitry Stogov#define ZEND_NS_DEP_FE(ns, name, arg_info)				ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
94907fa665SDmitry Stogov#define ZEND_NS_FALIAS(ns, name, alias, arg_info)		ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
95907fa665SDmitry Stogov#define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info)	ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
96907fa665SDmitry Stogov
97f1f2a649SFelipe Pena#define ZEND_FE_END            { NULL, NULL, NULL, 0, 0 }
98f1f2a649SFelipe Pena
99141d1ba9SDmitry Stogov#define ZEND_ARG_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 0},
100141d1ba9SDmitry Stogov#define ZEND_ARG_PASS_INFO(pass_by_ref)                              { NULL,  0, pass_by_ref, 0},
101141d1ba9SDmitry 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 },
102141d1ba9SDmitry Stogov#define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null)           { #name, ZEND_TYPE_ENCODE(IS_ARRAY, allow_null), pass_by_ref, 0 },
103141d1ba9SDmitry Stogov#define ZEND_ARG_CALLABLE_INFO(pass_by_ref, name, allow_null)        { #name, ZEND_TYPE_ENCODE(IS_CALLABLE, allow_null), pass_by_ref, 0 },
104141d1ba9SDmitry 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 },
105ab2489faSBogdan Padalko#define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name)                             { #name, 0, pass_by_ref, 1 },
106ab2489faSBogdan 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 },
107ab2489faSBogdan 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 },
1080d7a6388SNikita Popov
10966e5dc5bSRichard Fussenegger#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
110a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
11166e5dc5bSRichard Fussenegger		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, 0 },
11266e5dc5bSRichard Fussenegger
113141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \
11466e5dc5bSRichard Fussenegger	ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, 0, -1, class_name, allow_null)
115141d1ba9SDmitry Stogov
116141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
117141d1ba9SDmitry Stogov	static const zend_internal_arg_info name[] = { \
118141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE(type, allow_null), return_reference, 0 },
119141d1ba9SDmitry Stogov#define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(name, type, allow_null) \
120141d1ba9SDmitry Stogov	ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, type, allow_null)
121bff4c47fSReeze Xia
1220d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args)	\
123a3379d66SXinchen Hui	static const zend_internal_arg_info name[] = { \
124141d1ba9SDmitry Stogov		{ (const char*)(zend_uintptr_t)(required_num_args), 0, return_reference, 0 },
1250d7a6388SNikita Popov#define ZEND_BEGIN_ARG_INFO(name, _unused)	\
1260d7a6388SNikita Popov	ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
127f8bbafd6SZeev Suraski#define ZEND_END_ARG_INFO()		};
128342c6e0bSZeev Suraski
1298b6f848cSAndi Gutmans/* Name macros */
1308b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_N(module)       zm_startup_##module
1318b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_N(module)		zm_shutdown_##module
1328b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_N(module)		zm_activate_##module
1338b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_N(module)	zm_deactivate_##module
1346535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)	zm_post_zend_deactivate_##module
1358b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_N(module)			zm_info_##module
136ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_CTOR_N(module)  zm_globals_ctor_##module
137ada4e506SDmitry Stogov#define ZEND_MODULE_GLOBALS_DTOR_N(module)  zm_globals_dtor_##module
138342c6e0bSZeev Suraski
1398b6f848cSAndi Gutmans/* Declaration macros */
1408b6f848cSAndi Gutmans#define ZEND_MODULE_STARTUP_D(module)		int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
1418b6f848cSAndi Gutmans#define ZEND_MODULE_SHUTDOWN_D(module)		int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
1428b6f848cSAndi Gutmans#define ZEND_MODULE_ACTIVATE_D(module)		int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
1438b6f848cSAndi Gutmans#define ZEND_MODULE_DEACTIVATE_D(module)	int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
1446535933fSDerick Rethans#define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module)	int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
1458b6f848cSAndi Gutmans#define ZEND_MODULE_INFO_D(module)			void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
146bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_CTOR_D(module)  void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals)
147bdeb220fSAnatol Belski#define ZEND_MODULE_GLOBALS_DTOR_D(module)  void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals)
148342c6e0bSZeev Suraski
1490b6d923bSSascha Schumann#define ZEND_GET_MODULE(name) \
150cb71ac03SHartmut Holzgraefe    BEGIN_EXTERN_C()\
151cb71ac03SHartmut Holzgraefe	ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
152cb71ac03SHartmut Holzgraefe    END_EXTERN_C()
1530d21940dSZeev Suraski
1540d21940dSZeev Suraski#define ZEND_BEGIN_MODULE_GLOBALS(module_name)		\
1550d21940dSZeev Suraski	typedef struct _zend_##module_name##_globals {
1560d21940dSZeev Suraski#define ZEND_END_MODULE_GLOBALS(module_name)		\
1570d21940dSZeev Suraski	} zend_##module_name##_globals;
1580d21940dSZeev Suraski
1590d21940dSZeev Suraski#ifdef ZTS
1600d21940dSZeev Suraski
1610d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
16202af513cSAndi Gutmans	ts_rsrc_id module_name##_globals_id;
16302af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
16402af513cSAndi Gutmans	extern ts_rsrc_id module_name##_globals_id;
1650d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1662c254ba7SZeev Suraski	ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
16743cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) ZEND_TSRMG(module_name##_globals_id, zend_##module_name##_globals *, v)
168c9a538cdSAnatol Belski#if ZEND_ENABLE_STATIC_TSRMLS_CACHE
169c9a538cdSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK_STATIC(module_name##_globals_id, zend_##module_name##_globals *)
170c9a538cdSAnatol Belski#else
171ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) TSRMG_BULK(module_name##_globals_id, zend_##module_name##_globals *)
172c9a538cdSAnatol Belski#endif
1730d21940dSZeev Suraski
1740d21940dSZeev Suraski#else
1750d21940dSZeev Suraski
1760d21940dSZeev Suraski#define ZEND_DECLARE_MODULE_GLOBALS(module_name)							\
17702af513cSAndi Gutmans	zend_##module_name##_globals module_name##_globals;
17802af513cSAndi Gutmans#define ZEND_EXTERN_MODULE_GLOBALS(module_name)								\
17902af513cSAndi Gutmans	extern zend_##module_name##_globals module_name##_globals;
1800d21940dSZeev Suraski#define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)	\
1810d21940dSZeev Suraski	globals_ctor(&module_name##_globals);
18243cdfd9aSAnatol Belski#define ZEND_MODULE_GLOBALS_ACCESSOR(module_name, v) (module_name##_globals.v)
183ffa341deSAnatol Belski#define ZEND_MODULE_GLOBALS_BULK(module_name) (&module_name##_globals)
1840d21940dSZeev Suraski
1850d21940dSZeev Suraski#endif
1860d21940dSZeev Suraski
187b4892511SJani Taskinen#define INIT_CLASS_ENTRY(class_container, class_name, functions) \
1886e77a60aSDmitry Stogov	INIT_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions)
189741b8161SZeev Suraski
190b4892511SJani Taskinen#define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
191741b8161SZeev Suraski	{															\
192272f5a17SDmitry Stogov		class_container.name = zend_string_init_interned(class_name, class_name_len, 1); \
1936e77a60aSDmitry Stogov		INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
19403a1fcabSXinchen Hui	}
19503a1fcabSXinchen Hui
1966e77a60aSDmitry Stogov#define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions) \
19703a1fcabSXinchen Hui	{															\
1982eccd95cSAndi Gutmans		class_container.constructor = NULL;						\
19973b159e0SAndi Gutmans		class_container.destructor = NULL;						\
20029ea3da2SAndi Gutmans		class_container.clone = NULL;							\
201637a4042SMarcus Boerger		class_container.serialize = NULL;						\
202637a4042SMarcus Boerger		class_container.unserialize = NULL;						\
203637a4042SMarcus Boerger		class_container.create_object = NULL;					\
2043c62b3b5SMarcus Boerger		class_container.interface_gets_implemented = NULL;		\
20572d0454bSDmitry Stogov		class_container.get_static_method = NULL;				\
2066e77a60aSDmitry Stogov		class_container.__call = NULL;							\
207b4892511SJani Taskinen		class_container.__callstatic = NULL;					\
208637a4042SMarcus Boerger		class_container.__tostring = NULL;						\
2096e77a60aSDmitry Stogov		class_container.__get = NULL;							\
2106e77a60aSDmitry Stogov		class_container.__set = NULL;							\
2116e77a60aSDmitry Stogov		class_container.__unset = NULL;							\
2126e77a60aSDmitry Stogov		class_container.__isset = NULL;							\
2136e77a60aSDmitry Stogov		class_container.__debugInfo = NULL;						\
21410b484e6SNikita Popov		class_container.serialize_func = NULL;					\
21510b484e6SNikita Popov		class_container.unserialize_func = NULL;				\
216637a4042SMarcus Boerger		class_container.parent = NULL;							\
217637a4042SMarcus Boerger		class_container.num_interfaces = 0;						\
218fdb6077fSFelipe Pena		class_container.traits = NULL;							\
219fdb6077fSFelipe Pena		class_container.num_traits = 0;							\
220fdb6077fSFelipe Pena		class_container.trait_aliases = NULL;					\
221fdb6077fSFelipe Pena		class_container.trait_precedences = NULL;				\
222637a4042SMarcus Boerger		class_container.interfaces = NULL;						\
223637a4042SMarcus Boerger		class_container.get_iterator = NULL;					\
224637a4042SMarcus Boerger		class_container.iterator_funcs.funcs = NULL;			\
225f2df6a4aSDmitry Stogov		class_container.info.internal.module = NULL;			\
226f2df6a4aSDmitry Stogov		class_container.info.internal.builtin_functions = functions;	\
227741b8161SZeev Suraski	}
228741b8161SZeev Suraski
229345e0255SDmitry Stogov
230907fa665SDmitry Stogov#define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
231907fa665SDmitry Stogov	INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
232907fa665SDmitry Stogov
2338768ab94SDmitry Stogov#ifdef ZTS
234f23e8576SDmitry 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])
2358768ab94SDmitry Stogov#else
236c5237d82SDmitry Stogov#	define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
2378768ab94SDmitry Stogov#endif
2388768ab94SDmitry Stogov
239b4892511SJani Taskinen#define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
240b4892511SJani Taskinen
241c96a6b44SAnatol BelskiZEND_API int zend_next_free_module(void);
242573b4602SAndi Gutmans
2431727c6a2SHartmut HolzgraefeBEGIN_EXTERN_C()
244bdeb220fSAnatol BelskiZEND_API int _zend_get_parameters_array_ex(int param_count, zval *argument_array);
24511e5d2f2SZeev Suraski
246e39f3f3fSMarcus Boerger/* internal function to efficiently copy parameters when executing __call() */
247bdeb220fSAnatol BelskiZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
248e39f3f3fSMarcus Boerger
24995dbe1d0SBob Weinand#define zend_get_parameters_array(ht, param_count, argument_array) \
250bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
25195dbe1d0SBob Weinand#define zend_get_parameters_array_ex(param_count, argument_array) \
252bdeb220fSAnatol Belski	_zend_get_parameters_array_ex(param_count, argument_array)
25395dbe1d0SBob Weinand#define zend_parse_parameters_none() \
2547e329a82SDmitry Stogov	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_error())
2550affe1e7SKalle Sommer Nielsen#define zend_parse_parameters_none_throw() \
2567e329a82SDmitry Stogov	(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_wrong_parameters_none_exception())
25758f88057SAndrei Zmievski
25858f88057SAndrei Zmievski/* Parameter parsing API -- andrei */
25958f88057SAndrei Zmievski
26035f9b90bSDmitry Stogov#define ZEND_PARSE_PARAMS_QUIET (1<<1)
261122d7596SNikita Popov#define ZEND_PARSE_PARAMS_THROW (1<<2)
262bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
263bdeb220fSAnatol BelskiZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
264122d7596SNikita PopovZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...);
265cf7384aaSFelipe PenaZEND_API char *zend_zval_type_name(const zval *arg);
266f00d1c72SDmitry StogovZEND_API zend_string *zend_zval_get_type(const zval *arg);
26758f88057SAndrei Zmievski
268bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
269bdeb220fSAnatol BelskiZEND_API int zend_parse_method_parameters_ex(int flags, int num_args, zval *this_ptr, const char *type_spec, ...);
270c4528f82SHarald Radi
271bdeb220fSAnatol BelskiZEND_API int zend_parse_parameter(int flags, int arg_num, zval *arg, const char *spec, ...);
27213f1d53bSGustavo André dos Santos Lopes
273b5255495SZeev Suraski/* End of parameter parsing API -- andrei */
27439f9487eSAndi Gutmans
275bdeb220fSAnatol BelskiZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type);
276bdeb220fSAnatol BelskiZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table);
277bdeb220fSAnatol BelskiZEND_API int zend_startup_module(zend_module_entry *module_entry);
278bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry);
279bdeb220fSAnatol BelskiZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module);
280bdeb220fSAnatol BelskiZEND_API int zend_startup_module_ex(zend_module_entry *module);
281bdeb220fSAnatol BelskiZEND_API int zend_startup_modules(void);
282bdeb220fSAnatol BelskiZEND_API void zend_collect_module_handlers(void);
2831a1178a6SDmitry StogovZEND_API void zend_destroy_modules(void);
284bdeb220fSAnatol BelskiZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type);
285eb0e6946SAndi Gutmans
286bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
287bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
288bdeb220fSAnatol BelskiZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
289bdeb220fSAnatol BelskiZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);
290eb0e6946SAndi Gutmans
2918e01026bSDmitry StogovZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce, int persistent);
292907fa665SDmitry Stogov
2932bf8b427SDmitry Stogov#define zend_register_class_alias(name, ce) \
2942bf8b427SDmitry Stogov	zend_register_class_alias_ex(name, sizeof(name)-1, ce, 1)
2952bf8b427SDmitry Stogov#define zend_register_ns_class_alias(ns, name, ce) \
2962bf8b427SDmitry Stogov	zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)
297907fa665SDmitry Stogov
298bdeb220fSAnatol BelskiZEND_API int zend_disable_function(char *function_name, size_t function_name_length);
299bdeb220fSAnatol BelskiZEND_API int zend_disable_class(char *class_name, size_t class_name_length);
300573b4602SAndi Gutmans
30171af54e5SDmitry StogovZEND_API ZEND_COLD void zend_wrong_param_count(void);
302c81db6bcSDmitry Stogov
303c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
304c81db6bcSDmitry Stogov#define IS_CALLABLE_CHECK_NO_ACCESS   (1<<1)
30553e52606SMarcus Boerger#define IS_CALLABLE_CHECK_IS_STATIC   (1<<2)
306af05ce0aSDmitry Stogov#define IS_CALLABLE_CHECK_SILENT      (1<<3)
307c81db6bcSDmitry Stogov
3080cd997d7SMarcus Boerger#define IS_CALLABLE_STRICT  (IS_CALLABLE_CHECK_IS_STATIC)
3090cd997d7SMarcus Boerger
310ee8e75aaSNikita PopovZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *object);
311ee8e75aaSNikita PopovZEND_API zend_string *zend_get_callable_name(zval *callable);
312b204b3abSAnatol 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);
313b204b3abSAnatol BelskiZEND_API zend_bool zend_is_callable(zval *callable, uint32_t check_flags, zend_string **callable_name);
314bdeb220fSAnatol BelskiZEND_API zend_bool zend_make_callable(zval *callable, zend_string **callable_name);
3156c810b0dSDmitry StogovZEND_API const char *zend_get_module_version(const char *module_name);
316cf7384aaSFelipe PenaZEND_API int zend_get_module_started(const char *module_name);
317bdeb220fSAnatol BelskiZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment);
318bdeb220fSAnatol BelskiZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, size_t name_length, zval *property, int access_type);
319bdeb220fSAnatol BelskiZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, size_t name_length, int access_type);
320bdeb220fSAnatol BelskiZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
321bdeb220fSAnatol BelskiZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value, int access_type);
322bdeb220fSAnatol BelskiZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, size_t name_length, double value, int access_type);
323bdeb220fSAnatol BelskiZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value, int access_type);
324bdeb220fSAnatol 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);
325bdeb220fSAnatol Belski
326a75c1950SDmitry StogovZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *name, zval *value, int access_type, zend_string *doc_comment);
327bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value);
328bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length);
329bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, zend_long value);
330bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value);
331bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value);
332bdeb220fSAnatol 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);
333bdeb220fSAnatol BelskiZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value);
334bdeb220fSAnatol Belski
335ea09a9faSDmitry StogovZEND_API int zend_update_class_constants(zend_class_entry *class_type);
336ea09a9faSDmitry Stogov
33770c86732SDmitry StogovZEND_API void zend_update_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zval *value);
338bdeb220fSAnatol BelskiZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zval *value);
339bdeb220fSAnatol BelskiZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
340bdeb220fSAnatol BelskiZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
341bdeb220fSAnatol BelskiZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value);
342bdeb220fSAnatol BelskiZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, size_t name_length, double value);
343bdeb220fSAnatol BelskiZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value);
344bdeb220fSAnatol BelskiZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value);
345bdeb220fSAnatol 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);
346f42cbd74SStanislav MalyshevZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
347bdeb220fSAnatol Belski
348bdeb220fSAnatol BelskiZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
349bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
350bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
351bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
352bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
353bdeb220fSAnatol BelskiZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
354bdeb220fSAnatol 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);
355bdeb220fSAnatol Belski
3567b94b958SDmitry StogovZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zval *object, zend_string *name, zend_bool silent, zval *rv);
3573e31838dSDmitry StogovZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_bool silent, zval *rv);
358bdeb220fSAnatol Belski
359813b6fc9SNikita PopovZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, zend_bool silent);
360bdeb220fSAnatol BelskiZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, size_t name_length, zend_bool silent);
361248345d9SDmitry Stogov
3629dd24c6dSAntony DovgalZEND_API char *zend_get_type_by_const(int type);
3636ac6cb10SHarald Radi
3647abfaac9SDmitry Stogov#define getThis()							((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
365cf5920e8SNikita Popov#define ZEND_IS_METHOD_CALL()				(EX(func)->common.scope != NULL)
366741b8161SZeev Suraski
3678be4266fSAnthony Ferrara#define WRONG_PARAM_COUNT					ZEND_WRONG_PARAM_COUNT()
368579e7fa4SAnthony Ferrara#define WRONG_PARAM_COUNT_WITH_RETVAL(ret)	ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
36911384ba7SDmitry Stogov#define ARG_COUNT(dummy)					EX_NUM_ARGS()
37011384ba7SDmitry Stogov#define ZEND_NUM_ARGS()						EX_NUM_ARGS()
371579e7fa4SAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT()					{ zend_wrong_param_count(); return; }
3728be4266fSAnthony Ferrara#define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)		{ zend_wrong_param_count(); return ret; }
373573b4602SAndi Gutmans
37480bdd19eSZeev Suraski#ifndef ZEND_WIN32
375573b4602SAndi Gutmans#define DLEXPORT
376573b4602SAndi Gutmans#endif
377573b4602SAndi Gutmans
37844e0b79aSDmitry Stogov#define array_init(arg)				ZVAL_ARR((arg), zend_new_array(0))
37944e0b79aSDmitry Stogov#define array_init_size(arg, size)	ZVAL_ARR((arg), zend_new_array(size))
380bdeb220fSAnatol Belski#define object_init(arg)		_object_init((arg) ZEND_FILE_LINE_CC)
381bdeb220fSAnatol Belski#define object_init_ex(arg, ce)	_object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
382bdeb220fSAnatol Belski#define object_and_properties_init(arg, ce, properties)	_object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC)
383bdeb220fSAnatol BelskiZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
384bdeb220fSAnatol BelskiZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
385bdeb220fSAnatol BelskiZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC);
386c5237d82SDmitry StogovZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
387bdeb220fSAnatol BelskiZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);
388bdeb220fSAnatol BelskiZEND_API void object_properties_load(zend_object *object, HashTable *properties);
3896847fefaSThies C. Arntzen
390bdeb220fSAnatol BelskiZEND_API void zend_merge_properties(zval *obj, HashTable *properties);
391047a574eSMarcus Boerger
392f2279224SAnatol BelskiZEND_API int add_assoc_long_ex(zval *arg, const char *key, size_t key_len, zend_long n);
393f2279224SAnatol BelskiZEND_API int add_assoc_null_ex(zval *arg, const char *key, size_t key_len);
394f2279224SAnatol BelskiZEND_API int add_assoc_bool_ex(zval *arg, const char *key, size_t key_len, int b);
395f2279224SAnatol BelskiZEND_API int add_assoc_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
396f2279224SAnatol BelskiZEND_API int add_assoc_double_ex(zval *arg, const char *key, size_t key_len, double d);
397f2279224SAnatol BelskiZEND_API int add_assoc_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
398eb6614e4SJakub ZelenkaZEND_API int add_assoc_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
399eb6614e4SJakub ZelenkaZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length);
400f2279224SAnatol BelskiZEND_API int add_assoc_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
401f2279224SAnatol Belski
402f2279224SAnatol Belski#define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key), __n)
403f2279224SAnatol Belski#define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
404f2279224SAnatol Belski#define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key), __b)
405f2279224SAnatol Belski#define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key), __r)
406f2279224SAnatol Belski#define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key), __d)
407f2279224SAnatol Belski#define add_assoc_str(__arg, __key, __str) add_assoc_str_ex(__arg, __key, strlen(__key), __str)
408f2279224SAnatol Belski#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
409f2279224SAnatol Belski#define add_assoc_stringl(__arg, __key, __str, __length) add_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
410f2279224SAnatol Belski#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
4116847fefaSThies C. Arntzen
4122d48d734SGabriel Caruso/* unset() functions are only supported for legacy modules and null() functions should be used */
413f2279224SAnatol Belski#define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key))
4140611acb9SAndi Gutmans#define add_index_unset(__arg, __key) add_index_null(__arg, __key)
4150611acb9SAndi Gutmans#define add_next_index_unset(__arg) add_next_index_null(__arg)
4160611acb9SAndi Gutmans#define add_property_unset(__arg, __key) add_property_null(__arg, __key)
4170611acb9SAndi Gutmans
418c3e3c98eSAnatol BelskiZEND_API int add_index_long(zval *arg, zend_ulong idx, zend_long n);
419c3e3c98eSAnatol BelskiZEND_API int add_index_null(zval *arg, zend_ulong idx);
420c3e3c98eSAnatol BelskiZEND_API int add_index_bool(zval *arg, zend_ulong idx, int b);
421c3e3c98eSAnatol BelskiZEND_API int add_index_resource(zval *arg, zend_ulong idx, zend_resource *r);
422c3e3c98eSAnatol BelskiZEND_API int add_index_double(zval *arg, zend_ulong idx, double d);
423c3e3c98eSAnatol BelskiZEND_API int add_index_str(zval *arg, zend_ulong idx, zend_string *str);
424c3e3c98eSAnatol BelskiZEND_API int add_index_string(zval *arg, zend_ulong idx, const char *str);
425d6faac2cSAnatol BelskiZEND_API int add_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
426c3e3c98eSAnatol BelskiZEND_API int add_index_zval(zval *arg, zend_ulong index, zval *value);
427c3e3c98eSAnatol Belski
428c3e3c98eSAnatol BelskiZEND_API int add_next_index_long(zval *arg, zend_long n);
4290611acb9SAndi GutmansZEND_API int add_next_index_null(zval *arg);
4306847fefaSThies C. ArntzenZEND_API int add_next_index_bool(zval *arg, int b);
431f4cfaf36SDmitry StogovZEND_API int add_next_index_resource(zval *arg, zend_resource *r);
432573b4602SAndi GutmansZEND_API int add_next_index_double(zval *arg, double d);
433f4cfaf36SDmitry StogovZEND_API int add_next_index_str(zval *arg, zend_string *str);
434050d7e38SDmitry StogovZEND_API int add_next_index_string(zval *arg, const char *str);
435d6faac2cSAnatol BelskiZEND_API int add_next_index_stringl(zval *arg, const char *str, size_t length);
436ef95a346SAndi GutmansZEND_API int add_next_index_zval(zval *arg, zval *value);
437ef95a346SAndi Gutmans
438b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_string_ex(zval *arg, const char *key, uint32_t key_len, const char *str);
439b204b3abSAnatol BelskiZEND_API zval *add_get_assoc_stringl_ex(zval *arg, const char *key, uint32_t key_len, const char *str, size_t length);
440ef95a346SAndi Gutmans
441050d7e38SDmitry Stogov#define add_get_assoc_string(__arg, __key, __str) add_get_assoc_string_ex(__arg, __key, strlen(__key), __str)
442050d7e38SDmitry Stogov#define add_get_assoc_stringl(__arg, __key, __str, __length) add_get_assoc_stringl_ex(__arg, __key, strlen(__key), __str, __length)
443573b4602SAndi Gutmans
444c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_long(zval *arg, zend_ulong idx, zend_long l);
445c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_double(zval *arg, zend_ulong idx, double d);
446c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_str(zval *arg, zend_ulong index, zend_string *str);
447c3e3c98eSAnatol BelskiZEND_API zval *add_get_index_string(zval *arg, zend_ulong idx, const char *str);
448d6faac2cSAnatol BelskiZEND_API zval *add_get_index_stringl(zval *arg, zend_ulong idx, const char *str, size_t length);
449573b4602SAndi Gutmans
450bdeb220fSAnatol BelskiZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value);
451fcc6611dSNikita Popov
452bdeb220fSAnatol BelskiZEND_API int add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l);
453bdeb220fSAnatol BelskiZEND_API int add_property_null_ex(zval *arg, const char *key, size_t key_len);
454bdeb220fSAnatol BelskiZEND_API int add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b);
455bdeb220fSAnatol BelskiZEND_API int add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r);
456bdeb220fSAnatol BelskiZEND_API int add_property_double_ex(zval *arg, const char *key, size_t key_len, double d);
457bdeb220fSAnatol BelskiZEND_API int add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str);
458bdeb220fSAnatol BelskiZEND_API int add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str);
459bdeb220fSAnatol BelskiZEND_API int add_property_stringl_ex(zval *arg, const char *key, size_t key_len,  const char *str, size_t length);
460bdeb220fSAnatol BelskiZEND_API int add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value);
461f2279224SAnatol Belski
462bdeb220fSAnatol Belski#define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key), __n)
463bdeb220fSAnatol Belski#define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key))
464bdeb220fSAnatol Belski#define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key), __b)
465bdeb220fSAnatol Belski#define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key), __r)
466bdeb220fSAnatol Belski#define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key), __d)
467bdeb220fSAnatol Belski#define add_property_str(__arg, __key, __str) add_property_str_ex(__arg, __key, strlen(__key), __str)
468bdeb220fSAnatol Belski#define add_property_string(__arg, __key, __str) add_property_string_ex(__arg, __key, strlen(__key), __str)
469bdeb220fSAnatol Belski#define add_property_stringl(__arg, __key, __str, __length) add_property_stringl_ex(__arg, __key, strlen(__key), __str, __length)
470bdeb220fSAnatol Belski#define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key), __value)
471ef95a346SAndi Gutmans
47292b4013eSZeev Suraski
473f0a2e8ebSDmitry StogovZEND_API int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation);
474c67c166fSDmitry Stogov
475f0a2e8ebSDmitry Stogov#define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \
476f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, 1)
477c67c166fSDmitry Stogov#define call_user_function_ex(function_table, object, function_name, retval_ptr, param_count, params, no_separation, symbol_table) \
478f0a2e8ebSDmitry Stogov	_call_user_function_ex(object, function_name, retval_ptr, param_count, params, no_separation)
47992b4013eSZeev Suraski
480f87d4530SNuno LopesZEND_API extern const zend_fcall_info empty_fcall_info;
481f87d4530SNuno LopesZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
48292b4013eSZeev Suraski
48364c353abSMarcus Boerger/** Build zend_call_info/cache from a zval*
48464c353abSMarcus Boerger *
485a17e4187SJoe Watkins * Caller is responsible to provide a return value (fci->retval), otherwise the we will crash.
48664c353abSMarcus Boerger * In order to pass parameters the following members need to be set:
48764c353abSMarcus Boerger * fci->param_count = 0;
48864c353abSMarcus Boerger * fci->params = NULL;
489b4892511SJani Taskinen * The callable_name argument may be NULL.
490e8a8acdfSMarcus Boerger * Set check_flags to IS_CALLABLE_STRICT for every new usage!
491b4892511SJani Taskinen */
492b204b3abSAnatol 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);
493b4892511SJani Taskinen
49404145dc2SVeres Lajos/** Clear arguments connected with zend_fcall_info *fci
495b4892511SJani Taskinen * If free_mem is not zero then the params array gets free'd as well
496b4892511SJani Taskinen */
497b4892511SJani TaskinenZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
498b4892511SJani Taskinen
499b4892511SJani Taskinen/** Save current arguments from zend_fcall_info *fci
500b4892511SJani Taskinen * params array will be set to NULL
501b4892511SJani Taskinen */
502f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval **params);
503b4892511SJani Taskinen
504b4892511SJani Taskinen/** Free arguments connected with zend_fcall_info *fci andset back saved ones.
50564c353abSMarcus Boerger */
506f4cfaf36SDmitry StogovZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval *params);
50764c353abSMarcus Boerger
50864c353abSMarcus Boerger/** Set or clear the arguments in the zend_call_info struct taking care of
50964c353abSMarcus Boerger * refcount. If args is NULL and arguments are set then those are cleared.
51064c353abSMarcus Boerger */
511bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args);
512bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_args_ex(zend_fcall_info *fci, zend_function *func, zval *args);
51364c353abSMarcus Boerger
514b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
515b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
516b4892511SJani Taskinen * a variable amount of zval** arguments.
517b4892511SJani Taskinen */
518bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argp(zend_fcall_info *fci, int argc, zval *argv);
519b4892511SJani Taskinen
520b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
521b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
522b4892511SJani Taskinen * a variable amount of zval** arguments.
523b4892511SJani Taskinen */
524bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argv(zend_fcall_info *fci, int argc, va_list *argv);
525b4892511SJani Taskinen
526b4892511SJani Taskinen/** Set arguments in the zend_fcall_info struct taking care of refcount.
527b4892511SJani Taskinen * If argc is 0 the arguments which are set will be cleared, else pass
528b4892511SJani Taskinen * a variable amount of zval** arguments.
529b4892511SJani Taskinen */
530bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_argn(zend_fcall_info *fci, int argc, ...);
531b4892511SJani Taskinen
53264c353abSMarcus Boerger/** Call a function using information created by zend_fcall_info_init()/args().
53304145dc2SVeres Lajos * If args is given then those replace the argument info in fci is temporarily.
53464c353abSMarcus Boerger */
535bdeb220fSAnatol BelskiZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval *retval, zval *args);
53664c353abSMarcus Boerger
537bdeb220fSAnatol BelskiZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache);
53892b4013eSZeev Suraski
539cf7384aaSFelipe PenaZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
540f962a35dSAndrei Zmievski
541bdeb220fSAnatol BelskiZEND_API int zend_delete_global_variable(zend_string *name);
542453b49edSDmitry Stogov
543bdeb220fSAnatol BelskiZEND_API zend_array *zend_rebuild_symbol_table(void);
544ea2e1bb1SDmitry StogovZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data);
545ea2e1bb1SDmitry StogovZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data);
546bdeb220fSAnatol BelskiZEND_API int zend_set_local_var(zend_string *name, zval *value, int force);
547bdeb220fSAnatol BelskiZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force);
54891f59403SNikita PopovZEND_API int zend_forbid_dynamic_call(const char *func_name);
5492ecf4bb0SDmitry Stogov
550f4cfaf36SDmitry StogovZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
551f4cfaf36SDmitry StogovZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
5527dce0194SXinchen Hui
55302be73b5SKalle Sommer NielsenZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
554927d53fdSKalle Sommer Nielsen
55572692e9aSAaron PiotrowskiZEND_API zend_bool zend_is_iterable(zval *iterable);
55672692e9aSAaron Piotrowski
557d0ee2a82SGabriel CarusoZEND_API zend_bool zend_is_countable(zval *countable);
558d0ee2a82SGabriel Caruso
5594f6c95d1SZeev Suraski#define add_method(arg, key, method)	add_assoc_function((arg), (key), (method))
560573b4602SAndi Gutmans
561a35c61afSAndrei ZmievskiZEND_API ZEND_FUNCTION(display_disabled_function);
562a700180fSHarald RadiZEND_API ZEND_FUNCTION(display_disabled_class);
5631727c6a2SHartmut HolzgraefeEND_EXTERN_C()
564a35c61afSAndrei Zmievski
565bcddfd47SThies C. Arntzen#if ZEND_DEBUG
566050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING(str) \
5674a2e40bbSDmitry Stogov	if (ZSTR_VAL(str)[ZSTR_LEN(str)] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", ZSTR_VAL(str)); }
568050d7e38SDmitry Stogov#define CHECK_ZVAL_STRING_REL(str) \
5694a2e40bbSDmitry 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); }
570bcddfd47SThies C. Arntzen#else
571bcddfd47SThies C. Arntzen#define CHECK_ZVAL_STRING(z)
57243ebb868SZeev Suraski#define CHECK_ZVAL_STRING_REL(z)
573bcddfd47SThies C. Arntzen#endif
574bcddfd47SThies C. Arntzen
575c3e3c98eSAnatol Belski#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
57614331620SDmitry Stogov#define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
57732b5f8a1SFelipe Pena
578f4cfaf36SDmitry Stogov#define ZVAL_STRINGL(z, s, l) do {				\
579c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 0));		\
580453b49edSDmitry Stogov	} while (0)
581bcddfd47SThies C. Arntzen
582f4cfaf36SDmitry Stogov#define ZVAL_STRING(z, s) do {					\
583f4cfaf36SDmitry Stogov		const char *_s = (s);					\
584a0fe8e5aSDmitry Stogov		ZVAL_STRINGL(z, _s, strlen(_s));		\
585453b49edSDmitry Stogov	} while (0)
586bcddfd47SThies C. Arntzen
587f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_STRING(z) do {				\
5884bd22cf1SDmitry Stogov		ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC());		\
589453b49edSDmitry Stogov	} while (0)
590453b49edSDmitry Stogov
591f4cfaf36SDmitry Stogov#define ZVAL_PSTRINGL(z, s, l) do {				\
592c3e3c98eSAnatol Belski		ZVAL_NEW_STR(z, zend_string_init(s, l, 1));		\
593453b49edSDmitry Stogov	} while (0)
594453b49edSDmitry Stogov
595f4cfaf36SDmitry Stogov#define ZVAL_PSTRING(z, s) do {					\
596f4cfaf36SDmitry Stogov		const char *_s = (s);					\
597a0fe8e5aSDmitry Stogov		ZVAL_PSTRINGL(z, _s, strlen(_s));		\
598f4cfaf36SDmitry Stogov	} while (0)
599f4cfaf36SDmitry Stogov
600f4cfaf36SDmitry Stogov#define ZVAL_EMPTY_PSTRING(z) do {				\
6010e425121SDmitry Stogov		ZVAL_PSTRINGL(z, "", 0);				\
602453b49edSDmitry Stogov	} while (0)
603af22085cSThies C. Arntzen
604d18b9698SNikita Popov#define ZVAL_ZVAL(z, zv, copy, dtor) do {		\
605d18b9698SNikita Popov		zval *__z = (z);						\
606d18b9698SNikita Popov		zval *__zv = (zv);						\
607bfdaf6e8SDmitry Stogov		if (EXPECTED(!Z_ISREF_P(__zv))) {		\
6088e10e8f9SDmitry Stogov			if (copy && !dtor) {				\
6098e10e8f9SDmitry Stogov				ZVAL_COPY(__z, __zv);			\
6108e10e8f9SDmitry Stogov			} else {							\
6118e10e8f9SDmitry Stogov				ZVAL_COPY_VALUE(__z, __zv);		\
6128e10e8f9SDmitry Stogov			}									\
6138e10e8f9SDmitry Stogov		} else {								\
6148e10e8f9SDmitry Stogov			ZVAL_COPY(__z, Z_REFVAL_P(__zv));	\
6158e10e8f9SDmitry Stogov			if (dtor || !copy) {				\
6168e10e8f9SDmitry Stogov				zval_ptr_dtor(__zv);			\
617d90ebc65SDmitry Stogov			}									\
6188e10e8f9SDmitry Stogov		}										\
619d18b9698SNikita Popov	} while (0)
620c7d27ad9SMarcus Boerger
6214f6c95d1SZeev Suraski#define RETVAL_BOOL(b)					ZVAL_BOOL(return_value, b)
622bcddfd47SThies C. Arntzen#define RETVAL_NULL() 					ZVAL_NULL(return_value)
623c3e3c98eSAnatol Belski#define RETVAL_LONG(l) 					ZVAL_LONG(return_value, l)
6244f6c95d1SZeev Suraski#define RETVAL_DOUBLE(d) 				ZVAL_DOUBLE(return_value, d)
625f4cfaf36SDmitry Stogov#define RETVAL_STR(s)			 		ZVAL_STR(return_value, s)
62686336856SDmitry Stogov#define RETVAL_INTERNED_STR(s)	 		ZVAL_INTERNED_STR(return_value, s)
62776cc99feSDmitry Stogov#define RETVAL_NEW_STR(s)		 		ZVAL_NEW_STR(return_value, s)
62886336856SDmitry Stogov#define RETVAL_STR_COPY(s)		 		ZVAL_STR_COPY(return_value, s)
629f4cfaf36SDmitry Stogov#define RETVAL_STRING(s)		 		ZVAL_STRING(return_value, s)
630f4cfaf36SDmitry Stogov#define RETVAL_STRINGL(s, l)		 	ZVAL_STRINGL(return_value, s, l)
631bcddfd47SThies C. Arntzen#define RETVAL_EMPTY_STRING() 			ZVAL_EMPTY_STRING(return_value)
632398256e5SDmitry Stogov#define RETVAL_RES(r)			 		ZVAL_RES(return_value, r)
6331f28da02SJin Hu#define RETVAL_ARR(r)			 		ZVAL_ARR(return_value, r)
6342402d6cbSXinchen Hui#define RETVAL_OBJ(r)			 		ZVAL_OBJ(return_value, r)
635c7d27ad9SMarcus Boerger#define RETVAL_ZVAL(zv, copy, dtor)		ZVAL_ZVAL(return_value, zv, copy, dtor)
636b5b61767SXinchen Hui#define RETVAL_FALSE  					ZVAL_FALSE(return_value)
637b5b61767SXinchen Hui#define RETVAL_TRUE   					ZVAL_TRUE(return_value)
638bcddfd47SThies C. Arntzen
639bcddfd47SThies C. Arntzen#define RETURN_BOOL(b) 					{ RETVAL_BOOL(b); return; }
640bcddfd47SThies C. Arntzen#define RETURN_NULL() 					{ RETVAL_NULL(); return;}
641c3e3c98eSAnatol Belski#define RETURN_LONG(l) 					{ RETVAL_LONG(l); return; }
642bcddfd47SThies C. Arntzen#define RETURN_DOUBLE(d) 				{ RETVAL_DOUBLE(d); return; }
643f4cfaf36SDmitry Stogov#define RETURN_STR(s) 					{ RETVAL_STR(s); return; }
64486336856SDmitry Stogov#define RETURN_INTERNED_STR(s)			{ RETVAL_INTERNED_STR(s); return; }
64576cc99feSDmitry Stogov#define RETURN_NEW_STR(s)				{ RETVAL_NEW_STR(s); return; }
64686336856SDmitry Stogov#define RETURN_STR_COPY(s)				{ RETVAL_STR_COPY(s); return; }
647f4cfaf36SDmitry Stogov#define RETURN_STRING(s) 				{ RETVAL_STRING(s); return; }
648f4cfaf36SDmitry Stogov#define RETURN_STRINGL(s, l) 			{ RETVAL_STRINGL(s, l); return; }
649bcddfd47SThies C. Arntzen#define RETURN_EMPTY_STRING() 			{ RETVAL_EMPTY_STRING(); return; }
650398256e5SDmitry Stogov#define RETURN_RES(r) 					{ RETVAL_RES(r); return; }
6511f28da02SJin Hu#define RETURN_ARR(r) 					{ RETVAL_ARR(r); return; }
6522402d6cbSXinchen Hui#define RETURN_OBJ(r) 					{ RETVAL_OBJ(r); return; }
653c7d27ad9SMarcus Boerger#define RETURN_ZVAL(zv, copy, dtor)		{ RETVAL_ZVAL(zv, copy, dtor); return; }
654bcddfd47SThies C. Arntzen#define RETURN_FALSE  					{ RETVAL_FALSE; return; }
655bcddfd47SThies C. Arntzen#define RETURN_TRUE   					{ RETVAL_TRUE; return; }
6561f985edeSZeev Suraski
657bdeb220fSAnatol 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)))
658068ec75fSXinchen Hui#define ZVAL_IS_NULL(z) (Z_TYPE_P(z) == IS_NULL)
65906a18f16SAndi Gutmans
6608b6f848cSAndi Gutmans/* For compatibility */
6618b6f848cSAndi Gutmans#define ZEND_MINIT			ZEND_MODULE_STARTUP_N
6628b6f848cSAndi Gutmans#define ZEND_MSHUTDOWN		ZEND_MODULE_SHUTDOWN_N
6638b6f848cSAndi Gutmans#define ZEND_RINIT			ZEND_MODULE_ACTIVATE_N
6648b6f848cSAndi Gutmans#define ZEND_RSHUTDOWN		ZEND_MODULE_DEACTIVATE_N
6658b6f848cSAndi Gutmans#define ZEND_MINFO			ZEND_MODULE_INFO_N
666bdeb220fSAnatol Belski#define ZEND_GINIT(module)		((void (*)(void*))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
667bdeb220fSAnatol Belski#define ZEND_GSHUTDOWN(module)	((void (*)(void*))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
6688b6f848cSAndi Gutmans
6698b6f848cSAndi Gutmans#define ZEND_MINIT_FUNCTION			ZEND_MODULE_STARTUP_D
670f5c59863SStanislav Malyshev#define ZEND_MSHUTDOWN_FUNCTION		ZEND_MODULE_SHUTDOWN_D
671f5c59863SStanislav Malyshev#define ZEND_RINIT_FUNCTION			ZEND_MODULE_ACTIVATE_D
672f5c59863SStanislav Malyshev#define ZEND_RSHUTDOWN_FUNCTION		ZEND_MODULE_DEACTIVATE_D
673f5c59863SStanislav Malyshev#define ZEND_MINFO_FUNCTION			ZEND_MODULE_INFO_D
674ada4e506SDmitry Stogov#define ZEND_GINIT_FUNCTION			ZEND_MODULE_GLOBALS_CTOR_D
675ada4e506SDmitry Stogov#define ZEND_GSHUTDOWN_FUNCTION		ZEND_MODULE_GLOBALS_DTOR_D
6768b6f848cSAndi Gutmans
67727f38798SDmitry Stogov/* Fast parameter parsing API */
67827f38798SDmitry Stogov
679d690014bSAndrea Faulds/* Fast ZPP is always enabled now; this define is left in for compatibility
680d690014bSAndrea Faulds * with any existing conditional compilation blocks.
68127f38798SDmitry Stogov */
68227f38798SDmitry Stogov#define FAST_ZPP 1
68327f38798SDmitry Stogov
68427f38798SDmitry Stogov#define Z_EXPECTED_TYPES(_) \
685ce1d69a1SGabriel Caruso	_(Z_EXPECTED_LONG,		"int") \
686fef879a2SGabriel Caruso	_(Z_EXPECTED_BOOL,		"bool") \
68727f38798SDmitry Stogov	_(Z_EXPECTED_STRING,	"string") \
68827f38798SDmitry Stogov	_(Z_EXPECTED_ARRAY,		"array") \
68927f38798SDmitry Stogov	_(Z_EXPECTED_FUNC,		"valid callback") \
69027f38798SDmitry Stogov	_(Z_EXPECTED_RESOURCE,	"resource") \
69127f38798SDmitry Stogov	_(Z_EXPECTED_PATH,		"a valid path") \
69227f38798SDmitry Stogov	_(Z_EXPECTED_OBJECT,	"object") \
693e5eb9530SAndrea Faulds	_(Z_EXPECTED_DOUBLE,	"float")
69427f38798SDmitry Stogov
69527f38798SDmitry Stogov#define Z_EXPECTED_TYPE_ENUM(id, str) id,
69627f38798SDmitry Stogov#define Z_EXPECTED_TYPE_STR(id, str)  str,
69727f38798SDmitry Stogov
69827f38798SDmitry Stogovtypedef enum _zend_expected_type {
69927f38798SDmitry Stogov	Z_EXPECTED_TYPES(Z_EXPECTED_TYPE_ENUM)
70027f38798SDmitry Stogov	Z_EXPECTED_LAST
70127f38798SDmitry Stogov} zend_expected_type;
70227f38798SDmitry Stogov
7037e329a82SDmitry StogovZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_error(void);
7047e329a82SDmitry StogovZEND_API ZEND_COLD int  ZEND_FASTCALL zend_wrong_parameters_none_exception(void);
7057e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int min_num_args, int max_num_args);
7067e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_exception(int min_num_args, int max_num_args);
7077e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error(int num, zend_expected_type expected_type, zval *arg);
7087e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_exception(int num, zend_expected_type expected_type, zval *arg);
7097e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error(int num, char *name, zval *arg);
7107e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_exception(int num, char *name, zval *arg);
7117e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int num, char *error);
7127e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_deprecated(int num, char *error);
7137e329a82SDmitry StogovZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_exception(int num, char *error);
71427f38798SDmitry Stogov
7150ae305e6SDmitry Stogov#define ZPP_ERROR_OK             0
7160ae305e6SDmitry Stogov#define ZPP_ERROR_FAILURE        1
7170ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CALLBACK 2
7180ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_CLASS    3
7190ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_ARG      4
7200ae305e6SDmitry Stogov#define ZPP_ERROR_WRONG_COUNT    5
7210ae305e6SDmitry Stogov
72227f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START_EX(flags, min_num_args, max_num_args) do { \
72335f9b90bSDmitry Stogov		const int _flags = (flags); \
72427f38798SDmitry Stogov		int _min_num_args = (min_num_args); \
72527f38798SDmitry Stogov		int _max_num_args = (max_num_args); \
72611384ba7SDmitry Stogov		int _num_args = EX_NUM_ARGS(); \
72727f38798SDmitry Stogov		int _i; \
7280ae305e6SDmitry Stogov		zval *_real_arg, *_arg = NULL; \
729e88e83d3SSara Golemon		zend_expected_type _expected_type = Z_EXPECTED_LONG; \
7300ae305e6SDmitry Stogov		char *_error = NULL; \
73127f38798SDmitry Stogov		zend_bool _dummy; \
7320ae305e6SDmitry Stogov		zend_bool _optional = 0; \
7330ae305e6SDmitry Stogov		int error_code = ZPP_ERROR_OK; \
73427f38798SDmitry Stogov		((void)_i); \
73527f38798SDmitry Stogov		((void)_real_arg); \
73627f38798SDmitry Stogov		((void)_arg); \
73727f38798SDmitry Stogov		((void)_expected_type); \
73827f38798SDmitry Stogov		((void)_error); \
73927f38798SDmitry Stogov		((void)_dummy); \
7400ae305e6SDmitry Stogov		((void)_optional); \
7410ae305e6SDmitry Stogov		\
7420ae305e6SDmitry Stogov		do { \
7430ae305e6SDmitry Stogov			if (UNEXPECTED(_num_args < _min_num_args) || \
7440ae305e6SDmitry Stogov			    (UNEXPECTED(_num_args > _max_num_args) && \
7450ae305e6SDmitry Stogov			     EXPECTED(_max_num_args >= 0))) { \
7460ae305e6SDmitry Stogov				if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
7477e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7487e329a82SDmitry Stogov						zend_wrong_parameters_count_exception(_min_num_args, _max_num_args); \
7497e329a82SDmitry Stogov					} else { \
7507e329a82SDmitry Stogov						zend_wrong_parameters_count_error(_min_num_args, _max_num_args); \
7517e329a82SDmitry Stogov					} \
7520ae305e6SDmitry Stogov				} \
7530ae305e6SDmitry Stogov				error_code = ZPP_ERROR_FAILURE; \
7540ae305e6SDmitry Stogov				break; \
75527f38798SDmitry Stogov			} \
7560ae305e6SDmitry Stogov			_i = 0; \
757bd9a2346SDmitry Stogov			_real_arg = ZEND_CALL_ARG(execute_data, 0);
75827f38798SDmitry Stogov
75927f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args) \
76027f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_START_EX(0, min_num_args, max_num_args)
76127f38798SDmitry Stogov
7627e329a82SDmitry Stogov#define ZEND_PARSE_PARAMETERS_NONE() do { \
7637e329a82SDmitry Stogov		if (UNEXPECTED(ZEND_NUM_ARGS() != 0)) { \
7647e329a82SDmitry Stogov			zend_wrong_parameters_none_error(); \
765ea7a3c32SDmitry Stogov			return; \
7667e329a82SDmitry Stogov		} \
7677e329a82SDmitry Stogov	} while (0)
76867be32ceSKalle Sommer Nielsen
76927f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END_EX(failure) \
7700ae305e6SDmitry Stogov		} while (0); \
7710ae305e6SDmitry Stogov		if (UNEXPECTED(error_code != ZPP_ERROR_OK)) { \
77227f38798SDmitry Stogov			if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
7730ae305e6SDmitry Stogov				if (error_code == ZPP_ERROR_WRONG_CALLBACK) { \
7747e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7757e329a82SDmitry Stogov						zend_wrong_callback_exception(_i, _error); \
7767e329a82SDmitry Stogov					} else { \
7777e329a82SDmitry Stogov						zend_wrong_callback_error(_i, _error); \
7787e329a82SDmitry Stogov					} \
7790ae305e6SDmitry Stogov				} else if (error_code == ZPP_ERROR_WRONG_CLASS) { \
7807e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7817e329a82SDmitry Stogov						zend_wrong_parameter_class_exception(_i, _error, _arg); \
7827e329a82SDmitry Stogov					} else { \
7837e329a82SDmitry Stogov						zend_wrong_parameter_class_error(_i, _error, _arg); \
7847e329a82SDmitry Stogov					} \
7850ae305e6SDmitry Stogov				} else if (error_code == ZPP_ERROR_WRONG_ARG) { \
7867e329a82SDmitry Stogov					if (_flags & ZEND_PARSE_PARAMS_THROW) { \
7877e329a82SDmitry Stogov						zend_wrong_parameter_type_exception(_i, _expected_type, _arg); \
7887e329a82SDmitry Stogov					} else { \
7897e329a82SDmitry Stogov						zend_wrong_parameter_type_error(_i, _expected_type, _arg); \
7907e329a82SDmitry Stogov					} \
7910ae305e6SDmitry Stogov				} \
79227f38798SDmitry Stogov			} \
79327f38798SDmitry Stogov			failure; \
79427f38798SDmitry Stogov		} \
79527f38798SDmitry Stogov	} while (0)
79627f38798SDmitry Stogov
79727f38798SDmitry Stogov#define ZEND_PARSE_PARAMETERS_END() \
79827f38798SDmitry Stogov	ZEND_PARSE_PARAMETERS_END_EX(return)
79927f38798SDmitry Stogov
800ace9fe53SDmitry Stogov#define Z_PARAM_PROLOGUE(deref, separate) \
8010ae305e6SDmitry Stogov	++_i; \
802a861019bSRemi Collet	ZEND_ASSERT(_i <= _min_num_args || _optional==1); \
803a861019bSRemi Collet	ZEND_ASSERT(_i >  _min_num_args || _optional==0); \
8040ae305e6SDmitry Stogov	if (_optional) { \
8050ae305e6SDmitry Stogov		if (UNEXPECTED(_i >_num_args)) break; \
8060ae305e6SDmitry Stogov	} \
80727f38798SDmitry Stogov	_real_arg++; \
80827f38798SDmitry Stogov	_arg = _real_arg; \
809ace9fe53SDmitry Stogov	if (deref) { \
810ace9fe53SDmitry Stogov		ZVAL_DEREF(_arg); \
811ace9fe53SDmitry Stogov	} \
81227f38798SDmitry Stogov	if (separate) { \
81327f38798SDmitry Stogov		SEPARATE_ZVAL_NOREF(_arg); \
81427f38798SDmitry Stogov	}
81527f38798SDmitry Stogov
81627f38798SDmitry Stogov/* old "|" */
8170ae305e6SDmitry Stogov#define Z_PARAM_OPTIONAL \
8180ae305e6SDmitry Stogov	_optional = 1;
81927f38798SDmitry Stogov
82027f38798SDmitry Stogov/* old "a" */
821ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_EX2(dest, check_null, deref, separate) \
822ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
82341e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 0))) { \
82427f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8250ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8260ae305e6SDmitry Stogov			break; \
8270ae305e6SDmitry Stogov		}
82827f38798SDmitry Stogov
829ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_EX(dest, check_null, separate) \
830ace9fe53SDmitry Stogov	Z_PARAM_ARRAY_EX2(dest, check_null, separate, separate)
831ace9fe53SDmitry Stogov
83227f38798SDmitry Stogov#define Z_PARAM_ARRAY(dest) \
83327f38798SDmitry Stogov	Z_PARAM_ARRAY_EX(dest, 0, 0)
83427f38798SDmitry Stogov
83527f38798SDmitry Stogov/* old "A" */
836ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, deref, separate) \
837ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
83841e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_array(_arg, &dest, check_null, 1))) { \
83927f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
8400ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8410ae305e6SDmitry Stogov			break; \
8420ae305e6SDmitry Stogov		}
84327f38798SDmitry Stogov
844ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_OR_OBJECT_EX(dest, check_null, separate) \
845ace9fe53SDmitry Stogov	Z_PARAM_ARRAY_OR_OBJECT_EX2(dest, check_null, separate, separate)
846ace9fe53SDmitry Stogov
847a595b0f7SThomas Punt#define Z_PARAM_ARRAY_OR_OBJECT(dest) \
84827f38798SDmitry Stogov	Z_PARAM_ARRAY_OR_OBJECT_EX(dest, 0, 0)
84927f38798SDmitry Stogov
85027f38798SDmitry Stogov/* old "b" */
851ace9fe53SDmitry Stogov#define Z_PARAM_BOOL_EX2(dest, is_null, check_null, deref, separate) \
852ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
85335f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_bool(_arg, &dest, &is_null, check_null))) { \
85427f38798SDmitry Stogov			_expected_type = Z_EXPECTED_BOOL; \
8550ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8560ae305e6SDmitry Stogov			break; \
8570ae305e6SDmitry Stogov		}
85827f38798SDmitry Stogov
859ace9fe53SDmitry Stogov#define Z_PARAM_BOOL_EX(dest, is_null, check_null, separate) \
860ace9fe53SDmitry Stogov	Z_PARAM_BOOL_EX2(dest, is_null, check_null, separate, separate)
861ace9fe53SDmitry Stogov
86227f38798SDmitry Stogov#define Z_PARAM_BOOL(dest) \
86327f38798SDmitry Stogov	Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)
86427f38798SDmitry Stogov
86527f38798SDmitry Stogov/* old "C" */
866ace9fe53SDmitry Stogov#define Z_PARAM_CLASS_EX2(dest, check_null, deref, separate) \
867ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
86835f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_class(_arg, &dest, _i, check_null))) { \
8690ae305e6SDmitry Stogov			error_code = ZPP_ERROR_FAILURE; \
8700ae305e6SDmitry Stogov			break; \
8710ae305e6SDmitry Stogov		}
87227f38798SDmitry Stogov
873ace9fe53SDmitry Stogov#define Z_PARAM_CLASS_EX(dest, check_null, separate) \
874ace9fe53SDmitry Stogov	Z_PARAM_CLASS_EX2(dest, check_null, separate, separate)
875ace9fe53SDmitry Stogov
87627f38798SDmitry Stogov#define Z_PARAM_CLASS(dest) \
87727f38798SDmitry Stogov	Z_PARAM_CLASS_EX(dest, 0, 0)
87827f38798SDmitry Stogov
87927f38798SDmitry Stogov/* old "d" */
880ace9fe53SDmitry Stogov#define Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, deref, separate) \
881ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
88235f9b90bSDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_double(_arg, &dest, &is_null, check_null))) { \
88327f38798SDmitry Stogov			_expected_type = Z_EXPECTED_DOUBLE; \
8840ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
8850ae305e6SDmitry Stogov			break; \
8860ae305e6SDmitry Stogov		}
88727f38798SDmitry Stogov
888ace9fe53SDmitry Stogov#define Z_PARAM_DOUBLE_EX(dest, is_null, check_null, separate) \
889ace9fe53SDmitry Stogov	Z_PARAM_DOUBLE_EX2(dest, is_null, check_null, separate, separate)
890ace9fe53SDmitry Stogov
89127f38798SDmitry Stogov#define Z_PARAM_DOUBLE(dest) \
89227f38798SDmitry Stogov	Z_PARAM_DOUBLE_EX(dest, _dummy, 0, 0)
89327f38798SDmitry Stogov
89427f38798SDmitry Stogov/* old "f" */
895ace9fe53SDmitry Stogov#define Z_PARAM_FUNC_EX2(dest_fci, dest_fcc, check_null, deref, separate) \
896ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
89741e3fdbaSAndrea Faulds		if (UNEXPECTED(!zend_parse_arg_func(_arg, &dest_fci, &dest_fcc, check_null, &_error))) { \
89827f38798SDmitry Stogov			if (!_error) { \
89927f38798SDmitry Stogov				_expected_type = Z_EXPECTED_FUNC; \
9000ae305e6SDmitry Stogov				error_code = ZPP_ERROR_WRONG_ARG; \
9010ae305e6SDmitry Stogov				break; \
90227f38798SDmitry Stogov			} else { \
9030ae305e6SDmitry Stogov				error_code = ZPP_ERROR_WRONG_CALLBACK; \
9040ae305e6SDmitry Stogov				break; \
90527f38798SDmitry Stogov			} \
9060ae305e6SDmitry Stogov		} else if (UNEXPECTED(_error != NULL)) { \
9077e329a82SDmitry Stogov			zend_wrong_callback_deprecated(_i, _error); \
9080ae305e6SDmitry Stogov		}
90927f38798SDmitry Stogov
910ace9fe53SDmitry Stogov#define Z_PARAM_FUNC_EX(dest_fci, dest_fcc, check_null, separate) \
911ace9fe53SDmitry Stogov	Z_PARAM_FUNC_EX2(dest_fci, dest_fcc, check_null, separate, separate)
912ace9fe53SDmitry Stogov
91327f38798SDmitry Stogov#define Z_PARAM_FUNC(dest_fci, dest_fcc) \
91427f38798SDmitry Stogov	Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
91527f38798SDmitry Stogov
91627f38798SDmitry Stogov/* old "h" */
917ace9fe53SDmitry Stogov#define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
918ace9fe53SDmitry Stogov		Z_PARAM_PROLOGUE(deref, separate); \
91942184397SDmitry Stogov		if (UNEXPECTED(!zend_parse_arg_array_ht(_arg, &dest, check_null, 0, separate))) { \
92027f38798SDmitry Stogov			_expected_type = Z_EXPECTED_ARRAY; \
9210ae305e6SDmitry Stogov			error_code = ZPP_ERROR_WRONG_ARG; \
9220ae305e6SDmitry Stogov			break; \
923