home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Magazine / HomeAutomation / Apache / include / php / Zend / zend.h < prev   
Encoding:
C/C++ Source or Header  |  2000-06-28  |  11.8 KB  |  434 lines

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