zend.c revision b3b616cf
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
5c081ce62SXinchen Hui   | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
6573b4602SAndi Gutmans   +----------------------------------------------------------------------+
7d863d52aSSebastian Bergmann   | This source file is subject to version 2.00 of the Zend license,     |
8b5b11177SZeev Suraski   | that is bundled with this package in the file LICENSE, and is        |
9f68c7ff2SJames Cox   | available through the world-wide-web at the following url:           |
10d863d52aSSebastian Bergmann   | http://www.zend.com/license/2_00.txt.                                |
11b5b11177SZeev Suraski   | If you did not receive a copy of the Zend license and are unable to  |
12b5b11177SZeev Suraski   | obtain it through the world-wide-web, please send a note to          |
13b5b11177SZeev Suraski   | license@zend.com so we can mail you a copy immediately.              |
14573b4602SAndi Gutmans   +----------------------------------------------------------------------+
15573b4602SAndi Gutmans   | Authors: Andi Gutmans <andi@zend.com>                                |
16573b4602SAndi Gutmans   |          Zeev Suraski <zeev@zend.com>                                |
17573b4602SAndi Gutmans   +----------------------------------------------------------------------+
18573b4602SAndi Gutmans*/
19573b4602SAndi Gutmans
20333406bdSfoobar/* $Id$ */
21a6043d3eSRasmus Lerdorf
22573b4602SAndi Gutmans#include "zend.h"
23573b4602SAndi Gutmans#include "zend_extensions.h"
247080fa5bSAndi Gutmans#include "zend_modules.h"
25573b4602SAndi Gutmans#include "zend_constants.h"
26573b4602SAndi Gutmans#include "zend_list.h"
27da9faa2cSZeev Suraski#include "zend_API.h"
2800ed3badSZeev Suraski#include "zend_exceptions.h"
2913d840bcSZeev Suraski#include "zend_builtin_functions.h"
3054d53055SZeev Suraski#include "zend_ini.h"
31fcaa1c6dSDmitry Stogov#include "zend_vm.h"
3208b9fdc8SDavid Soria Parra#include "zend_dtrace.h"
33cf6ab0e9SAnatol Belski#include "zend_virtual_cwd.h"
34573b4602SAndi Gutmans
357a87fcbbSZeev Suraski#ifdef ZTS
36b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		global_function_table
37b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			global_class_table
38b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		global_constants_table
39b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
407a87fcbbSZeev Suraski#else
41b4892511SJani Taskinen# define GLOBAL_FUNCTION_TABLE		CG(function_table)
42b4892511SJani Taskinen# define GLOBAL_CLASS_TABLE			CG(class_table)
43b4892511SJani Taskinen# define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
44b4892511SJani Taskinen# define GLOBAL_CONSTANTS_TABLE		EG(zend_constants)
457a87fcbbSZeev Suraski#endif
467a87fcbbSZeev Suraski
47573b4602SAndi Gutmans/* true multithread-shared globals */
4892dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
49573b4602SAndi GutmansZEND_API int (*zend_printf)(const char *format, ...);
505dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
5185ab4235SFelipe PenaZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC);
52e52aac94SWez FurlongZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
5393536507SStig S. BakkenZEND_API void (*zend_block_interruptions)(void);
5493536507SStig S. BakkenZEND_API void (*zend_unblock_interruptions)(void);
55aed4b086SKalle Sommer NielsenZEND_API void (*zend_ticks_function)(int ticks TSRMLS_DC);
56536221beSStanislav MalyshevZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
57d45fd8a1SMarcus Boergerint (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
5888c550a7SXinchen Huizend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
5985a36e2bSZeev SuraskiZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
60ab232458SDmitry StogovZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
61536221beSStanislav Malyshev
62bd115087SZeev Suraskivoid (*zend_on_timeout)(int seconds TSRMLS_DC);
63bd115087SZeev Suraski
644a25a774SDmitry Stogovstatic void (*zend_message_dispatcher_p)(long message, const void *data TSRMLS_DC);
65cf7384aaSFelipe Penastatic int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents);
66d035af4aSZeev Suraski
67b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
684be862b0SZeev Suraski{
694be862b0SZeev Suraski	if (!new_value) {
70d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
714be862b0SZeev Suraski	} else {
724be862b0SZeev Suraski		EG(error_reporting) = atoi(new_value);
734be862b0SZeev Suraski	}
744be862b0SZeev Suraski	return SUCCESS;
754be862b0SZeev Suraski}
76b4892511SJani Taskinen/* }}} */
774be862b0SZeev Suraski
7871592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
7971592cecSDmitry Stogov{
8071592cecSDmitry Stogov	OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
8171592cecSDmitry Stogov
8271592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
8371592cecSDmitry Stogov		gc_init(TSRMLS_C);
8471592cecSDmitry Stogov	}
8571592cecSDmitry Stogov
8671592cecSDmitry Stogov	return SUCCESS;
8771592cecSDmitry Stogov}
8871592cecSDmitry Stogov/* }}} */
8971592cecSDmitry Stogov
90bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
91bbf3d43cSMoriyoshi Koizumi{
92bbf3d43cSMoriyoshi Koizumi	if (!CG(multibyte)) {
93bbf3d43cSMoriyoshi Koizumi		return FAILURE;
94bbf3d43cSMoriyoshi Koizumi	}
95bbf3d43cSMoriyoshi Koizumi	if (!zend_multibyte_get_functions(TSRMLS_C)) {
96bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
97bbf3d43cSMoriyoshi Koizumi	}
98bbf3d43cSMoriyoshi Koizumi	return zend_multibyte_set_script_encoding_by_string(new_value, new_value_length TSRMLS_CC);
99bbf3d43cSMoriyoshi Koizumi}
100bbf3d43cSMoriyoshi Koizumi/* }}} */
101bbf3d43cSMoriyoshi Koizumi
102bbf3d43cSMoriyoshi Koizumi
1034be862b0SZeev SuraskiZEND_INI_BEGIN()
104eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
10571592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
106ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
107bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
108bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
10934d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
11034d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
11134d93f0cSIlia Alshanetsky#endif
1124be862b0SZeev SuraskiZEND_INI_END()
1134be862b0SZeev Suraski
1144be862b0SZeev Suraski
1157a87fcbbSZeev Suraski#ifdef ZTS
116e06a1ed2SZeev SuraskiZEND_API int compiler_globals_id;
117e06a1ed2SZeev SuraskiZEND_API int executor_globals_id;
118b4892511SJani Taskinenstatic HashTable *global_function_table = NULL;
119b4892511SJani Taskinenstatic HashTable *global_class_table = NULL;
120b4892511SJani Taskinenstatic HashTable *global_constants_table = NULL;
121b4892511SJani Taskinenstatic HashTable *global_auto_globals_table = NULL;
12221698c12SDmitry Stogovstatic HashTable *global_persistent_list = NULL;
1237a87fcbbSZeev Suraski#endif
124573b4602SAndi Gutmans
125e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
126573b4602SAndi Gutmans
127573b4602SAndi Gutmans/* version information */
128573b4602SAndi Gutmansstatic char *zend_version_info;
129573b4602SAndi Gutmansstatic uint zend_version_info_length;
130c081ce62SXinchen Hui#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2014 Zend Technologies\n"
13180bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
132573b4602SAndi Gutmans
133d3d02fbcSDmitry Stogovstatic void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
134573b4602SAndi Gutmans{
135f4cfaf36SDmitry Stogov	zval *tmp;
136f4cfaf36SDmitry Stogov	zend_string *string_key;
1374757104eSZeev Suraski	ulong num_key;
138573b4602SAndi Gutmans	int i;
139573b4602SAndi Gutmans
140b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
141d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
142573b4602SAndi Gutmans	}
143d3d02fbcSDmitry Stogov	ZEND_PUTS_EX("(\n");
14480bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
1457652a977SDmitry Stogov	ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
146887189caSDmitry Stogov		if (Z_TYPE_P(tmp) == IS_INDIRECT) {
147887189caSDmitry Stogov			tmp = Z_INDIRECT_P(tmp);
148887189caSDmitry Stogov			if (Z_TYPE_P(tmp) == IS_UNDEF) {
149887189caSDmitry Stogov				continue;
150887189caSDmitry Stogov			}
151887189caSDmitry Stogov		}
152b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
153d3d02fbcSDmitry Stogov			ZEND_PUTS_EX(" ");
154573b4602SAndi Gutmans		}
155d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("[");
1567652a977SDmitry Stogov		if (string_key) {
1577652a977SDmitry Stogov			if (is_object) {
1587652a977SDmitry Stogov				const char *prop_name, *class_name;
1597652a977SDmitry Stogov				int prop_len;
1607652a977SDmitry Stogov				int mangled = zend_unmangle_property_name_ex(string_key->val, string_key->len, &class_name, &prop_name, &prop_len);
1617652a977SDmitry Stogov
1627652a977SDmitry Stogov				ZEND_WRITE_EX(prop_name, prop_len);
1637652a977SDmitry Stogov				if (class_name && mangled == SUCCESS) {
1647652a977SDmitry Stogov					if (class_name[0]=='*') {
1657652a977SDmitry Stogov						ZEND_PUTS_EX(":protected");
1667652a977SDmitry Stogov					} else {
1677652a977SDmitry Stogov						ZEND_PUTS_EX(":");
1687652a977SDmitry Stogov						ZEND_PUTS_EX(class_name);
1697652a977SDmitry Stogov						ZEND_PUTS_EX(":private");
170d329ce93SZeev Suraski					}
171d3d02fbcSDmitry Stogov				}
1727652a977SDmitry Stogov			} else {
1737652a977SDmitry Stogov				ZEND_WRITE_EX(string_key->val, string_key->len);
1747652a977SDmitry Stogov			}
1757652a977SDmitry Stogov		} else {
1767652a977SDmitry Stogov			char key[25];
1777652a977SDmitry Stogov			snprintf(key, sizeof(key), "%ld", num_key);
1787652a977SDmitry Stogov			ZEND_PUTS_EX(key);
179573b4602SAndi Gutmans		}
180d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("] => ");
181f4cfaf36SDmitry Stogov		zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
182d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("\n");
1837652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
18480bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
185b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
186d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
187573b4602SAndi Gutmans	}
188d3d02fbcSDmitry Stogov	ZEND_PUTS_EX(")\n");
189573b4602SAndi Gutmans}
190b4892511SJani Taskinen/* }}} */
191573b4602SAndi Gutmans
192b4892511SJani Taskinenstatic void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
19327de54b0SAndi Gutmans{
194f4cfaf36SDmitry Stogov	zval *tmp;
195f4cfaf36SDmitry Stogov	zend_string *string_key;
196b4892511SJani Taskinen	ulong num_key;
197b4892511SJani Taskinen	int i = 0;
198b4892511SJani Taskinen
1990ade00c8SNikita Popov	ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
200b4892511SJani Taskinen		if (i++ > 0) {
201b4892511SJani Taskinen			ZEND_PUTS(",");
202b4892511SJani Taskinen		}
203b4892511SJani Taskinen		ZEND_PUTS("[");
2047652a977SDmitry Stogov		if (string_key) {
2057652a977SDmitry Stogov			ZEND_WRITE(string_key->val, string_key->len);
2067652a977SDmitry Stogov		} else {
2077652a977SDmitry Stogov			zend_printf("%ld", num_key);
208b4892511SJani Taskinen		}
209b4892511SJani Taskinen		ZEND_PUTS("] => ");
210f4cfaf36SDmitry Stogov		zend_print_flat_zval_r(tmp TSRMLS_CC);
2117652a977SDmitry Stogov	} ZEND_HASH_FOREACH_END();
21227de54b0SAndi Gutmans}
213b4892511SJani Taskinen/* }}} */
2147a87fcbbSZeev Suraski
215b4892511SJani TaskinenZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
216573b4602SAndi Gutmans{
217f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
218da9faa2cSZeev Suraski		*use_copy = 0;
219da9faa2cSZeev Suraski		return;
220da9faa2cSZeev Suraski	}
221f3a6c30cSXinchen Hui
222f3a6c30cSXinchen Huiagain:
223b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
22417d027edSDmitry Stogov		case IS_NULL:
22517d027edSDmitry Stogov		case IS_FALSE: {
22620f2e598SNikita Popov			TSRMLS_FETCH();
22776cc99feSDmitry Stogov			ZVAL_EMPTY_STRING(expr_copy);
2288c4ab98eSThies C. Arntzen			break;
22920f2e598SNikita Popov		}
23017d027edSDmitry Stogov		case IS_TRUE:
23117d027edSDmitry Stogov			// TODO: use interned string ???
23217d027edSDmitry Stogov			ZVAL_NEW_STR(expr_copy, STR_INIT("1", 1, 0));
233da9faa2cSZeev Suraski			break;
234f4cfaf36SDmitry Stogov		case IS_RESOURCE: {
235f4cfaf36SDmitry Stogov				char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
236f4cfaf36SDmitry Stogov				int len;
237f4cfaf36SDmitry Stogov
238f4cfaf36SDmitry Stogov				len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(expr));
23976cc99feSDmitry Stogov				ZVAL_NEW_STR(expr_copy, STR_INIT(buf, len, 0));
240f4cfaf36SDmitry Stogov			}
241da9faa2cSZeev Suraski			break;
242da9faa2cSZeev Suraski		case IS_ARRAY:
243d81ea16eSStanislav Malyshev			zend_error(E_NOTICE, "Array to string conversion");
244050d7e38SDmitry Stogov			// TODO: use interned string ???
24576cc99feSDmitry Stogov			ZVAL_NEW_STR(expr_copy, STR_INIT("Array", sizeof("Array") - 1, 0));
246da9faa2cSZeev Suraski			break;
2471b282b35SAndi Gutmans		case IS_OBJECT:
2487901a221SAndi Gutmans			{
249ae2bfb78SSterling Hughes				TSRMLS_FETCH();
250637a4042SMarcus Boerger
251750e4e10SDmitry Stogov				if (Z_OBJ_HANDLER_P(expr, cast_object)) {
252f4cfaf36SDmitry Stogov					zval val;
253750e4e10SDmitry Stogov
25417bf59f8SDmitry Stogov					ZVAL_DUP_DEREF(&val, expr);
255f4cfaf36SDmitry Stogov					if (Z_OBJ_HANDLER_P(expr, cast_object)(&val, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
256750e4e10SDmitry Stogov						zval_ptr_dtor(&val);
257750e4e10SDmitry Stogov						break;
258750e4e10SDmitry Stogov					}
259750e4e10SDmitry Stogov					zval_ptr_dtor(&val);
260848c5c76SMarcus Boerger				}
261b3c3c6deSMarcus Boerger				if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
262a0690ff2SXinchen Hui					zval rv;
263a0690ff2SXinchen Hui					zval *z = Z_OBJ_HANDLER_P(expr, get)(expr, &rv TSRMLS_CC);
2647addae50SMarcus Boerger
2654b4d634cSYiduo (David) Wang					Z_ADDREF_P(z);
266b4892511SJani Taskinen					if (Z_TYPE_P(z) != IS_OBJECT) {
267b3c3c6deSMarcus Boerger						zend_make_printable_zval(z, expr_copy, use_copy);
268b3c3c6deSMarcus Boerger						if (*use_copy) {
269f4cfaf36SDmitry Stogov							zval_ptr_dtor(z);
270b3c3c6deSMarcus Boerger						} else {
271b3c3c6deSMarcus Boerger							ZVAL_ZVAL(expr_copy, z, 0, 1);
272b3c3c6deSMarcus Boerger							*use_copy = 1;
2733b8b43a9SStanislav Malyshev						}
274b3c3c6deSMarcus Boerger						return;
2753b8b43a9SStanislav Malyshev					}
276f4cfaf36SDmitry Stogov					zval_ptr_dtor(z);
27771ba4427SMarcus Boerger				}
278f4cfaf36SDmitry Stogov				zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name->val);
27976cc99feSDmitry Stogov				ZVAL_EMPTY_STRING(expr_copy);
280ae2bfb78SSterling Hughes			}
281da9faa2cSZeev Suraski			break;
282e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
283f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
284e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
285e842ef9fSIlia Alshanetsky			break;
286f3a6c30cSXinchen Hui		case IS_REFERENCE:
287f3a6c30cSXinchen Hui			expr = Z_REFVAL_P(expr);
288f3a6c30cSXinchen Hui			if (Z_TYPE_P(expr) == IS_STRING) {
289f3a6c30cSXinchen Hui				ZVAL_STR(expr_copy, STR_COPY(Z_STR_P(expr)));
290f3a6c30cSXinchen Hui				*use_copy = 1;
291f3a6c30cSXinchen Hui				return;
292f3a6c30cSXinchen Hui			}
293f3a6c30cSXinchen Hui			goto again;
294f3a6c30cSXinchen Hui			break;
295da9faa2cSZeev Suraski		default:
296f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
297da9faa2cSZeev Suraski			convert_to_string(expr_copy);
298da9faa2cSZeev Suraski			break;
299da9faa2cSZeev Suraski	}
300da9faa2cSZeev Suraski	*use_copy = 1;
301da9faa2cSZeev Suraski}
302b4892511SJani Taskinen/* }}} */
303da9faa2cSZeev Suraski
304bda96e3cSNikita PopovZEND_API int zend_print_zval(zval *expr, int indent TSRMLS_DC) /* {{{ */
305da9faa2cSZeev Suraski{
306bda96e3cSNikita Popov	return zend_print_zval_ex(zend_write, expr, indent TSRMLS_CC);
3075dba4774SZeev Suraski}
308b4892511SJani Taskinen/* }}} */
3095dba4774SZeev Suraski
310bda96e3cSNikita PopovZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
3115dba4774SZeev Suraski{
3124ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
313bda96e3cSNikita Popov	int len = str->len;
314da9faa2cSZeev Suraski
315bda96e3cSNikita Popov	if (len != 0) {
316bda96e3cSNikita Popov		write_func(str->val, len);
317573b4602SAndi Gutmans	}
318bda96e3cSNikita Popov
319bda96e3cSNikita Popov	STR_RELEASE(str);
320bda96e3cSNikita Popov	return len;
321573b4602SAndi Gutmans}
322b4892511SJani Taskinen/* }}} */
323573b4602SAndi Gutmans
324b4892511SJani TaskinenZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
32527de54b0SAndi Gutmans{
326b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
327b4892511SJani Taskinen		case IS_ARRAY:
328b4892511SJani Taskinen			ZEND_PUTS("Array (");
329b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
330b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
331b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
33272c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
333b4892511SJani Taskinen				return;
334b4892511SJani Taskinen			}
335b4892511SJani Taskinen			print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
336b4892511SJani Taskinen			ZEND_PUTS(")");
337b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
338b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
339b3b616cfSDmitry Stogov			}
340b4892511SJani Taskinen			break;
341b4892511SJani Taskinen		case IS_OBJECT:
342b4892511SJani Taskinen		{
3439bba373aSStanislav Malyshev			HashTable *properties = NULL;
344f4cfaf36SDmitry Stogov			zend_string *class_name = NULL;
3458ce1211aSMarcus Boerger
346f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
347ea85451bSDmitry Stogov				class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr), 0 TSRMLS_CC);
3489bba373aSStanislav Malyshev			}
349b4892511SJani Taskinen			if (class_name) {
350f4cfaf36SDmitry Stogov				zend_printf("%s Object (", class_name->val);
351b4892511SJani Taskinen			} else {
352b4892511SJani Taskinen				zend_printf("%s Object (", "Unknown Class");
353b4892511SJani Taskinen			}
354288daccaSAndi Gutmans			if (class_name) {
355d062fb33SDmitry Stogov				STR_RELEASE(class_name);
3569bba373aSStanislav Malyshev			}
357f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3589bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3599bba373aSStanislav Malyshev			}
360f30f3590SStanislav Malyshev			if (properties) {
36172c287bdSDmitry Stogov				if (++properties->u.v.nApplyCount>1) {
3629bba373aSStanislav Malyshev					ZEND_PUTS(" *RECURSION*");
36372c287bdSDmitry Stogov					properties->u.v.nApplyCount--;
3649bba373aSStanislav Malyshev					return;
3659bba373aSStanislav Malyshev				}
36624db7f18SSebastian Bergmann				print_flat_hash(properties TSRMLS_CC);
36772c287bdSDmitry Stogov				properties->u.v.nApplyCount--;
3689bba373aSStanislav Malyshev			}
3699bba373aSStanislav Malyshev			ZEND_PUTS(")");
3709bba373aSStanislav Malyshev			break;
371b4892511SJani Taskinen		}
372b4892511SJani Taskinen		default:
373bda96e3cSNikita Popov			zend_print_variable(expr TSRMLS_CC);
374b4892511SJani Taskinen			break;
375b4892511SJani Taskinen	}
37627de54b0SAndi Gutmans}
377b4892511SJani Taskinen/* }}} */
378573b4602SAndi Gutmans
379b4892511SJani TaskinenZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
3805dba4774SZeev Suraski{
38124db7f18SSebastian Bergmann	zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
3825dba4774SZeev Suraski}
383b4892511SJani Taskinen/* }}} */
3845dba4774SZeev Suraski
385b4892511SJani TaskinenZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
386573b4602SAndi Gutmans{
387c6cba554SDmitry Stogov	ZVAL_DEREF(expr);
388b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
389573b4602SAndi Gutmans		case IS_ARRAY:
390d3d02fbcSDmitry Stogov			ZEND_PUTS_EX("Array\n");
391b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
392b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
393d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" *RECURSION*");
39472c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
3956053f2a1SZeev Suraski				return;
3966053f2a1SZeev Suraski			}
397d3d02fbcSDmitry Stogov			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
398b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
399b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
400b3b616cfSDmitry Stogov			}
401573b4602SAndi Gutmans			break;
402573b4602SAndi Gutmans		case IS_OBJECT:
403c259cb7cSAndi Gutmans			{
4048ce1211aSMarcus Boerger				HashTable *properties;
405f4cfaf36SDmitry Stogov				zend_string *class_name = NULL;
4068ce1211aSMarcus Boerger				int is_temp;
4078ce1211aSMarcus Boerger
408f30f3590SStanislav Malyshev				if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
409ea85451bSDmitry Stogov					class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr), 0 TSRMLS_CC);
4109bba373aSStanislav Malyshev				}
411f1fb77d1SIlia Alshanetsky				if (class_name) {
412f4cfaf36SDmitry Stogov					ZEND_PUTS_EX(class_name->val);
413f1fb77d1SIlia Alshanetsky				} else {
414d3d02fbcSDmitry Stogov					ZEND_PUTS_EX("Unknown Class");
415f1fb77d1SIlia Alshanetsky				}
416d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" Object\n");
417288daccaSAndi Gutmans				if (class_name) {
418bdeaf2efSDmitry Stogov					STR_RELEASE(class_name);
4199bba373aSStanislav Malyshev				}
4208ce1211aSMarcus Boerger				if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
4218ce1211aSMarcus Boerger					break;
4229bba373aSStanislav Malyshev				}
42372c287bdSDmitry Stogov				if (++properties->u.v.nApplyCount>1) {
424d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(" *RECURSION*");
42572c287bdSDmitry Stogov					properties->u.v.nApplyCount--;
4268ce1211aSMarcus Boerger					return;
4278ce1211aSMarcus Boerger				}
428d3d02fbcSDmitry Stogov				print_hash(write_func, properties, indent, 1 TSRMLS_CC);
42972c287bdSDmitry Stogov				properties->u.v.nApplyCount--;
4308ce1211aSMarcus Boerger				if (is_temp) {
4318ce1211aSMarcus Boerger					zend_hash_destroy(properties);
4324e7cbf3fSDmitry Stogov					FREE_HASHTABLE(properties);
433c259cb7cSAndi Gutmans				}
434c259cb7cSAndi Gutmans				break;
4356053f2a1SZeev Suraski			}
436573b4602SAndi Gutmans		default:
437bda96e3cSNikita Popov			zend_print_zval_ex(write_func, expr, indent TSRMLS_CC);
438573b4602SAndi Gutmans			break;
439573b4602SAndi Gutmans	}
440573b4602SAndi Gutmans}
441b4892511SJani Taskinen/* }}} */
442573b4602SAndi Gutmans
44385ab4235SFelipe Penastatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
444573b4602SAndi Gutmans{
4455463dd5bSAndi Gutmans	if (opened_path) {
44627de5001SAndi Gutmans		*opened_path = estrdup(filename);
4475463dd5bSAndi Gutmans	}
448f311ab16SAndi Gutmans	return fopen(filename, "rb");
449573b4602SAndi Gutmans}
450b4892511SJani Taskinen/* }}} */
451573b4602SAndi Gutmans
4522f586e96SDmitry Stogov#ifdef ZTS
4538c885b89SDmitry Stogovstatic zend_bool asp_tags_default		  = 0;
4548c885b89SDmitry Stogovstatic zend_bool short_tags_default		  = 1;
4558c885b89SDmitry Stogovstatic zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
4562f586e96SDmitry Stogov#else
4578c885b89SDmitry Stogov# define asp_tags_default			0
4588c885b89SDmitry Stogov# define short_tags_default			1
4598c885b89SDmitry Stogov# define compiler_options_default	ZEND_COMPILE_DEFAULT
4602f586e96SDmitry Stogov#endif
4612f586e96SDmitry Stogov
462b4892511SJani Taskinenstatic void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
4638b794bb1SZeev Suraski{
4648b794bb1SZeev Suraski	/* default compile-time values */
4652f586e96SDmitry Stogov	CG(asp_tags) = asp_tags_default;
4662f586e96SDmitry Stogov	CG(short_tags) = short_tags_default;
4678c885b89SDmitry Stogov	CG(compiler_options) = compiler_options_default;
4688b794bb1SZeev Suraski}
469b4892511SJani Taskinen/* }}} */
4708b794bb1SZeev Suraski
471fcaa1c6dSDmitry Stogovstatic void zend_init_exception_op(TSRMLS_D) /* {{{ */
472fcaa1c6dSDmitry Stogov{
473fcaa1c6dSDmitry Stogov	memset(EG(exception_op), 0, sizeof(EG(exception_op)));
474fcaa1c6dSDmitry Stogov	EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
47594dd8372SDmitry Stogov	EG(exception_op)[0].op1_type = IS_UNUSED;
47694dd8372SDmitry Stogov	EG(exception_op)[0].op2_type = IS_UNUSED;
47794dd8372SDmitry Stogov	EG(exception_op)[0].result_type = IS_UNUSED;
478fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
479fcaa1c6dSDmitry Stogov	EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
48094dd8372SDmitry Stogov	EG(exception_op)[1].op1_type = IS_UNUSED;
48194dd8372SDmitry Stogov	EG(exception_op)[1].op2_type = IS_UNUSED;
48294dd8372SDmitry Stogov	EG(exception_op)[1].result_type = IS_UNUSED;
483fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
484fcaa1c6dSDmitry Stogov	EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
48594dd8372SDmitry Stogov	EG(exception_op)[2].op1_type = IS_UNUSED;
48694dd8372SDmitry Stogov	EG(exception_op)[2].op2_type = IS_UNUSED;
48794dd8372SDmitry Stogov	EG(exception_op)[2].result_type = IS_UNUSED;
488fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
489fcaa1c6dSDmitry Stogov}
490fcaa1c6dSDmitry Stogov/* }}} */
491fcaa1c6dSDmitry Stogov
4927a87fcbbSZeev Suraski#ifdef ZTS
4933ce96eabSNikita Popovstatic void function_copy_ctor(zval *zv)
4943ce96eabSNikita Popov{
4953ce96eabSNikita Popov	zend_function *old_func = Z_FUNC_P(zv);
4963ce96eabSNikita Popov	Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1);
4973ce96eabSNikita Popov	memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function));
4983ce96eabSNikita Popov	function_add_ref(Z_FUNC_P(zv));
4993ce96eabSNikita Popov}
5003ce96eabSNikita Popov
501b4892511SJani Taskinenstatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5027a87fcbbSZeev Suraski{
5037f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
5047f4909d9SThies C. Arntzen
505f7f5a5eaSStanislav Malyshev	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
50672c287bdSDmitry Stogov	zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
5073ce96eabSNikita Popov	zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor);
5087a87fcbbSZeev Suraski
509b4892511SJani Taskinen	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
51072c287bdSDmitry Stogov	zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
5112b9b9afaSDmitry Stogov	zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
5129cf1a98dSThies C. Arntzen
513b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
51485b4df53SZeev Suraski
51585b4df53SZeev Suraski	CG(interactive) = 0;
5169d11db12SAndi Gutmans
5179d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
5189d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
51920f2e598SNikita Popov	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL /* empty element */);
5208768ab94SDmitry Stogov
5218768ab94SDmitry Stogov	compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
5228768ab94SDmitry Stogov	if (compiler_globals->last_static_member) {
523f23e8576SDmitry Stogov		compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval**));
5248768ab94SDmitry Stogov	} else {
525f23e8576SDmitry Stogov		compiler_globals->static_members_table = NULL;
5268768ab94SDmitry Stogov	}
527ae0e5a0cSAntony Dovgal	compiler_globals->script_encoding_list = NULL;
5287a87fcbbSZeev Suraski}
529b4892511SJani Taskinen/* }}} */
5307a87fcbbSZeev Suraski
531b4892511SJani Taskinenstatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5327a87fcbbSZeev Suraski{
533ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
53474a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
5358fb5ea30SMarcus Boerger		free(compiler_globals->function_table);
53674a9ed7bSZeev Suraski	}
537ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
53874a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
5398fb5ea30SMarcus Boerger		free(compiler_globals->class_table);
54074a9ed7bSZeev Suraski	}
5418fb5ea30SMarcus Boerger	if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
5429d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
5439d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
5449d11db12SAndi Gutmans	}
545f23e8576SDmitry Stogov	if (compiler_globals->static_members_table) {
546f23e8576SDmitry Stogov		free(compiler_globals->static_members_table);
5478768ab94SDmitry Stogov	}
548bbf3d43cSMoriyoshi Koizumi	if (compiler_globals->script_encoding_list) {
549bbf3d43cSMoriyoshi Koizumi		pefree(compiler_globals->script_encoding_list, 1);
550bbf3d43cSMoriyoshi Koizumi	}
5518768ab94SDmitry Stogov	compiler_globals->last_static_member = 0;
5527a87fcbbSZeev Suraski}
553b4892511SJani Taskinen/* }}} */
554a9f9ae79SZeev Suraski
555b4892511SJani Taskinenstatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
556a9f9ae79SZeev Suraski{
5575fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
5585fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
5592c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
560fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
561b4892511SJani Taskinen	EG(lambda_count) = 0;
56220f2e598SNikita Popov	ZVAL_UNDEF(&EG(user_error_handler));
56320f2e598SNikita Popov	ZVAL_UNDEF(&EG(user_exception_handler));
564ab30c8ccSZeev Suraski	EG(in_execution) = 0;
56555cf45abSDmitry Stogov	EG(in_autoload) = NULL;
566e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
56752303217SMarcus Boerger	EG(current_module) = NULL;
5689d576212SAntony Dovgal	EG(exit_status) = 0;
569ee4f5ac1SFelipe Pena#if XPFPA_HAVE_CW
570ee4f5ac1SFelipe Pena	EG(saved_fpu_cw) = 0;
571ee4f5ac1SFelipe Pena#endif
57225710a40SFelipe Pena	EG(saved_fpu_cw_ptr) = NULL;
573d6ee9d48SAntony Dovgal	EG(active) = 0;
574a9f9ae79SZeev Suraski}
575b4892511SJani Taskinen/* }}} */
576a9f9ae79SZeev Suraski
577b4892511SJani Taskinenstatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
578a9f9ae79SZeev Suraski{
5792c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
58021698c12SDmitry Stogov	if (&executor_globals->persistent_list != global_persistent_list) {
58121698c12SDmitry Stogov		zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
58221698c12SDmitry Stogov	}
58321698c12SDmitry Stogov	if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
58421698c12SDmitry Stogov		zend_hash_destroy(executor_globals->zend_constants);
58521698c12SDmitry Stogov		free(executor_globals->zend_constants);
58621698c12SDmitry Stogov	}
587a9f9ae79SZeev Suraski}
588b4892511SJani Taskinen/* }}} */
589a9f9ae79SZeev Suraski
590b4892511SJani Taskinenstatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
591609d58a4SZeev Suraski{
592a84a2eaeSDmitry Stogov	if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
593a84a2eaeSDmitry Stogov		zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
594a84a2eaeSDmitry Stogov	}
595609d58a4SZeev Suraski}
596b4892511SJani Taskinen/* }}} */
59766d9314bSZeev Suraski#endif
59866d9314bSZeev Suraski
599d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
600d46f8078SJon Parise/* FreeBSD and DragonFly floating point precision fix */
6015928970dSAndi Gutmans#include <floatingpoint.h>
6025928970dSAndi Gutmans#endif
6037a87fcbbSZeev Suraski
604af316021SMarcus Boergerstatic void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
605af316021SMarcus Boerger{
606af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
607af316021SMarcus Boerger}
608af316021SMarcus Boerger/* }}} */
609af316021SMarcus Boerger
610af316021SMarcus Boergerstatic void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
61154d53055SZeev Suraski{
612af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
61354d53055SZeev Suraski}
614b4892511SJani Taskinen/* }}} */
61554d53055SZeev Suraski
616226c56feSJani Taskinenvoid zend_init_opcodes_handlers(void);
61754d53055SZeev Suraski
6182b9b9afaSDmitry Stogovstatic void module_destructor_zval(zval *zv) /* {{{ */
6192b9b9afaSDmitry Stogov{
6202b9b9afaSDmitry Stogov	zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
6212b9b9afaSDmitry Stogov
6222b9b9afaSDmitry Stogov	module_destructor(module);
6232b9b9afaSDmitry Stogov	free(module);
6242b9b9afaSDmitry Stogov}
6252b9b9afaSDmitry Stogov/* }}} */
6262b9b9afaSDmitry Stogov
6272b9b9afaSDmitry Stogovstatic void auto_global_dtor(zval *zv) /* {{{ */
6282b9b9afaSDmitry Stogov{
6292b9b9afaSDmitry Stogov	free(Z_PTR_P(zv));
6302b9b9afaSDmitry Stogov}
6312b9b9afaSDmitry Stogov/* }}} */
6322b9b9afaSDmitry Stogov
633f4cfaf36SDmitry Stogovstatic zend_bool php_auto_globals_create_globals(zend_string *name TSRMLS_DC) /* {{{ */
634f0c8366aSDmitry Stogov{
635f4cfaf36SDmitry Stogov	zval globals;
636f4cfaf36SDmitry Stogov
637f4cfaf36SDmitry Stogov	ZVAL_ARR(&globals, &EG(symbol_table));
638f4cfaf36SDmitry Stogov	ZVAL_NEW_REF(&globals, &globals);
639f4cfaf36SDmitry Stogov	zend_hash_update(&EG(symbol_table).ht, name, &globals);
640f0c8366aSDmitry Stogov	return 0;
641f0c8366aSDmitry Stogov}
642f0c8366aSDmitry Stogov/* }}} */
643f0c8366aSDmitry Stogov
6442faea53dSMarcus Boergerint zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
645573b4602SAndi Gutmans{
646a9f9ae79SZeev Suraski#ifdef ZTS
6477c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
648a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
649609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
650609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
651609d58a4SZeev Suraski#else
652af316021SMarcus Boerger	extern zend_ini_scanner_globals ini_scanner_globals;
653af316021SMarcus Boerger	extern zend_php_scanner_globals language_scanner_globals;
654609d58a4SZeev Suraski#endif
655a9f9ae79SZeev Suraski
65629ed52ffSDmitry Stogov	start_memory_manager(TSRMLS_C);
657a9f9ae79SZeev Suraski
658cf6ab0e9SAnatol Belski	virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
659cf6ab0e9SAnatol Belski
660d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
661d46f8078SJon Parise	/* FreeBSD and DragonFly floating point precision fix */
662c3340584SSascha Schumann	fpsetmask(0);
6635928970dSAndi Gutmans#endif
664309827ecSZeev Suraski
6654d44a5b7SAntony Dovgal	zend_startup_strtod();
666309827ecSZeev Suraski	zend_startup_extensions_mechanism();
667309827ecSZeev Suraski
668573b4602SAndi Gutmans	/* Set up utility functions and values */
66967f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
670573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
6715dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
672573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
673573b4602SAndi Gutmans	if (!zend_fopen) {
674573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
675573b4602SAndi Gutmans	}
676e52aac94SWez Furlong	zend_stream_open_function = utility_functions->stream_open_function;
67756251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
67834d93f0cSIlia Alshanetsky#ifndef ZEND_SIGNALS
679573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
680573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
68134d93f0cSIlia Alshanetsky#endif
682903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
683fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
684bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
685d45fd8a1SMarcus Boerger	zend_vspprintf = utility_functions->vspprintf_function;
68688c550a7SXinchen Hui	zend_vstrpprintf = utility_functions->vstrpprintf_function;
68785a36e2bSZeev Suraski	zend_getenv = utility_functions->getenv_function;
688ab232458SDmitry Stogov	zend_resolve_path = utility_functions->resolve_path_function;
689d035af4aSZeev Suraski
69008b9fdc8SDavid Soria Parra#if HAVE_DTRACE
69108b9fdc8SDavid Soria Parra/* build with dtrace support */
69208b9fdc8SDavid Soria Parra	zend_compile_file = dtrace_compile_file;
69370f83f35SDmitry Stogov	zend_execute_ex = dtrace_execute_ex;
69408b9fdc8SDavid Soria Parra	zend_execute_internal = dtrace_execute_internal;
69508b9fdc8SDavid Soria Parra#else
696c06692e9SZeev Suraski	zend_compile_file = compile_file;
69770f83f35SDmitry Stogov	zend_execute_ex = execute_ex;
6982c44fab3SDerick Rethans	zend_execute_internal = NULL;
69908b9fdc8SDavid Soria Parra#endif /* HAVE_SYS_SDT_H */
70008b9fdc8SDavid Soria Parra	zend_compile_string = compile_string;
701979da661SAndi Gutmans	zend_throw_exception_hook = NULL;
702573b4602SAndi Gutmans
703cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
704cf36abb2SAndi Gutmans
705573b4602SAndi Gutmans	/* set up version */
706573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
707b4892511SJani Taskinen	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
708b4892511SJani Taskinen
709b4892511SJani Taskinen	GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
710b4892511SJani Taskinen	GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
711b4892511SJani Taskinen	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
712b4892511SJani Taskinen	GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
713573b4602SAndi Gutmans
71472c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
71572c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
7162b9b9afaSDmitry Stogov	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
71772c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0);
7182eabb14dSAndi Gutmans
71972c287bdSDmitry Stogov	zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0);
7204cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
721573b4602SAndi Gutmans
7227a87fcbbSZeev Suraski#ifdef ZTS
7232c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
7242c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
725af316021SMarcus Boerger	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
726af316021SMarcus Boerger	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
7277c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
728a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
7295fcae67eSZeev Suraski
7308fb5ea30SMarcus Boerger	compiler_globals_dtor(compiler_globals TSRMLS_CC);
7312a8426a6SMarcus Boerger	compiler_globals->in_compilation = 0;
7328fb5ea30SMarcus Boerger	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
7338fb5ea30SMarcus Boerger	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
7348fb5ea30SMarcus Boerger
735f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
736f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
7379d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
7385fcae67eSZeev Suraski
7395fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
7405fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
741762158aaSAndi Gutmans#else
742af316021SMarcus Boerger	ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
743af316021SMarcus Boerger	php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
744b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
745f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_error_handler));
746f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_exception_handler));
7477a87fcbbSZeev Suraski#endif
748826cc0dcSMarcus Boerger
749dd5c478bSDmitry Stogov	zend_interned_strings_init(TSRMLS_C);
7502faea53dSMarcus Boerger	zend_startup_builtin_functions(TSRMLS_C);
7512c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
7522b9b9afaSDmitry Stogov	zend_register_auto_global(STR_INIT("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals TSRMLS_CC);
7537a87fcbbSZeev Suraski
754bfbe8618SZeev Suraski#ifndef ZTS
7552c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
756fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
757bfbe8618SZeev Suraski#endif
758a9f9ae79SZeev Suraski
7592c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
76054d53055SZeev Suraski
76154d53055SZeev Suraski#ifdef ZTS
76254d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
76354d53055SZeev Suraski#endif
76454d53055SZeev Suraski
765573b4602SAndi Gutmans	return SUCCESS;
766573b4602SAndi Gutmans}
767b4892511SJani Taskinen/* }}} */
768573b4602SAndi Gutmans
769b4892511SJani Taskinenvoid zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
7704be862b0SZeev Suraski{
7714be862b0SZeev Suraski	int module_number = 0;
7724be862b0SZeev Suraski
7734be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
7744be862b0SZeev Suraski}
775b4892511SJani Taskinen/* }}} */
7764be862b0SZeev Suraski
777711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
778711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
779711be83dSZeev Suraski */
780b4892511SJani Taskinenvoid zend_post_startup(TSRMLS_D) /* {{{ */
781711be83dSZeev Suraski{
782b4892511SJani Taskinen#ifdef ZTS
78372f19e9aSXinchen Hui	zend_encoding **script_encoding_list;
78472f19e9aSXinchen Hui
785711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
7865fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
787711be83dSZeev Suraski
7885fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
7895fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
7905fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
7912f586e96SDmitry Stogov
7922f586e96SDmitry Stogov	asp_tags_default = CG(asp_tags);
7932f586e96SDmitry Stogov	short_tags_default = CG(short_tags);
7948c885b89SDmitry Stogov	compiler_options_default = CG(compiler_options);
7958ce1211aSMarcus Boerger
796b817dab2SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
7978fb5ea30SMarcus Boerger	free(compiler_globals->function_table);
7988fb5ea30SMarcus Boerger	free(compiler_globals->class_table);
79972f19e9aSXinchen Hui	if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
80072f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
80172f19e9aSXinchen Hui		compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
80272f19e9aSXinchen Hui	} else {
80372f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
80472f19e9aSXinchen Hui	}
8058fb5ea30SMarcus Boerger	free(EG(zend_constants));
806cf6ab0e9SAnatol Belski
807cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
808cf6ab0e9SAnatol Belski
8095fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
81021698c12SDmitry Stogov	global_persistent_list = &EG(persistent_list);
811a84a2eaeSDmitry Stogov	zend_copy_ini_directives(TSRMLS_C);
812cf6ab0e9SAnatol Belski#else
813cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
814711be83dSZeev Suraski#endif
815b4892511SJani Taskinen}
816b4892511SJani Taskinen/* }}} */
817711be83dSZeev Suraski
818b4892511SJani Taskinenvoid zend_shutdown(TSRMLS_D) /* {{{ */
819573b4602SAndi Gutmans{
82034d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
82134d93f0cSIlia Alshanetsky	zend_signal_shutdown(TSRMLS_C);
82234d93f0cSIlia Alshanetsky#endif
82384eb48f0SZeev Suraski#ifdef ZEND_WIN32
82484eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
82584eb48f0SZeev Suraski#endif
8269e1beb4fSDmitry Stogov	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
8271a1178a6SDmitry Stogov	zend_destroy_modules();
8283458373eSAndi Gutmans
829cf6ab0e9SAnatol Belski 	virtual_cwd_deactivate(TSRMLS_C);
830cf6ab0e9SAnatol Belski 	virtual_cwd_shutdown();
831cf6ab0e9SAnatol Belski
8327a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
83376b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
8343458373eSAndi Gutmans
8359d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
8369d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
8372da8b014Sfoobar
838d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
839573b4602SAndi Gutmans	free(zend_version_info);
84048b33032SSterling Hughes
841a2513618SMarcus Boerger	free(GLOBAL_FUNCTION_TABLE);
842a2513618SMarcus Boerger	free(GLOBAL_CLASS_TABLE);
84321698c12SDmitry Stogov
84448b33032SSterling Hughes	zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
845a54c7dcbSMarcus Boerger	free(GLOBAL_CONSTANTS_TABLE);
8464d44a5b7SAntony Dovgal	zend_shutdown_strtod();
847b4892511SJani Taskinen
84821698c12SDmitry Stogov#ifdef ZTS
8498fb5ea30SMarcus Boerger	GLOBAL_FUNCTION_TABLE = NULL;
8508fb5ea30SMarcus Boerger	GLOBAL_CLASS_TABLE = NULL;
8518fb5ea30SMarcus Boerger	GLOBAL_AUTO_GLOBALS_TABLE = NULL;
85221698c12SDmitry Stogov	GLOBAL_CONSTANTS_TABLE = NULL;
853a17d2f37SSebastian Bergmann#endif
8544c283fffSIlia Alshanetsky	zend_destroy_rsrc_list_dtors();
855dd5c478bSDmitry Stogov
856dd5c478bSDmitry Stogov	zend_interned_strings_dtor(TSRMLS_C);
857573b4602SAndi Gutmans}
858b4892511SJani Taskinen/* }}} */
859573b4602SAndi Gutmans
860b4892511SJani Taskinenvoid zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
8617656c77cSZeev Suraski{
8627656c77cSZeev Suraski	zend_uv = *utility_values;
8639baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
8647656c77cSZeev Suraski}
865b4892511SJani Taskinen/* }}} */
8667656c77cSZeev Suraski
867573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
868cf7384aaSFelipe Penavoid zenderror(const char *error) /* {{{ */
869573b4602SAndi Gutmans{
87010def9a8SIlia Alshanetsky	zend_error(E_PARSE, "%s", error);
871573b4602SAndi Gutmans}
872b4892511SJani Taskinen/* }}} */
873573b4602SAndi Gutmans
874b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
875b4892511SJani TaskinenZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
876573b4602SAndi Gutmans{
8772c254ba7SZeev Suraski	TSRMLS_FETCH();
878573b4602SAndi Gutmans
87914f6b914SDmitry Stogov	if (!EG(bailout)) {
880ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
881931ebe08SZeev Suraski		exit(-1);
882931ebe08SZeev Suraski	}
8836bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
88408b3d76cSFelipe Pena	CG(active_class_entry) = NULL;
885b23d83cfSZeev Suraski	CG(in_compilation) = EG(in_execution) = 0;
886bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
88710afe5d9SRasmus Lerdorf	LONGJMP(*EG(bailout), FAILURE);
888573b4602SAndi Gutmans}
889b4892511SJani Taskinen/* }}} */
890b0bfa458SZeev SuraskiEND_EXTERN_C()
891573b4602SAndi Gutmans
892cf7384aaSFelipe Penavoid zend_append_version_info(const zend_extension *extension) /* {{{ */
893573b4602SAndi Gutmans{
894573b4602SAndi Gutmans	char *new_info;
895573b4602SAndi Gutmans	uint new_info_length;
896573b4602SAndi Gutmans
897ed7b3e70SPierrick Charron	new_info_length = sizeof("    with  v, , by \n")
898573b4602SAndi Gutmans						+ strlen(extension->name)
899573b4602SAndi Gutmans						+ strlen(extension->version)
900573b4602SAndi Gutmans						+ strlen(extension->copyright)
901573b4602SAndi Gutmans						+ strlen(extension->author);
902573b4602SAndi Gutmans
903b4892511SJani Taskinen	new_info = (char *) malloc(new_info_length + 1);
904573b4602SAndi Gutmans
905ed7b3e70SPierrick Charron	snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
906573b4602SAndi Gutmans
907b4892511SJani Taskinen	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
908ed7b3e70SPierrick Charron	strncat(zend_version_info, new_info, new_info_length);
909573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
910573b4602SAndi Gutmans	free(new_info);
911573b4602SAndi Gutmans}
912b4892511SJani Taskinen/* }}} */
913573b4602SAndi Gutmans
914b4892511SJani TaskinenZEND_API char *get_zend_version(void) /* {{{ */
915573b4602SAndi Gutmans{
916573b4602SAndi Gutmans	return zend_version_info;
917573b4602SAndi Gutmans}
918b4892511SJani Taskinen/* }}} */
919ed06a70fSZeev Suraski
920f046189eSkrakjoeZEND_API void zend_activate(TSRMLS_D) /* {{{ */
921ed06a70fSZeev Suraski{
922699f07baSAnatol Belski#ifdef ZTS
9239df78bf9SAnatol Belski	virtual_cwd_activate(TSRMLS_C);
924699f07baSAnatol Belski#endif
92571592cecSDmitry Stogov	gc_reset(TSRMLS_C);
926b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
927b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
928b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
929ed06a70fSZeev Suraski}
930b4892511SJani Taskinen/* }}} */
931ed06a70fSZeev Suraski
932b4892511SJani Taskinenvoid zend_call_destructors(TSRMLS_D) /* {{{ */
9330cd2da03SMarcus Boerger{
9340cd2da03SMarcus Boerger	zend_try {
9350cd2da03SMarcus Boerger		shutdown_destructors(TSRMLS_C);
9360cd2da03SMarcus Boerger	} zend_end_try();
9370cd2da03SMarcus Boerger}
938b4892511SJani Taskinen/* }}} */
9390cd2da03SMarcus Boerger
940f046189eSkrakjoeZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */
941ed06a70fSZeev Suraski{
942372f71ebSThies C. Arntzen	/* we're no longer executing anything */
943424e98f4SZeev Suraski	EG(opline_ptr) = NULL;
944372f71ebSThies C. Arntzen	EG(active_symbol_table) = NULL;
945f4c9d96fSThies C. Arntzen
946931ebe08SZeev Suraski	zend_try {
947b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
948931ebe08SZeev Suraski	} zend_end_try();
949931ebe08SZeev Suraski
9508084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
9512c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
952931ebe08SZeev Suraski
953931ebe08SZeev Suraski	zend_try {
954b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
955931ebe08SZeev Suraski	} zend_end_try();
956931ebe08SZeev Suraski
95759a46c34SDmitry Stogov	zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
95859a46c34SDmitry Stogov
9590d5121a3SAnatol Belski#if ZEND_DEBUG
96071592cecSDmitry Stogov	if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
96171592cecSDmitry Stogov		gc_collect_cycles(TSRMLS_C);
96271592cecSDmitry Stogov	}
96371592cecSDmitry Stogov#endif
96471592cecSDmitry Stogov
9653bd291e1SDerick Rethans#if GC_BENCH
96613d75ce6SDerick Rethans	fprintf(stderr, "GC Statistics\n");
96713d75ce6SDerick Rethans	fprintf(stderr, "-------------\n");
96813d75ce6SDerick Rethans	fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
96913d75ce6SDerick Rethans	fprintf(stderr, "Collected:          %d\n", GC_G(collected));
97013d75ce6SDerick Rethans	fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
97113d75ce6SDerick Rethans	fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
97213d75ce6SDerick Rethans	fprintf(stderr, "      Possible            Remove from  Marked\n");
97313d75ce6SDerick Rethans	fprintf(stderr, "        Root    Buffered     buffer     grey\n");
97413d75ce6SDerick Rethans	fprintf(stderr, "      --------  --------  -----------  ------\n");
97513d75ce6SDerick Rethans	fprintf(stderr, "ZVAL  %8d  %8d  %9d  %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey));
97613d75ce6SDerick Rethans	fprintf(stderr, "ZOBJ  %8d  %8d  %9d  %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey));
9773bd291e1SDerick Rethans#endif
9783bd291e1SDerick Rethans
979931ebe08SZeev Suraski	zend_try {
9802c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
981931ebe08SZeev Suraski	} zend_end_try();
982ed06a70fSZeev Suraski}
983b4892511SJani Taskinen/* }}} */
98456251a72SZeev Suraski
985fc173b6aSSam RubyBEGIN_EXTERN_C()
9864a25a774SDmitry StogovZEND_API void zend_message_dispatcher(long message, const void *data TSRMLS_DC) /* {{{ */
98756251a72SZeev Suraski{
98856251a72SZeev Suraski	if (zend_message_dispatcher_p) {
98985ab4235SFelipe Pena		zend_message_dispatcher_p(message, data TSRMLS_CC);
99056251a72SZeev Suraski	}
99156251a72SZeev Suraski}
992b4892511SJani Taskinen/* }}} */
993fc173b6aSSam RubyEND_EXTERN_C()
99456251a72SZeev Suraski
995cf7384aaSFelipe PenaZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
99656251a72SZeev Suraski{
997903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
998903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
99956251a72SZeev Suraski	} else {
100056251a72SZeev Suraski		return FAILURE;
100156251a72SZeev Suraski	}
100256251a72SZeev Suraski}
1003b4892511SJani Taskinen/* }}} */
100467f69743SZeev Suraski
1005a550566cSDmitry Stogov#define SAVE_STACK(stack) do { \
1006a550566cSDmitry Stogov		if (CG(stack).top) { \
1007a550566cSDmitry Stogov			memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
1008a550566cSDmitry Stogov			CG(stack).top = CG(stack).max = 0; \
1009a550566cSDmitry Stogov			CG(stack).elements = NULL; \
1010a550566cSDmitry Stogov		} else { \
1011a550566cSDmitry Stogov			stack.top = 0; \
1012a550566cSDmitry Stogov		} \
1013a550566cSDmitry Stogov	} while (0)
1014a550566cSDmitry Stogov
1015a550566cSDmitry Stogov#define RESTORE_STACK(stack) do { \
1016a550566cSDmitry Stogov		if (stack.top) { \
1017a550566cSDmitry Stogov			zend_stack_destroy(&CG(stack)); \
1018a550566cSDmitry Stogov			memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
1019a550566cSDmitry Stogov		} \
1020a550566cSDmitry Stogov	} while (0)
1021a550566cSDmitry Stogov
1022b4892511SJani TaskinenZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
102367f69743SZeev Suraski{
1024f4cfaf36SDmitry Stogov	char *str;
1025f4cfaf36SDmitry Stogov	int len;
102667f69743SZeev Suraski	va_list args;
10279e9c193eSStanislav Malyshev	va_list usr_copy;
1028f4cfaf36SDmitry Stogov	zval params[5];
1029f4cfaf36SDmitry Stogov	zval retval;
10304a25a774SDmitry Stogov	const char *error_filename;
10315864ce8aSDmitry Stogov	uint error_lineno = 0;
1032f4cfaf36SDmitry Stogov	zval orig_user_error_handler;
10332e1a2438SDmitry Stogov	zend_bool in_compilation;
10342e1a2438SDmitry Stogov	zend_class_entry *saved_class_entry;
1035a550566cSDmitry Stogov	zend_stack bp_stack;
1036a550566cSDmitry Stogov	zend_stack function_call_stack;
1037a550566cSDmitry Stogov	zend_stack switch_cond_stack;
1038a550566cSDmitry Stogov	zend_stack foreach_copy_stack;
1039a550566cSDmitry Stogov	zend_stack object_stack;
1040a550566cSDmitry Stogov	zend_stack declare_stack;
1041a550566cSDmitry Stogov	zend_stack list_stack;
1042a550566cSDmitry Stogov	zend_stack context_stack;
10432c254ba7SZeev Suraski	TSRMLS_FETCH();
104467f69743SZeev Suraski
1045b29dc146SDmitry Stogov	/* Report about uncaught exception in case of fatal errors */
1046b29dc146SDmitry Stogov	if (EG(exception)) {
1047b29dc146SDmitry Stogov		switch (type) {
1048b29dc146SDmitry Stogov			case E_CORE_ERROR:
1049b29dc146SDmitry Stogov			case E_ERROR:
1050b29dc146SDmitry Stogov			case E_RECOVERABLE_ERROR:
1051b29dc146SDmitry Stogov			case E_PARSE:
1052b29dc146SDmitry Stogov			case E_COMPILE_ERROR:
1053b29dc146SDmitry Stogov			case E_USER_ERROR:
1054b29dc146SDmitry Stogov				if (zend_is_executing(TSRMLS_C)) {
1055b29dc146SDmitry Stogov					error_lineno = zend_get_executed_lineno(TSRMLS_C);
1056b29dc146SDmitry Stogov				}
1057b29dc146SDmitry Stogov				zend_exception_error(EG(exception), E_WARNING TSRMLS_CC);
1058b29dc146SDmitry Stogov				EG(exception) = NULL;
1059b29dc146SDmitry Stogov				if (zend_is_executing(TSRMLS_C) && EG(opline_ptr)) {
1060b29dc146SDmitry Stogov					active_opline->lineno = error_lineno;
1061b29dc146SDmitry Stogov				}
1062b29dc146SDmitry Stogov				break;
1063b29dc146SDmitry Stogov			default:
1064b29dc146SDmitry Stogov				break;
1065b29dc146SDmitry Stogov		}
1066b29dc146SDmitry Stogov	}
1067b29dc146SDmitry Stogov
1068b80b8381SZeev Suraski	/* Obtain relevant filename and lineno */
1069b80b8381SZeev Suraski	switch (type) {
1070b80b8381SZeev Suraski		case E_CORE_ERROR:
1071b80b8381SZeev Suraski		case E_CORE_WARNING:
1072b80b8381SZeev Suraski			error_filename = NULL;
1073b80b8381SZeev Suraski			error_lineno = 0;
1074b80b8381SZeev Suraski			break;
1075b80b8381SZeev Suraski		case E_PARSE:
1076b80b8381SZeev Suraski		case E_COMPILE_ERROR:
1077b80b8381SZeev Suraski		case E_COMPILE_WARNING:
1078b80b8381SZeev Suraski		case E_ERROR:
1079b80b8381SZeev Suraski		case E_NOTICE:
1080c0df4502SAndi Gutmans		case E_STRICT:
1081d3e50265SMarcus Boerger		case E_DEPRECATED:
1082b80b8381SZeev Suraski		case E_WARNING:
1083b80b8381SZeev Suraski		case E_USER_ERROR:
1084b80b8381SZeev Suraski		case E_USER_WARNING:
1085b80b8381SZeev Suraski		case