zend.c revision 9d6e45a0
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
2159d6e45a0SDmitry StogovZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
216573b4602SAndi Gutmans{
217f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
2189d6e45a0SDmitry Stogov		return 0;
219da9faa2cSZeev Suraski	}
220f3a6c30cSXinchen Hui
221f3a6c30cSXinchen Huiagain:
222b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
22317d027edSDmitry Stogov		case IS_NULL:
22417d027edSDmitry Stogov		case IS_FALSE: {
22520f2e598SNikita Popov			TSRMLS_FETCH();
22676cc99feSDmitry Stogov			ZVAL_EMPTY_STRING(expr_copy);
2278c4ab98eSThies C. Arntzen			break;
22820f2e598SNikita Popov		}
22917d027edSDmitry Stogov		case IS_TRUE:
23017d027edSDmitry Stogov			// TODO: use interned string ???
23117d027edSDmitry Stogov			ZVAL_NEW_STR(expr_copy, STR_INIT("1", 1, 0));
232da9faa2cSZeev Suraski			break;
233f4cfaf36SDmitry Stogov		case IS_RESOURCE: {
234f4cfaf36SDmitry Stogov				char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
235f4cfaf36SDmitry Stogov				int len;
236f4cfaf36SDmitry Stogov
237f4cfaf36SDmitry Stogov				len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(expr));
23876cc99feSDmitry Stogov				ZVAL_NEW_STR(expr_copy, STR_INIT(buf, len, 0));
239f4cfaf36SDmitry Stogov			}
240da9faa2cSZeev Suraski			break;
241da9faa2cSZeev Suraski		case IS_ARRAY:
242d81ea16eSStanislav Malyshev			zend_error(E_NOTICE, "Array to string conversion");
243050d7e38SDmitry Stogov			// TODO: use interned string ???
24476cc99feSDmitry Stogov			ZVAL_NEW_STR(expr_copy, STR_INIT("Array", sizeof("Array") - 1, 0));
245da9faa2cSZeev Suraski			break;
2461b282b35SAndi Gutmans		case IS_OBJECT:
2477901a221SAndi Gutmans			{
248ae2bfb78SSterling Hughes				TSRMLS_FETCH();
249637a4042SMarcus Boerger
250750e4e10SDmitry Stogov				if (Z_OBJ_HANDLER_P(expr, cast_object)) {
2510427ae08SDmitry Stogov					Z_ADDREF_P(expr);
2520427ae08SDmitry Stogov					if (Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
2530427ae08SDmitry Stogov						zval_ptr_dtor(expr);
254750e4e10SDmitry Stogov						break;
255750e4e10SDmitry Stogov					}
2560427ae08SDmitry Stogov					zval_ptr_dtor(expr);
257848c5c76SMarcus Boerger				}
258b3c3c6deSMarcus Boerger				if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
259a0690ff2SXinchen Hui					zval rv;
260a0690ff2SXinchen Hui					zval *z = Z_OBJ_HANDLER_P(expr, get)(expr, &rv TSRMLS_CC);
2617addae50SMarcus Boerger
2624b4d634cSYiduo (David) Wang					Z_ADDREF_P(z);
263b4892511SJani Taskinen					if (Z_TYPE_P(z) != IS_OBJECT) {
2649d6e45a0SDmitry Stogov						if (zend_make_printable_zval(z, expr_copy)) {
265f4cfaf36SDmitry Stogov							zval_ptr_dtor(z);
266b3c3c6deSMarcus Boerger						} else {
267b3c3c6deSMarcus Boerger							ZVAL_ZVAL(expr_copy, z, 0, 1);
2683b8b43a9SStanislav Malyshev						}
2699d6e45a0SDmitry Stogov						return 1;
2703b8b43a9SStanislav Malyshev					}
271f4cfaf36SDmitry Stogov					zval_ptr_dtor(z);
27271ba4427SMarcus Boerger				}
273f4cfaf36SDmitry 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);
27476cc99feSDmitry Stogov				ZVAL_EMPTY_STRING(expr_copy);
275ae2bfb78SSterling Hughes			}
276da9faa2cSZeev Suraski			break;
277e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
278f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
279e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
280e842ef9fSIlia Alshanetsky			break;
281f3a6c30cSXinchen Hui		case IS_REFERENCE:
282f3a6c30cSXinchen Hui			expr = Z_REFVAL_P(expr);
283f3a6c30cSXinchen Hui			if (Z_TYPE_P(expr) == IS_STRING) {
284f3a6c30cSXinchen Hui				ZVAL_STR(expr_copy, STR_COPY(Z_STR_P(expr)));
2859d6e45a0SDmitry Stogov				return 1;
286f3a6c30cSXinchen Hui			}
287f3a6c30cSXinchen Hui			goto again;
288f3a6c30cSXinchen Hui			break;
289da9faa2cSZeev Suraski		default:
290f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
291da9faa2cSZeev Suraski			convert_to_string(expr_copy);
292da9faa2cSZeev Suraski			break;
293da9faa2cSZeev Suraski	}
2949d6e45a0SDmitry Stogov	return 1;
295da9faa2cSZeev Suraski}
296b4892511SJani Taskinen/* }}} */
297da9faa2cSZeev Suraski
298bda96e3cSNikita PopovZEND_API int zend_print_zval(zval *expr, int indent TSRMLS_DC) /* {{{ */
299da9faa2cSZeev Suraski{
300bda96e3cSNikita Popov	return zend_print_zval_ex(zend_write, expr, indent TSRMLS_CC);
3015dba4774SZeev Suraski}
302b4892511SJani Taskinen/* }}} */
3035dba4774SZeev Suraski
304bda96e3cSNikita PopovZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
3055dba4774SZeev Suraski{
3064ed452c1SDmitry Stogov	zend_string *str = zval_get_string(expr);
307bda96e3cSNikita Popov	int len = str->len;
308da9faa2cSZeev Suraski
309bda96e3cSNikita Popov	if (len != 0) {
310bda96e3cSNikita Popov		write_func(str->val, len);
311573b4602SAndi Gutmans	}
312bda96e3cSNikita Popov
313bda96e3cSNikita Popov	STR_RELEASE(str);
314bda96e3cSNikita Popov	return len;
315573b4602SAndi Gutmans}
316b4892511SJani Taskinen/* }}} */
317573b4602SAndi Gutmans
318b4892511SJani TaskinenZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
31927de54b0SAndi Gutmans{
320b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
321b4892511SJani Taskinen		case IS_ARRAY:
322b4892511SJani Taskinen			ZEND_PUTS("Array (");
323b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
324b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
325b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
32672c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
327b4892511SJani Taskinen				return;
328b4892511SJani Taskinen			}
329b4892511SJani Taskinen			print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
330b4892511SJani Taskinen			ZEND_PUTS(")");
331b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
332b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
333b3b616cfSDmitry Stogov			}
334b4892511SJani Taskinen			break;
335b4892511SJani Taskinen		case IS_OBJECT:
336b4892511SJani Taskinen		{
3379bba373aSStanislav Malyshev			HashTable *properties = NULL;
338f4cfaf36SDmitry Stogov			zend_string *class_name = NULL;
3398ce1211aSMarcus Boerger
340f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
341ea85451bSDmitry Stogov				class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr), 0 TSRMLS_CC);
3429bba373aSStanislav Malyshev			}
343b4892511SJani Taskinen			if (class_name) {
344f4cfaf36SDmitry Stogov				zend_printf("%s Object (", class_name->val);
345b4892511SJani Taskinen			} else {
346b4892511SJani Taskinen				zend_printf("%s Object (", "Unknown Class");
347b4892511SJani Taskinen			}
348288daccaSAndi Gutmans			if (class_name) {
349d062fb33SDmitry Stogov				STR_RELEASE(class_name);
3509bba373aSStanislav Malyshev			}
351f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3529bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3539bba373aSStanislav Malyshev			}
354f30f3590SStanislav Malyshev			if (properties) {
35572c287bdSDmitry Stogov				if (++properties->u.v.nApplyCount>1) {
3569bba373aSStanislav Malyshev					ZEND_PUTS(" *RECURSION*");
35772c287bdSDmitry Stogov					properties->u.v.nApplyCount--;
3589bba373aSStanislav Malyshev					return;
3599bba373aSStanislav Malyshev				}
36024db7f18SSebastian Bergmann				print_flat_hash(properties TSRMLS_CC);
36172c287bdSDmitry Stogov				properties->u.v.nApplyCount--;
3629bba373aSStanislav Malyshev			}
3639bba373aSStanislav Malyshev			ZEND_PUTS(")");
3649bba373aSStanislav Malyshev			break;
365b4892511SJani Taskinen		}
366b4892511SJani Taskinen		default:
367bda96e3cSNikita Popov			zend_print_variable(expr TSRMLS_CC);
368b4892511SJani Taskinen			break;
369b4892511SJani Taskinen	}
37027de54b0SAndi Gutmans}
371b4892511SJani Taskinen/* }}} */
372573b4602SAndi Gutmans
373b4892511SJani TaskinenZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
3745dba4774SZeev Suraski{
37524db7f18SSebastian Bergmann	zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
3765dba4774SZeev Suraski}
377b4892511SJani Taskinen/* }}} */
3785dba4774SZeev Suraski
379b4892511SJani TaskinenZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
380573b4602SAndi Gutmans{
381c6cba554SDmitry Stogov	ZVAL_DEREF(expr);
382b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
383573b4602SAndi Gutmans		case IS_ARRAY:
384d3d02fbcSDmitry Stogov			ZEND_PUTS_EX("Array\n");
385b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
386b3b616cfSDmitry Stogov			    ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
387d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" *RECURSION*");
38872c287bdSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
3896053f2a1SZeev Suraski				return;
3906053f2a1SZeev Suraski			}
391d3d02fbcSDmitry Stogov			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
392b3b616cfSDmitry Stogov			if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
393b3b616cfSDmitry Stogov				Z_ARRVAL_P(expr)->u.v.nApplyCount--;
394b3b616cfSDmitry Stogov			}
395573b4602SAndi Gutmans			break;
396573b4602SAndi Gutmans		case IS_OBJECT:
397c259cb7cSAndi Gutmans			{
3988ce1211aSMarcus Boerger				HashTable *properties;
399f4cfaf36SDmitry Stogov				zend_string *class_name = NULL;
4008ce1211aSMarcus Boerger				int is_temp;
4018ce1211aSMarcus Boerger
402f30f3590SStanislav Malyshev				if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
403ea85451bSDmitry Stogov					class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr), 0 TSRMLS_CC);
4049bba373aSStanislav Malyshev				}
405f1fb77d1SIlia Alshanetsky				if (class_name) {
406f4cfaf36SDmitry Stogov					ZEND_PUTS_EX(class_name->val);
407f1fb77d1SIlia Alshanetsky				} else {
408d3d02fbcSDmitry Stogov					ZEND_PUTS_EX("Unknown Class");
409f1fb77d1SIlia Alshanetsky				}
410d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" Object\n");
411288daccaSAndi Gutmans				if (class_name) {
412bdeaf2efSDmitry Stogov					STR_RELEASE(class_name);
4139bba373aSStanislav Malyshev				}
4148ce1211aSMarcus Boerger				if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
4158ce1211aSMarcus Boerger					break;
4169bba373aSStanislav Malyshev				}
41772c287bdSDmitry Stogov				if (++properties->u.v.nApplyCount>1) {
418d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(" *RECURSION*");
41972c287bdSDmitry Stogov					properties->u.v.nApplyCount--;
4208ce1211aSMarcus Boerger					return;
4218ce1211aSMarcus Boerger				}
422d3d02fbcSDmitry Stogov				print_hash(write_func, properties, indent, 1 TSRMLS_CC);
42372c287bdSDmitry Stogov				properties->u.v.nApplyCount--;
4248ce1211aSMarcus Boerger				if (is_temp) {
4258ce1211aSMarcus Boerger					zend_hash_destroy(properties);
4264e7cbf3fSDmitry Stogov					FREE_HASHTABLE(properties);
427c259cb7cSAndi Gutmans				}
428c259cb7cSAndi Gutmans				break;
4296053f2a1SZeev Suraski			}
430573b4602SAndi Gutmans		default:
431bda96e3cSNikita Popov			zend_print_zval_ex(write_func, expr, indent TSRMLS_CC);
432573b4602SAndi Gutmans			break;
433573b4602SAndi Gutmans	}
434573b4602SAndi Gutmans}
435b4892511SJani Taskinen/* }}} */
436573b4602SAndi Gutmans
43785ab4235SFelipe Penastatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
438573b4602SAndi Gutmans{
4395463dd5bSAndi Gutmans	if (opened_path) {
44027de5001SAndi Gutmans		*opened_path = estrdup(filename);
4415463dd5bSAndi Gutmans	}
442f311ab16SAndi Gutmans	return fopen(filename, "rb");
443573b4602SAndi Gutmans}
444b4892511SJani Taskinen/* }}} */
445573b4602SAndi Gutmans
4462f586e96SDmitry Stogov#ifdef ZTS
4478c885b89SDmitry Stogovstatic zend_bool asp_tags_default		  = 0;
4488c885b89SDmitry Stogovstatic zend_bool short_tags_default		  = 1;
4498c885b89SDmitry Stogovstatic zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
4502f586e96SDmitry Stogov#else
4518c885b89SDmitry Stogov# define asp_tags_default			0
4528c885b89SDmitry Stogov# define short_tags_default			1
4538c885b89SDmitry Stogov# define compiler_options_default	ZEND_COMPILE_DEFAULT
4542f586e96SDmitry Stogov#endif
4552f586e96SDmitry Stogov
456b4892511SJani Taskinenstatic void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
4578b794bb1SZeev Suraski{
4588b794bb1SZeev Suraski	/* default compile-time values */
4592f586e96SDmitry Stogov	CG(asp_tags) = asp_tags_default;
4602f586e96SDmitry Stogov	CG(short_tags) = short_tags_default;
4618c885b89SDmitry Stogov	CG(compiler_options) = compiler_options_default;
4628b794bb1SZeev Suraski}
463b4892511SJani Taskinen/* }}} */
4648b794bb1SZeev Suraski
465fcaa1c6dSDmitry Stogovstatic void zend_init_exception_op(TSRMLS_D) /* {{{ */
466fcaa1c6dSDmitry Stogov{
467fcaa1c6dSDmitry Stogov	memset(EG(exception_op), 0, sizeof(EG(exception_op)));
468fcaa1c6dSDmitry Stogov	EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
46994dd8372SDmitry Stogov	EG(exception_op)[0].op1_type = IS_UNUSED;
47094dd8372SDmitry Stogov	EG(exception_op)[0].op2_type = IS_UNUSED;
47194dd8372SDmitry Stogov	EG(exception_op)[0].result_type = IS_UNUSED;
472fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
473fcaa1c6dSDmitry Stogov	EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
47494dd8372SDmitry Stogov	EG(exception_op)[1].op1_type = IS_UNUSED;
47594dd8372SDmitry Stogov	EG(exception_op)[1].op2_type = IS_UNUSED;
47694dd8372SDmitry Stogov	EG(exception_op)[1].result_type = IS_UNUSED;
477fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
478fcaa1c6dSDmitry Stogov	EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
47994dd8372SDmitry Stogov	EG(exception_op)[2].op1_type = IS_UNUSED;
48094dd8372SDmitry Stogov	EG(exception_op)[2].op2_type = IS_UNUSED;
48194dd8372SDmitry Stogov	EG(exception_op)[2].result_type = IS_UNUSED;
482fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
483fcaa1c6dSDmitry Stogov}
484fcaa1c6dSDmitry Stogov/* }}} */
485fcaa1c6dSDmitry Stogov
4867a87fcbbSZeev Suraski#ifdef ZTS
4873ce96eabSNikita Popovstatic void function_copy_ctor(zval *zv)
4883ce96eabSNikita Popov{
4893ce96eabSNikita Popov	zend_function *old_func = Z_FUNC_P(zv);
4903ce96eabSNikita Popov	Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1);
4913ce96eabSNikita Popov	memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function));
4923ce96eabSNikita Popov	function_add_ref(Z_FUNC_P(zv));
4933ce96eabSNikita Popov}
4943ce96eabSNikita Popov
495b4892511SJani Taskinenstatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
4967a87fcbbSZeev Suraski{
4977f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
4987f4909d9SThies C. Arntzen
499f7f5a5eaSStanislav Malyshev	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
50072c287bdSDmitry Stogov	zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
5013ce96eabSNikita Popov	zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor);
5027a87fcbbSZeev Suraski
503b4892511SJani Taskinen	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
50472c287bdSDmitry Stogov	zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
5052b9b9afaSDmitry Stogov	zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
5069cf1a98dSThies C. Arntzen
507b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
50885b4df53SZeev Suraski
50985b4df53SZeev Suraski	CG(interactive) = 0;
5109d11db12SAndi Gutmans
5119d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
5129d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
51320f2e598SNikita Popov	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL /* empty element */);
5148768ab94SDmitry Stogov
5158768ab94SDmitry Stogov	compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
5168768ab94SDmitry Stogov	if (compiler_globals->last_static_member) {
517f23e8576SDmitry Stogov		compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval**));
5188768ab94SDmitry Stogov	} else {
519f23e8576SDmitry Stogov		compiler_globals->static_members_table = NULL;
5208768ab94SDmitry Stogov	}
521ae0e5a0cSAntony Dovgal	compiler_globals->script_encoding_list = NULL;
5227a87fcbbSZeev Suraski}
523b4892511SJani Taskinen/* }}} */
5247a87fcbbSZeev Suraski
525b4892511SJani Taskinenstatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5267a87fcbbSZeev Suraski{
527ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
52874a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
5298fb5ea30SMarcus Boerger		free(compiler_globals->function_table);
53074a9ed7bSZeev Suraski	}
531ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
53274a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
5338fb5ea30SMarcus Boerger		free(compiler_globals->class_table);
53474a9ed7bSZeev Suraski	}
5358fb5ea30SMarcus Boerger	if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
5369d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
5379d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
5389d11db12SAndi Gutmans	}
539f23e8576SDmitry Stogov	if (compiler_globals->static_members_table) {
540f23e8576SDmitry Stogov		free(compiler_globals->static_members_table);
5418768ab94SDmitry Stogov	}
542bbf3d43cSMoriyoshi Koizumi	if (compiler_globals->script_encoding_list) {
543bbf3d43cSMoriyoshi Koizumi		pefree(compiler_globals->script_encoding_list, 1);
544bbf3d43cSMoriyoshi Koizumi	}
5458768ab94SDmitry Stogov	compiler_globals->last_static_member = 0;
5467a87fcbbSZeev Suraski}
547b4892511SJani Taskinen/* }}} */
548a9f9ae79SZeev Suraski
549b4892511SJani Taskinenstatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
550a9f9ae79SZeev Suraski{
5515fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
5525fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
5532c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
554fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
555b4892511SJani Taskinen	EG(lambda_count) = 0;
55620f2e598SNikita Popov	ZVAL_UNDEF(&EG(user_error_handler));
55720f2e598SNikita Popov	ZVAL_UNDEF(&EG(user_exception_handler));
55855cf45abSDmitry Stogov	EG(in_autoload) = NULL;
559e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
56052303217SMarcus Boerger	EG(current_module) = NULL;
5619d576212SAntony Dovgal	EG(exit_status) = 0;
562ee4f5ac1SFelipe Pena#if XPFPA_HAVE_CW
563ee4f5ac1SFelipe Pena	EG(saved_fpu_cw) = 0;
564ee4f5ac1SFelipe Pena#endif
56525710a40SFelipe Pena	EG(saved_fpu_cw_ptr) = NULL;
566d6ee9d48SAntony Dovgal	EG(active) = 0;
567a9f9ae79SZeev Suraski}
568b4892511SJani Taskinen/* }}} */
569a9f9ae79SZeev Suraski
570b4892511SJani Taskinenstatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
571a9f9ae79SZeev Suraski{
5722c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
57321698c12SDmitry Stogov	if (&executor_globals->persistent_list != global_persistent_list) {
57421698c12SDmitry Stogov		zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
57521698c12SDmitry Stogov	}
57621698c12SDmitry Stogov	if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
57721698c12SDmitry Stogov		zend_hash_destroy(executor_globals->zend_constants);
57821698c12SDmitry Stogov		free(executor_globals->zend_constants);
57921698c12SDmitry Stogov	}
580a9f9ae79SZeev Suraski}
581b4892511SJani Taskinen/* }}} */
582a9f9ae79SZeev Suraski
583b4892511SJani Taskinenstatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
584609d58a4SZeev Suraski{
585a84a2eaeSDmitry Stogov	if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
586a84a2eaeSDmitry Stogov		zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
587a84a2eaeSDmitry Stogov	}
588609d58a4SZeev Suraski}
589b4892511SJani Taskinen/* }}} */
59066d9314bSZeev Suraski#endif
59166d9314bSZeev Suraski
592d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
593d46f8078SJon Parise/* FreeBSD and DragonFly floating point precision fix */
5945928970dSAndi Gutmans#include <floatingpoint.h>
5955928970dSAndi Gutmans#endif
5967a87fcbbSZeev Suraski
597af316021SMarcus Boergerstatic void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
598af316021SMarcus Boerger{
599af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
600af316021SMarcus Boerger}
601af316021SMarcus Boerger/* }}} */
602af316021SMarcus Boerger
603af316021SMarcus Boergerstatic void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
60454d53055SZeev Suraski{
605af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
60654d53055SZeev Suraski}
607b4892511SJani Taskinen/* }}} */
60854d53055SZeev Suraski
609226c56feSJani Taskinenvoid zend_init_opcodes_handlers(void);
61054d53055SZeev Suraski
6112b9b9afaSDmitry Stogovstatic void module_destructor_zval(zval *zv) /* {{{ */
6122b9b9afaSDmitry Stogov{
6132b9b9afaSDmitry Stogov	zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
6142b9b9afaSDmitry Stogov
6152b9b9afaSDmitry Stogov	module_destructor(module);
6162b9b9afaSDmitry Stogov	free(module);
6172b9b9afaSDmitry Stogov}
6182b9b9afaSDmitry Stogov/* }}} */
6192b9b9afaSDmitry Stogov
6202b9b9afaSDmitry Stogovstatic void auto_global_dtor(zval *zv) /* {{{ */
6212b9b9afaSDmitry Stogov{
6222b9b9afaSDmitry Stogov	free(Z_PTR_P(zv));
6232b9b9afaSDmitry Stogov}
6242b9b9afaSDmitry Stogov/* }}} */
6252b9b9afaSDmitry Stogov
626f4cfaf36SDmitry Stogovstatic zend_bool php_auto_globals_create_globals(zend_string *name TSRMLS_DC) /* {{{ */
627f0c8366aSDmitry Stogov{
628f4cfaf36SDmitry Stogov	zval globals;
629f4cfaf36SDmitry Stogov
630f4cfaf36SDmitry Stogov	ZVAL_ARR(&globals, &EG(symbol_table));
631f4cfaf36SDmitry Stogov	ZVAL_NEW_REF(&globals, &globals);
632f4cfaf36SDmitry Stogov	zend_hash_update(&EG(symbol_table).ht, name, &globals);
633f0c8366aSDmitry Stogov	return 0;
634f0c8366aSDmitry Stogov}
635f0c8366aSDmitry Stogov/* }}} */
636f0c8366aSDmitry Stogov
6372faea53dSMarcus Boergerint zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
638573b4602SAndi Gutmans{
639a9f9ae79SZeev Suraski#ifdef ZTS
6407c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
641a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
642609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
643609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
644609d58a4SZeev Suraski#else
645af316021SMarcus Boerger	extern zend_ini_scanner_globals ini_scanner_globals;
646af316021SMarcus Boerger	extern zend_php_scanner_globals language_scanner_globals;
647609d58a4SZeev Suraski#endif
648a9f9ae79SZeev Suraski
64929ed52ffSDmitry Stogov	start_memory_manager(TSRMLS_C);
650a9f9ae79SZeev Suraski
651cf6ab0e9SAnatol Belski	virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
652cf6ab0e9SAnatol Belski
653d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
654d46f8078SJon Parise	/* FreeBSD and DragonFly floating point precision fix */
655c3340584SSascha Schumann	fpsetmask(0);
6565928970dSAndi Gutmans#endif
657309827ecSZeev Suraski
6584d44a5b7SAntony Dovgal	zend_startup_strtod();
659309827ecSZeev Suraski	zend_startup_extensions_mechanism();
660309827ecSZeev Suraski
661573b4602SAndi Gutmans	/* Set up utility functions and values */
66267f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
663573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
6645dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
665573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
666573b4602SAndi Gutmans	if (!zend_fopen) {
667573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
668573b4602SAndi Gutmans	}
669e52aac94SWez Furlong	zend_stream_open_function = utility_functions->stream_open_function;
67056251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
67134d93f0cSIlia Alshanetsky#ifndef ZEND_SIGNALS
672573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
673573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
67434d93f0cSIlia Alshanetsky#endif
675903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
676fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
677bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
678d45fd8a1SMarcus Boerger	zend_vspprintf = utility_functions->vspprintf_function;
67988c550a7SXinchen Hui	zend_vstrpprintf = utility_functions->vstrpprintf_function;
68085a36e2bSZeev Suraski	zend_getenv = utility_functions->getenv_function;
681ab232458SDmitry Stogov	zend_resolve_path = utility_functions->resolve_path_function;
682d035af4aSZeev Suraski
68308b9fdc8SDavid Soria Parra#if HAVE_DTRACE
68408b9fdc8SDavid Soria Parra/* build with dtrace support */
68508b9fdc8SDavid Soria Parra	zend_compile_file = dtrace_compile_file;
68670f83f35SDmitry Stogov	zend_execute_ex = dtrace_execute_ex;
68708b9fdc8SDavid Soria Parra	zend_execute_internal = dtrace_execute_internal;
68808b9fdc8SDavid Soria Parra#else
689c06692e9SZeev Suraski	zend_compile_file = compile_file;
69070f83f35SDmitry Stogov	zend_execute_ex = execute_ex;
6912c44fab3SDerick Rethans	zend_execute_internal = NULL;
69208b9fdc8SDavid Soria Parra#endif /* HAVE_SYS_SDT_H */
69308b9fdc8SDavid Soria Parra	zend_compile_string = compile_string;
694979da661SAndi Gutmans	zend_throw_exception_hook = NULL;
695573b4602SAndi Gutmans
696cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
697cf36abb2SAndi Gutmans
698573b4602SAndi Gutmans	/* set up version */
699573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
700b4892511SJani Taskinen	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
701b4892511SJani Taskinen
702b4892511SJani Taskinen	GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
703b4892511SJani Taskinen	GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
704b4892511SJani Taskinen	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
705b4892511SJani Taskinen	GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
706573b4602SAndi Gutmans
70772c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
70872c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
7092b9b9afaSDmitry Stogov	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
71072c287bdSDmitry Stogov	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0);
7112eabb14dSAndi Gutmans
71272c287bdSDmitry Stogov	zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0);
7134cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
714573b4602SAndi Gutmans
7157a87fcbbSZeev Suraski#ifdef ZTS
7162c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
7172c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
718af316021SMarcus Boerger	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
719af316021SMarcus Boerger	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
7207c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
721a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
7225fcae67eSZeev Suraski
7238fb5ea30SMarcus Boerger	compiler_globals_dtor(compiler_globals TSRMLS_CC);
7242a8426a6SMarcus Boerger	compiler_globals->in_compilation = 0;
7258fb5ea30SMarcus Boerger	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
7268fb5ea30SMarcus Boerger	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
7278fb5ea30SMarcus Boerger
728f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
729f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
7309d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
7315fcae67eSZeev Suraski
7325fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
7335fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
734762158aaSAndi Gutmans#else
735af316021SMarcus Boerger	ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
736af316021SMarcus Boerger	php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
737b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
738f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_error_handler));
739f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_exception_handler));
7407a87fcbbSZeev Suraski#endif
741826cc0dcSMarcus Boerger
742dd5c478bSDmitry Stogov	zend_interned_strings_init(TSRMLS_C);
7432faea53dSMarcus Boerger	zend_startup_builtin_functions(TSRMLS_C);
7442c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
7452b9b9afaSDmitry Stogov	zend_register_auto_global(STR_INIT("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals TSRMLS_CC);
7467a87fcbbSZeev Suraski
747bfbe8618SZeev Suraski#ifndef ZTS
7482c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
749fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
750bfbe8618SZeev Suraski#endif
751a9f9ae79SZeev Suraski
7522c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
75354d53055SZeev Suraski
75454d53055SZeev Suraski#ifdef ZTS
75554d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
75654d53055SZeev Suraski#endif
75754d53055SZeev Suraski
758573b4602SAndi Gutmans	return SUCCESS;
759573b4602SAndi Gutmans}
760b4892511SJani Taskinen/* }}} */
761573b4602SAndi Gutmans
762b4892511SJani Taskinenvoid zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
7634be862b0SZeev Suraski{
7644be862b0SZeev Suraski	int module_number = 0;
7654be862b0SZeev Suraski
7664be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
7674be862b0SZeev Suraski}
768b4892511SJani Taskinen/* }}} */
7694be862b0SZeev Suraski
770711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
771711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
772711be83dSZeev Suraski */
773b4892511SJani Taskinenvoid zend_post_startup(TSRMLS_D) /* {{{ */
774711be83dSZeev Suraski{
775b4892511SJani Taskinen#ifdef ZTS
77672f19e9aSXinchen Hui	zend_encoding **script_encoding_list;
77772f19e9aSXinchen Hui
778711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
7795fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
780711be83dSZeev Suraski
7815fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
7825fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
7835fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
7842f586e96SDmitry Stogov
7852f586e96SDmitry Stogov	asp_tags_default = CG(asp_tags);
7862f586e96SDmitry Stogov	short_tags_default = CG(short_tags);
7878c885b89SDmitry Stogov	compiler_options_default = CG(compiler_options);
7888ce1211aSMarcus Boerger
789b817dab2SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
7908fb5ea30SMarcus Boerger	free(compiler_globals->function_table);
7918fb5ea30SMarcus Boerger	free(compiler_globals->class_table);
79272f19e9aSXinchen Hui	if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
79372f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
79472f19e9aSXinchen Hui		compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
79572f19e9aSXinchen Hui	} else {
79672f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
79772f19e9aSXinchen Hui	}
7988fb5ea30SMarcus Boerger	free(EG(zend_constants));
799cf6ab0e9SAnatol Belski
800cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
801cf6ab0e9SAnatol Belski
8025fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
80321698c12SDmitry Stogov	global_persistent_list = &EG(persistent_list);
804a84a2eaeSDmitry Stogov	zend_copy_ini_directives(TSRMLS_C);
805cf6ab0e9SAnatol Belski#else
806cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
807711be83dSZeev Suraski#endif
808b4892511SJani Taskinen}
809b4892511SJani Taskinen/* }}} */
810711be83dSZeev Suraski
811b4892511SJani Taskinenvoid zend_shutdown(TSRMLS_D) /* {{{ */
812573b4602SAndi Gutmans{
81334d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
81434d93f0cSIlia Alshanetsky	zend_signal_shutdown(TSRMLS_C);
81534d93f0cSIlia Alshanetsky#endif
81684eb48f0SZeev Suraski#ifdef ZEND_WIN32
81784eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
81884eb48f0SZeev Suraski#endif
8199e1beb4fSDmitry Stogov	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
8201a1178a6SDmitry Stogov	zend_destroy_modules();
8213458373eSAndi Gutmans
822cf6ab0e9SAnatol Belski 	virtual_cwd_deactivate(TSRMLS_C);
823cf6ab0e9SAnatol Belski 	virtual_cwd_shutdown();
824cf6ab0e9SAnatol Belski
8257a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
82676b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
8273458373eSAndi Gutmans
8289d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
8299d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
8302da8b014Sfoobar
831d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
832573b4602SAndi Gutmans	free(zend_version_info);
83348b33032SSterling Hughes
834a2513618SMarcus Boerger	free(GLOBAL_FUNCTION_TABLE);
835a2513618SMarcus Boerger	free(GLOBAL_CLASS_TABLE);
83621698c12SDmitry Stogov
83748b33032SSterling Hughes	zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
838a54c7dcbSMarcus Boerger	free(GLOBAL_CONSTANTS_TABLE);
8394d44a5b7SAntony Dovgal	zend_shutdown_strtod();
840b4892511SJani Taskinen
84121698c12SDmitry Stogov#ifdef ZTS
8428fb5ea30SMarcus Boerger	GLOBAL_FUNCTION_TABLE = NULL;
8438fb5ea30SMarcus Boerger	GLOBAL_CLASS_TABLE = NULL;
8448fb5ea30SMarcus Boerger	GLOBAL_AUTO_GLOBALS_TABLE = NULL;
84521698c12SDmitry Stogov	GLOBAL_CONSTANTS_TABLE = NULL;
846a17d2f37SSebastian Bergmann#endif
8474c283fffSIlia Alshanetsky	zend_destroy_rsrc_list_dtors();
848dd5c478bSDmitry Stogov
849dd5c478bSDmitry Stogov	zend_interned_strings_dtor(TSRMLS_C);
850573b4602SAndi Gutmans}
851b4892511SJani Taskinen/* }}} */
852573b4602SAndi Gutmans
853b4892511SJani Taskinenvoid zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
8547656c77cSZeev Suraski{
8557656c77cSZeev Suraski	zend_uv = *utility_values;
8569baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
8577656c77cSZeev Suraski}
858b4892511SJani Taskinen/* }}} */
8597656c77cSZeev Suraski
860573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
861cf7384aaSFelipe Penavoid zenderror(const char *error) /* {{{ */
862573b4602SAndi Gutmans{
86310def9a8SIlia Alshanetsky	zend_error(E_PARSE, "%s", error);
864573b4602SAndi Gutmans}
865b4892511SJani Taskinen/* }}} */
866573b4602SAndi Gutmans
867b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
868b4892511SJani TaskinenZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
869573b4602SAndi Gutmans{
8702c254ba7SZeev Suraski	TSRMLS_FETCH();
871573b4602SAndi Gutmans
87214f6b914SDmitry Stogov	if (!EG(bailout)) {
873ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
874931ebe08SZeev Suraski		exit(-1);
875931ebe08SZeev Suraski	}
8766bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
87708b3d76cSFelipe Pena	CG(active_class_entry) = NULL;
8780a77dcd4SDmitry Stogov	CG(in_compilation) = 0;
879bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
88010afe5d9SRasmus Lerdorf	LONGJMP(*EG(bailout), FAILURE);
881573b4602SAndi Gutmans}
882b4892511SJani Taskinen/* }}} */
883b0bfa458SZeev SuraskiEND_EXTERN_C()
884573b4602SAndi Gutmans
885cf7384aaSFelipe Penavoid zend_append_version_info(const zend_extension *extension) /* {{{ */
886573b4602SAndi Gutmans{
887573b4602SAndi Gutmans	char *new_info;
888573b4602SAndi Gutmans	uint new_info_length;
889573b4602SAndi Gutmans
890ed7b3e70SPierrick Charron	new_info_length = sizeof("    with  v, , by \n")
891573b4602SAndi Gutmans						+ strlen(extension->name)
892573b4602SAndi Gutmans						+ strlen(extension->version)
893573b4602SAndi Gutmans						+ strlen(extension->copyright)
894573b4602SAndi Gutmans						+ strlen(extension->author);
895573b4602SAndi Gutmans
896b4892511SJani Taskinen	new_info = (char *) malloc(new_info_length + 1);
897573b4602SAndi Gutmans
898ed7b3e70SPierrick Charron	snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
899573b4602SAndi Gutmans
900b4892511SJani Taskinen	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
901ed7b3e70SPierrick Charron	strncat(zend_version_info, new_info, new_info_length);
902573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
903573b4602SAndi Gutmans	free(new_info);
904573b4602SAndi Gutmans}
905b4892511SJani Taskinen/* }}} */
906573b4602SAndi Gutmans
907b4892511SJani TaskinenZEND_API char *get_zend_version(void) /* {{{ */
908573b4602SAndi Gutmans{
909573b4602SAndi Gutmans	return zend_version_info;
910573b4602SAndi Gutmans}
911b4892511SJani Taskinen/* }}} */
912ed06a70fSZeev Suraski
913f046189eSkrakjoeZEND_API void zend_activate(TSRMLS_D) /* {{{ */
914ed06a70fSZeev Suraski{
915699f07baSAnatol Belski#ifdef ZTS
9169df78bf9SAnatol Belski	virtual_cwd_activate(TSRMLS_C);
917699f07baSAnatol Belski#endif
91871592cecSDmitry Stogov	gc_reset(TSRMLS_C);
919b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
920b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
921b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
922ed06a70fSZeev Suraski}
923b4892511SJani Taskinen/* }}} */
924ed06a70fSZeev Suraski
925b4892511SJani Taskinenvoid zend_call_destructors(TSRMLS_D) /* {{{ */
9260cd2da03SMarcus Boerger{
9270cd2da03SMarcus Boerger	zend_try {
9280cd2da03SMarcus Boerger		shutdown_destructors(TSRMLS_C);
9290cd2da03SMarcus Boerger	} zend_end_try();
9300cd2da03SMarcus Boerger}
931b4892511SJani Taskinen/* }}} */
9320cd2da03SMarcus Boerger
933f046189eSkrakjoeZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */
934ed06a70fSZeev Suraski{
935372f71ebSThies C. Arntzen	/* we're no longer executing anything */
93663c057e3SDmitry Stogov	EG(current_execute_data) = NULL;
937f4c9d96fSThies C. Arntzen
938931ebe08SZeev Suraski	zend_try {
939b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
940931ebe08SZeev Suraski	} zend_end_try();
941931ebe08SZeev Suraski
9428084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
9432c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
944931ebe08SZeev Suraski
945931ebe08SZeev Suraski	zend_try {
946b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
947931ebe08SZeev Suraski	} zend_end_try();
948931ebe08SZeev Suraski
94959a46c34SDmitry Stogov	zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
95059a46c34SDmitry Stogov
9510d5121a3SAnatol Belski#if ZEND_DEBUG
95271592cecSDmitry Stogov	if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
95371592cecSDmitry Stogov		gc_collect_cycles(TSRMLS_C);
95471592cecSDmitry Stogov	}
95571592cecSDmitry Stogov#endif
95671592cecSDmitry Stogov
9573bd291e1SDerick Rethans#if GC_BENCH
95813d75ce6SDerick Rethans	fprintf(stderr, "GC Statistics\n");
95913d75ce6SDerick Rethans	fprintf(stderr, "-------------\n");
96013d75ce6SDerick Rethans	fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
96113d75ce6SDerick Rethans	fprintf(stderr, "Collected:          %d\n", GC_G(collected));
96213d75ce6SDerick Rethans	fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
96313d75ce6SDerick Rethans	fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
96413d75ce6SDerick Rethans	fprintf(stderr, "      Possible            Remove from  Marked\n");
96513d75ce6SDerick Rethans	fprintf(stderr, "        Root    Buffered     buffer     grey\n");
96613d75ce6SDerick Rethans	fprintf(stderr, "      --------  --------  -----------  ------\n");
96713d75ce6SDerick 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));
96813d75ce6SDerick 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));
9693bd291e1SDerick Rethans#endif
9703bd291e1SDerick Rethans
971931ebe08SZeev Suraski	zend_try {
9722c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
973931ebe08SZeev Suraski	} zend_end_try();
974ed06a70fSZeev Suraski}
975b4892511SJani Taskinen/* }}} */
97656251a72SZeev Suraski
977fc173b6aSSam RubyBEGIN_EXTERN_C()
9784a25a774SDmitry StogovZEND_API void zend_message_dispatcher(long message, const void *data TSRMLS_DC) /* {{{ */
97956251a72SZeev Suraski{
98056251a72SZeev Suraski	if (zend_message_dispatcher_p) {
98185ab4235SFelipe Pena		zend_message_dispatcher_p(message, data TSRMLS_CC);
98256251a72SZeev Suraski	}
98356251a72SZeev Suraski}
984b4892511SJani Taskinen/* }}} */
985fc173b6aSSam RubyEND_EXTERN_C()
98656251a72SZeev Suraski
987cf7384aaSFelipe PenaZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
98856251a72SZeev Suraski{
989903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
990903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
99156251a72SZeev Suraski	} else {
99256251a72SZeev Suraski		return FAILURE;
99356251a72SZeev Suraski	}
99456251a72SZeev Suraski}
995b4892511SJani Taskinen/* }}} */
99667f69743SZeev Suraski
997a550566cSDmitry Stogov#define SAVE_STACK(stack) do { \
998a550566cSDmitry Stogov		if (CG(stack).top) { \
999a550566cSDmitry Stogov			memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
1000a550566cSDmitry Stogov			CG(stack).top = CG(stack).max = 0; \
1001a550566cSDmitry Stogov			CG(stack).elements = NULL; \
1002a550566cSDmitry Stogov		} else { \
1003a550566cSDmitry Stogov			stack.top = 0; \
1004a550566cSDmitry Stogov		} \
1005a550566cSDmitry Stogov	} while (0)
1006a550566cSDmitry Stogov
1007a550566cSDmitry Stogov#define RESTORE_STACK(stack) do { \
1008a550566cSDmitry Stogov		if (stack.top) { \
1009a550566cSDmitry Stogov			zend_stack_destroy(&CG(stack)); \
1010a550566cSDmitry Stogov			memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
1011a550566cSDmitry Stogov		} \
1012a550566cSDmitry Stogov	} while (0)
1013a550566cSDmitry Stogov
1014b4892511SJani TaskinenZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
101567f69743SZeev Suraski{
1016f4cfaf36SDmitry Stogov	char *str;
1017f4cfaf36SDmitry Stogov	int len;
101867f69743SZeev Suraski	va_list args;
10199e9c193eSStanislav Malyshev	va_list usr_copy;
1020f4cfaf36SDmitry Stogov	zval params[5];
1021f4cfaf36SDmitry Stogov	zval retval;
10224a25a774SDmitry Stogov	const char *error_filename;
10235864ce8aSDmitry Stogov	uint error_lineno = 0;
1024f4cfaf36SDmitry Stogov	zval orig_user_error_handler;
10252e1a2438SDmitry Stogov	zend_bool in_compilation;
10262e1a2438SDmitry Stogov	zend_class_entry *saved_class_entry;
1027a550566cSDmitry Stogov	zend_stack bp_stack;
1028a550566cSDmitry Stogov	zend_stack function_call_stack;
1029a550566cSDmitry Stogov	zend_stack switch_cond_stack;
1030a550566cSDmitry Stogov	zend_stack foreach_copy_stack;
1031a550566cSDmitry Stogov	zend_stack object_stack;
1032a550566cSDmitry Stogov	zend_stack declare_stack;
1033a550566cSDmitry Stogov	zend_stack list_stack;
1034a550566cSDmitry Stogov	zend_stack context_stack;
10356bf24f4dSDmitry Stogov	zend_array *symbol_table;
10362c254ba7SZeev Suraski	TSRMLS_FETCH();
103767f69743SZeev Suraski
1038b29dc146SDmitry Stogov	/* Report about uncaught exception in case of fatal errors */
1039b29dc146SDmitry Stogov	if (EG(exception)) {
104063c057e3SDmitry Stogov		zend_execute_data *ex;
104163c057e3SDmitry Stogov		zend_op *opline;
104263c057e3SDmitry Stogov
1043b29dc146SDmitry Stogov		switch (type) {
1044b29dc146SDmitry Stogov			case E_CORE_ERROR:
1045b29dc146SDmitry Stogov			case E_ERROR:
1046b29dc146SDmitry Stogov			case E_RECOVERABLE_ERROR:
1047b29dc146SDmitry Stogov			case E_PARSE:
1048b29dc146SDmitry Stogov			case E_COMPILE_ERROR:
1049b29dc146SDmitry Stogov			case E_USER_ERROR:
105063c057e3SDmitry Stogov				ex = EG(current_execute_data);
105163c057e3SDmitry Stogov				opline = NULL;
105263c057e3SDmitry Stogov				while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
105363c057e3SDmitry Stogov					ex = ex->prev_execute_data;
105463c057e3SDmitry Stogov				}
10555aa91be5SDmitry Stogov				if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
105663c057e3SDmitry Stogov				    EG(opline_before_exception)) {
105763c057e3SDmitry Stogov					opline = EG(opline_before_exception);
1058b29dc146SDmitry Stogov				}
1059b29dc146SDmitry Stogov				zend_exception_error(EG(exception), E_WARNING TSRMLS_CC);
1060b29dc146SDmitry Stogov				EG(exception) = NULL;
106163c057e3SDmitry Stogov				if (opline) {
106263c057e3SDmitry Stogov					ex->opline = opline;
1063b29dc146SDmitry Stogov				}
1064b29dc146SDmitry Stogov				break;
1065b29dc146SDmitry Stogov			default:
1066b29dc146SDmitry Stogov				break;
1067b29dc146SDmitry Stogov		}
1068b29dc146SDmitry Stogov	}
1069b29dc146SDmitry Stogov
1070b80b8381SZeev Suraski	/* Obtain relevant filename and lineno */
1071b80b8381SZeev Suraski	switch (type) {
1072b80b8381SZeev Suraski		case E_CORE_ERROR:
1073b80b8381SZeev Suraski		case E_CORE_WARNING:
1074b80b8381SZeev Suraski			error_filename = NULL;
1075b80b8381SZeev Suraski			error_lineno = 0;
1076b80b8381SZeev Suraski			break;
1077b80b8381SZeev Suraski		case E_PARSE:
1078b80b8381SZeev Suraski		case E_COMPILE_ERROR:
1079b80b8381SZeev Suraski		case E_COMPILE_WARNING:
1080b80b8381SZeev Suraski		case E_ERROR:
1081b80b8381SZeev Suraski		case E_NOTICE:
1082c0df4502SAndi Gutmans		case E_STRICT:
1083d3e50265SMarcus Boerger		case E_DEPRECATED:
1084b80b8381SZeev Suraski		case E_WARNING:
1085b80b8381SZeev Suraski		case E_USER_ERROR:
1086b80b8381SZeev Suraski		case E_USER_WARNING:
1087b80b8381SZeev Suraski		case E_USER_NOTICE:
1088d619b57eSHannes Magnusson		case E_USER_DEPRECATED:
10898a03fc5eSAntony Dovgal		case E_RECOVERABLE_ERROR:
10904187439cSZeev Suraski			if (zend_is_compiling(TSRMLS_C)) {
1091f4cfaf36SDmitry Stogov				error_filename = zend_get_compiled_filename(