zend.c revision f3a6c30c
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);
5885a36e2bSZeev SuraskiZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
59ab232458SDmitry StogovZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC);
60536221beSStanislav Malyshev
61bd115087SZeev Suraskivoid (*zend_on_timeout)(int seconds TSRMLS_DC);
62bd115087SZeev Suraski
634a25a774SDmitry Stogovstatic void (*zend_message_dispatcher_p)(long message, const void *data TSRMLS_DC);
64cf7384aaSFelipe Penastatic int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents);
65d035af4aSZeev Suraski
66b4892511SJani Taskinenstatic ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
674be862b0SZeev Suraski{
684be862b0SZeev Suraski	if (!new_value) {
69d3e50265SMarcus Boerger		EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
704be862b0SZeev Suraski	} else {
714be862b0SZeev Suraski		EG(error_reporting) = atoi(new_value);
724be862b0SZeev Suraski	}
734be862b0SZeev Suraski	return SUCCESS;
744be862b0SZeev Suraski}
75b4892511SJani Taskinen/* }}} */
764be862b0SZeev Suraski
7771592cecSDmitry Stogovstatic ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
7871592cecSDmitry Stogov{
7971592cecSDmitry Stogov	OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
8071592cecSDmitry Stogov
8171592cecSDmitry Stogov	if (GC_G(gc_enabled)) {
8271592cecSDmitry Stogov		gc_init(TSRMLS_C);
8371592cecSDmitry Stogov	}
8471592cecSDmitry Stogov
8571592cecSDmitry Stogov	return SUCCESS;
8671592cecSDmitry Stogov}
8771592cecSDmitry Stogov/* }}} */
8871592cecSDmitry Stogov
89bbf3d43cSMoriyoshi Koizumistatic ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
90bbf3d43cSMoriyoshi Koizumi{
91bbf3d43cSMoriyoshi Koizumi	if (!CG(multibyte)) {
92bbf3d43cSMoriyoshi Koizumi		return FAILURE;
93bbf3d43cSMoriyoshi Koizumi	}
94bbf3d43cSMoriyoshi Koizumi	if (!zend_multibyte_get_functions(TSRMLS_C)) {
95bbf3d43cSMoriyoshi Koizumi		return SUCCESS;
96bbf3d43cSMoriyoshi Koizumi	}
97bbf3d43cSMoriyoshi Koizumi	return zend_multibyte_set_script_encoding_by_string(new_value, new_value_length TSRMLS_CC);
98bbf3d43cSMoriyoshi Koizumi}
99bbf3d43cSMoriyoshi Koizumi/* }}} */
100bbf3d43cSMoriyoshi Koizumi
101bbf3d43cSMoriyoshi Koizumi
1024be862b0SZeev SuraskiZEND_INI_BEGIN()
103eb6fd52eSZeev Suraski	ZEND_INI_ENTRY("error_reporting",				NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
10471592cecSDmitry Stogov	STD_ZEND_INI_BOOLEAN("zend.enable_gc",				"1",	ZEND_INI_ALL,		OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
105ab93d8c6SDmitry Stogov 	STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
106bbf3d43cSMoriyoshi Koizumi 	ZEND_INI_ENTRY("zend.script_encoding",			NULL,		ZEND_INI_ALL,		OnUpdateScriptEncoding)
107bbf3d43cSMoriyoshi Koizumi 	STD_ZEND_INI_BOOLEAN("zend.detect_unicode",			"1",	ZEND_INI_ALL,		OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
10834d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
10934d93f0cSIlia Alshanetsky	STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
11034d93f0cSIlia Alshanetsky#endif
1114be862b0SZeev SuraskiZEND_INI_END()
1124be862b0SZeev Suraski
1134be862b0SZeev Suraski
1147a87fcbbSZeev Suraski#ifdef ZTS
115e06a1ed2SZeev SuraskiZEND_API int compiler_globals_id;
116e06a1ed2SZeev SuraskiZEND_API int executor_globals_id;
117b4892511SJani Taskinenstatic HashTable *global_function_table = NULL;
118b4892511SJani Taskinenstatic HashTable *global_class_table = NULL;
119b4892511SJani Taskinenstatic HashTable *global_constants_table = NULL;
120b4892511SJani Taskinenstatic HashTable *global_auto_globals_table = NULL;
12121698c12SDmitry Stogovstatic HashTable *global_persistent_list = NULL;
1227a87fcbbSZeev Suraski#endif
123573b4602SAndi Gutmans
124e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
125573b4602SAndi Gutmans
126573b4602SAndi Gutmans/* version information */
127573b4602SAndi Gutmansstatic char *zend_version_info;
128573b4602SAndi Gutmansstatic uint zend_version_info_length;
129c081ce62SXinchen Hui#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2014 Zend Technologies\n"
13080bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
131573b4602SAndi Gutmans
132d3d02fbcSDmitry Stogovstatic void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
133573b4602SAndi Gutmans{
134f4cfaf36SDmitry Stogov	zval *tmp;
135f4cfaf36SDmitry Stogov	zend_string *string_key;
13663873abaSStanislav Malyshev	HashPosition iterator;
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;
14563873abaSStanislav Malyshev	zend_hash_internal_pointer_reset_ex(ht, &iterator);
146f4cfaf36SDmitry Stogov	while ((tmp = zend_hash_get_current_data_ex(ht, &iterator)) != NULL) {
147b4892511SJani Taskinen		for (i = 0; i < indent; i++) {
148d3d02fbcSDmitry Stogov			ZEND_PUTS_EX(" ");
149573b4602SAndi Gutmans		}
150d3d02fbcSDmitry Stogov		ZEND_PUTS_EX("[");
151f4cfaf36SDmitry Stogov		switch (zend_hash_get_current_key_ex(ht, &string_key, &num_key, 0, &iterator)) {
152573b4602SAndi Gutmans			case HASH_KEY_IS_STRING:
153d329ce93SZeev Suraski				if (is_object) {
1544a25a774SDmitry Stogov					const char *prop_name, *class_name;
15562059c16SXinchen Hui					int prop_len;
156f4cfaf36SDmitry Stogov					int mangled = zend_unmangle_property_name_ex(string_key->val, string_key->len, &class_name, &prop_name, &prop_len);
157d329ce93SZeev Suraski
15862059c16SXinchen Hui					ZEND_WRITE_EX(prop_name, prop_len);
159978dd0fdSMarcus Boerger					if (class_name && mangled == SUCCESS) {
160d329ce93SZeev Suraski						if (class_name[0]=='*') {
161d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":protected");
162d329ce93SZeev Suraski						} else {
163d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":");
164d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(class_name);
165d3d02fbcSDmitry Stogov							ZEND_PUTS_EX(":private");
166d329ce93SZeev Suraski						}
167d329ce93SZeev Suraski					}
168d329ce93SZeev Suraski				} else {
169f4cfaf36SDmitry Stogov					ZEND_WRITE_EX(string_key->val, string_key->len);
170d329ce93SZeev Suraski				}
171573b4602SAndi Gutmans				break;
172573b4602SAndi Gutmans			case HASH_KEY_IS_LONG:
173d3d02fbcSDmitry Stogov				{
174d3d02fbcSDmitry Stogov					char key[25];
175d3d02fbcSDmitry Stogov					snprintf(key, sizeof(key), "%ld", num_key);
176d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(key);
177d3d02fbcSDmitry Stogov				}
178573b4602SAndi Gutmans				break;
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");
18363873abaSStanislav Malyshev		zend_hash_move_forward_ex(ht, &iterator);
184573b4602SAndi Gutmans	}
18580bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
186b4892511SJani Taskinen	for (i = 0; i < indent; i++) {
187d3d02fbcSDmitry Stogov		ZEND_PUTS_EX(" ");
188573b4602SAndi Gutmans	}
189d3d02fbcSDmitry Stogov	ZEND_PUTS_EX(")\n");
190573b4602SAndi Gutmans}
191b4892511SJani Taskinen/* }}} */
192573b4602SAndi Gutmans
193b4892511SJani Taskinenstatic void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
19427de54b0SAndi Gutmans{
195f4cfaf36SDmitry Stogov	zval *tmp;
196f4cfaf36SDmitry Stogov	zend_string *string_key;
197b4892511SJani Taskinen	HashPosition iterator;
198b4892511SJani Taskinen	ulong num_key;
199b4892511SJani Taskinen	int i = 0;
200b4892511SJani Taskinen
201b4892511SJani Taskinen	zend_hash_internal_pointer_reset_ex(ht, &iterator);
202f4cfaf36SDmitry Stogov	while ((tmp = zend_hash_get_current_data_ex(ht, &iterator)) != NULL) {
203b4892511SJani Taskinen		if (i++ > 0) {
204b4892511SJani Taskinen			ZEND_PUTS(",");
205b4892511SJani Taskinen		}
206b4892511SJani Taskinen		ZEND_PUTS("[");
207f4cfaf36SDmitry Stogov		switch (zend_hash_get_current_key_ex(ht, &string_key, &num_key, 0, &iterator)) {
208b4892511SJani Taskinen			case HASH_KEY_IS_STRING:
209f4cfaf36SDmitry Stogov				ZEND_WRITE(string_key->val, string_key->len);
210b4892511SJani Taskinen				break;
211b4892511SJani Taskinen			case HASH_KEY_IS_LONG:
212b4892511SJani Taskinen				zend_printf("%ld", num_key);
213b4892511SJani Taskinen				break;
214b4892511SJani Taskinen		}
215b4892511SJani Taskinen		ZEND_PUTS("] => ");
216f4cfaf36SDmitry Stogov		zend_print_flat_zval_r(tmp TSRMLS_CC);
217b4892511SJani Taskinen		zend_hash_move_forward_ex(ht, &iterator);
21827de54b0SAndi Gutmans	}
21927de54b0SAndi Gutmans}
220b4892511SJani Taskinen/* }}} */
2217a87fcbbSZeev Suraski
222b4892511SJani TaskinenZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */
223573b4602SAndi Gutmans{
224f3a6c30cSXinchen Hui	if (Z_TYPE_P(expr) == IS_STRING) {
225da9faa2cSZeev Suraski		*use_copy = 0;
226da9faa2cSZeev Suraski		return;
227da9faa2cSZeev Suraski	}
228f3a6c30cSXinchen Hui
229f3a6c30cSXinchen Huiagain:
230b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
231bdefd5daSAndi Gutmans		case IS_NULL:
232f4cfaf36SDmitry Stogov			Z_STR_P(expr_copy) = STR_EMPTY_ALLOC();
2338c4ab98eSThies C. Arntzen			break;
234da9faa2cSZeev Suraski		case IS_BOOL:
235b4892511SJani Taskinen			if (Z_LVAL_P(expr)) {
236f4cfaf36SDmitry Stogov				// TODO: ??? use interned string
237f4cfaf36SDmitry Stogov				Z_STR_P(expr_copy) = STR_INIT("1", 1, 0);
23891d7ba76SAndi Gutmans			} else {
239f4cfaf36SDmitry Stogov				Z_STR_P(expr_copy) = STR_EMPTY_ALLOC();
24091d7ba76SAndi Gutmans			}
241da9faa2cSZeev Suraski			break;
242f4cfaf36SDmitry Stogov		case IS_RESOURCE: {
243f4cfaf36SDmitry Stogov				char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
244f4cfaf36SDmitry Stogov				int len;
245f4cfaf36SDmitry Stogov
246f4cfaf36SDmitry Stogov				len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(expr));
247f4cfaf36SDmitry Stogov				Z_STR_P(expr_copy) = STR_INIT(buf, len, 0);
248f4cfaf36SDmitry Stogov			}
249da9faa2cSZeev Suraski			break;
250da9faa2cSZeev Suraski		case IS_ARRAY:
251d81ea16eSStanislav Malyshev			zend_error(E_NOTICE, "Array to string conversion");
252f4cfaf36SDmitry Stogov			// TODO: ??? use interned string
253e687939fSXinchen Hui			Z_STR_P(expr_copy) = STR_INIT("Array", sizeof("Array") - 1, 0);
254da9faa2cSZeev Suraski			break;
2551b282b35SAndi Gutmans		case IS_OBJECT:
2567901a221SAndi Gutmans			{
257ae2bfb78SSterling Hughes				TSRMLS_FETCH();
258637a4042SMarcus Boerger
2597b307fb9SXinchen Hui				if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
2607b307fb9SXinchen Hui					break;
2617b307fb9SXinchen Hui				}
262750e4e10SDmitry Stogov				if (Z_OBJ_HANDLER_P(expr, cast_object)) {
263f4cfaf36SDmitry Stogov					zval val;
264750e4e10SDmitry Stogov
26517bf59f8SDmitry Stogov					ZVAL_DUP_DEREF(&val, expr);
266f4cfaf36SDmitry Stogov					if (Z_OBJ_HANDLER_P(expr, cast_object)(&val, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
267750e4e10SDmitry Stogov						zval_ptr_dtor(&val);
268750e4e10SDmitry Stogov						break;
269750e4e10SDmitry Stogov					}
270750e4e10SDmitry Stogov					zval_ptr_dtor(&val);
271848c5c76SMarcus Boerger				}
272b3c3c6deSMarcus Boerger				if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
273b3c3c6deSMarcus Boerger					zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC);
2747addae50SMarcus Boerger
2754b4d634cSYiduo (David) Wang					Z_ADDREF_P(z);
276b4892511SJani Taskinen					if (Z_TYPE_P(z) != IS_OBJECT) {
277b3c3c6deSMarcus Boerger						zend_make_printable_zval(z, expr_copy, use_copy);
278b3c3c6deSMarcus Boerger						if (*use_copy) {
279f4cfaf36SDmitry Stogov							zval_ptr_dtor(z);
280b3c3c6deSMarcus Boerger						} else {
281b3c3c6deSMarcus Boerger							ZVAL_ZVAL(expr_copy, z, 0, 1);
282b3c3c6deSMarcus Boerger							*use_copy = 1;
2833b8b43a9SStanislav Malyshev						}
284b3c3c6deSMarcus Boerger						return;
2853b8b43a9SStanislav Malyshev					}
286f4cfaf36SDmitry Stogov					zval_ptr_dtor(z);
28771ba4427SMarcus Boerger				}
288f4cfaf36SDmitry 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);
289f4cfaf36SDmitry Stogov				Z_STR_P(expr_copy) = STR_EMPTY_ALLOC();
290ae2bfb78SSterling Hughes			}
291da9faa2cSZeev Suraski			break;
292e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
293f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
294e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
295e842ef9fSIlia Alshanetsky			break;
296f3a6c30cSXinchen Hui		case IS_REFERENCE:
297f3a6c30cSXinchen Hui			expr = Z_REFVAL_P(expr);
298f3a6c30cSXinchen Hui			if (Z_TYPE_P(expr) == IS_STRING) {
299f3a6c30cSXinchen Hui				ZVAL_STR(expr_copy, STR_COPY(Z_STR_P(expr)));
300f3a6c30cSXinchen Hui				*use_copy = 1;
301f3a6c30cSXinchen Hui				return;
302f3a6c30cSXinchen Hui			}
303f3a6c30cSXinchen Hui			goto again;
304f3a6c30cSXinchen Hui			break;
305da9faa2cSZeev Suraski		default:
306f4cfaf36SDmitry Stogov			ZVAL_DUP(expr_copy, expr);
307da9faa2cSZeev Suraski			convert_to_string(expr_copy);
308da9faa2cSZeev Suraski			break;
309da9faa2cSZeev Suraski	}
310b4892511SJani Taskinen	Z_TYPE_P(expr_copy) = IS_STRING;
311da9faa2cSZeev Suraski	*use_copy = 1;
312da9faa2cSZeev Suraski}
313b4892511SJani Taskinen/* }}} */
314da9faa2cSZeev Suraski
315b4892511SJani TaskinenZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */
316da9faa2cSZeev Suraski{
3175dba4774SZeev Suraski	return zend_print_zval_ex(zend_write, expr, indent);
3185dba4774SZeev Suraski}
319b4892511SJani Taskinen/* }}} */
3205dba4774SZeev Suraski
321b4892511SJani TaskinenZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
3225dba4774SZeev Suraski{
323da9faa2cSZeev Suraski	zval expr_copy;
324da9faa2cSZeev Suraski	int use_copy;
325d062fb33SDmitry Stogov	int ret;
326da9faa2cSZeev Suraski
327da9faa2cSZeev Suraski	zend_make_printable_zval(expr, &expr_copy, &use_copy);
328da9faa2cSZeev Suraski	if (use_copy) {
329573b4602SAndi Gutmans		expr = &expr_copy;
330573b4602SAndi Gutmans	}
331b4892511SJani Taskinen	if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */
332da9faa2cSZeev Suraski		if (use_copy) {
333da9faa2cSZeev Suraski			zval_dtor(expr);
334da9faa2cSZeev Suraski		}
335573b4602SAndi Gutmans		return 0;
336573b4602SAndi Gutmans	}
337b4892511SJani Taskinen	write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr));
338d062fb33SDmitry Stogov	ret = Z_STRLEN_P(expr);
339da9faa2cSZeev Suraski	if (use_copy) {
340573b4602SAndi Gutmans		zval_dtor(expr);
341573b4602SAndi Gutmans	}
342d062fb33SDmitry Stogov	return ret;
343573b4602SAndi Gutmans}
344b4892511SJani Taskinen/* }}} */
345573b4602SAndi Gutmans
346b4892511SJani TaskinenZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */
34727de54b0SAndi Gutmans{
348b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
349b4892511SJani Taskinen		case IS_ARRAY:
350b4892511SJani Taskinen			ZEND_PUTS("Array (");
351b4892511SJani Taskinen			if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
352b4892511SJani Taskinen				ZEND_PUTS(" *RECURSION*");
353b4892511SJani Taskinen				Z_ARRVAL_P(expr)->nApplyCount--;
354b4892511SJani Taskinen				return;
355b4892511SJani Taskinen			}
356b4892511SJani Taskinen			print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC);
357b4892511SJani Taskinen			ZEND_PUTS(")");
358b4892511SJani Taskinen			Z_ARRVAL_P(expr)->nApplyCount--;
359b4892511SJani Taskinen			break;
360b4892511SJani Taskinen		case IS_OBJECT:
361b4892511SJani Taskinen		{
3629bba373aSStanislav Malyshev			HashTable *properties = NULL;
363f4cfaf36SDmitry Stogov			zend_string *class_name = NULL;
3648ce1211aSMarcus Boerger
365f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
366f4cfaf36SDmitry Stogov				class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(expr, 0 TSRMLS_CC);
3679bba373aSStanislav Malyshev			}
368b4892511SJani Taskinen			if (class_name) {
369f4cfaf36SDmitry Stogov				zend_printf("%s Object (", class_name->val);
370b4892511SJani Taskinen			} else {
371b4892511SJani Taskinen				zend_printf("%s Object (", "Unknown Class");
372b4892511SJani Taskinen			}
373288daccaSAndi Gutmans			if (class_name) {
374d062fb33SDmitry Stogov				STR_RELEASE(class_name);
3759bba373aSStanislav Malyshev			}
376f30f3590SStanislav Malyshev			if (Z_OBJ_HANDLER_P(expr, get_properties)) {
3779bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
3789bba373aSStanislav Malyshev			}
379f30f3590SStanislav Malyshev			if (properties) {
3809bba373aSStanislav Malyshev				if (++properties->nApplyCount>1) {
3819bba373aSStanislav Malyshev					ZEND_PUTS(" *RECURSION*");
3829bba373aSStanislav Malyshev					properties->nApplyCount--;
3839bba373aSStanislav Malyshev					return;
3849bba373aSStanislav Malyshev				}
38524db7f18SSebastian Bergmann				print_flat_hash(properties TSRMLS_CC);
3869bba373aSStanislav Malyshev				properties->nApplyCount--;
3879bba373aSStanislav Malyshev			}
3889bba373aSStanislav Malyshev			ZEND_PUTS(")");
3899bba373aSStanislav Malyshev			break;
390b4892511SJani Taskinen		}
391b4892511SJani Taskinen		default:
392b4892511SJani Taskinen			zend_print_variable(expr);
393b4892511SJani Taskinen			break;
394b4892511SJani Taskinen	}
39527de54b0SAndi Gutmans}
396b4892511SJani Taskinen/* }}} */
397573b4602SAndi Gutmans
398b4892511SJani TaskinenZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */
3995dba4774SZeev Suraski{
40024db7f18SSebastian Bergmann	zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC);
4015dba4774SZeev Suraski}
402b4892511SJani Taskinen/* }}} */
4035dba4774SZeev Suraski
404b4892511SJani TaskinenZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */
405573b4602SAndi Gutmans{
4065e4a97f3SDmitry Stogov	if (Z_ISREF_P(expr)) {
4075e4a97f3SDmitry Stogov		expr = Z_REFVAL_P(expr);
4085e4a97f3SDmitry Stogov	}
409b4892511SJani Taskinen	switch (Z_TYPE_P(expr)) {
410573b4602SAndi Gutmans		case IS_ARRAY:
411d3d02fbcSDmitry Stogov			ZEND_PUTS_EX("Array\n");
412b4892511SJani Taskinen			if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
413d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" *RECURSION*");
414b4892511SJani Taskinen				Z_ARRVAL_P(expr)->nApplyCount--;
4156053f2a1SZeev Suraski				return;
4166053f2a1SZeev Suraski			}
417d3d02fbcSDmitry Stogov			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
418b4892511SJani Taskinen			Z_ARRVAL_P(expr)->nApplyCount--;
419573b4602SAndi Gutmans			break;
420573b4602SAndi Gutmans		case IS_OBJECT:
421c259cb7cSAndi Gutmans			{
4228ce1211aSMarcus Boerger				HashTable *properties;
423f4cfaf36SDmitry Stogov				zend_string *class_name = NULL;
4248ce1211aSMarcus Boerger				int is_temp;
4258ce1211aSMarcus Boerger
426f30f3590SStanislav Malyshev				if (Z_OBJ_HANDLER_P(expr, get_class_name)) {
427f4cfaf36SDmitry Stogov					class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(expr, 0 TSRMLS_CC);
4289bba373aSStanislav Malyshev				}
429f1fb77d1SIlia Alshanetsky				if (class_name) {
430f4cfaf36SDmitry Stogov					ZEND_PUTS_EX(class_name->val);
431f1fb77d1SIlia Alshanetsky				} else {
432d3d02fbcSDmitry Stogov					ZEND_PUTS_EX("Unknown Class");
433f1fb77d1SIlia Alshanetsky				}
434d3d02fbcSDmitry Stogov				ZEND_PUTS_EX(" Object\n");
435288daccaSAndi Gutmans				if (class_name) {
436bdeaf2efSDmitry Stogov					STR_RELEASE(class_name);
4379bba373aSStanislav Malyshev				}
4388ce1211aSMarcus Boerger				if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
4398ce1211aSMarcus Boerger					break;
4409bba373aSStanislav Malyshev				}
4418ce1211aSMarcus Boerger				if (++properties->nApplyCount>1) {
442d3d02fbcSDmitry Stogov					ZEND_PUTS_EX(" *RECURSION*");
4439bba373aSStanislav Malyshev					properties->nApplyCount--;
4448ce1211aSMarcus Boerger					return;
4458ce1211aSMarcus Boerger				}
446d3d02fbcSDmitry Stogov				print_hash(write_func, properties, indent, 1 TSRMLS_CC);
4478ce1211aSMarcus Boerger				properties->nApplyCount--;
4488ce1211aSMarcus Boerger				if (is_temp) {
4498ce1211aSMarcus Boerger					zend_hash_destroy(properties);
4508ce1211aSMarcus Boerger					efree(properties);
451c259cb7cSAndi Gutmans				}
452c259cb7cSAndi Gutmans				break;
4536053f2a1SZeev Suraski			}
454573b4602SAndi Gutmans		default:
455d3d02fbcSDmitry Stogov			zend_print_zval_ex(write_func, expr, indent);
456573b4602SAndi Gutmans			break;
457573b4602SAndi Gutmans	}
458573b4602SAndi Gutmans}
459b4892511SJani Taskinen/* }}} */
460573b4602SAndi Gutmans
46185ab4235SFelipe Penastatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */
462573b4602SAndi Gutmans{
4635463dd5bSAndi Gutmans	if (opened_path) {
46427de5001SAndi Gutmans		*opened_path = estrdup(filename);
4655463dd5bSAndi Gutmans	}
466f311ab16SAndi Gutmans	return fopen(filename, "rb");
467573b4602SAndi Gutmans}
468b4892511SJani Taskinen/* }}} */
469573b4602SAndi Gutmans
4702f586e96SDmitry Stogov#ifdef ZTS
4718c885b89SDmitry Stogovstatic zend_bool asp_tags_default		  = 0;
4728c885b89SDmitry Stogovstatic zend_bool short_tags_default		  = 1;
4738c885b89SDmitry Stogovstatic zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT;
4742f586e96SDmitry Stogov#else
4758c885b89SDmitry Stogov# define asp_tags_default			0
4768c885b89SDmitry Stogov# define short_tags_default			1
4778c885b89SDmitry Stogov# define compiler_options_default	ZEND_COMPILE_DEFAULT
4782f586e96SDmitry Stogov#endif
4792f586e96SDmitry Stogov
480b4892511SJani Taskinenstatic void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */
4818b794bb1SZeev Suraski{
4828b794bb1SZeev Suraski	/* default compile-time values */
4832f586e96SDmitry Stogov	CG(asp_tags) = asp_tags_default;
4842f586e96SDmitry Stogov	CG(short_tags) = short_tags_default;
4858c885b89SDmitry Stogov	CG(compiler_options) = compiler_options_default;
4868b794bb1SZeev Suraski}
487b4892511SJani Taskinen/* }}} */
4888b794bb1SZeev Suraski
489fcaa1c6dSDmitry Stogovstatic void zend_init_exception_op(TSRMLS_D) /* {{{ */
490fcaa1c6dSDmitry Stogov{
491fcaa1c6dSDmitry Stogov	memset(EG(exception_op), 0, sizeof(EG(exception_op)));
492fcaa1c6dSDmitry Stogov	EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
49394dd8372SDmitry Stogov	EG(exception_op)[0].op1_type = IS_UNUSED;
49494dd8372SDmitry Stogov	EG(exception_op)[0].op2_type = IS_UNUSED;
49594dd8372SDmitry Stogov	EG(exception_op)[0].result_type = IS_UNUSED;
496fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
497fcaa1c6dSDmitry Stogov	EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
49894dd8372SDmitry Stogov	EG(exception_op)[1].op1_type = IS_UNUSED;
49994dd8372SDmitry Stogov	EG(exception_op)[1].op2_type = IS_UNUSED;
50094dd8372SDmitry Stogov	EG(exception_op)[1].result_type = IS_UNUSED;
501fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
502fcaa1c6dSDmitry Stogov	EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
50394dd8372SDmitry Stogov	EG(exception_op)[2].op1_type = IS_UNUSED;
50494dd8372SDmitry Stogov	EG(exception_op)[2].op2_type = IS_UNUSED;
50594dd8372SDmitry Stogov	EG(exception_op)[2].result_type = IS_UNUSED;
506fcaa1c6dSDmitry Stogov	ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
507fcaa1c6dSDmitry Stogov}
508fcaa1c6dSDmitry Stogov/* }}} */
509fcaa1c6dSDmitry Stogov
5107a87fcbbSZeev Suraski#ifdef ZTS
511b4892511SJani Taskinenstatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5127a87fcbbSZeev Suraski{
5137c4a0838SZeev Suraski	zend_function tmp_func;
514334ddd12SAndi Gutmans	zend_class_entry *tmp_class;
5157c4a0838SZeev Suraski
5167f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
5177f4909d9SThies C. Arntzen
518f7f5a5eaSStanislav Malyshev	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
519b4892511SJani Taskinen	zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
520b4892511SJani Taskinen	zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
5217a87fcbbSZeev Suraski
522b4892511SJani Taskinen	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
523b4892511SJani Taskinen	zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
5242b9b9afaSDmitry Stogov	zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
5259cf1a98dSThies C. Arntzen
526b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
52785b4df53SZeev Suraski
52885b4df53SZeev Suraski	CG(interactive) = 0;
5299d11db12SAndi Gutmans
5309d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
5319d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
532f7b78004SZeev Suraski	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */);
5338768ab94SDmitry Stogov
5348768ab94SDmitry Stogov	compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
5358768ab94SDmitry Stogov	if (compiler_globals->last_static_member) {
536f23e8576SDmitry Stogov		compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval**));
5378768ab94SDmitry Stogov	} else {
538f23e8576SDmitry Stogov		compiler_globals->static_members_table = NULL;
5398768ab94SDmitry Stogov	}
540ae0e5a0cSAntony Dovgal	compiler_globals->script_encoding_list = NULL;
5417a87fcbbSZeev Suraski}
542b4892511SJani Taskinen/* }}} */
5437a87fcbbSZeev Suraski
544b4892511SJani Taskinenstatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */
5457a87fcbbSZeev Suraski{
546ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
54774a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
5488fb5ea30SMarcus Boerger		free(compiler_globals->function_table);
54974a9ed7bSZeev Suraski	}
550ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
55174a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
5528fb5ea30SMarcus Boerger		free(compiler_globals->class_table);
55374a9ed7bSZeev Suraski	}
5548fb5ea30SMarcus Boerger	if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
5559d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
5569d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
5579d11db12SAndi Gutmans	}
558f23e8576SDmitry Stogov	if (compiler_globals->static_members_table) {
559f23e8576SDmitry Stogov		free(compiler_globals->static_members_table);
5608768ab94SDmitry Stogov	}
561bbf3d43cSMoriyoshi Koizumi	if (compiler_globals->script_encoding_list) {
562bbf3d43cSMoriyoshi Koizumi		pefree(compiler_globals->script_encoding_list, 1);
563bbf3d43cSMoriyoshi Koizumi	}
5648768ab94SDmitry Stogov	compiler_globals->last_static_member = 0;
5657a87fcbbSZeev Suraski}
566b4892511SJani Taskinen/* }}} */
567a9f9ae79SZeev Suraski
568b4892511SJani Taskinenstatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
569a9f9ae79SZeev Suraski{
5705fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
5715fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
5722c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
573fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
574b4892511SJani Taskinen	EG(lambda_count) = 0;
5751f23e507SZeev Suraski	EG(user_error_handler) = NULL;
57604788f95SStig Bakken	EG(user_exception_handler) = NULL;
577ab30c8ccSZeev Suraski	EG(in_execution) = 0;
57855cf45abSDmitry Stogov	EG(in_autoload) = NULL;
579e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
58052303217SMarcus Boerger	EG(current_module) = NULL;
5819d576212SAntony Dovgal	EG(exit_status) = 0;
582ee4f5ac1SFelipe Pena#if XPFPA_HAVE_CW
583ee4f5ac1SFelipe Pena	EG(saved_fpu_cw) = 0;
584ee4f5ac1SFelipe Pena#endif
58525710a40SFelipe Pena	EG(saved_fpu_cw_ptr) = NULL;
586d6ee9d48SAntony Dovgal	EG(active) = 0;
587a9f9ae79SZeev Suraski}
588b4892511SJani Taskinen/* }}} */
589a9f9ae79SZeev Suraski
590b4892511SJani Taskinenstatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */
591a9f9ae79SZeev Suraski{
5922c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
59321698c12SDmitry Stogov	if (&executor_globals->persistent_list != global_persistent_list) {
59421698c12SDmitry Stogov		zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC);
59521698c12SDmitry Stogov	}
59621698c12SDmitry Stogov	if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
59721698c12SDmitry Stogov		zend_hash_destroy(executor_globals->zend_constants);
59821698c12SDmitry Stogov		free(executor_globals->zend_constants);
59921698c12SDmitry Stogov	}
600a9f9ae79SZeev Suraski}
601b4892511SJani Taskinen/* }}} */
602a9f9ae79SZeev Suraski
603b4892511SJani Taskinenstatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */
604609d58a4SZeev Suraski{
605a84a2eaeSDmitry Stogov	if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) {
606a84a2eaeSDmitry Stogov		zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
607a84a2eaeSDmitry Stogov	}
608609d58a4SZeev Suraski}
609b4892511SJani Taskinen/* }}} */
61066d9314bSZeev Suraski#endif
61166d9314bSZeev Suraski
612d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
613d46f8078SJon Parise/* FreeBSD and DragonFly floating point precision fix */
6145928970dSAndi Gutmans#include <floatingpoint.h>
6155928970dSAndi Gutmans#endif
6167a87fcbbSZeev Suraski
617af316021SMarcus Boergerstatic void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
618af316021SMarcus Boerger{
619af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
620af316021SMarcus Boerger}
621af316021SMarcus Boerger/* }}} */
622af316021SMarcus Boerger
623af316021SMarcus Boergerstatic void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */
62454d53055SZeev Suraski{
625af316021SMarcus Boerger	memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
62654d53055SZeev Suraski}
627b4892511SJani Taskinen/* }}} */
62854d53055SZeev Suraski
629226c56feSJani Taskinenvoid zend_init_opcodes_handlers(void);
63054d53055SZeev Suraski
6312b9b9afaSDmitry Stogovstatic void module_destructor_zval(zval *zv) /* {{{ */
6322b9b9afaSDmitry Stogov{
6332b9b9afaSDmitry Stogov	zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
6342b9b9afaSDmitry Stogov
6352b9b9afaSDmitry Stogov	module_destructor(module);
6362b9b9afaSDmitry Stogov	free(module);
6372b9b9afaSDmitry Stogov}
6382b9b9afaSDmitry Stogov/* }}} */
6392b9b9afaSDmitry Stogov
6402b9b9afaSDmitry Stogovstatic void auto_global_dtor(zval *zv) /* {{{ */
6412b9b9afaSDmitry Stogov{
6422b9b9afaSDmitry Stogov	free(Z_PTR_P(zv));
6432b9b9afaSDmitry Stogov}
6442b9b9afaSDmitry Stogov/* }}} */
6452b9b9afaSDmitry Stogov
646f4cfaf36SDmitry Stogovstatic zend_bool php_auto_globals_create_globals(zend_string *name TSRMLS_DC) /* {{{ */
647f0c8366aSDmitry Stogov{
648f4cfaf36SDmitry Stogov	zval globals;
649f4cfaf36SDmitry Stogov
650f4cfaf36SDmitry Stogov	ZVAL_ARR(&globals, &EG(symbol_table));
651f4cfaf36SDmitry Stogov	ZVAL_NEW_REF(&globals, &globals);
652f4cfaf36SDmitry Stogov	zend_hash_update(&EG(symbol_table).ht, name, &globals);
653f0c8366aSDmitry Stogov	return 0;
654f0c8366aSDmitry Stogov}
655f0c8366aSDmitry Stogov/* }}} */
656f0c8366aSDmitry Stogov
6572faea53dSMarcus Boergerint zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */
658573b4602SAndi Gutmans{
659a9f9ae79SZeev Suraski#ifdef ZTS
6607c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
661a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
662609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
663609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
664609d58a4SZeev Suraski#else
665af316021SMarcus Boerger	extern zend_ini_scanner_globals ini_scanner_globals;
666af316021SMarcus Boerger	extern zend_php_scanner_globals language_scanner_globals;
667609d58a4SZeev Suraski#endif
668a9f9ae79SZeev Suraski
66929ed52ffSDmitry Stogov	start_memory_manager(TSRMLS_C);
670a9f9ae79SZeev Suraski
671cf6ab0e9SAnatol Belski	virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
672cf6ab0e9SAnatol Belski
673d46f8078SJon Parise#if defined(__FreeBSD__) || defined(__DragonFly__)
674d46f8078SJon Parise	/* FreeBSD and DragonFly floating point precision fix */
675c3340584SSascha Schumann	fpsetmask(0);
6765928970dSAndi Gutmans#endif
677309827ecSZeev Suraski
6784d44a5b7SAntony Dovgal	zend_startup_strtod();
679309827ecSZeev Suraski	zend_startup_extensions_mechanism();
680309827ecSZeev Suraski
681573b4602SAndi Gutmans	/* Set up utility functions and values */
68267f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
683573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
6845dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
685573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
686573b4602SAndi Gutmans	if (!zend_fopen) {
687573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
688573b4602SAndi Gutmans	}
689e52aac94SWez Furlong	zend_stream_open_function = utility_functions->stream_open_function;
69056251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
69134d93f0cSIlia Alshanetsky#ifndef ZEND_SIGNALS
692573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
693573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
69434d93f0cSIlia Alshanetsky#endif
695903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
696fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
697bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
698d45fd8a1SMarcus Boerger	zend_vspprintf = utility_functions->vspprintf_function;
69985a36e2bSZeev Suraski	zend_getenv = utility_functions->getenv_function;
700ab232458SDmitry Stogov	zend_resolve_path = utility_functions->resolve_path_function;
701d035af4aSZeev Suraski
70208b9fdc8SDavid Soria Parra#if HAVE_DTRACE
70308b9fdc8SDavid Soria Parra/* build with dtrace support */
70408b9fdc8SDavid Soria Parra	zend_compile_file = dtrace_compile_file;
70570f83f35SDmitry Stogov	zend_execute_ex = dtrace_execute_ex;
70608b9fdc8SDavid Soria Parra	zend_execute_internal = dtrace_execute_internal;
70708b9fdc8SDavid Soria Parra#else
708c06692e9SZeev Suraski	zend_compile_file = compile_file;
70970f83f35SDmitry Stogov	zend_execute_ex = execute_ex;
7102c44fab3SDerick Rethans	zend_execute_internal = NULL;
71108b9fdc8SDavid Soria Parra#endif /* HAVE_SYS_SDT_H */
71208b9fdc8SDavid Soria Parra	zend_compile_string = compile_string;
713979da661SAndi Gutmans	zend_throw_exception_hook = NULL;
714573b4602SAndi Gutmans
715cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
716cf36abb2SAndi Gutmans
717573b4602SAndi Gutmans	/* set up version */
718573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
719b4892511SJani Taskinen	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
720b4892511SJani Taskinen
721b4892511SJani Taskinen	GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
722b4892511SJani Taskinen	GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
723b4892511SJani Taskinen	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
724b4892511SJani Taskinen	GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
725573b4602SAndi Gutmans
7261263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
7271263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
7282b9b9afaSDmitry Stogov	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
729b4892511SJani Taskinen	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
7302eabb14dSAndi Gutmans
7312b9b9afaSDmitry Stogov	zend_hash_init_ex(&module_registry, 50, NULL, module_destructor_zval, 1, 0);
7324cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
733573b4602SAndi Gutmans
7347a87fcbbSZeev Suraski#ifdef ZTS
7352c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
7362c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
737af316021SMarcus Boerger	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
738af316021SMarcus Boerger	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
7397c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
740a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
7415fcae67eSZeev Suraski
7428fb5ea30SMarcus Boerger	compiler_globals_dtor(compiler_globals TSRMLS_CC);
7432a8426a6SMarcus Boerger	compiler_globals->in_compilation = 0;
7448fb5ea30SMarcus Boerger	compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
7458fb5ea30SMarcus Boerger	compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
7468fb5ea30SMarcus Boerger
747f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
748f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
7499d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
7505fcae67eSZeev Suraski
7515fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
7525fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
753762158aaSAndi Gutmans#else
754af316021SMarcus Boerger	ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
755af316021SMarcus Boerger	php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
756b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
757f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_error_handler));
758f4cfaf36SDmitry Stogov	ZVAL_UNDEF(&EG(user_exception_handler));
7597a87fcbbSZeev Suraski#endif
760826cc0dcSMarcus Boerger
761dd5c478bSDmitry Stogov	zend_interned_strings_init(TSRMLS_C);
7622faea53dSMarcus Boerger	zend_startup_builtin_functions(TSRMLS_C);
7632c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
7642b9b9afaSDmitry Stogov	zend_register_auto_global(STR_INIT("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals TSRMLS_CC);
7657a87fcbbSZeev Suraski
766bfbe8618SZeev Suraski#ifndef ZTS
7672c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
768fcaa1c6dSDmitry Stogov	zend_init_exception_op(TSRMLS_C);
769bfbe8618SZeev Suraski#endif
770a9f9ae79SZeev Suraski
7712c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
77254d53055SZeev Suraski
77354d53055SZeev Suraski#ifdef ZTS
77454d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
77554d53055SZeev Suraski#endif
77654d53055SZeev Suraski
777573b4602SAndi Gutmans	return SUCCESS;
778573b4602SAndi Gutmans}
779b4892511SJani Taskinen/* }}} */
780573b4602SAndi Gutmans
781b4892511SJani Taskinenvoid zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */
7824be862b0SZeev Suraski{
7834be862b0SZeev Suraski	int module_number = 0;
7844be862b0SZeev Suraski
7854be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
7864be862b0SZeev Suraski}
787b4892511SJani Taskinen/* }}} */
7884be862b0SZeev Suraski
789711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
790711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
791711be83dSZeev Suraski */
792b4892511SJani Taskinenvoid zend_post_startup(TSRMLS_D) /* {{{ */
793711be83dSZeev Suraski{
794b4892511SJani Taskinen#ifdef ZTS
79572f19e9aSXinchen Hui	zend_encoding **script_encoding_list;
79672f19e9aSXinchen Hui
797711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
7985fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
799711be83dSZeev Suraski
8005fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
8015fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
8025fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
8032f586e96SDmitry Stogov
8042f586e96SDmitry Stogov	asp_tags_default = CG(asp_tags);
8052f586e96SDmitry Stogov	short_tags_default = CG(short_tags);
8068c885b89SDmitry Stogov	compiler_options_default = CG(compiler_options);
8078ce1211aSMarcus Boerger
808b817dab2SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
8098fb5ea30SMarcus Boerger	free(compiler_globals->function_table);
8108fb5ea30SMarcus Boerger	free(compiler_globals->class_table);
81172f19e9aSXinchen Hui	if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
81272f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
81372f19e9aSXinchen Hui		compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
81472f19e9aSXinchen Hui	} else {
81572f19e9aSXinchen Hui		compiler_globals_ctor(compiler_globals, tsrm_ls);
81672f19e9aSXinchen Hui	}
8178fb5ea30SMarcus Boerger	free(EG(zend_constants));
818cf6ab0e9SAnatol Belski
819cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
820cf6ab0e9SAnatol Belski
8215fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
82221698c12SDmitry Stogov	global_persistent_list = &EG(persistent_list);
823a84a2eaeSDmitry Stogov	zend_copy_ini_directives(TSRMLS_C);
824cf6ab0e9SAnatol Belski#else
825cf6ab0e9SAnatol Belski	virtual_cwd_deactivate(TSRMLS_C);
826711be83dSZeev Suraski#endif
827b4892511SJani Taskinen}
828b4892511SJani Taskinen/* }}} */
829711be83dSZeev Suraski
830b4892511SJani Taskinenvoid zend_shutdown(TSRMLS_D) /* {{{ */
831573b4602SAndi Gutmans{
83234d93f0cSIlia Alshanetsky#ifdef ZEND_SIGNALS
83334d93f0cSIlia Alshanetsky	zend_signal_shutdown(TSRMLS_C);
83434d93f0cSIlia Alshanetsky#endif
83584eb48f0SZeev Suraski#ifdef ZEND_WIN32
83684eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
83784eb48f0SZeev Suraski#endif
8389e1beb4fSDmitry Stogov	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
8391a1178a6SDmitry Stogov	zend_destroy_modules();
8403458373eSAndi Gutmans
841cf6ab0e9SAnatol Belski 	virtual_cwd_deactivate(TSRMLS_C);
842cf6ab0e9SAnatol Belski 	virtual_cwd_shutdown();
843cf6ab0e9SAnatol Belski
8447a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
84576b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
8463458373eSAndi Gutmans
8479d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
8489d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
8492da8b014Sfoobar
850d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
851573b4602SAndi Gutmans	free(zend_version_info);
85248b33032SSterling Hughes
853a2513618SMarcus Boerger	free(GLOBAL_FUNCTION_TABLE);
854a2513618SMarcus Boerger	free(GLOBAL_CLASS_TABLE);
85521698c12SDmitry Stogov
85648b33032SSterling Hughes	zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
857a54c7dcbSMarcus Boerger	free(GLOBAL_CONSTANTS_TABLE);
8584d44a5b7SAntony Dovgal	zend_shutdown_strtod();
859b4892511SJani Taskinen
86021698c12SDmitry Stogov#ifdef ZTS
8618fb5ea30SMarcus Boerger	GLOBAL_FUNCTION_TABLE = NULL;
8628fb5ea30SMarcus Boerger	GLOBAL_CLASS_TABLE = NULL;
8638fb5ea30SMarcus Boerger	GLOBAL_AUTO_GLOBALS_TABLE = NULL;
86421698c12SDmitry Stogov	GLOBAL_CONSTANTS_TABLE = NULL;
865a17d2f37SSebastian Bergmann#endif
8664c283fffSIlia Alshanetsky	zend_destroy_rsrc_list_dtors();
867dd5c478bSDmitry Stogov
868dd5c478bSDmitry Stogov	zend_interned_strings_dtor(TSRMLS_C);
869573b4602SAndi Gutmans}
870b4892511SJani Taskinen/* }}} */
871573b4602SAndi Gutmans
872b4892511SJani Taskinenvoid zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
8737656c77cSZeev Suraski{
8747656c77cSZeev Suraski	zend_uv = *utility_values;
8759baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
8767656c77cSZeev Suraski}
877b4892511SJani Taskinen/* }}} */
8787656c77cSZeev Suraski
879573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
880cf7384aaSFelipe Penavoid zenderror(const char *error) /* {{{ */
881573b4602SAndi Gutmans{
88210def9a8SIlia Alshanetsky	zend_error(E_PARSE, "%s", error);
883573b4602SAndi Gutmans}
884b4892511SJani Taskinen/* }}} */
885573b4602SAndi Gutmans
886b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
887b4892511SJani TaskinenZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
888573b4602SAndi Gutmans{
8892c254ba7SZeev Suraski	TSRMLS_FETCH();
890573b4602SAndi Gutmans
89114f6b914SDmitry Stogov	if (!EG(bailout)) {
892ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
893931ebe08SZeev Suraski		exit(-1);
894931ebe08SZeev Suraski	}
8956bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
89608b3d76cSFelipe Pena	CG(active_class_entry) = NULL;
897b23d83cfSZeev Suraski	CG(in_compilation) = EG(in_execution) = 0;
898bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
89910afe5d9SRasmus Lerdorf	LONGJMP(*EG(bailout), FAILURE);
900573b4602SAndi Gutmans}
901b4892511SJani Taskinen/* }}} */
902b0bfa458SZeev SuraskiEND_EXTERN_C()
903573b4602SAndi Gutmans
904cf7384aaSFelipe Penavoid zend_append_version_info(const zend_extension *extension) /* {{{ */
905573b4602SAndi Gutmans{
906573b4602SAndi Gutmans	char *new_info;
907573b4602SAndi Gutmans	uint new_info_length;
908573b4602SAndi Gutmans
909ed7b3e70SPierrick Charron	new_info_length = sizeof("    with  v, , by \n")
910573b4602SAndi Gutmans						+ strlen(extension->name)
911573b4602SAndi Gutmans						+ strlen(extension->version)
912573b4602SAndi Gutmans						+ strlen(extension->copyright)
913573b4602SAndi Gutmans						+ strlen(extension->author);
914573b4602SAndi Gutmans
915b4892511SJani Taskinen	new_info = (char *) malloc(new_info_length + 1);
916573b4602SAndi Gutmans
917ed7b3e70SPierrick Charron	snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
918573b4602SAndi Gutmans
919b4892511SJani Taskinen	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
920ed7b3e70SPierrick Charron	strncat(zend_version_info, new_info, new_info_length);
921573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
922573b4602SAndi Gutmans	free(new_info);
923573b4602SAndi Gutmans}
924b4892511SJani Taskinen/* }}} */
925573b4602SAndi Gutmans
926b4892511SJani TaskinenZEND_API char *get_zend_version(void) /* {{{ */
927573b4602SAndi Gutmans{
928573b4602SAndi Gutmans	return zend_version_info;
929573b4602SAndi Gutmans}
930b4892511SJani Taskinen/* }}} */
931ed06a70fSZeev Suraski
932f046189eSkrakjoeZEND_API void zend_activate(TSRMLS_D) /* {{{ */
933ed06a70fSZeev Suraski{
934699f07baSAnatol Belski#ifdef ZTS
9359df78bf9SAnatol Belski	virtual_cwd_activate(TSRMLS_C);
936699f07baSAnatol Belski#endif
93771592cecSDmitry Stogov	gc_reset(TSRMLS_C);
938b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
939b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
940b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
941ed06a70fSZeev Suraski}
942b4892511SJani Taskinen/* }}} */
943ed06a70fSZeev Suraski
944b4892511SJani Taskinenvoid zend_call_destructors(TSRMLS_D) /* {{{ */
9450cd2da03SMarcus Boerger{
9460cd2da03SMarcus Boerger	zend_try {
9470cd2da03SMarcus Boerger		shutdown_destructors(TSRMLS_C);
9480cd2da03SMarcus Boerger	} zend_end_try();
9490cd2da03SMarcus Boerger}
950b4892511SJani Taskinen/* }}} */
9510cd2da03SMarcus Boerger
952f046189eSkrakjoeZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */
953ed06a70fSZeev Suraski{
954372f71ebSThies C. Arntzen	/* we're no longer executing anything */
955424e98f4SZeev Suraski	EG(opline_ptr) = NULL;
956372f71ebSThies C. Arntzen	EG(active_symbol_table) = NULL;
957f4c9d96fSThies C. Arntzen
958931ebe08SZeev Suraski	zend_try {
959b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
960931ebe08SZeev Suraski	} zend_end_try();
961931ebe08SZeev Suraski
9628084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
9632c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
964931ebe08SZeev Suraski
965931ebe08SZeev Suraski	zend_try {
966b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
967931ebe08SZeev Suraski	} zend_end_try();
968931ebe08SZeev Suraski
96959a46c34SDmitry Stogov	zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC);
97059a46c34SDmitry Stogov
97171592cecSDmitry Stogov#ifdef ZEND_DEBUG
97271592cecSDmitry Stogov	if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
97371592cecSDmitry Stogov		gc_collect_cycles(TSRMLS_C);
97471592cecSDmitry Stogov	}
97571592cecSDmitry Stogov#endif
97671592cecSDmitry Stogov
9773bd291e1SDerick Rethans#if GC_BENCH
97813d75ce6SDerick Rethans	fprintf(stderr, "GC Statistics\n");
97913d75ce6SDerick Rethans	fprintf(stderr, "-------------\n");
98013d75ce6SDerick Rethans	fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
98113d75ce6SDerick Rethans	fprintf(stderr, "Collected:          %d\n", GC_G(collected));
98213d75ce6SDerick Rethans	fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
98313d75ce6SDerick Rethans	fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
98413d75ce6SDerick Rethans	fprintf(stderr, "      Possible            Remove from  Marked\n");
98513d75ce6SDerick Rethans	fprintf(stderr, "        Root    Buffered     buffer     grey\n");
98613d75ce6SDerick Rethans	fprintf(stderr, "      --------  --------  -----------  ------\n");
98713d75ce6SDerick 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));
98813d75ce6SDerick 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));
9893bd291e1SDerick Rethans#endif
9903bd291e1SDerick Rethans
991931ebe08SZeev Suraski	zend_try {
9922c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
993931ebe08SZeev Suraski	} zend_end_try();
994ed06a70fSZeev Suraski}
995b4892511SJani Taskinen/* }}} */
99656251a72SZeev Suraski
997fc173b6aSSam RubyBEGIN_EXTERN_C()
9984a25a774SDmitry StogovZEND_API void zend_message_dispatcher(long message, const void *data TSRMLS_DC) /* {{{ */
99956251a72SZeev Suraski{
100056251a72SZeev Suraski	if (zend_message_dispatcher_p) {
100185ab4235SFelipe Pena		zend_message_dispatcher_p(message, data TSRMLS_CC);
100256251a72SZeev Suraski	}
100356251a72SZeev Suraski}
1004b4892511SJani Taskinen/* }}} */
1005fc173b6aSSam RubyEND_EXTERN_C()
100656251a72SZeev Suraski
1007cf7384aaSFelipe PenaZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */
100856251a72SZeev Suraski{
1009903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
1010903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
101156251a72SZeev Suraski	} else {
101256251a72SZeev Suraski		return FAILURE;
101356251a72SZeev Suraski	}
101456251a72SZeev Suraski}
1015b4892511SJani Taskinen/* }}} */
101667f69743SZeev Suraski
1017a550566cSDmitry Stogov#define SAVE_STACK(stack) do { \
1018a550566cSDmitry Stogov		if (CG(stack).top) { \
1019a550566cSDmitry Stogov			memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
1020a550566cSDmitry Stogov			CG(stack).top = CG(stack).max = 0; \
1021a550566cSDmitry Stogov			CG(stack).elements = NULL; \
1022a550566cSDmitry Stogov		} else { \
1023a550566cSDmitry Stogov			stack.top = 0; \
1024a550566cSDmitry Stogov		} \
1025a550566cSDmitry Stogov	} while (0)
1026a550566cSDmitry Stogov
1027a550566cSDmitry Stogov#define RESTORE_STACK(stack) do { \
1028a550566cSDmitry Stogov		if (stack.top) { \
1029a550566cSDmitry Stogov			zend_stack_destroy(&CG(stack)); \
1030a550566cSDmitry Stogov			memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
1031a550566cSDmitry Stogov		} \
1032a550566cSDmitry Stogov	} while (0)
1033a550566cSDmitry Stogov
1034b4892511SJani TaskinenZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
103567f69743SZeev Suraski{
1036f4cfaf36SDmitry Stogov	char *str;
1037f4cfaf36SDmitry Stogov	int len;
103867f69743SZeev Suraski	va_list args;
10399e9c193eSStanislav Malyshev	va_list usr_copy;
1040f4cfaf36SDmitry Stogov	zval params[5];
1041f4cfaf36SDmitry Stogov	zval retval;
10424a25a774SDmitry Stogov	const char *error_filename;
1043b80b8381SZeev Suraski	uint error_lineno;
1044f4cfaf36SDmitry Stogov	zval orig_user_error_handler;
10452e1a2438SDmitry Stogov	zend_bool in_compilation;
10462e1a2438SDmitry Stogov	zend_class_entry *saved_class_entry;
1047a550566cSDmitry Stogov	zend_stack bp_stack;
1048a550566cSDmitry Stogov	zend_stack function_call_stack;
1049a550566cSDmitry Stogov	zend_stack switch_cond_stack;
1050a550566cSDmitry Stogov	zend_stack foreach_copy_stack;
1051a550566cSDmitry Stogov	zend_stack object_stack;
1052a550566cSDmitry Stogov	zend_stack declare_stack;
1053a550566cSDmitry Stogov	zend_stack list_stack;
1054a550566cSDmitry Stogov	zend_stack context_stack;
10552c254ba7SZeev Suraski	TSRMLS_FETCH();
105667f69743S