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