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