home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / PHP / include / php / Zend / zend.h < prev   
Encoding:
C/C++ Source or Header  |  2001-02-26  |  12.7 KB  |  464 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2001 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.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.  
  20.  
  21. #ifndef ZEND_H
  22. #define ZEND_H
  23.  
  24. #define ZEND_VERSION "1.0.5"
  25.  
  26. #ifdef __cplusplus
  27. #define BEGIN_EXTERN_C() extern "C" {
  28. #define END_EXTERN_C() }
  29. #else
  30. #define BEGIN_EXTERN_C()
  31. #define END_EXTERN_C()
  32. #endif
  33.  
  34. #include <stdio.h>
  35.  
  36. /*
  37.  * general definitions
  38.  */
  39.  
  40. #ifdef ZEND_WIN32
  41. # include "zend_config.w32.h"
  42. # define ZEND_PATHS_SEPARATOR        ';'
  43. #else
  44. # include "zend_config.h"
  45. # define ZEND_PATHS_SEPARATOR        ':'
  46. #endif
  47.  
  48. /* all HAVE_XXX test have to be after the include of zend_config above */
  49.  
  50. #ifdef HAVE_UNIX_H
  51. # include <unix.h>
  52. #endif
  53.  
  54. #ifdef HAVE_STDARG_H
  55. # include <stdarg.h>
  56. #endif
  57.  
  58. #ifdef HAVE_DLFCN_H
  59. # include <dlfcn.h>
  60. #endif
  61.  
  62. #if defined(HAVE_LIBDL)
  63.  
  64. # ifndef RTLD_LAZY
  65. #  define RTLD_LAZY 1    /* Solaris 1, FreeBSD's (2.1.7.1 and older) */
  66. # endif
  67.  
  68. # ifndef RTLD_GLOBAL
  69. #  define RTLD_GLOBAL 0
  70. # endif
  71.  
  72. # define DL_LOAD(libname)            dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
  73. # define DL_UNLOAD                    dlclose
  74. # define DL_FETCH_SYMBOL            dlsym
  75. # define DL_HANDLE                    void *
  76. # define ZEND_EXTENSIONS_SUPPORT    1
  77. #elif defined(ZEND_WIN32)
  78. # define DL_LOAD(libname)            LoadLibrary(libname)
  79. # define DL_FETCH_SYMBOL            GetProcAddress
  80. # define DL_UNLOAD                    FreeLibrary
  81. # define DL_HANDLE                    HMODULE
  82. # define ZEND_EXTENSIONS_SUPPORT    1
  83. #else
  84. # define DL_HANDLE                    void *
  85. # define ZEND_EXTENSIONS_SUPPORT    0
  86. #endif
  87.  
  88. #if HAVE_ALLOCA_H
  89. # include <alloca.h>
  90. #endif
  91.  
  92. #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(ZEND_WIN32))
  93. # define do_alloca(p) alloca(p)
  94. # define free_alloca(p)
  95. #else
  96. # define do_alloca(p)        emalloc(p)
  97. # define free_alloca(p)    efree(p)
  98. #endif
  99.  
  100. #if ZEND_DEBUG
  101. #define ZEND_FILE_LINE_D                char *__zend_filename, uint __zend_lineno
  102. #define ZEND_FILE_LINE_DC                , ZEND_FILE_LINE_D
  103. #define ZEND_FILE_LINE_ORIG_D            char *__zend_orig_filename, uint __zend_orig_lineno
  104. #define ZEND_FILE_LINE_ORIG_DC            , ZEND_FILE_LINE_ORIG_D
  105. #define ZEND_FILE_LINE_RELAY_C            __zend_filename, __zend_lineno
  106. #define ZEND_FILE_LINE_RELAY_CC            , ZEND_FILE_LINE_RELAY_C
  107. #define ZEND_FILE_LINE_C                __FILE__, __LINE__
  108. #define ZEND_FILE_LINE_CC                , ZEND_FILE_LINE_C
  109. #define ZEND_FILE_LINE_EMPTY_C            NULL, 0
  110. #define ZEND_FILE_LINE_EMPTY_CC            , ZEND_FILE_LINE_EMPTY_C
  111. #define ZEND_FILE_LINE_ORIG_RELAY_C        __zend_orig_filename, __zend_orig_lineno
  112. #define ZEND_FILE_LINE_ORIG_RELAY_CC    , ZEND_FILE_LINE_ORIG_RELAY_C
  113. #else
  114. #define ZEND_FILE_LINE_D
  115. #define ZEND_FILE_LINE_DC
  116. #define ZEND_FILE_LINE_ORIG_D
  117. #define ZEND_FILE_LINE_ORIG_DC
  118. #define ZEND_FILE_LINE_RELAY_C
  119. #define ZEND_FILE_LINE_RELAY_CC
  120. #define ZEND_FILE_LINE_C
  121. #define ZEND_FILE_LINE_CC
  122. #define ZEND_FILE_LINE_EMPTY_C
  123. #define ZEND_FILE_LINE_EMPTY_CC
  124. #define ZEND_FILE_LINE_ORIG_RELAY_C
  125. #define ZEND_FILE_LINE_ORIG_RELAY_CC
  126. #endif    /* ZEND_DEBUG */
  127.  
  128. #ifdef ZTS
  129. #define ZTS_V 1
  130. #else
  131. #define ZTS_V 0
  132. #endif
  133.  
  134. #include "zend_errors.h"
  135. #include "zend_alloc.h"
  136.  
  137. typedef unsigned char zend_bool;
  138. typedef unsigned char zend_uchar;
  139. typedef unsigned int zend_uint;
  140. typedef unsigned long zend_ulong;
  141. typedef unsigned short zend_ushort;
  142.  
  143. #undef SUCCESS
  144. #undef FAILURE
  145. #define SUCCESS 0
  146. #define FAILURE -1                /* this MUST stay a negative number, or it may affect functions! */
  147.  
  148.  
  149. #include "zend_hash.h"
  150. #include "zend_llist.h"
  151.  
  152. #define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval *this_ptr, int return_value_used ELS_DC
  153. #define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, this_ptr, return_value_used ELS_CC
  154.  
  155. /*
  156.  * zval
  157.  */
  158. typedef struct _zval_struct zval;
  159. typedef struct _zend_class_entry zend_class_entry;
  160.  
  161. typedef union _zvalue_value {
  162.     long lval;                    /* long value */
  163.     double dval;                /* double value */
  164.     struct {
  165.         char *val;
  166.         int len;
  167.     } str;
  168.     HashTable *ht;                /* hash table value */
  169.     struct {
  170.         zend_class_entry *ce;
  171.         HashTable *properties;
  172.     } obj;
  173. } zvalue_value;
  174.  
  175.  
  176. struct _zval_struct {
  177.     /* Variable information */
  178.     zvalue_value value;        /* value */
  179.     zend_uchar type;    /* active type */
  180.     zend_uchar is_ref;
  181.     zend_ushort refcount;
  182. };
  183.  
  184.  
  185.  
  186. typedef struct _zend_function_entry {
  187.     char *fname;
  188.     void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
  189.     unsigned char *func_arg_types;
  190. } zend_function_entry;
  191.  
  192.  
  193. typedef struct _zend_property_reference {
  194.     int type;  /* read, write or r/w */
  195.     zval *object;
  196.     zend_llist *elements_list;
  197. } zend_property_reference;
  198.  
  199.  
  200.  
  201. typedef struct _zend_overloaded_element {
  202.     int type;        /* array offset or object proprety */
  203.     zval element;
  204. } zend_overloaded_element;
  205.  
  206. /* excpt.h on Digital Unix 4.0 defines function_table */
  207. #undef function_table
  208.  
  209. struct _zend_class_entry {
  210.     char type;
  211.     char *name;
  212.     uint name_length;
  213.     struct _zend_class_entry *parent; 
  214.     int *refcount;
  215.     zend_bool constants_updated;
  216.  
  217.     HashTable function_table;
  218.     HashTable default_properties;
  219.     zend_function_entry *builtin_functions;
  220.  
  221.     /* handlers */
  222.     void (*handle_function_call)(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference);
  223.     zval (*handle_property_get)(zend_property_reference *property_reference);
  224.     int (*handle_property_set)(zend_property_reference *property_reference, zval *value);
  225. };
  226.  
  227.  
  228.  
  229. typedef struct _zend_utility_functions {
  230.     void (*error_function)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
  231.     int (*printf_function)(const char *format, ...);
  232.     int (*write_function)(const char *str, uint str_length);
  233.     FILE *(*fopen_function)(const char *filename, char **opened_path);
  234.     void (*message_handler)(long message, void *data);
  235.     void (*block_interruptions)(void);
  236.     void (*unblock_interruptions)(void);
  237.     int (*get_configuration_directive)(char *name, uint name_length, zval *contents);
  238.     void (*ticks_function)(int ticks);
  239. } zend_utility_functions;
  240.  
  241.         
  242. typedef struct _zend_utility_values {
  243.     char *import_use_extension;
  244.     uint import_use_extension_length;
  245. } zend_utility_values;
  246.  
  247.  
  248. typedef int (*zend_write_func_t)(const char *str, uint str_length);
  249.  
  250.  
  251. #undef MIN
  252. #undef MAX
  253. #define MAX(a,b)  (((a)>(b))?(a):(b))
  254. #define MIN(a,b)  (((a)<(b))?(a):(b))
  255. #define ZEND_STRL(str)        (str), (sizeof(str)-1)
  256. #define ZEND_STRS(str)        (str), (sizeof(str)
  257. #define ZEND_NORMALIZE_BOOL(n)            \
  258.     ((n) ? (((n)>0) ? 1 : -1) : 0)
  259.  
  260.  
  261. /* data types */
  262. #define IS_NULL        0
  263. #define IS_LONG        1
  264. #define IS_DOUBLE    2
  265. #define IS_STRING    3
  266. #define IS_ARRAY    4
  267. #define IS_OBJECT    5
  268. #define IS_BOOL        6
  269. #define IS_RESOURCE    7
  270. #define IS_CONSTANT    8
  271. #define IS_CONSTANT_ARRAY    9
  272.  
  273. /* Special data type to temporarily mark large numbers */
  274. #define FLAG_IS_BC    10 /* for parser internal use only */
  275.  
  276. /* overloaded elements data types */
  277. #define OE_IS_ARRAY    (1<<0)
  278. #define OE_IS_OBJECT    (1<<1)
  279. #define OE_IS_METHOD    (1<<2)
  280.  
  281.  
  282. /* Argument passing types */
  283. #define BYREF_NONE 0
  284. #define BYREF_FORCE 1
  285. #define BYREF_ALLOW 2
  286. #define BYREF_FORCE_REST 3
  287.  
  288. int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions);
  289. void zend_shutdown(void);
  290.  
  291. void zend_set_utility_values(zend_utility_values *utility_values);
  292. BEGIN_EXTERN_C()
  293. ZEND_API void zend_bailout(void);
  294. END_EXTERN_C()
  295. ZEND_API char *get_zend_version(void);
  296.  
  297. ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy);
  298. ZEND_API int zend_print_zval(zval *expr, int indent);
  299. ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent);
  300. ZEND_API void zend_print_zval_r(zval *expr, int indent);
  301. ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent);
  302.  
  303. ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...);
  304. #if ZEND_DEBUG
  305. #define Z_DBG(expr)        (expr)
  306. #else
  307. #define    Z_DBG(expr)
  308. #endif
  309.  
  310. ZEND_API extern char *empty_string;
  311.  
  312. ZEND_API void free_estring(char **str_p);
  313.  
  314. #define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); }
  315. #define STR_FREE_REL(ptr) if (ptr && ptr!=empty_string) { efree_rel(ptr); }
  316.  
  317. #define STR_REALLOC(ptr, size)                                        \
  318.     if (ptr!=empty_string) {                                        \
  319.         ptr = (char *) erealloc(ptr, size);                            \
  320.     } else {                                                        \
  321.         ptr = (char *) emalloc(size);                                \
  322.         memset(ptr, 0, size);                                        \
  323.     }
  324.  
  325. /* output support */
  326. #define ZEND_WRITE(str, str_len)        zend_write((str), (str_len))
  327. #define ZEND_PUTS(str)                    zend_write((str), strlen((str)))
  328. #define ZEND_PUTC(c)                    zend_write(&(c), 1), (c)
  329.  
  330.  
  331. BEGIN_EXTERN_C()
  332. extern ZEND_API int (*zend_printf)(const char *format, ...);
  333. extern ZEND_API zend_write_func_t zend_write;
  334. extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
  335. extern ZEND_API void (*zend_block_interruptions)(void);
  336. extern ZEND_API void (*zend_unblock_interruptions)(void);
  337. extern ZEND_API void (*zend_ticks_function)(int ticks);
  338. extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
  339.  
  340.  
  341. ZEND_API void zend_error(int type, const char *format, ...);
  342.  
  343. void zenderror(char *error);
  344.  
  345. extern ZEND_API zend_class_entry zend_standard_class_def;
  346. extern zend_utility_values zend_uv;
  347. extern ZEND_API zval zval_used_for_init;
  348.  
  349. END_EXTERN_C()
  350.  
  351. #define ZEND_UV(name) (zend_uv.name)
  352.  
  353.  
  354. #define HANDLE_BLOCK_INTERRUPTIONS()        if (zend_block_interruptions) { zend_block_interruptions(); }
  355. #define HANDLE_UNBLOCK_INTERRUPTIONS()        if (zend_unblock_interruptions) { zend_unblock_interruptions(); }
  356.  
  357. BEGIN_EXTERN_C()
  358. ZEND_API void zend_message_dispatcher(long message, void *data);
  359. END_EXTERN_C()
  360.  
  361. ZEND_API int zend_get_configuration_directive(char *name, uint name_length, zval *contents);
  362.  
  363.  
  364. /* Messages for applications of Zend */
  365. #define ZMSG_FAILED_INCLUDE_FOPEN        1L
  366. #define ZMSG_FAILED_REQUIRE_FOPEN        2L
  367. #define ZMSG_FAILED_HIGHLIGHT_FOPEN        3L
  368. #define ZMSG_MEMORY_LEAK_DETECTED        4L
  369. #define ZMSG_MEMORY_LEAK_REPEATED        5L
  370. #define ZMSG_LOG_SCRIPT_NAME            6L
  371.  
  372.  
  373. #define ZVAL_ADDREF(pz)        (++(pz)->refcount)
  374. #define ZVAL_DELREF(pz)        (--(pz)->refcount)
  375. #define ZVAL_REFCOUNT(pz)    ((pz)->refcount)
  376.  
  377. #define INIT_PZVAL(z)        \
  378.     (z)->refcount = 1;        \
  379.     (z)->is_ref = 0;    
  380.  
  381. #define INIT_ZVAL(z) z = zval_used_for_init;
  382.  
  383. #define ALLOC_INIT_ZVAL(zp)                        \
  384.     ALLOC_ZVAL(zp);        \
  385.     INIT_ZVAL(*zp);
  386.  
  387. #define MAKE_STD_ZVAL(zv)                 \
  388.     ALLOC_ZVAL(zv); \
  389.     INIT_PZVAL(zv);
  390.  
  391. #define PZVAL_IS_REF(z)        ((z)->is_ref)
  392.  
  393. #define SEPARATE_ZVAL(ppzv)                                    \
  394.     {                                                        \
  395.         zval *orig_ptr = *(ppzv);                            \
  396.                                                             \
  397.         if (orig_ptr->refcount>1) {                            \
  398.             orig_ptr->refcount--;                            \
  399.             ALLOC_ZVAL(*(ppzv));                            \
  400.             **(ppzv) = *orig_ptr;                            \
  401.             zval_copy_ctor(*(ppzv));                        \
  402.             (*(ppzv))->refcount=1;                            \
  403.             (*(ppzv))->is_ref = 0;                            \
  404.         }                                                    \
  405.     }
  406.  
  407. #define SEPARATE_ZVAL_IF_NOT_REF(ppzv)        \
  408.     if (!PZVAL_IS_REF(*ppzv)) {                \
  409.         SEPARATE_ZVAL(ppzv);                \
  410.     }
  411.  
  412. #define SEPARATE_ZVAL_TO_MAKE_IS_REF(ppzv)    \
  413.     if (!PZVAL_IS_REF(*ppzv)) {                \
  414.         SEPARATE_ZVAL(ppzv);                \
  415.         (*(ppzv))->is_ref = 1;                \
  416.     }
  417.  
  418. #define COPY_PZVAL_TO_ZVAL(zv, pzv)            \
  419.     (zv) = *(pzv);                            \
  420.     if ((pzv)->refcount>1) {                \
  421.         zval_copy_ctor(&(zv));                \
  422.         (pzv)->refcount--;                    \
  423.     } else {                                \
  424.         FREE_ZVAL(pzv);                        \
  425.     }                                        \
  426.     INIT_PZVAL(&(zv));
  427.  
  428. #define REPLACE_ZVAL_VALUE(ppzv_dest,pzv_src,copy) {    \
  429.     int is_ref,refcount;                        \
  430.                                                 \
  431.     SEPARATE_ZVAL_IF_NOT_REF(ppzv_dest);        \
  432.     is_ref = (*ppzv_dest)->is_ref;                \
  433.     refcount = (*ppzv_dest)->refcount;            \
  434.     zval_dtor(*ppzv_dest);                        \
  435.     **ppzv_dest = *pzv_src;                        \
  436.     if(copy) {                                  \
  437.         zval_copy_ctor(*ppzv_dest);                \
  438.     }                                            \
  439.     (*ppzv_dest)->is_ref = is_ref;                \
  440.     (*ppzv_dest)->refcount = refcount;            \
  441. }
  442.  
  443. #define ZEND_MAX_RESERVED_RESOURCES    4
  444.  
  445. #ifdef ZEND_WIN32
  446. /* Only use this macro if you know for sure that all of the switches values
  447.    are covered by its case statements */
  448. #define EMPTY_SWITCH_DEFAULT_CASE() \
  449.             default:                \
  450.                 __assume(0);        \
  451.                 break;
  452. #else
  453. #define EMPTY_SWITCH_DEFAULT_CASE()
  454. #endif
  455.  
  456. #endif /* ZEND_H */
  457.  
  458. /*
  459.  * Local variables:
  460.  * tab-width: 4
  461.  * c-basic-offset: 4
  462.  * End:
  463.  */
  464.