Back to index

php5  5.3.10
zend.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        | 
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Authors: Andi Gutmans <andi@zend.com>                                |
00016    |          Zeev Suraski <zeev@zend.com>                                |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: zend.h 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifndef ZEND_H
00023 #define ZEND_H
00024 
00025 #define ZEND_VERSION "2.3.0"
00026 
00027 #define ZEND_ENGINE_2
00028 
00029 #ifdef __cplusplus
00030 #define BEGIN_EXTERN_C() extern "C" {
00031 #define END_EXTERN_C() }
00032 #else
00033 #define BEGIN_EXTERN_C()
00034 #define END_EXTERN_C()
00035 #endif
00036 
00037 /*
00038  * general definitions
00039  */
00040 
00041 #ifdef ZEND_WIN32
00042 # include "zend_config.w32.h"
00043 # define ZEND_PATHS_SEPARATOR             ';'
00044 #elif defined(NETWARE)
00045 # include <zend_config.h>
00046 # define ZEND_PATHS_SEPARATOR             ';'
00047 #elif defined(__riscos__)
00048 # include <zend_config.h>
00049 # define ZEND_PATHS_SEPARATOR             ';'
00050 #else
00051 # include <zend_config.h>
00052 # define ZEND_PATHS_SEPARATOR             ':'
00053 #endif
00054 
00055 #ifdef ZEND_WIN32
00056 /* Only use this macro if you know for sure that all of the switches values
00057    are covered by its case statements */
00058 #define EMPTY_SWITCH_DEFAULT_CASE() \
00059                      default:                           \
00060                             __assume(0);         \
00061                             break;
00062 #else
00063 #define EMPTY_SWITCH_DEFAULT_CASE()
00064 #endif
00065 
00066 /* all HAVE_XXX test have to be after the include of zend_config above */
00067 
00068 #include <stdio.h>
00069 
00070 #ifdef HAVE_UNIX_H
00071 # include <unix.h>
00072 #endif
00073 
00074 #ifdef HAVE_STDARG_H
00075 # include <stdarg.h>
00076 #endif
00077 
00078 #ifdef HAVE_DLFCN_H
00079 # include <dlfcn.h>
00080 #endif
00081 
00082 #if defined(HAVE_LIBDL) && !defined(ZEND_WIN32)
00083 
00084 # ifndef RTLD_LAZY
00085 #  define RTLD_LAZY 1    /* Solaris 1, FreeBSD's (2.1.7.1 and older) */
00086 # endif
00087 
00088 # ifndef RTLD_GLOBAL
00089 #  define RTLD_GLOBAL 0
00090 # endif
00091 
00092 # if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT)
00093 #  define DL_LOAD(libname)                dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
00094 # elif defined(RTLD_DEEPBIND)
00095 #  define DL_LOAD(libname)                dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND)
00096 # else
00097 #  define DL_LOAD(libname)                dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
00098 # endif
00099 # define DL_UNLOAD                               dlclose
00100 # if defined(DLSYM_NEEDS_UNDERSCORE)
00101 #  define DL_FETCH_SYMBOL(h,s)            dlsym((h), "_" s)
00102 # else
00103 #  define DL_FETCH_SYMBOL                 dlsym
00104 # endif
00105 # define DL_ERROR                                dlerror
00106 # define DL_HANDLE                               void *
00107 # define ZEND_EXTENSIONS_SUPPORT   1
00108 #elif defined(ZEND_WIN32)
00109 # define DL_LOAD(libname)                 LoadLibrary(libname)
00110 # define DL_FETCH_SYMBOL                  GetProcAddress
00111 # define DL_UNLOAD                               FreeLibrary
00112 # define DL_HANDLE                               HMODULE
00113 # define ZEND_EXTENSIONS_SUPPORT   1
00114 #else
00115 # define DL_HANDLE                               void *
00116 # define ZEND_EXTENSIONS_SUPPORT   0
00117 #endif
00118 
00119 #if HAVE_ALLOCA_H && !defined(_ALLOCA_H)
00120 #  include <alloca.h>
00121 #endif
00122 
00123 /* AIX requires this to be the first thing in the file.  */
00124 #ifndef __GNUC__
00125 # ifndef HAVE_ALLOCA_H
00126 #  ifdef _AIX
00127 #pragma alloca
00128 #  else
00129 #   ifndef alloca /* predefined by HP cc +Olibcalls */
00130 char *alloca ();
00131 #   endif
00132 #  endif
00133 # endif
00134 #endif
00135 
00136 /* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */
00137 #ifdef __GNUC__
00138 # define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
00139 #else
00140 # define ZEND_GCC_VERSION 0
00141 #endif
00142 
00143 #if ZEND_GCC_VERSION >= 2096
00144 # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
00145 #else
00146 # define ZEND_ATTRIBUTE_MALLOC
00147 #endif
00148 
00149 #if ZEND_GCC_VERSION >= 2007
00150 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
00151 #else
00152 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first)
00153 #endif
00154 
00155 #if ZEND_GCC_VERSION >= 3001 && !defined(__INTEL_COMPILER)
00156 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
00157 #else
00158 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first)
00159 #endif
00160 
00161 #if ZEND_GCC_VERSION >= 3001
00162 # define ZEND_ATTRIBUTE_DEPRECATED  __attribute__((deprecated))
00163 #elif defined(ZEND_WIN32) && defined(_MSC_VER) && _MSC_VER >= 1300
00164 # define ZEND_ATTRIBUTE_DEPRECATED  __declspec(deprecated)
00165 #else
00166 # define ZEND_ATTRIBUTE_DEPRECATED
00167 #endif
00168 
00169 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__)
00170 # define ZEND_FASTCALL __attribute__((fastcall))
00171 #elif defined(_MSC_VER) && defined(_M_IX86)
00172 # define ZEND_FASTCALL __fastcall
00173 #else
00174 # define ZEND_FASTCALL
00175 #endif
00176 
00177 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004
00178 #else
00179 # define __restrict__
00180 #endif
00181 #define restrict __restrict__
00182 
00183 #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(ZEND_WIN32)) && !(defined(ZTS) && defined(NETWARE)) && !(defined(ZTS) && defined(HPUX)) && !defined(DARWIN)
00184 # define ZEND_ALLOCA_MAX_SIZE (32 * 1024)
00185 # define ALLOCA_FLAG(name) \
00186        zend_bool name;
00187 # define SET_ALLOCA_FLAG(name) \
00188        name = 1
00189 # define do_alloca_ex(size, limit, use_heap) \
00190        ((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size))
00191 # define do_alloca(size, use_heap) \
00192        do_alloca_ex(size, ZEND_ALLOCA_MAX_SIZE, use_heap)
00193 # define free_alloca(p, use_heap) \
00194        do { if (UNEXPECTED(use_heap)) efree(p); } while (0)
00195 #else
00196 # define ALLOCA_FLAG(name)
00197 # define SET_ALLOCA_FLAG(name)
00198 # define do_alloca(p, use_heap)           emalloc(p)
00199 # define free_alloca(p, use_heap)  efree(p)
00200 #endif
00201 
00202 #if ZEND_DEBUG
00203 #define ZEND_FILE_LINE_D                         char *__zend_filename, uint __zend_lineno
00204 #define ZEND_FILE_LINE_DC                        , ZEND_FILE_LINE_D
00205 #define ZEND_FILE_LINE_ORIG_D                    char *__zend_orig_filename, uint __zend_orig_lineno
00206 #define ZEND_FILE_LINE_ORIG_DC                   , ZEND_FILE_LINE_ORIG_D
00207 #define ZEND_FILE_LINE_RELAY_C                   __zend_filename, __zend_lineno
00208 #define ZEND_FILE_LINE_RELAY_CC                  , ZEND_FILE_LINE_RELAY_C
00209 #define ZEND_FILE_LINE_C                         __FILE__, __LINE__
00210 #define ZEND_FILE_LINE_CC                        , ZEND_FILE_LINE_C
00211 #define ZEND_FILE_LINE_EMPTY_C                   NULL, 0
00212 #define ZEND_FILE_LINE_EMPTY_CC                  , ZEND_FILE_LINE_EMPTY_C
00213 #define ZEND_FILE_LINE_ORIG_RELAY_C              __zend_orig_filename, __zend_orig_lineno
00214 #define ZEND_FILE_LINE_ORIG_RELAY_CC      , ZEND_FILE_LINE_ORIG_RELAY_C
00215 #else
00216 #define ZEND_FILE_LINE_D
00217 #define ZEND_FILE_LINE_DC
00218 #define ZEND_FILE_LINE_ORIG_D
00219 #define ZEND_FILE_LINE_ORIG_DC
00220 #define ZEND_FILE_LINE_RELAY_C
00221 #define ZEND_FILE_LINE_RELAY_CC
00222 #define ZEND_FILE_LINE_C
00223 #define ZEND_FILE_LINE_CC
00224 #define ZEND_FILE_LINE_EMPTY_C
00225 #define ZEND_FILE_LINE_EMPTY_CC
00226 #define ZEND_FILE_LINE_ORIG_RELAY_C
00227 #define ZEND_FILE_LINE_ORIG_RELAY_CC
00228 #endif /* ZEND_DEBUG */
00229 
00230 #ifdef ZTS
00231 #define ZTS_V 1
00232 #else
00233 #define ZTS_V 0
00234 #endif
00235 
00236 #include "zend_errors.h"
00237 #include "zend_alloc.h"
00238 
00239 #include "zend_types.h"
00240 
00241 #ifdef HAVE_LIMITS_H
00242 # include <limits.h>
00243 #endif
00244 
00245 #ifndef LONG_MAX
00246 #define LONG_MAX 2147483647L
00247 #endif
00248 
00249 #ifndef LONG_MIN
00250 #define LONG_MIN (- LONG_MAX - 1)
00251 #endif
00252 
00253 #if SIZEOF_LONG == 4
00254 #define MAX_LENGTH_OF_LONG 11
00255 static const char long_min_digits[] = "2147483648";
00256 #elif SIZEOF_LONG == 8
00257 #define MAX_LENGTH_OF_LONG 20
00258 static const char long_min_digits[] = "9223372036854775808";
00259 #else
00260 #error "Unknown SIZEOF_LONG"
00261 #endif
00262 
00263 #define MAX_LENGTH_OF_DOUBLE 32
00264 
00265 #undef SUCCESS
00266 #undef FAILURE
00267 #define SUCCESS 0
00268 #define FAILURE -1                        /* this MUST stay a negative number, or it may affect functions! */
00269 
00270 #include "zend_hash.h"
00271 #include "zend_ts_hash.h"
00272 #include "zend_llist.h"
00273 
00274 #define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC
00275 #define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, return_value_ptr, this_ptr, return_value_used TSRMLS_CC
00276 
00277 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
00278 void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((noreturn));
00279 #else
00280 #  define zend_error_noreturn zend_error
00281 #endif
00282 
00283 /*
00284  * zval
00285  */
00286 typedef struct _zval_struct zval;
00287 typedef struct _zend_class_entry zend_class_entry;
00288 
00289 typedef struct _zend_guard {
00290        zend_bool in_get;
00291        zend_bool in_set;
00292        zend_bool in_unset;
00293        zend_bool in_isset;
00294        zend_bool dummy; /* sizeof(zend_guard) must not be equal to sizeof(void*) */
00295 } zend_guard;
00296 
00297 typedef struct _zend_object {
00298        zend_class_entry *ce;
00299        HashTable *properties;
00300        HashTable *guards; /* protects from __get/__set ... recursion */
00301 } zend_object;
00302 
00303 #include "zend_object_handlers.h"
00304 
00305 typedef union _zvalue_value {
00306        long lval;                                /* long value */
00307        double dval;                       /* double value */
00308        struct {
00309               char *val;
00310               int len;
00311        } str;
00312        HashTable *ht;                            /* hash table value */
00313        zend_object_value obj;
00314 } zvalue_value;
00315 
00316 struct _zval_struct {
00317        /* Variable information */
00318        zvalue_value value;         /* value */
00319        zend_uint refcount__gc;
00320        zend_uchar type;     /* active type */
00321        zend_uchar is_ref__gc;
00322 };
00323 
00324 #define Z_REFCOUNT_PP(ppz)         Z_REFCOUNT_P(*(ppz))
00325 #define Z_SET_REFCOUNT_PP(ppz, rc) Z_SET_REFCOUNT_P(*(ppz), rc)
00326 #define Z_ADDREF_PP(ppz)           Z_ADDREF_P(*(ppz))
00327 #define Z_DELREF_PP(ppz)           Z_DELREF_P(*(ppz))
00328 #define Z_ISREF_PP(ppz)                   Z_ISREF_P(*(ppz))
00329 #define Z_SET_ISREF_PP(ppz)        Z_SET_ISREF_P(*(ppz))
00330 #define Z_UNSET_ISREF_PP(ppz)             Z_UNSET_ISREF_P(*(ppz))
00331 #define Z_SET_ISREF_TO_PP(ppz, isref)     Z_SET_ISREF_TO_P(*(ppz), isref)
00332 
00333 #define Z_REFCOUNT_P(pz)           zval_refcount_p(pz)
00334 #define Z_SET_REFCOUNT_P(pz, rc)   zval_set_refcount_p(pz, rc)
00335 #define Z_ADDREF_P(pz)                    zval_addref_p(pz)
00336 #define Z_DELREF_P(pz)                    zval_delref_p(pz)
00337 #define Z_ISREF_P(pz)                     zval_isref_p(pz)
00338 #define Z_SET_ISREF_P(pz)          zval_set_isref_p(pz)
00339 #define Z_UNSET_ISREF_P(pz)        zval_unset_isref_p(pz)
00340 #define Z_SET_ISREF_TO_P(pz, isref)       zval_set_isref_to_p(pz, isref)
00341 
00342 #define Z_REFCOUNT(z)                     Z_REFCOUNT_P(&(z))
00343 #define Z_SET_REFCOUNT(z, rc)             Z_SET_REFCOUNT_P(&(z), rc)
00344 #define Z_ADDREF(z)                Z_ADDREF_P(&(z))
00345 #define Z_DELREF(z)                Z_DELREF_P(&(z))
00346 #define Z_ISREF(z)                 Z_ISREF_P(&(z))
00347 #define Z_SET_ISREF(z)                    Z_SET_ISREF_P(&(z))
00348 #define Z_UNSET_ISREF(z)           Z_UNSET_ISREF_P(&(z))
00349 #define Z_SET_ISREF_TO(z, isref)   Z_SET_ISREF_TO_P(&(z), isref)
00350 
00351 #if defined(__GNUC__)
00352 #if __GNUC__ >= 3
00353 #define zend_always_inline inline __attribute__((always_inline))
00354 #else
00355 #define zend_always_inline inline
00356 #endif
00357 
00358 #elif defined(_MSC_VER)
00359 #define zend_always_inline __forceinline
00360 #else
00361 #define zend_always_inline inline
00362 #endif
00363 
00364 #if (defined (__GNUC__) && __GNUC__ > 2 ) && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX)
00365 # define EXPECTED(condition)   __builtin_expect(condition, 1)
00366 # define UNEXPECTED(condition) __builtin_expect(condition, 0)
00367 #else
00368 # define EXPECTED(condition)   (condition)
00369 # define UNEXPECTED(condition) (condition)
00370 #endif
00371 
00372 static zend_always_inline zend_uint zval_refcount_p(zval* pz) {
00373        return pz->refcount__gc;
00374 }
00375 
00376 static zend_always_inline zend_uint zval_set_refcount_p(zval* pz, zend_uint rc) {
00377        return pz->refcount__gc = rc;
00378 }
00379 
00380 static zend_always_inline zend_uint zval_addref_p(zval* pz) {
00381        return ++pz->refcount__gc;
00382 }
00383 
00384 static zend_always_inline zend_uint zval_delref_p(zval* pz) {
00385        return --pz->refcount__gc;
00386 }
00387 
00388 static zend_always_inline zend_bool zval_isref_p(zval* pz) {
00389        return pz->is_ref__gc;
00390 }
00391 
00392 static zend_always_inline zend_bool zval_set_isref_p(zval* pz) {
00393        return pz->is_ref__gc = 1;
00394 }
00395 
00396 static zend_always_inline zend_bool zval_unset_isref_p(zval* pz) {
00397        return pz->is_ref__gc = 0;
00398 }
00399 
00400 static zend_always_inline zend_bool zval_set_isref_to_p(zval* pz, zend_bool isref) {
00401        return pz->is_ref__gc = isref;
00402 }
00403 
00404 /* excpt.h on Digital Unix 4.0 defines function_table */
00405 #undef function_table
00406 
00407 /* A lot of stuff needs shifiting around in order to include zend_compile.h here */
00408 union _zend_function;
00409 
00410 #include "zend_iterators.h"
00411 
00412 struct _zend_serialize_data;
00413 struct _zend_unserialize_data;
00414 
00415 typedef struct _zend_serialize_data zend_serialize_data;
00416 typedef struct _zend_unserialize_data zend_unserialize_data;
00417 
00418 struct _zend_class_entry {
00419        char type;
00420        char *name;
00421        zend_uint name_length;
00422        struct _zend_class_entry *parent;
00423        int refcount;
00424        zend_bool constants_updated;
00425        zend_uint ce_flags;
00426 
00427        HashTable function_table;
00428        HashTable default_properties;
00429        HashTable properties_info;
00430        HashTable default_static_members;
00431        HashTable *static_members;
00432        HashTable constants_table;
00433        const struct _zend_function_entry *builtin_functions;
00434 
00435        union _zend_function *constructor;
00436        union _zend_function *destructor;
00437        union _zend_function *clone;
00438        union _zend_function *__get;
00439        union _zend_function *__set;
00440        union _zend_function *__unset;
00441        union _zend_function *__isset;
00442        union _zend_function *__call;
00443        union _zend_function *__callstatic;
00444        union _zend_function *__tostring;
00445        union _zend_function *serialize_func;
00446        union _zend_function *unserialize_func;
00447 
00448        zend_class_iterator_funcs iterator_funcs;
00449 
00450        /* handlers */
00451        zend_object_value (*create_object)(zend_class_entry *class_type TSRMLS_DC);
00452        zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
00453        int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */
00454        union _zend_function *(*get_static_method)(zend_class_entry *ce, char* method, int method_len TSRMLS_DC);
00455 
00456        /* serializer callbacks */
00457        int (*serialize)(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC);
00458        int (*unserialize)(zval **object, zend_class_entry *ce, const unsigned char *buf, zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC);
00459 
00460        zend_class_entry **interfaces;
00461        zend_uint num_interfaces;
00462 
00463        char *filename;
00464        zend_uint line_start;
00465        zend_uint line_end;
00466        char *doc_comment;
00467        zend_uint doc_comment_len;
00468 
00469        struct _zend_module_entry *module;
00470 };
00471 
00472 #include "zend_stream.h"
00473 typedef struct _zend_utility_functions {
00474        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);
00475        int (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
00476        int (*write_function)(const char *str, uint str_length);
00477        FILE *(*fopen_function)(const char *filename, char **opened_path TSRMLS_DC);
00478        void (*message_handler)(long message, void *data TSRMLS_DC);
00479        void (*block_interruptions)(void);
00480        void (*unblock_interruptions)(void);
00481        int (*get_configuration_directive)(const char *name, uint name_length, zval *contents);
00482        void (*ticks_function)(int ticks);
00483        void (*on_timeout)(int seconds TSRMLS_DC);
00484        int (*stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
00485        int (*vspprintf_function)(char **pbuf, size_t max_len, const char *format, va_list ap);
00486        char *(*getenv_function)(char *name, size_t name_len TSRMLS_DC);
00487        char *(*resolve_path_function)(const char *filename, int filename_len TSRMLS_DC);
00488 } zend_utility_functions;
00489 
00490 typedef struct _zend_utility_values {
00491        char *import_use_extension;
00492        uint import_use_extension_length;
00493        zend_bool html_errors;
00494 } zend_utility_values;
00495 
00496 typedef int (*zend_write_func_t)(const char *str, uint str_length);
00497 
00498 #undef MIN
00499 #undef MAX
00500 #define MAX(a, b)  (((a)>(b))?(a):(b))
00501 #define MIN(a, b)  (((a)<(b))?(a):(b))
00502 #define ZEND_STRL(str)             (str), (sizeof(str)-1)
00503 #define ZEND_STRS(str)             (str), (sizeof(str))
00504 #define ZEND_NORMALIZE_BOOL(n)                   \
00505        ((n) ? (((n)>0) ? 1 : -1) : 0)
00506 #define ZEND_TRUTH(x)              ((x) ? 1 : 0)
00507 #define ZEND_LOG_XOR(a, b)         (ZEND_TRUTH(a) ^ ZEND_TRUTH(b))
00508 
00509 /* data types */
00510 /* All data types <= IS_BOOL have their constructor/destructors skipped */
00511 #define IS_NULL             0
00512 #define IS_LONG             1
00513 #define IS_DOUBLE    2
00514 #define IS_BOOL             3
00515 #define IS_ARRAY     4
00516 #define IS_OBJECT    5
00517 #define IS_STRING    6
00518 #define IS_RESOURCE  7
00519 #define IS_CONSTANT  8
00520 #define IS_CONSTANT_ARRAY   9
00521 
00522 /* Ugly hack to support constants as static array indices */
00523 #define IS_CONSTANT_TYPE_MASK      0x0f
00524 #define IS_CONSTANT_UNQUALIFIED    0x10
00525 #define IS_CONSTANT_INDEX          0x80
00526 #define IS_LEXICAL_VAR                    0x20
00527 #define IS_LEXICAL_REF                    0x40
00528 
00529 /* overloaded elements data types */
00530 #define OE_IS_ARRAY         (1<<0)
00531 #define OE_IS_OBJECT (1<<1)
00532 #define OE_IS_METHOD (1<<2)
00533 
00534 int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC);
00535 void zend_shutdown(TSRMLS_D);
00536 void zend_register_standard_ini_entries(TSRMLS_D);
00537 void zend_post_startup(TSRMLS_D);
00538 void zend_set_utility_values(zend_utility_values *utility_values);
00539 
00540 BEGIN_EXTERN_C()
00541 ZEND_API void _zend_bailout(char *filename, uint lineno);
00542 END_EXTERN_C()
00543 
00544 #define zend_bailout()             _zend_bailout(__FILE__, __LINE__)
00545 
00546 #ifdef HAVE_SIGSETJMP
00547 #      define SETJMP(a) sigsetjmp(a, 0)
00548 #      define LONGJMP(a,b) siglongjmp(a, b)
00549 #      define JMP_BUF sigjmp_buf
00550 #else
00551 #      define SETJMP(a) setjmp(a)
00552 #      define LONGJMP(a,b) longjmp(a, b)
00553 #      define JMP_BUF jmp_buf
00554 #endif
00555 
00556 #define zend_try                                                                                  \
00557        {                                                                                                        \
00558               JMP_BUF *__orig_bailout = EG(bailout);                                \
00559               JMP_BUF __bailout;                                                                  \
00560                                                                                                                 \
00561               EG(bailout) = &__bailout;                                                    \
00562               if (SETJMP(__bailout)==0) {
00563 #define zend_catch                                                                                \
00564               } else {                                                                                   \
00565                      EG(bailout) = __orig_bailout;
00566 #define zend_end_try()                                                                            \
00567               }                                                                                                 \
00568               EG(bailout) = __orig_bailout;                                                \
00569        }
00570 #define zend_first_try             EG(bailout)=NULL;    zend_try
00571 
00572 BEGIN_EXTERN_C()
00573 ZEND_API char *get_zend_version(void);
00574 ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy);
00575 ZEND_API int zend_print_zval(zval *expr, int indent);
00576 ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent);
00577 ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC);
00578 ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC);
00579 ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC);
00580 ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
00581 END_EXTERN_C()
00582 
00583 void zend_activate(TSRMLS_D);
00584 void zend_deactivate(TSRMLS_D);
00585 void zend_call_destructors(TSRMLS_D);
00586 void zend_activate_modules(TSRMLS_D);
00587 void zend_deactivate_modules(TSRMLS_D);
00588 void zend_post_deactivate_modules(TSRMLS_D);
00589 
00590 #if ZEND_DEBUG
00591 #define Z_DBG(expr)         (expr)
00592 #else
00593 #define       Z_DBG(expr)
00594 #endif
00595 
00596 BEGIN_EXTERN_C()
00597 ZEND_API void free_estring(char **str_p);
00598 END_EXTERN_C()
00599 
00600 /* FIXME: Check if we can save if (ptr) too */
00601 
00602 #define STR_FREE(ptr) if (ptr) { efree(ptr); }
00603 #define STR_FREE_REL(ptr) if (ptr) { efree_rel(ptr); }
00604 
00605 #define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
00606 
00607 #define STR_REALLOC(ptr, size) \
00608                      ptr = (char *) erealloc(ptr, size);
00609 
00610 /* output support */
00611 #define ZEND_WRITE(str, str_len)          zend_write((str), (str_len))
00612 #define ZEND_WRITE_EX(str, str_len)              write_func((str), (str_len))
00613 #define ZEND_PUTS(str)                                  zend_write((str), strlen((str)))
00614 #define ZEND_PUTS_EX(str)                        write_func((str), strlen((str)))
00615 #define ZEND_PUTC(c)                             zend_write(&(c), 1), (c)
00616 
00617 BEGIN_EXTERN_C()
00618 extern ZEND_API int (*zend_printf)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
00619 extern ZEND_API zend_write_func_t zend_write;
00620 extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
00621 extern ZEND_API void (*zend_block_interruptions)(void);
00622 extern ZEND_API void (*zend_unblock_interruptions)(void);
00623 extern ZEND_API void (*zend_ticks_function)(int ticks);
00624 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);
00625 extern void (*zend_on_timeout)(int seconds TSRMLS_DC);
00626 extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
00627 extern int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
00628 extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
00629 extern ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
00630 
00631 ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
00632 
00633 void zenderror(const char *error);
00634 
00635 /* The following #define is used for code duality in PHP for Engine 1 & 2 */
00636 #define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def
00637 extern ZEND_API zend_class_entry *zend_standard_class_def;
00638 extern ZEND_API zend_utility_values zend_uv;
00639 extern ZEND_API zval zval_used_for_init;
00640 
00641 END_EXTERN_C()
00642 
00643 #define ZEND_UV(name) (zend_uv.name)
00644 
00645 #define HANDLE_BLOCK_INTERRUPTIONS()             if (zend_block_interruptions) { zend_block_interruptions(); }
00646 #define HANDLE_UNBLOCK_INTERRUPTIONS()           if (zend_unblock_interruptions) { zend_unblock_interruptions(); }
00647 
00648 BEGIN_EXTERN_C()
00649 ZEND_API void zend_message_dispatcher(long message, void *data TSRMLS_DC);
00650 
00651 ZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents);
00652 END_EXTERN_C()
00653 
00654 /* Messages for applications of Zend */
00655 #define ZMSG_FAILED_INCLUDE_FOPEN         1L
00656 #define ZMSG_FAILED_REQUIRE_FOPEN         2L
00657 #define ZMSG_FAILED_HIGHLIGHT_FOPEN              3L
00658 #define ZMSG_MEMORY_LEAK_DETECTED         4L
00659 #define ZMSG_MEMORY_LEAK_REPEATED         5L
00660 #define ZMSG_LOG_SCRIPT_NAME                     6L
00661 #define ZMSG_MEMORY_LEAKS_GRAND_TOTAL     7L
00662 
00663 #define INIT_PZVAL(z)              \
00664        (z)->refcount__gc = 1;      \
00665        (z)->is_ref__gc = 0;
00666 
00667 #define INIT_ZVAL(z) z = zval_used_for_init;
00668 
00669 #define ALLOC_INIT_ZVAL(zp)                                    \
00670        ALLOC_ZVAL(zp);             \
00671        INIT_ZVAL(*zp);
00672 
00673 #define MAKE_STD_ZVAL(zv)                         \
00674        ALLOC_ZVAL(zv); \
00675        INIT_PZVAL(zv);
00676 
00677 #define PZVAL_IS_REF(z)            Z_ISREF_P(z)
00678 
00679 #define SEPARATE_ZVAL(ppzv)                                                         \
00680        {                                                                                                 \
00681               zval *orig_ptr = *(ppzv);                                             \
00682                                                                                                          \
00683               if (Z_REFCOUNT_P(orig_ptr) > 1) {                              \
00684                      Z_DELREF_P(orig_ptr);                                                 \
00685                      ALLOC_ZVAL(*(ppzv));                                           \
00686                      **(ppzv) = *orig_ptr;                                                 \
00687                      zval_copy_ctor(*(ppzv));                                       \
00688                      Z_SET_REFCOUNT_PP(ppzv, 1);                                    \
00689                      Z_UNSET_ISREF_PP((ppzv));                                      \
00690               }                                                                                          \
00691        }
00692 
00693 #define SEPARATE_ZVAL_IF_NOT_REF(ppzv)           \
00694        if (!PZVAL_IS_REF(*ppzv)) {                      \
00695               SEPARATE_ZVAL(ppzv);                      \
00696        }
00697 
00698 #define SEPARATE_ZVAL_TO_MAKE_IS_REF(ppzv)       \
00699        if (!PZVAL_IS_REF(*ppzv)) {                      \
00700               SEPARATE_ZVAL(ppzv);                      \
00701               Z_SET_ISREF_PP((ppzv));                          \
00702        }
00703 
00704 #define COPY_PZVAL_TO_ZVAL(zv, pzv)                     \
00705        (zv) = *(pzv);                                                 \
00706        if (Z_REFCOUNT_P(pzv)>1) {                       \
00707               zval_copy_ctor(&(zv));                           \
00708               Z_DELREF_P((pzv));                               \
00709        } else {                                                       \
00710               FREE_ZVAL(pzv);                                         \
00711        }                                                                     \
00712        INIT_PZVAL(&(zv));
00713        
00714 #define MAKE_COPY_ZVAL(ppzv, pzv) \
00715        *(pzv) = **(ppzv);            \
00716        zval_copy_ctor((pzv));        \
00717        INIT_PZVAL((pzv));
00718 
00719 #define REPLACE_ZVAL_VALUE(ppzv_dest, pzv_src, copy) {  \
00720        int is_ref, refcount;                                          \
00721                                                                                     \
00722        SEPARATE_ZVAL_IF_NOT_REF(ppzv_dest);             \
00723        is_ref = Z_ISREF_PP(ppzv_dest);                         \
00724        refcount = Z_REFCOUNT_PP(ppzv_dest);             \
00725        zval_dtor(*ppzv_dest);                                         \
00726        **ppzv_dest = *pzv_src;                                        \
00727        if (copy) {                                 \
00728               zval_copy_ctor(*ppzv_dest);                      \
00729     }                                             \
00730        Z_SET_ISREF_TO_PP(ppzv_dest, is_ref);            \
00731        Z_SET_REFCOUNT_PP(ppzv_dest, refcount);          \
00732 }
00733 
00734 #define SEPARATE_ARG_IF_REF(varptr) \
00735        if (PZVAL_IS_REF(varptr)) { \
00736               zval *original_var = varptr; \
00737               ALLOC_ZVAL(varptr); \
00738               varptr->value = original_var->value; \
00739               Z_TYPE_P(varptr) = Z_TYPE_P(original_var); \
00740               Z_UNSET_ISREF_P(varptr); \
00741               Z_SET_REFCOUNT_P(varptr, 1); \
00742               zval_copy_ctor(varptr); \
00743        } else { \
00744               Z_ADDREF_P(varptr); \
00745        }
00746 
00747 #define READY_TO_DESTROY(zv) \
00748        (Z_REFCOUNT_P(zv) == 1 && \
00749         (Z_TYPE_P(zv) != IS_OBJECT || \
00750          zend_objects_store_get_refcount(zv TSRMLS_CC) == 1))
00751 
00752 #define ZEND_MAX_RESERVED_RESOURCES       4
00753 
00754 #include "zend_gc.h"
00755 #include "zend_operators.h"
00756 #include "zend_variables.h"
00757 
00758 typedef enum {
00759        EH_NORMAL = 0,
00760        EH_SUPPRESS,
00761        EH_THROW
00762 } zend_error_handling_t;
00763 
00764 typedef struct {
00765        zend_error_handling_t  handling;
00766        zend_class_entry       *exception;
00767        zval                   *user_handler;
00768 } zend_error_handling;
00769 
00770 ZEND_API void zend_save_error_handling(zend_error_handling *current TSRMLS_DC);
00771 ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current TSRMLS_DC);
00772 ZEND_API void zend_restore_error_handling(zend_error_handling *saved TSRMLS_DC);
00773 
00774 #define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)
00775 #define DEBUG_BACKTRACE_IGNORE_ARGS    (1<<1)
00776 
00777 #endif /* ZEND_H */
00778 
00779 /*
00780  * Local variables:
00781  * tab-width: 4
00782  * c-basic-offset: 4
00783  * indent-tabs-mode: t
00784  * End:
00785  */