zend_API.h 58 KB

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