zend_API.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@zend.com> |
  16. | Zeev Suraski <zeev@zend.com> |
  17. | Andrei Zmievski <andrei@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id$ */
  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. void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
  32. const struct _zend_arg_info *arg_info;
  33. zend_uint num_args;
  34. zend_uint flags;
  35. } zend_function_entry;
  36. typedef struct _zend_fcall_info {
  37. size_t size;
  38. HashTable *function_table;
  39. zval *function_name;
  40. HashTable *symbol_table;
  41. zval **retval_ptr_ptr;
  42. zend_uint param_count;
  43. zval ***params;
  44. zval *object_ptr;
  45. zend_bool no_separation;
  46. } zend_fcall_info;
  47. typedef struct _zend_fcall_info_cache {
  48. zend_bool initialized;
  49. zend_function *function_handler;
  50. zend_class_entry *calling_scope;
  51. zend_class_entry *called_scope;
  52. zval *object_ptr;
  53. } zend_fcall_info_cache;
  54. #define ZEND_NS_NAME(ns, name) ns "\\" name
  55. #define ZEND_FN(name) zif_##name
  56. #define ZEND_MN(name) zim_##name
  57. #define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
  58. #define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
  59. #define ZEND_METHOD(classname, name) ZEND_NAMED_FUNCTION(ZEND_MN(classname##_##name))
  60. #define ZEND_FENTRY(zend_name, name, arg_info, flags) { #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
  61. #define ZEND_RAW_FENTRY(zend_name, name, arg_info, flags) { zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },
  62. #define ZEND_RAW_NAMED_FE(zend_name, name, arg_info) ZEND_RAW_FENTRY(#zend_name, name, arg_info, 0)
  63. #define ZEND_NAMED_FE(zend_name, name, arg_info) ZEND_FENTRY(zend_name, name, arg_info, 0)
  64. #define ZEND_FE(name, arg_info) ZEND_FENTRY(name, ZEND_FN(name), arg_info, 0)
  65. #define ZEND_DEP_FE(name, arg_info) ZEND_FENTRY(name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
  66. #define ZEND_FALIAS(name, alias, arg_info) ZEND_FENTRY(name, ZEND_FN(alias), arg_info, 0)
  67. #define ZEND_DEP_FALIAS(name, alias, arg_info) ZEND_FENTRY(name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
  68. #define ZEND_NAMED_ME(zend_name, name, arg_info, flags) ZEND_FENTRY(zend_name, name, arg_info, flags)
  69. #define ZEND_ME(classname, name, arg_info, flags) ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)
  70. #define ZEND_ABSTRACT_ME(classname, name, arg_info) ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)
  71. #define ZEND_MALIAS(classname, name, alias, arg_info, flags) \
  72. ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)
  73. #define ZEND_ME_MAPPING(name, func_name, arg_types, flags) ZEND_NAMED_ME(name, ZEND_FN(func_name), arg_types, flags)
  74. #define ZEND_NS_FENTRY(ns, zend_name, name, arg_info, flags) ZEND_RAW_FENTRY(ZEND_NS_NAME(ns, #zend_name), name, arg_info, flags)
  75. #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)
  76. #define ZEND_NS_RAW_NAMED_FE(ns, zend_name, name, arg_info) ZEND_NS_RAW_FENTRY(ns, #zend_name, name, arg_info, 0)
  77. #define ZEND_NS_NAMED_FE(ns, zend_name, name, arg_info) ZEND_NS_FENTRY(ns, zend_name, name, arg_info, 0)
  78. #define ZEND_NS_FE(ns, name, arg_info) ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, 0)
  79. #define ZEND_NS_DEP_FE(ns, name, arg_info) ZEND_NS_FENTRY(ns, name, ZEND_FN(name), arg_info, ZEND_ACC_DEPRECATED)
  80. #define ZEND_NS_FALIAS(ns, name, alias, arg_info) ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, 0)
  81. #define ZEND_NS_DEP_FALIAS(ns, name, alias, arg_info) ZEND_NS_FENTRY(ns, name, ZEND_FN(alias), arg_info, ZEND_ACC_DEPRECATED)
  82. #define ZEND_FE_END { NULL, NULL, NULL, 0, 0 }
  83. #define ZEND_ARG_INFO(pass_by_ref, name) { #name, sizeof(#name)-1, NULL, 0, 0, pass_by_ref, 0, 0 },
  84. #define ZEND_ARG_PASS_INFO(pass_by_ref) { NULL, 0, NULL, 0, 0, pass_by_ref, 0, 0 },
  85. #define ZEND_ARG_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, sizeof(#name)-1, #classname, sizeof(#classname)-1, IS_OBJECT, pass_by_ref, allow_null, 0 },
  86. #define ZEND_ARG_ARRAY_INFO(pass_by_ref, name, allow_null) { #name, sizeof(#name)-1, NULL, 0, IS_ARRAY, pass_by_ref, allow_null, 0 },
  87. #define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, sizeof(#name)-1, NULL, 0, type_hint, pass_by_ref, allow_null, 0 },
  88. #define ZEND_ARG_VARIADIC_INFO(pass_by_ref, name) { #name, sizeof(#name)-1, NULL, 0, 0, pass_by_ref, 0, 1 },
  89. #define ZEND_BEGIN_ARG_INFO_EX(name, _unused, return_reference, required_num_args) \
  90. static const zend_arg_info name[] = { \
  91. { NULL, 0, NULL, required_num_args, 0, return_reference, 0, 0 },
  92. #define ZEND_BEGIN_ARG_INFO(name, _unused) \
  93. ZEND_BEGIN_ARG_INFO_EX(name, 0, ZEND_RETURN_VALUE, -1)
  94. #define ZEND_END_ARG_INFO() };
  95. /* Name macros */
  96. #define ZEND_MODULE_STARTUP_N(module) zm_startup_##module
  97. #define ZEND_MODULE_SHUTDOWN_N(module) zm_shutdown_##module
  98. #define ZEND_MODULE_ACTIVATE_N(module) zm_activate_##module
  99. #define ZEND_MODULE_DEACTIVATE_N(module) zm_deactivate_##module
  100. #define ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module) zm_post_zend_deactivate_##module
  101. #define ZEND_MODULE_INFO_N(module) zm_info_##module
  102. #define ZEND_MODULE_GLOBALS_CTOR_N(module) zm_globals_ctor_##module
  103. #define ZEND_MODULE_GLOBALS_DTOR_N(module) zm_globals_dtor_##module
  104. /* Declaration macros */
  105. #define ZEND_MODULE_STARTUP_D(module) int ZEND_MODULE_STARTUP_N(module)(INIT_FUNC_ARGS)
  106. #define ZEND_MODULE_SHUTDOWN_D(module) int ZEND_MODULE_SHUTDOWN_N(module)(SHUTDOWN_FUNC_ARGS)
  107. #define ZEND_MODULE_ACTIVATE_D(module) int ZEND_MODULE_ACTIVATE_N(module)(INIT_FUNC_ARGS)
  108. #define ZEND_MODULE_DEACTIVATE_D(module) int ZEND_MODULE_DEACTIVATE_N(module)(SHUTDOWN_FUNC_ARGS)
  109. #define ZEND_MODULE_POST_ZEND_DEACTIVATE_D(module) int ZEND_MODULE_POST_ZEND_DEACTIVATE_N(module)(void)
  110. #define ZEND_MODULE_INFO_D(module) void ZEND_MODULE_INFO_N(module)(ZEND_MODULE_INFO_FUNC_ARGS)
  111. #define ZEND_MODULE_GLOBALS_CTOR_D(module) void ZEND_MODULE_GLOBALS_CTOR_N(module)(zend_##module##_globals *module##_globals TSRMLS_DC)
  112. #define ZEND_MODULE_GLOBALS_DTOR_D(module) void ZEND_MODULE_GLOBALS_DTOR_N(module)(zend_##module##_globals *module##_globals TSRMLS_DC)
  113. #define ZEND_GET_MODULE(name) \
  114. BEGIN_EXTERN_C()\
  115. ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }\
  116. END_EXTERN_C()
  117. #define ZEND_BEGIN_MODULE_GLOBALS(module_name) \
  118. typedef struct _zend_##module_name##_globals {
  119. #define ZEND_END_MODULE_GLOBALS(module_name) \
  120. } zend_##module_name##_globals;
  121. #ifdef ZTS
  122. #define ZEND_DECLARE_MODULE_GLOBALS(module_name) \
  123. ts_rsrc_id module_name##_globals_id;
  124. #define ZEND_EXTERN_MODULE_GLOBALS(module_name) \
  125. extern ts_rsrc_id module_name##_globals_id;
  126. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor) \
  127. ts_allocate_id(&module_name##_globals_id, sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
  128. #else
  129. #define ZEND_DECLARE_MODULE_GLOBALS(module_name) \
  130. zend_##module_name##_globals module_name##_globals;
  131. #define ZEND_EXTERN_MODULE_GLOBALS(module_name) \
  132. extern zend_##module_name##_globals module_name##_globals;
  133. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor) \
  134. globals_ctor(&module_name##_globals);
  135. #endif
  136. #define INIT_CLASS_ENTRY(class_container, class_name, functions) \
  137. INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, NULL, NULL, NULL)
  138. #define INIT_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions) \
  139. INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, NULL, NULL, NULL, NULL, NULL)
  140. #define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, class_name_len, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
  141. { \
  142. const char *cl_name = class_name; \
  143. int _len = class_name_len; \
  144. class_container.name = zend_new_interned_string(cl_name, _len+1, 0 TSRMLS_CC); \
  145. if (class_container.name == cl_name) { \
  146. class_container.name = zend_strndup(cl_name, _len); \
  147. } \
  148. class_container.name_length = _len; \
  149. INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
  150. }
  151. #define INIT_CLASS_ENTRY_INIT_METHODS(class_container, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
  152. { \
  153. class_container.constructor = NULL; \
  154. class_container.destructor = NULL; \
  155. class_container.clone = NULL; \
  156. class_container.serialize = NULL; \
  157. class_container.unserialize = NULL; \
  158. class_container.create_object = NULL; \
  159. class_container.interface_gets_implemented = NULL; \
  160. class_container.get_static_method = NULL; \
  161. class_container.__call = handle_fcall; \
  162. class_container.__callstatic = NULL; \
  163. class_container.__tostring = NULL; \
  164. class_container.__get = handle_propget; \
  165. class_container.__set = handle_propset; \
  166. class_container.__unset = handle_propunset; \
  167. class_container.__isset = handle_propisset; \
  168. class_container.__debugInfo = NULL; \
  169. class_container.serialize_func = NULL; \
  170. class_container.unserialize_func = NULL; \
  171. class_container.serialize = NULL; \
  172. class_container.unserialize = NULL; \
  173. class_container.parent = NULL; \
  174. class_container.num_interfaces = 0; \
  175. class_container.traits = NULL; \
  176. class_container.num_traits = 0; \
  177. class_container.trait_aliases = NULL; \
  178. class_container.trait_precedences = NULL; \
  179. class_container.interfaces = NULL; \
  180. class_container.get_iterator = NULL; \
  181. class_container.iterator_funcs.funcs = NULL; \
  182. class_container.info.internal.module = NULL; \
  183. class_container.info.internal.builtin_functions = functions; \
  184. }
  185. #define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
  186. INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, sizeof(class_name)-1, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL)
  187. #define INIT_NS_CLASS_ENTRY(class_container, ns, class_name, functions) \
  188. INIT_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions)
  189. #define INIT_OVERLOADED_NS_CLASS_ENTRY_EX(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
  190. INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, ZEND_NS_NAME(ns, class_name), sizeof(ZEND_NS_NAME(ns, class_name))-1, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset)
  191. #define INIT_OVERLOADED_NS_CLASS_ENTRY(class_container, ns, class_name, functions, handle_fcall, handle_propget, handle_propset) \
  192. INIT_OVERLOADED_CLASS_ENTRY(class_container, ZEND_NS_NAME(ns, class_name), functions, handle_fcall, handle_propget, handle_propset)
  193. #ifdef ZTS
  194. # 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])
  195. #else
  196. # define CE_STATIC_MEMBERS(ce) ((ce)->static_members_table)
  197. #endif
  198. #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
  199. ZEND_API int zend_next_free_module(void);
  200. BEGIN_EXTERN_C()
  201. ZEND_API int zend_get_parameters(int ht, int param_count, ...);
  202. ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC);
  203. ZEND_API ZEND_ATTRIBUTE_DEPRECATED int zend_get_parameters_ex(int param_count, ...);
  204. ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC);
  205. /* internal function to efficiently copy parameters when executing __call() */
  206. ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array TSRMLS_DC);
  207. #define zend_get_parameters_array(ht, param_count, argument_array) \
  208. _zend_get_parameters_array(ht, param_count, argument_array TSRMLS_CC)
  209. #define zend_get_parameters_array_ex(param_count, argument_array) \
  210. _zend_get_parameters_array_ex(param_count, argument_array TSRMLS_CC)
  211. #define zend_parse_parameters_none() \
  212. zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
  213. /* Parameter parsing API -- andrei */
  214. #define ZEND_PARSE_PARAMS_QUIET 1<<1
  215. ZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, const char *type_spec, ...);
  216. ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, const char *type_spec, ...);
  217. ZEND_API char *zend_zval_type_name(const zval *arg);
  218. ZEND_API int zend_parse_method_parameters(int num_args TSRMLS_DC, zval *this_ptr, const char *type_spec, ...);
  219. ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC, zval *this_ptr, const char *type_spec, ...);
  220. ZEND_API int zend_parse_parameter(int flags, int arg_num TSRMLS_DC, zval **arg, const char *spec, ...);
  221. /* End of parameter parsing API -- andrei */
  222. ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC);
  223. ZEND_API void zend_unregister_functions(const zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC);
  224. ZEND_API int zend_startup_module(zend_module_entry *module_entry);
  225. ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *module_entry TSRMLS_DC);
  226. ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TSRMLS_DC);
  227. ZEND_API int zend_startup_module_ex(zend_module_entry *module TSRMLS_DC);
  228. ZEND_API int zend_startup_modules(TSRMLS_D);
  229. ZEND_API void zend_collect_module_handlers(TSRMLS_D);
  230. ZEND_API void zend_destroy_modules(void);
  231. ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type TSRMLS_DC);
  232. ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC);
  233. ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC);
  234. ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry TSRMLS_DC);
  235. ZEND_API void zend_class_implements(zend_class_entry *class_entry TSRMLS_DC, int num_interfaces, ...);
  236. ZEND_API int zend_register_class_alias_ex(const char *name, int name_len, zend_class_entry *ce TSRMLS_DC);
  237. #define zend_register_class_alias(name, ce) \
  238. zend_register_class_alias_ex(name, sizeof(name)-1, ce TSRMLS_CC)
  239. #define zend_register_ns_class_alias(ns, name, ce) \
  240. zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce TSRMLS_CC)
  241. ZEND_API int zend_disable_function(char *function_name, uint function_name_length TSRMLS_DC);
  242. ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_DC);
  243. ZEND_API void zend_wrong_param_count(TSRMLS_D);
  244. #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
  245. #define IS_CALLABLE_CHECK_NO_ACCESS (1<<1)
  246. #define IS_CALLABLE_CHECK_IS_STATIC (1<<2)
  247. #define IS_CALLABLE_CHECK_SILENT (1<<3)
  248. #define IS_CALLABLE_STRICT (IS_CALLABLE_CHECK_IS_STATIC)
  249. ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint check_flags, char **callable_name, int *callable_name_len, zend_fcall_info_cache *fcc, char **error TSRMLS_DC);
  250. ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, char **callable_name TSRMLS_DC);
  251. ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC);
  252. ZEND_API const char *zend_get_module_version(const char *module_name);
  253. ZEND_API int zend_get_module_started(const char *module_name);
  254. ZEND_API int zend_declare_property(zend_class_entry *ce, const char *name, int name_length, zval *property, int access_type TSRMLS_DC);
  255. ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, int name_length, zval *property, int access_type, const char *doc_comment, int doc_comment_len TSRMLS_DC);
  256. ZEND_API int zend_declare_property_null(zend_class_entry *ce, const char *name, int name_length, int access_type TSRMLS_DC);
  257. ZEND_API int zend_declare_property_bool(zend_class_entry *ce, const char *name, int name_length, long value, int access_type TSRMLS_DC);
  258. ZEND_API int zend_declare_property_long(zend_class_entry *ce, const char *name, int name_length, long value, int access_type TSRMLS_DC);
  259. ZEND_API int zend_declare_property_double(zend_class_entry *ce, const char *name, int name_length, double value, int access_type TSRMLS_DC);
  260. ZEND_API int zend_declare_property_string(zend_class_entry *ce, const char *name, int name_length, const char *value, int access_type TSRMLS_DC);
  261. ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, const char *name, int name_length, const char *value, int value_len, int access_type TSRMLS_DC);
  262. ZEND_API int zend_declare_class_constant(zend_class_entry *ce, const char *name, size_t name_length, zval *value TSRMLS_DC);
  263. ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, const char *name, size_t name_length TSRMLS_DC);
  264. ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, const char *name, size_t name_length, long value TSRMLS_DC);
  265. ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, const char *name, size_t name_length, zend_bool value TSRMLS_DC);
  266. ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, const char *name, size_t name_length, double value TSRMLS_DC);
  267. 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 TSRMLS_DC);
  268. ZEND_API int zend_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value TSRMLS_DC);
  269. ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC);
  270. ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, const char *name, int name_length, zval *value TSRMLS_DC);
  271. ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, const char *name, int name_length TSRMLS_DC);
  272. ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, int name_length, long value TSRMLS_DC);
  273. ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, const char *name, int name_length, long value TSRMLS_DC);
  274. ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object, const char *name, int name_length, double value TSRMLS_DC);
  275. ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, int name_length, const char *value TSRMLS_DC);
  276. ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, int name_length, const char *value, int value_length TSRMLS_DC);
  277. ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, int name_length TSRMLS_DC);
  278. ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, int name_length, zval *value TSRMLS_DC);
  279. ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, int name_length TSRMLS_DC);
  280. ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, int name_length, long value TSRMLS_DC);
  281. ZEND_API int zend_update_static_property_long(zend_class_entry *scope, const char *name, int name_length, long value TSRMLS_DC);
  282. ZEND_API int zend_update_static_property_double(zend_class_entry *scope, const char *name, int name_length, double value TSRMLS_DC);
  283. ZEND_API int zend_update_static_property_string(zend_class_entry *scope, const char *name, int name_length, const char *value TSRMLS_DC);
  284. ZEND_API int zend_update_static_property_stringl(zend_class_entry *scope, const char *name, int name_length, const char *value, int value_length TSRMLS_DC);
  285. ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, const char *name, int name_length, zend_bool silent TSRMLS_DC);
  286. ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *name, int name_length, zend_bool silent TSRMLS_DC);
  287. ZEND_API zend_class_entry *zend_get_class_entry(const zval *zobject TSRMLS_DC);
  288. ZEND_API int zend_get_object_classname(const zval *object, const char **class_name, zend_uint *class_name_len TSRMLS_DC);
  289. ZEND_API char *zend_get_type_by_const(int type);
  290. #define getThis() (this_ptr)
  291. #define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
  292. #define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
  293. #define ARG_COUNT(dummy) (ht)
  294. #define ZEND_NUM_ARGS() (ht)
  295. #define ZEND_WRONG_PARAM_COUNT() { zend_wrong_param_count(TSRMLS_C); return; }
  296. #define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret) { zend_wrong_param_count(TSRMLS_C); return ret; }
  297. #ifndef ZEND_WIN32
  298. #define DLEXPORT
  299. #endif
  300. #define array_init(arg) _array_init((arg), 0 ZEND_FILE_LINE_CC)
  301. #define array_init_size(arg, size) _array_init((arg), (size) ZEND_FILE_LINE_CC)
  302. #define object_init(arg) _object_init((arg) ZEND_FILE_LINE_CC TSRMLS_CC)
  303. #define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC TSRMLS_CC)
  304. #define object_and_properties_init(arg, ce, properties) _object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC TSRMLS_CC)
  305. ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC);
  306. ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC);
  307. ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC TSRMLS_DC);
  308. ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC);
  309. ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
  310. ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC);
  311. /* no longer supported */
  312. ZEND_API int add_assoc_function(zval *arg, const char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
  313. ZEND_API int add_assoc_long_ex(zval *arg, const char *key, uint key_len, long n);
  314. ZEND_API int add_assoc_null_ex(zval *arg, const char *key, uint key_len);
  315. ZEND_API int add_assoc_bool_ex(zval *arg, const char *key, uint key_len, int b);
  316. ZEND_API int add_assoc_resource_ex(zval *arg, const char *key, uint key_len, int r);
  317. ZEND_API int add_assoc_double_ex(zval *arg, const char *key, uint key_len, double d);
  318. ZEND_API int add_assoc_string_ex(zval *arg, const char *key, uint key_len, char *str, int duplicate);
  319. ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, uint key_len, char *str, uint length, int duplicate);
  320. ZEND_API int add_assoc_zval_ex(zval *arg, const char *key, uint key_len, zval *value);
  321. #define add_assoc_long(__arg, __key, __n) add_assoc_long_ex(__arg, __key, strlen(__key)+1, __n)
  322. #define add_assoc_null(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
  323. #define add_assoc_bool(__arg, __key, __b) add_assoc_bool_ex(__arg, __key, strlen(__key)+1, __b)
  324. #define add_assoc_resource(__arg, __key, __r) add_assoc_resource_ex(__arg, __key, strlen(__key)+1, __r)
  325. #define add_assoc_double(__arg, __key, __d) add_assoc_double_ex(__arg, __key, strlen(__key)+1, __d)
  326. #define add_assoc_string(__arg, __key, __str, __duplicate) add_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate)
  327. #define add_assoc_stringl(__arg, __key, __str, __length, __duplicate) add_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate)
  328. #define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key)+1, __value)
  329. /* unset() functions are only suported for legacy modules and null() functions should be used */
  330. #define add_assoc_unset(__arg, __key) add_assoc_null_ex(__arg, __key, strlen(__key) + 1)
  331. #define add_index_unset(__arg, __key) add_index_null(__arg, __key)
  332. #define add_next_index_unset(__arg) add_next_index_null(__arg)
  333. #define add_property_unset(__arg, __key) add_property_null(__arg, __key)
  334. ZEND_API int add_index_long(zval *arg, ulong idx, long n);
  335. ZEND_API int add_index_null(zval *arg, ulong idx);
  336. ZEND_API int add_index_bool(zval *arg, ulong idx, int b);
  337. ZEND_API int add_index_resource(zval *arg, ulong idx, int r);
  338. ZEND_API int add_index_double(zval *arg, ulong idx, double d);
  339. ZEND_API int add_index_string(zval *arg, ulong idx, const char *str, int duplicate);
  340. ZEND_API int add_index_stringl(zval *arg, ulong idx, const char *str, uint length, int duplicate);
  341. ZEND_API int add_index_zval(zval *arg, ulong index, zval *value);
  342. ZEND_API int add_next_index_long(zval *arg, long n);
  343. ZEND_API int add_next_index_null(zval *arg);
  344. ZEND_API int add_next_index_bool(zval *arg, int b);
  345. ZEND_API int add_next_index_resource(zval *arg, int r);
  346. ZEND_API int add_next_index_double(zval *arg, double d);
  347. ZEND_API int add_next_index_string(zval *arg, const char *str, int duplicate);
  348. ZEND_API int add_next_index_stringl(zval *arg, const char *str, uint length, int duplicate);
  349. ZEND_API int add_next_index_zval(zval *arg, zval *value);
  350. ZEND_API int add_get_assoc_string_ex(zval *arg, const char *key, uint key_len, const char *str, void **dest, int duplicate);
  351. ZEND_API int add_get_assoc_stringl_ex(zval *arg, const char *key, uint key_len, const char *str, uint length, void **dest, int duplicate);
  352. #define add_get_assoc_string(__arg, __key, __str, __dest, __duplicate) add_get_assoc_string_ex(__arg, __key, strlen(__key)+1, __str, __dest, __duplicate)
  353. #define add_get_assoc_stringl(__arg, __key, __str, __length, __dest, __duplicate) add_get_assoc_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __dest, __duplicate)
  354. ZEND_API int add_get_index_long(zval *arg, ulong idx, long l, void **dest);
  355. ZEND_API int add_get_index_double(zval *arg, ulong idx, double d, void **dest);
  356. ZEND_API int add_get_index_string(zval *arg, ulong idx, const char *str, void **dest, int duplicate);
  357. ZEND_API int add_get_index_stringl(zval *arg, ulong idx, const char *str, uint length, void **dest, int duplicate);
  358. ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value);
  359. ZEND_API int add_property_long_ex(zval *arg, const char *key, uint key_len, long l TSRMLS_DC);
  360. ZEND_API int add_property_null_ex(zval *arg, const char *key, uint key_len TSRMLS_DC);
  361. ZEND_API int add_property_bool_ex(zval *arg, const char *key, uint key_len, int b TSRMLS_DC);
  362. ZEND_API int add_property_resource_ex(zval *arg, const char *key, uint key_len, long r TSRMLS_DC);
  363. ZEND_API int add_property_double_ex(zval *arg, const char *key, uint key_len, double d TSRMLS_DC);
  364. ZEND_API int add_property_string_ex(zval *arg, const char *key, uint key_len, const char *str, int duplicate TSRMLS_DC);
  365. ZEND_API int add_property_stringl_ex(zval *arg, const char *key, uint key_len, const char *str, uint length, int duplicate TSRMLS_DC);
  366. ZEND_API int add_property_zval_ex(zval *arg, const char *key, uint key_len, zval *value TSRMLS_DC);
  367. #define add_property_long(__arg, __key, __n) add_property_long_ex(__arg, __key, strlen(__key)+1, __n TSRMLS_CC)
  368. #define add_property_null(__arg, __key) add_property_null_ex(__arg, __key, strlen(__key) + 1 TSRMLS_CC)
  369. #define add_property_bool(__arg, __key, __b) add_property_bool_ex(__arg, __key, strlen(__key)+1, __b TSRMLS_CC)
  370. #define add_property_resource(__arg, __key, __r) add_property_resource_ex(__arg, __key, strlen(__key)+1, __r TSRMLS_CC)
  371. #define add_property_double(__arg, __key, __d) add_property_double_ex(__arg, __key, strlen(__key)+1, __d TSRMLS_CC)
  372. #define add_property_string(__arg, __key, __str, __duplicate) add_property_string_ex(__arg, __key, strlen(__key)+1, __str, __duplicate TSRMLS_CC)
  373. #define add_property_stringl(__arg, __key, __str, __length, __duplicate) add_property_stringl_ex(__arg, __key, strlen(__key)+1, __str, __length, __duplicate TSRMLS_CC)
  374. #define add_property_zval(__arg, __key, __value) add_property_zval_ex(__arg, __key, strlen(__key)+1, __value TSRMLS_CC)
  375. ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC);
  376. ZEND_API int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *function_name, zval **retval_ptr_ptr, zend_uint param_count, zval **params[], int no_separation, HashTable *symbol_table TSRMLS_DC);
  377. ZEND_API extern const zend_fcall_info empty_fcall_info;
  378. ZEND_API extern const zend_fcall_info_cache empty_fcall_info_cache;
  379. /** Build zend_call_info/cache from a zval*
  380. *
  381. * Caller is responsible to provide a return value, otherwise the we will crash.
  382. * fci->retval_ptr_ptr = NULL;
  383. * In order to pass parameters the following members need to be set:
  384. * fci->param_count = 0;
  385. * fci->params = NULL;
  386. * The callable_name argument may be NULL.
  387. * Set check_flags to IS_CALLABLE_STRICT for every new usage!
  388. */
  389. ZEND_API int zend_fcall_info_init(zval *callable, uint check_flags, zend_fcall_info *fci, zend_fcall_info_cache *fcc, char **callable_name, char **error TSRMLS_DC);
  390. /** Clear arguments connected with zend_fcall_info *fci
  391. * If free_mem is not zero then the params array gets free'd as well
  392. */
  393. ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem);
  394. /** Save current arguments from zend_fcall_info *fci
  395. * params array will be set to NULL
  396. */
  397. ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval ****params);
  398. /** Free arguments connected with zend_fcall_info *fci andset back saved ones.
  399. */
  400. ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval ***params);
  401. /** Set or clear the arguments in the zend_call_info struct taking care of
  402. * refcount. If args is NULL and arguments are set then those are cleared.
  403. */
  404. ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC);
  405. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  406. * If argc is 0 the arguments which are set will be cleared, else pass
  407. * a variable amount of zval** arguments.
  408. */
  409. ZEND_API int zend_fcall_info_argp(zend_fcall_info *fci TSRMLS_DC, int argc, zval ***argv);
  410. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  411. * If argc is 0 the arguments which are set will be cleared, else pass
  412. * a variable amount of zval** arguments.
  413. */
  414. ZEND_API int zend_fcall_info_argv(zend_fcall_info *fci TSRMLS_DC, int argc, va_list *argv);
  415. /** Set arguments in the zend_fcall_info struct taking care of refcount.
  416. * If argc is 0 the arguments which are set will be cleared, else pass
  417. * a variable amount of zval** arguments.
  418. */
  419. ZEND_API int zend_fcall_info_argn(zend_fcall_info *fci TSRMLS_DC, int argc, ...);
  420. /** Call a function using information created by zend_fcall_info_init()/args().
  421. * If args is given then those replace the argument info in fci is temporarily.
  422. */
  423. ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *fcc, zval **retval, zval *args TSRMLS_DC);
  424. ZEND_API int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC);
  425. ZEND_API int zend_set_hash_symbol(zval *symbol, const char *name, int name_length, zend_bool is_ref, int num_symbol_tables, ...);
  426. ZEND_API void zend_delete_variable(zend_execute_data *ex, HashTable *ht, const char *name, int name_len, ulong hash_value TSRMLS_DC);
  427. ZEND_API int zend_delete_global_variable(const char *name, int name_len TSRMLS_DC);
  428. ZEND_API int zend_delete_global_variable_ex(const char *name, int name_len, ulong hash_value TSRMLS_DC);
  429. ZEND_API void zend_reset_all_cv(HashTable *symbol_table TSRMLS_DC);
  430. ZEND_API void zend_rebuild_symbol_table(TSRMLS_D);
  431. ZEND_API const char* zend_find_alias_name(zend_class_entry *ce, const char *name, zend_uint len);
  432. ZEND_API const char* zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
  433. #define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
  434. ZEND_API ZEND_FUNCTION(display_disabled_function);
  435. ZEND_API ZEND_FUNCTION(display_disabled_class);
  436. END_EXTERN_C()
  437. #if ZEND_DEBUG
  438. #define CHECK_ZVAL_STRING(z) \
  439. if (Z_STRVAL_P(z)[ Z_STRLEN_P(z) ] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s)", Z_STRVAL_P(z)); }
  440. #define CHECK_ZVAL_STRING_REL(z) \
  441. if (Z_STRVAL_P(z)[ Z_STRLEN_P(z) ] != '\0') { zend_error(E_WARNING, "String is not zero-terminated (%s) (source: %s:%d)", Z_STRVAL_P(z) ZEND_FILE_LINE_RELAY_CC); }
  442. #else
  443. #define CHECK_ZVAL_STRING(z)
  444. #define CHECK_ZVAL_STRING_REL(z)
  445. #endif
  446. #define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
  447. #define CHECK_NULL_PATH(p, l) (strlen(p) != l)
  448. #define ZVAL_RESOURCE(z, l) do { \
  449. zval *__z = (z); \
  450. Z_LVAL_P(__z) = l; \
  451. Z_TYPE_P(__z) = IS_RESOURCE;\
  452. } while (0)
  453. #define ZVAL_BOOL(z, b) do { \
  454. zval *__z = (z); \
  455. Z_LVAL_P(__z) = ((b) != 0); \
  456. Z_TYPE_P(__z) = IS_BOOL; \
  457. } while (0)
  458. #define ZVAL_NULL(z) { \
  459. Z_TYPE_P(z) = IS_NULL; \
  460. }
  461. #define ZVAL_LONG(z, l) { \
  462. zval *__z = (z); \
  463. Z_LVAL_P(__z) = l; \
  464. Z_TYPE_P(__z) = IS_LONG; \
  465. }
  466. #define ZVAL_DOUBLE(z, d) { \
  467. zval *__z = (z); \
  468. Z_DVAL_P(__z) = d; \
  469. Z_TYPE_P(__z) = IS_DOUBLE; \
  470. }
  471. #define ZVAL_STRING(z, s, duplicate) do { \
  472. const char *__s=(s); \
  473. zval *__z = (z); \
  474. Z_STRLEN_P(__z) = strlen(__s); \
  475. if (UNEXPECTED(Z_STRLEN_P(__z) < 0)) { \
  476. zend_error(E_ERROR, "String size overflow"); \
  477. } \
  478. Z_STRVAL_P(__z) = (duplicate?estrndup(__s, Z_STRLEN_P(__z)):(char*)__s);\
  479. Z_TYPE_P(__z) = IS_STRING; \
  480. } while (0)
  481. #define ZVAL_STRINGL(z, s, l, duplicate) do { \
  482. const char *__s=(s); int __l=l; \
  483. zval *__z = (z); \
  484. Z_STRLEN_P(__z) = __l; \
  485. Z_STRVAL_P(__z) = (duplicate?estrndup(__s, __l):(char*)__s);\
  486. Z_TYPE_P(__z) = IS_STRING; \
  487. } while (0)
  488. #define ZVAL_EMPTY_STRING(z) do { \
  489. zval *__z = (z); \
  490. Z_STRLEN_P(__z) = 0; \
  491. Z_STRVAL_P(__z) = STR_EMPTY_ALLOC();\
  492. Z_TYPE_P(__z) = IS_STRING; \
  493. } while (0)
  494. #define ZVAL_ZVAL(z, zv, copy, dtor) do { \
  495. zval *__z = (z); \
  496. zval *__zv = (zv); \
  497. ZVAL_COPY_VALUE(__z, __zv); \
  498. if (copy) { \
  499. zval_copy_ctor(__z); \
  500. } \
  501. if (dtor) { \
  502. if (!copy) { \
  503. ZVAL_NULL(__zv); \
  504. } \
  505. zval_ptr_dtor(&__zv); \
  506. } \
  507. } while (0)
  508. #define ZVAL_FALSE(z) ZVAL_BOOL(z, 0)
  509. #define ZVAL_TRUE(z) ZVAL_BOOL(z, 1)
  510. #define RETVAL_RESOURCE(l) ZVAL_RESOURCE(return_value, l)
  511. #define RETVAL_BOOL(b) ZVAL_BOOL(return_value, b)
  512. #define RETVAL_NULL() ZVAL_NULL(return_value)
  513. #define RETVAL_LONG(l) ZVAL_LONG(return_value, l)
  514. #define RETVAL_DOUBLE(d) ZVAL_DOUBLE(return_value, d)
  515. #define RETVAL_STRING(s, duplicate) ZVAL_STRING(return_value, s, duplicate)
  516. #define RETVAL_STRINGL(s, l, duplicate) ZVAL_STRINGL(return_value, s, l, duplicate)
  517. #define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value)
  518. #define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
  519. #define RETVAL_FALSE ZVAL_BOOL(return_value, 0)
  520. #define RETVAL_TRUE ZVAL_BOOL(return_value, 1)
  521. #define RETURN_RESOURCE(l) { RETVAL_RESOURCE(l); return; }
  522. #define RETURN_BOOL(b) { RETVAL_BOOL(b); return; }
  523. #define RETURN_NULL() { RETVAL_NULL(); return;}
  524. #define RETURN_LONG(l) { RETVAL_LONG(l); return; }
  525. #define RETURN_DOUBLE(d) { RETVAL_DOUBLE(d); return; }
  526. #define RETURN_STRING(s, duplicate) { RETVAL_STRING(s, duplicate); return; }
  527. #define RETURN_STRINGL(s, l, duplicate) { RETVAL_STRINGL(s, l, duplicate); return; }
  528. #define RETURN_EMPTY_STRING() { RETVAL_EMPTY_STRING(); return; }
  529. #define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
  530. #define RETURN_FALSE { RETVAL_FALSE; return; }
  531. #define RETURN_TRUE { RETVAL_TRUE; return; }
  532. #define RETVAL_ZVAL_FAST(z) do { \
  533. zval *_z = (z); \
  534. if (Z_ISREF_P(_z)) { \
  535. RETVAL_ZVAL(_z, 1, 0); \
  536. } else { \
  537. zval_ptr_dtor(&return_value); \
  538. Z_ADDREF_P(_z); \
  539. *return_value_ptr = _z; \
  540. } \
  541. } while (0)
  542. #define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }
  543. /* Check that returned string length fits int */
  544. #define RETVAL_STRINGL_CHECK(s, len, dup) do { \
  545. size_t __len = (len); \
  546. if (UNEXPECTED(__len > INT_MAX)) { \
  547. php_error_docref(NULL TSRMLS_CC, E_WARNING, "String too long, max is %d", INT_MAX); \
  548. if(!(dup)) { \
  549. efree((s)); \
  550. } \
  551. RETURN_FALSE; \
  552. } \
  553. RETVAL_STRINGL((s), (int)__len, (dup)); \
  554. } while (0)
  555. #define RETURN_STRINGL_CHECK(s, len, dup) { RETVAL_STRINGL_CHECK(s, len, dup); return; }
  556. #define SET_VAR_STRING(n, v) { \
  557. { \
  558. zval *var; \
  559. ALLOC_ZVAL(var); \
  560. ZVAL_STRING(var, v, 0); \
  561. ZEND_SET_GLOBAL_VAR(n, var); \
  562. } \
  563. }
  564. #define SET_VAR_STRINGL(n, v, l) { \
  565. { \
  566. zval *var; \
  567. ALLOC_ZVAL(var); \
  568. ZVAL_STRINGL(var, v, l, 0); \
  569. ZEND_SET_GLOBAL_VAR(n, var); \
  570. } \
  571. }
  572. #define SET_VAR_LONG(n, v) { \
  573. { \
  574. zval *var; \
  575. ALLOC_ZVAL(var); \
  576. ZVAL_LONG(var, v); \
  577. ZEND_SET_GLOBAL_VAR(n, var); \
  578. } \
  579. }
  580. #define SET_VAR_DOUBLE(n, v) { \
  581. { \
  582. zval *var; \
  583. ALLOC_ZVAL(var); \
  584. ZVAL_DOUBLE(var, v); \
  585. ZEND_SET_GLOBAL_VAR(n, var); \
  586. } \
  587. }
  588. #define ZEND_SET_SYMBOL(symtable, name, var) \
  589. { \
  590. char *_name = (name); \
  591. \
  592. ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0); \
  593. }
  594. #define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref) \
  595. { \
  596. zval **orig_var; \
  597. \
  598. if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS \
  599. && PZVAL_IS_REF(*orig_var)) { \
  600. Z_SET_REFCOUNT_P(var, Z_REFCOUNT_PP(orig_var)); \
  601. Z_SET_ISREF_P(var); \
  602. \
  603. if (_refcount) { \
  604. Z_SET_REFCOUNT_P(var, Z_REFCOUNT_P(var) + _refcount - 1); \
  605. } \
  606. zval_dtor(*orig_var); \
  607. **orig_var = *(var); \
  608. FREE_ZVAL(var); \
  609. } else { \
  610. Z_SET_ISREF_TO_P(var, _is_ref); \
  611. if (_refcount) { \
  612. Z_SET_REFCOUNT_P(var, _refcount); \
  613. } \
  614. zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL); \
  615. } \
  616. }
  617. #define ZEND_SET_GLOBAL_VAR(name, var) \
  618. ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
  619. #define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref) \
  620. ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
  621. #define ZEND_DEFINE_PROPERTY(class_ptr, name, value, mask) \
  622. { \
  623. char *_name = (name); \
  624. int namelen = strlen(_name); \
  625. zend_declare_property(class_ptr, _name, namelen, value, mask TSRMLS_CC); \
  626. }
  627. #define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p) TSRMLS_CC) : NULL)))
  628. #define ZVAL_IS_NULL(z) (Z_TYPE_P(z)==IS_NULL)
  629. /* For compatibility */
  630. #define ZEND_MINIT ZEND_MODULE_STARTUP_N
  631. #define ZEND_MSHUTDOWN ZEND_MODULE_SHUTDOWN_N
  632. #define ZEND_RINIT ZEND_MODULE_ACTIVATE_N
  633. #define ZEND_RSHUTDOWN ZEND_MODULE_DEACTIVATE_N
  634. #define ZEND_MINFO ZEND_MODULE_INFO_N
  635. #define ZEND_GINIT(module) ((void (*)(void* TSRMLS_DC))(ZEND_MODULE_GLOBALS_CTOR_N(module)))
  636. #define ZEND_GSHUTDOWN(module) ((void (*)(void* TSRMLS_DC))(ZEND_MODULE_GLOBALS_DTOR_N(module)))
  637. #define ZEND_MINIT_FUNCTION ZEND_MODULE_STARTUP_D
  638. #define ZEND_MSHUTDOWN_FUNCTION ZEND_MODULE_SHUTDOWN_D
  639. #define ZEND_RINIT_FUNCTION ZEND_MODULE_ACTIVATE_D
  640. #define ZEND_RSHUTDOWN_FUNCTION ZEND_MODULE_DEACTIVATE_D
  641. #define ZEND_MINFO_FUNCTION ZEND_MODULE_INFO_D
  642. #define ZEND_GINIT_FUNCTION ZEND_MODULE_GLOBALS_CTOR_D
  643. #define ZEND_GSHUTDOWN_FUNCTION ZEND_MODULE_GLOBALS_DTOR_D
  644. END_EXTERN_C()
  645. #endif /* ZEND_API_H */
  646. /*
  647. * Local variables:
  648. * tab-width: 4
  649. * c-basic-offset: 4
  650. * indent-tabs-mode: t
  651. * End:
  652. */