zend.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #ifndef ZEND_H
  21. #define ZEND_H
  22. #define ZEND_VERSION "2.6.0"
  23. #define ZEND_ENGINE_2
  24. #ifdef __cplusplus
  25. #define BEGIN_EXTERN_C() extern "C" {
  26. #define END_EXTERN_C() }
  27. #else
  28. #define BEGIN_EXTERN_C()
  29. #define END_EXTERN_C()
  30. #endif
  31. /*
  32. * general definitions
  33. */
  34. #ifdef ZEND_WIN32
  35. # include "zend_config.w32.h"
  36. # define ZEND_PATHS_SEPARATOR ';'
  37. #elif defined(NETWARE)
  38. # include <zend_config.h>
  39. # define ZEND_PATHS_SEPARATOR ';'
  40. #elif defined(__riscos__)
  41. # include <zend_config.h>
  42. # define ZEND_PATHS_SEPARATOR ';'
  43. #else
  44. # include <zend_config.h>
  45. # define ZEND_PATHS_SEPARATOR ':'
  46. #endif
  47. #ifdef ZEND_WIN32
  48. /* Only use this macro if you know for sure that all of the switches values
  49. are covered by its case statements */
  50. #define EMPTY_SWITCH_DEFAULT_CASE() \
  51. default: \
  52. __assume(0); \
  53. break;
  54. #else
  55. #define EMPTY_SWITCH_DEFAULT_CASE()
  56. #endif
  57. /* all HAVE_XXX test have to be after the include of zend_config above */
  58. #include <stdio.h>
  59. #ifdef HAVE_UNIX_H
  60. # include <unix.h>
  61. #endif
  62. #ifdef HAVE_STDARG_H
  63. # include <stdarg.h>
  64. #endif
  65. #ifdef HAVE_DLFCN_H
  66. # include <dlfcn.h>
  67. #endif
  68. #if defined(HAVE_LIBDL) && !defined(ZEND_WIN32)
  69. # ifndef RTLD_LAZY
  70. # define RTLD_LAZY 1 /* Solaris 1, FreeBSD's (2.1.7.1 and older) */
  71. # endif
  72. # ifndef RTLD_GLOBAL
  73. # define RTLD_GLOBAL 0
  74. # endif
  75. # if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT)
  76. # define DL_LOAD(libname) dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
  77. # elif defined(RTLD_DEEPBIND)
  78. # define DL_LOAD(libname) dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND)
  79. # else
  80. # define DL_LOAD(libname) dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
  81. # endif
  82. # define DL_UNLOAD dlclose
  83. # if defined(DLSYM_NEEDS_UNDERSCORE)
  84. # define DL_FETCH_SYMBOL(h,s) dlsym((h), "_" s)
  85. # else
  86. # define DL_FETCH_SYMBOL dlsym
  87. # endif
  88. # define DL_ERROR dlerror
  89. # define DL_HANDLE void *
  90. # define ZEND_EXTENSIONS_SUPPORT 1
  91. #elif defined(ZEND_WIN32)
  92. # define DL_LOAD(libname) LoadLibrary(libname)
  93. # define DL_FETCH_SYMBOL GetProcAddress
  94. # define DL_UNLOAD FreeLibrary
  95. # define DL_HANDLE HMODULE
  96. # define ZEND_EXTENSIONS_SUPPORT 1
  97. #else
  98. # define DL_HANDLE void *
  99. # define ZEND_EXTENSIONS_SUPPORT 0
  100. #endif
  101. #if HAVE_ALLOCA_H && !defined(_ALLOCA_H)
  102. # include <alloca.h>
  103. #endif
  104. /* AIX requires this to be the first thing in the file. */
  105. #ifndef __GNUC__
  106. # ifndef HAVE_ALLOCA_H
  107. # ifdef _AIX
  108. #pragma alloca
  109. # else
  110. # ifndef alloca /* predefined by HP cc +Olibcalls */
  111. char *alloca ();
  112. # endif
  113. # endif
  114. # endif
  115. #endif
  116. /* Compatibility with non-clang compilers */
  117. #ifndef __has_attribute
  118. # define __has_attribute(x) 0
  119. #endif
  120. /* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */
  121. #ifdef __GNUC__
  122. # define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  123. #else
  124. # define ZEND_GCC_VERSION 0
  125. #endif
  126. #if ZEND_GCC_VERSION >= 2096
  127. # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
  128. #else
  129. # define ZEND_ATTRIBUTE_MALLOC
  130. #endif
  131. #if ZEND_GCC_VERSION >= 4003 || __has_attribute(alloc_size)
  132. # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) __attribute__ ((alloc_size(X)))
  133. # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) __attribute__ ((alloc_size(X,Y)))
  134. #else
  135. # define ZEND_ATTRIBUTE_ALLOC_SIZE(X)
  136. # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y)
  137. #endif
  138. #if ZEND_GCC_VERSION >= 2007
  139. # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
  140. #else
  141. # define ZEND_ATTRIBUTE_FORMAT(type, idx, first)
  142. #endif
  143. #if ZEND_GCC_VERSION >= 3001 && !defined(__INTEL_COMPILER)
  144. # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
  145. #else
  146. # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first)
  147. #endif
  148. #if ZEND_GCC_VERSION >= 3001
  149. # define ZEND_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
  150. #elif defined(ZEND_WIN32) && defined(_MSC_VER) && _MSC_VER >= 1300
  151. # define ZEND_ATTRIBUTE_DEPRECATED __declspec(deprecated)
  152. #else
  153. # define ZEND_ATTRIBUTE_DEPRECATED
  154. #endif
  155. #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__)
  156. # define ZEND_FASTCALL __attribute__((fastcall))
  157. #elif defined(_MSC_VER) && defined(_M_IX86)
  158. # define ZEND_FASTCALL __fastcall
  159. #else
  160. # define ZEND_FASTCALL
  161. #endif
  162. #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004
  163. #else
  164. # define __restrict__
  165. #endif
  166. #define restrict __restrict__
  167. #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(NETWARE)) && !(defined(ZTS) && defined(HPUX)) && !defined(DARWIN)
  168. # define ZEND_ALLOCA_MAX_SIZE (32 * 1024)
  169. # define ALLOCA_FLAG(name) \
  170. zend_bool name;
  171. # define SET_ALLOCA_FLAG(name) \
  172. name = 1
  173. # define do_alloca_ex(size, limit, use_heap) \
  174. ((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size))
  175. # define do_alloca(size, use_heap) \
  176. do_alloca_ex(size, ZEND_ALLOCA_MAX_SIZE, use_heap)
  177. # define free_alloca(p, use_heap) \
  178. do { if (UNEXPECTED(use_heap)) efree(p); } while (0)
  179. #else
  180. # define ALLOCA_FLAG(name)
  181. # define SET_ALLOCA_FLAG(name)
  182. # define do_alloca(p, use_heap) emalloc(p)
  183. # define free_alloca(p, use_heap) efree(p)
  184. #endif
  185. #if ZEND_DEBUG
  186. #define ZEND_FILE_LINE_D const char *__zend_filename, const uint __zend_lineno
  187. #define ZEND_FILE_LINE_DC , ZEND_FILE_LINE_D
  188. #define ZEND_FILE_LINE_ORIG_D const char *__zend_orig_filename, const uint __zend_orig_lineno
  189. #define ZEND_FILE_LINE_ORIG_DC , ZEND_FILE_LINE_ORIG_D
  190. #define ZEND_FILE_LINE_RELAY_C __zend_filename, __zend_lineno
  191. #define ZEND_FILE_LINE_RELAY_CC , ZEND_FILE_LINE_RELAY_C
  192. #define ZEND_FILE_LINE_C __FILE__, __LINE__
  193. #define ZEND_FILE_LINE_CC , ZEND_FILE_LINE_C
  194. #define ZEND_FILE_LINE_EMPTY_C NULL, 0
  195. #define ZEND_FILE_LINE_EMPTY_CC , ZEND_FILE_LINE_EMPTY_C
  196. #define ZEND_FILE_LINE_ORIG_RELAY_C __zend_orig_filename, __zend_orig_lineno
  197. #define ZEND_FILE_LINE_ORIG_RELAY_CC , ZEND_FILE_LINE_ORIG_RELAY_C
  198. #define ZEND_ASSERT(c) assert(c)
  199. #else
  200. #define ZEND_FILE_LINE_D
  201. #define ZEND_FILE_LINE_DC
  202. #define ZEND_FILE_LINE_ORIG_D
  203. #define ZEND_FILE_LINE_ORIG_DC
  204. #define ZEND_FILE_LINE_RELAY_C
  205. #define ZEND_FILE_LINE_RELAY_CC
  206. #define ZEND_FILE_LINE_C
  207. #define ZEND_FILE_LINE_CC
  208. #define ZEND_FILE_LINE_EMPTY_C
  209. #define ZEND_FILE_LINE_EMPTY_CC
  210. #define ZEND_FILE_LINE_ORIG_RELAY_C
  211. #define ZEND_FILE_LINE_ORIG_RELAY_CC
  212. #define ZEND_ASSERT(c)
  213. #endif /* ZEND_DEBUG */
  214. #ifdef ZTS
  215. #define ZTS_V 1
  216. #else
  217. #define ZTS_V 0
  218. #endif
  219. #include "zend_errors.h"
  220. #include "zend_alloc.h"
  221. #include "zend_types.h"
  222. #include "zend_string.h"
  223. #ifdef HAVE_LIMITS_H
  224. # include <limits.h>
  225. #endif
  226. #ifndef LONG_MAX
  227. #define LONG_MAX 2147483647L
  228. #endif
  229. #ifndef LONG_MIN
  230. #define LONG_MIN (- LONG_MAX - 1)
  231. #endif
  232. #if SIZEOF_LONG == 4
  233. #define MAX_LENGTH_OF_LONG 11
  234. static const char long_min_digits[] = "2147483648";
  235. #elif SIZEOF_LONG == 8
  236. #define MAX_LENGTH_OF_LONG 20
  237. static const char long_min_digits[] = "9223372036854775808";
  238. #else
  239. #error "Unknown SIZEOF_LONG"
  240. #endif
  241. #define MAX_LENGTH_OF_DOUBLE 32
  242. typedef enum {
  243. SUCCESS = 0,
  244. FAILURE = -1, /* this MUST stay a negative number, or it may affect functions! */
  245. } ZEND_RESULT_CODE;
  246. #include "zend_hash.h"
  247. #include "zend_ts_hash.h"
  248. #include "zend_llist.h"
  249. #define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC
  250. #define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, return_value_ptr, this_ptr, return_value_used TSRMLS_CC
  251. #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
  252. void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((noreturn));
  253. #else
  254. # define zend_error_noreturn zend_error
  255. #endif
  256. /*
  257. * zval
  258. */
  259. typedef struct _zend_class_entry zend_class_entry;
  260. typedef struct _zend_guard {
  261. zend_bool in_get;
  262. zend_bool in_set;
  263. zend_bool in_unset;
  264. zend_bool in_isset;
  265. zend_bool dummy; /* sizeof(zend_guard) must not be equal to sizeof(void*) */
  266. } zend_guard;
  267. typedef struct _zend_object {
  268. zend_class_entry *ce;
  269. HashTable *properties;
  270. zval **properties_table;
  271. HashTable *guards; /* protects from __get/__set ... recursion */
  272. } zend_object;
  273. #include "zend_object_handlers.h"
  274. #include "zend_ast.h"
  275. typedef union _zvalue_value {
  276. long lval; /* long value */
  277. double dval; /* double value */
  278. struct {
  279. char *val;
  280. int len;
  281. } str;
  282. HashTable *ht; /* hash table value */
  283. zend_object_value obj;
  284. zend_ast *ast;
  285. } zvalue_value;
  286. struct _zval_struct {
  287. /* Variable information */
  288. zvalue_value value; /* value */
  289. zend_uint refcount__gc;
  290. zend_uchar type; /* active type */
  291. zend_uchar is_ref__gc;
  292. };
  293. #define Z_REFCOUNT_PP(ppz) Z_REFCOUNT_P(*(ppz))
  294. #define Z_SET_REFCOUNT_PP(ppz, rc) Z_SET_REFCOUNT_P(*(ppz), rc)
  295. #define Z_ADDREF_PP(ppz) Z_ADDREF_P(*(ppz))
  296. #define Z_DELREF_PP(ppz) Z_DELREF_P(*(ppz))
  297. #define Z_ISREF_PP(ppz) Z_ISREF_P(*(ppz))
  298. #define Z_SET_ISREF_PP(ppz) Z_SET_ISREF_P(*(ppz))
  299. #define Z_UNSET_ISREF_PP(ppz) Z_UNSET_ISREF_P(*(ppz))
  300. #define Z_SET_ISREF_TO_PP(ppz, isref) Z_SET_ISREF_TO_P(*(ppz), isref)
  301. #define Z_REFCOUNT_P(pz) zval_refcount_p(pz)
  302. #define Z_SET_REFCOUNT_P(pz, rc) zval_set_refcount_p(pz, rc)
  303. #define Z_ADDREF_P(pz) zval_addref_p(pz)
  304. #define Z_DELREF_P(pz) zval_delref_p(pz)
  305. #define Z_ISREF_P(pz) zval_isref_p(pz)
  306. #define Z_SET_ISREF_P(pz) zval_set_isref_p(pz)
  307. #define Z_UNSET_ISREF_P(pz) zval_unset_isref_p(pz)
  308. #define Z_SET_ISREF_TO_P(pz, isref) zval_set_isref_to_p(pz, isref)
  309. #define Z_REFCOUNT(z) Z_REFCOUNT_P(&(z))
  310. #define Z_SET_REFCOUNT(z, rc) Z_SET_REFCOUNT_P(&(z), rc)
  311. #define Z_ADDREF(z) Z_ADDREF_P(&(z))
  312. #define Z_DELREF(z) Z_DELREF_P(&(z))
  313. #define Z_ISREF(z) Z_ISREF_P(&(z))
  314. #define Z_SET_ISREF(z) Z_SET_ISREF_P(&(z))
  315. #define Z_UNSET_ISREF(z) Z_UNSET_ISREF_P(&(z))
  316. #define Z_SET_ISREF_TO(z, isref) Z_SET_ISREF_TO_P(&(z), isref)
  317. #if ZEND_DEBUG
  318. #define zend_always_inline inline
  319. #define zend_never_inline
  320. #else
  321. #if defined(__GNUC__)
  322. #if __GNUC__ >= 3
  323. #define zend_always_inline inline __attribute__((always_inline))
  324. #define zend_never_inline __attribute__((noinline))
  325. #else
  326. #define zend_always_inline inline
  327. #define zend_never_inline
  328. #endif
  329. #elif defined(_MSC_VER)
  330. #define zend_always_inline __forceinline
  331. #define zend_never_inline
  332. #else
  333. #define zend_always_inline inline
  334. #define zend_never_inline
  335. #endif
  336. #endif /* ZEND_DEBUG */
  337. #if (defined (__GNUC__) && __GNUC__ > 2 ) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX)
  338. # define EXPECTED(condition) __builtin_expect(condition, 1)
  339. # define UNEXPECTED(condition) __builtin_expect(condition, 0)
  340. #else
  341. # define EXPECTED(condition) (condition)
  342. # define UNEXPECTED(condition) (condition)
  343. #endif
  344. static zend_always_inline zend_uint zval_refcount_p(zval* pz) {
  345. return pz->refcount__gc;
  346. }
  347. static zend_always_inline zend_uint zval_set_refcount_p(zval* pz, zend_uint rc) {
  348. return pz->refcount__gc = rc;
  349. }
  350. static zend_always_inline zend_uint zval_addref_p(zval* pz) {
  351. return ++pz->refcount__gc;
  352. }
  353. static zend_always_inline zend_uint zval_delref_p(zval* pz) {
  354. return --pz->refcount__gc;
  355. }
  356. static zend_always_inline zend_bool zval_isref_p(zval* pz) {
  357. return pz->is_ref__gc;
  358. }
  359. static zend_always_inline zend_bool zval_set_isref_p(zval* pz) {
  360. return pz->is_ref__gc = 1;
  361. }
  362. static zend_always_inline zend_bool zval_unset_isref_p(zval* pz) {
  363. return pz->is_ref__gc = 0;
  364. }
  365. static zend_always_inline zend_bool zval_set_isref_to_p(zval* pz, zend_bool isref) {
  366. return pz->is_ref__gc = isref;
  367. }
  368. /* excpt.h on Digital Unix 4.0 defines function_table */
  369. #undef function_table
  370. /* A lot of stuff needs shifiting around in order to include zend_compile.h here */
  371. union _zend_function;
  372. #include "zend_iterators.h"
  373. struct _zend_serialize_data;
  374. struct _zend_unserialize_data;
  375. typedef struct _zend_serialize_data zend_serialize_data;
  376. typedef struct _zend_unserialize_data zend_unserialize_data;
  377. struct _zend_trait_method_reference {
  378. const char* method_name;
  379. unsigned int mname_len;
  380. zend_class_entry *ce;
  381. const char* class_name;
  382. unsigned int cname_len;
  383. };
  384. typedef struct _zend_trait_method_reference zend_trait_method_reference;
  385. struct _zend_trait_precedence {
  386. zend_trait_method_reference *trait_method;
  387. zend_class_entry** exclude_from_classes;
  388. };
  389. typedef struct _zend_trait_precedence zend_trait_precedence;
  390. struct _zend_trait_alias {
  391. zend_trait_method_reference *trait_method;
  392. /**
  393. * name for method to be added
  394. */
  395. const char* alias;
  396. unsigned int alias_len;
  397. /**
  398. * modifiers to be set on trait method
  399. */
  400. zend_uint modifiers;
  401. };
  402. typedef struct _zend_trait_alias zend_trait_alias;
  403. struct _zend_class_entry {
  404. char type;
  405. const char *name;
  406. zend_uint name_length;
  407. struct _zend_class_entry *parent;
  408. int refcount;
  409. zend_uint ce_flags;
  410. HashTable function_table;
  411. HashTable properties_info;
  412. zval **default_properties_table;
  413. zval **default_static_members_table;
  414. zval **static_members_table;
  415. HashTable constants_table;
  416. int default_properties_count;
  417. int default_static_members_count;
  418. union _zend_function *constructor;
  419. union _zend_function *destructor;
  420. union _zend_function *clone;
  421. union _zend_function *__get;
  422. union _zend_function *__set;
  423. union _zend_function *__unset;
  424. union _zend_function *__isset;
  425. union _zend_function *__call;
  426. union _zend_function *__callstatic;
  427. union _zend_function *__tostring;
  428. union _zend_function *__debugInfo;
  429. union _zend_function *serialize_func;
  430. union _zend_function *unserialize_func;
  431. zend_class_iterator_funcs iterator_funcs;
  432. /* handlers */
  433. zend_object_value (*create_object)(zend_class_entry *class_type TSRMLS_DC);
  434. zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
  435. int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */
  436. union _zend_function *(*get_static_method)(zend_class_entry *ce, char* method, int method_len TSRMLS_DC);
  437. /* serializer callbacks */
  438. int (*serialize)(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
  439. int (*unserialize)(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
  440. zend_class_entry **interfaces;
  441. zend_uint num_interfaces;
  442. zend_class_entry **traits;
  443. zend_uint num_traits;
  444. zend_trait_alias **trait_aliases;
  445. zend_trait_precedence **trait_precedences;
  446. union {
  447. struct {
  448. const char *filename;
  449. zend_uint line_start;
  450. zend_uint line_end;
  451. const char *doc_comment;
  452. zend_uint doc_comment_len;
  453. } user;
  454. struct {
  455. const struct _zend_function_entry *builtin_functions;
  456. struct _zend_module_entry *module;
  457. } internal;
  458. } info;
  459. };
  460. #include "zend_stream.h"
  461. typedef struct _zend_utility_functions {
  462. void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
  463. int (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
  464. int (*write_function)(const char *str, uint str_length);
  465. FILE *(*fopen_function)(const char *filename, char **opened_path TSRMLS_DC);
  466. void (*message_handler)(long message, const void *data TSRMLS_DC);
  467. void (*block_interruptions)(void);
  468. void (*unblock_interruptions)(void);
  469. int (*get_configuration_directive)(const char *name, uint name_length, zval *contents);
  470. void (*ticks_function)(int ticks);
  471. void (*on_timeout)(int seconds TSRMLS_DC);
  472. int (*stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
  473. int (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap);
  474. char *(*getenv_function)(char *name, size_t name_len TSRMLS_DC);
  475. char *(*resolve_path_function)(const char *filename, int filename_len TSRMLS_DC);
  476. } zend_utility_functions;
  477. typedef struct _zend_utility_values {
  478. char *import_use_extension;
  479. uint import_use_extension_length;
  480. zend_bool html_errors;
  481. } zend_utility_values;
  482. typedef int (*zend_write_func_t)(const char *str, uint str_length);
  483. #undef MIN
  484. #undef MAX
  485. #define MAX(a, b) (((a)>(b))?(a):(b))
  486. #define MIN(a, b) (((a)<(b))?(a):(b))
  487. #define ZEND_STRL(str) (str), (sizeof(str)-1)
  488. #define ZEND_STRS(str) (str), (sizeof(str))
  489. #define ZEND_NORMALIZE_BOOL(n) \
  490. ((n) ? (((n)>0) ? 1 : -1) : 0)
  491. #define ZEND_TRUTH(x) ((x) ? 1 : 0)
  492. #define ZEND_LOG_XOR(a, b) (ZEND_TRUTH(a) ^ ZEND_TRUTH(b))
  493. /* data types */
  494. /* All data types <= IS_BOOL have their constructor/destructors skipped */
  495. #define IS_NULL 0
  496. #define IS_LONG 1
  497. #define IS_DOUBLE 2
  498. #define IS_BOOL 3
  499. #define IS_ARRAY 4
  500. #define IS_OBJECT 5
  501. #define IS_STRING 6
  502. #define IS_RESOURCE 7
  503. #define IS_CONSTANT 8
  504. #define IS_CONSTANT_AST 9
  505. #define IS_CALLABLE 10
  506. #define IS_CONSTANT_TYPE_MASK 0x00f
  507. #define IS_CONSTANT_UNQUALIFIED 0x010
  508. #define IS_LEXICAL_VAR 0x020
  509. #define IS_LEXICAL_REF 0x040
  510. #define IS_CONSTANT_IN_NAMESPACE 0x100
  511. #define IS_CONSTANT_TYPE(type) (((type) & IS_CONSTANT_TYPE_MASK) >= IS_CONSTANT && ((type) & IS_CONSTANT_TYPE_MASK) <= IS_CONSTANT_AST)
  512. /* overloaded elements data types */
  513. #define OE_IS_ARRAY (1<<0)
  514. #define OE_IS_OBJECT (1<<1)
  515. #define OE_IS_METHOD (1<<2)
  516. int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC);
  517. void zend_shutdown(TSRMLS_D);
  518. void zend_register_standard_ini_entries(TSRMLS_D);
  519. void zend_post_startup(TSRMLS_D);
  520. void zend_set_utility_values(zend_utility_values *utility_values);
  521. BEGIN_EXTERN_C()
  522. ZEND_API void _zend_bailout(char *filename, uint lineno);
  523. END_EXTERN_C()
  524. #define zend_bailout() _zend_bailout(__FILE__, __LINE__)
  525. #ifdef HAVE_SIGSETJMP
  526. # define SETJMP(a) sigsetjmp(a, 0)
  527. # define LONGJMP(a,b) siglongjmp(a, b)
  528. # define JMP_BUF sigjmp_buf
  529. #else
  530. # define SETJMP(a) setjmp(a)
  531. # define LONGJMP(a,b) longjmp(a, b)
  532. # define JMP_BUF jmp_buf
  533. #endif
  534. #define zend_try \
  535. { \
  536. JMP_BUF *__orig_bailout = EG(bailout); \
  537. JMP_BUF __bailout; \
  538. \
  539. EG(bailout) = &__bailout; \
  540. if (SETJMP(__bailout)==0) {
  541. #define zend_catch \
  542. } else { \
  543. EG(bailout) = __orig_bailout;
  544. #define zend_end_try() \
  545. } \
  546. EG(bailout) = __orig_bailout; \
  547. }
  548. #define zend_first_try EG(bailout)=NULL; zend_try
  549. BEGIN_EXTERN_C()
  550. ZEND_API char *get_zend_version(void);
  551. ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy);
  552. ZEND_API int zend_print_zval(zval *expr, int indent);
  553. ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent);
  554. ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC);
  555. ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC);
  556. ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC);
  557. ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
  558. END_EXTERN_C()
  559. BEGIN_EXTERN_C()
  560. ZEND_API void zend_activate(TSRMLS_D);
  561. ZEND_API void zend_deactivate(TSRMLS_D);
  562. ZEND_API void zend_call_destructors(TSRMLS_D);
  563. ZEND_API void zend_activate_modules(TSRMLS_D);
  564. ZEND_API void zend_deactivate_modules(TSRMLS_D);
  565. ZEND_API void zend_post_deactivate_modules(TSRMLS_D);
  566. END_EXTERN_C()
  567. #if ZEND_DEBUG
  568. #define Z_DBG(expr) (expr)
  569. #else
  570. #define Z_DBG(expr)
  571. #endif
  572. BEGIN_EXTERN_C()
  573. ZEND_API void free_estring(char **str_p);
  574. END_EXTERN_C()
  575. /* FIXME: Check if we can save if (ptr) too */
  576. #define STR_FREE(ptr) if (ptr) { str_efree(ptr); }
  577. #define STR_FREE_REL(ptr) if (ptr) { str_efree_rel(ptr); }
  578. #ifndef ZTS
  579. #define STR_EMPTY_ALLOC() CG(interned_empty_string)? CG(interned_empty_string) : estrndup("", sizeof("")-1)
  580. #else
  581. #define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
  582. #endif
  583. #define STR_REALLOC(ptr, size) \
  584. ptr = (char *) erealloc(ptr, size);
  585. /* output support */
  586. #define ZEND_WRITE(str, str_len) zend_write((str), (str_len))
  587. #define ZEND_WRITE_EX(str, str_len) write_func((str), (str_len))
  588. #define ZEND_PUTS(str) zend_write((str), strlen((str)))
  589. #define ZEND_PUTS_EX(str) write_func((str), strlen((str)))
  590. #define ZEND_PUTC(c) zend_write(&(c), 1)
  591. BEGIN_EXTERN_C()
  592. extern ZEND_API int (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
  593. extern ZEND_API zend_write_func_t zend_write;
  594. extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
  595. extern ZEND_API void (*zend_block_interruptions)(void);
  596. extern ZEND_API void (*zend_unblock_interruptions)(void);
  597. extern ZEND_API void (*zend_ticks_function)(int ticks);
  598. extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
  599. extern ZEND_API void (*zend_on_timeout)(int seconds TSRMLS_DC);
  600. extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
  601. extern int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
  602. extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
  603. extern ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
  604. ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
  605. void zenderror(const char *error);
  606. /* The following #define is used for code duality in PHP for Engine 1 & 2 */
  607. #define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def
  608. extern ZEND_API zend_class_entry *zend_standard_class_def;
  609. extern ZEND_API zend_utility_values zend_uv;
  610. extern ZEND_API zval zval_used_for_init;
  611. END_EXTERN_C()
  612. #define ZEND_UV(name) (zend_uv.name)
  613. #ifndef ZEND_SIGNALS
  614. #define HANDLE_BLOCK_INTERRUPTIONS() if (zend_block_interruptions) { zend_block_interruptions(); }
  615. #define HANDLE_UNBLOCK_INTERRUPTIONS() if (zend_unblock_interruptions) { zend_unblock_interruptions(); }
  616. #else
  617. #include "zend_signal.h"
  618. #define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPUTIONS()
  619. #define HANDLE_UNBLOCK_INTERRUPTIONS() ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS()
  620. #endif
  621. BEGIN_EXTERN_C()
  622. ZEND_API void zend_message_dispatcher(long message, const void *data TSRMLS_DC);
  623. ZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents);
  624. END_EXTERN_C()
  625. /* Messages for applications of Zend */
  626. #define ZMSG_FAILED_INCLUDE_FOPEN 1L
  627. #define ZMSG_FAILED_REQUIRE_FOPEN 2L
  628. #define ZMSG_FAILED_HIGHLIGHT_FOPEN 3L
  629. #define ZMSG_MEMORY_LEAK_DETECTED 4L
  630. #define ZMSG_MEMORY_LEAK_REPEATED 5L
  631. #define ZMSG_LOG_SCRIPT_NAME 6L
  632. #define ZMSG_MEMORY_LEAKS_GRAND_TOTAL 7L
  633. #define INIT_PZVAL(z) \
  634. (z)->refcount__gc = 1; \
  635. (z)->is_ref__gc = 0;
  636. #define INIT_ZVAL(z) z = zval_used_for_init;
  637. #define ALLOC_INIT_ZVAL(zp) \
  638. ALLOC_ZVAL(zp); \
  639. INIT_ZVAL(*zp);
  640. #define MAKE_STD_ZVAL(zv) \
  641. ALLOC_ZVAL(zv); \
  642. INIT_PZVAL(zv);
  643. #define PZVAL_IS_REF(z) Z_ISREF_P(z)
  644. #define ZVAL_COPY_VALUE(z, v) \
  645. do { \
  646. (z)->value = (v)->value; \
  647. Z_TYPE_P(z) = Z_TYPE_P(v); \
  648. } while (0)
  649. #define INIT_PZVAL_COPY(z, v) \
  650. do { \
  651. ZVAL_COPY_VALUE(z, v); \
  652. Z_SET_REFCOUNT_P(z, 1); \
  653. Z_UNSET_ISREF_P(z); \
  654. } while (0)
  655. #define SEPARATE_ZVAL(ppzv) \
  656. do { \
  657. if (Z_REFCOUNT_PP((ppzv)) > 1) { \
  658. zval *new_zv; \
  659. Z_DELREF_PP(ppzv); \
  660. ALLOC_ZVAL(new_zv); \
  661. INIT_PZVAL_COPY(new_zv, *(ppzv)); \
  662. *(ppzv) = new_zv; \
  663. zval_copy_ctor(new_zv); \
  664. } \
  665. } while (0)
  666. #define SEPARATE_ZVAL_IF_NOT_REF(ppzv) \
  667. if (!PZVAL_IS_REF(*ppzv)) { \
  668. SEPARATE_ZVAL(ppzv); \
  669. }
  670. #define SEPARATE_ZVAL_TO_MAKE_IS_REF(ppzv) \
  671. if (!PZVAL_IS_REF(*ppzv)) { \
  672. SEPARATE_ZVAL(ppzv); \
  673. Z_SET_ISREF_PP((ppzv)); \
  674. }
  675. #define COPY_PZVAL_TO_ZVAL(zv, pzv) \
  676. (zv) = *(pzv); \
  677. if (Z_REFCOUNT_P(pzv)>1) { \
  678. zval_copy_ctor(&(zv)); \
  679. Z_DELREF_P((pzv)); \
  680. } else { \
  681. FREE_ZVAL(pzv); \
  682. } \
  683. INIT_PZVAL(&(zv));
  684. #define MAKE_COPY_ZVAL(ppzv, pzv) \
  685. INIT_PZVAL_COPY(pzv, *(ppzv)); \
  686. zval_copy_ctor((pzv));
  687. #define REPLACE_ZVAL_VALUE(ppzv_dest, pzv_src, copy) { \
  688. int is_ref, refcount; \
  689. \
  690. SEPARATE_ZVAL_IF_NOT_REF(ppzv_dest); \
  691. is_ref = Z_ISREF_PP(ppzv_dest); \
  692. refcount = Z_REFCOUNT_PP(ppzv_dest); \
  693. zval_dtor(*ppzv_dest); \
  694. ZVAL_COPY_VALUE(*ppzv_dest, pzv_src); \
  695. if (copy) { \
  696. zval_copy_ctor(*ppzv_dest); \
  697. } \
  698. Z_SET_ISREF_TO_PP(ppzv_dest, is_ref); \
  699. Z_SET_REFCOUNT_PP(ppzv_dest, refcount); \
  700. }
  701. #define SEPARATE_ARG_IF_REF(varptr) \
  702. if (PZVAL_IS_REF(varptr)) { \
  703. zval *original_var = varptr; \
  704. ALLOC_ZVAL(varptr); \
  705. INIT_PZVAL_COPY(varptr, original_var); \
  706. zval_copy_ctor(varptr); \
  707. } else { \
  708. Z_ADDREF_P(varptr); \
  709. }
  710. #define READY_TO_DESTROY(zv) \
  711. (Z_REFCOUNT_P(zv) == 1 && \
  712. (Z_TYPE_P(zv) != IS_OBJECT || \
  713. zend_objects_store_get_refcount(zv TSRMLS_CC) == 1))
  714. #define ZEND_MAX_RESERVED_RESOURCES 4
  715. #include "zend_gc.h"
  716. #include "zend_operators.h"
  717. #include "zend_variables.h"
  718. typedef enum {
  719. EH_NORMAL = 0,
  720. EH_SUPPRESS,
  721. EH_THROW
  722. } zend_error_handling_t;
  723. typedef struct {
  724. zend_error_handling_t handling;
  725. zend_class_entry *exception;
  726. zval *user_handler;
  727. } zend_error_handling;
  728. ZEND_API void zend_save_error_handling(zend_error_handling *current TSRMLS_DC);
  729. ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current TSRMLS_DC);
  730. ZEND_API void zend_restore_error_handling(zend_error_handling *saved TSRMLS_DC);
  731. #define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)
  732. #define DEBUG_BACKTRACE_IGNORE_ARGS (1<<1)
  733. #endif /* ZEND_H */
  734. /*
  735. * Local variables:
  736. * tab-width: 4
  737. * c-basic-offset: 4
  738. * indent-tabs-mode: t
  739. * End:
  740. */