zend.c revision 9bba373a
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
52c5d4b8cSSebastian Bergmann   | Copyright (c) 1998-2003 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        |
9b5b11177SZeev Suraski   | available at through the world-wide-web at                           |
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
20a6043d3eSRasmus Lerdorf
21573b4602SAndi Gutmans#include "zend.h"
22573b4602SAndi Gutmans#include "zend_extensions.h"
237080fa5bSAndi Gutmans#include "zend_modules.h"
24573b4602SAndi Gutmans#include "zend_constants.h"
25573b4602SAndi Gutmans#include "zend_list.h"
26da9faa2cSZeev Suraski#include "zend_API.h"
2713d840bcSZeev Suraski#include "zend_builtin_functions.h"
2854d53055SZeev Suraski#include "zend_ini.h"
29573b4602SAndi Gutmans
307a87fcbbSZeev Suraski#ifdef ZTS
31ce98c73fSAndi Gutmans#	define GLOBAL_FUNCTION_TABLE	&global_main_class.function_table
32ce98c73fSAndi Gutmans#	define GLOBAL_CLASS_TABLE		&global_main_class.class_table
33ce98c73fSAndi Gutmans#	define GLOBAL_CONSTANTS_TABLE	&global_main_class.constants_table
349d11db12SAndi Gutmans#	define GLOBAL_AUTO_GLOBALS_TABLE	global_auto_globals_table
357a87fcbbSZeev Suraski#else
367a87fcbbSZeev Suraski#	define GLOBAL_FUNCTION_TABLE	CG(function_table)
377a87fcbbSZeev Suraski#	define GLOBAL_CLASS_TABLE		CG(class_table)
389d11db12SAndi Gutmans#	define GLOBAL_AUTO_GLOBALS_TABLE	CG(auto_globals)
397a87fcbbSZeev Suraski#endif
407a87fcbbSZeev Suraski
41f34b9d41SZeev Suraski#if defined(ZEND_WIN32) && ZEND_DEBUG
422ffe85ddSZeev SuraskiBOOL WINAPI IsDebuggerPresent(VOID);
432ffe85ddSZeev Suraski#endif
442ffe85ddSZeev Suraski
45573b4602SAndi Gutmans/* true multithread-shared globals */
4692dd5e61SStanislav MalyshevZEND_API zend_class_entry *zend_standard_class_def = NULL;
47573b4602SAndi GutmansZEND_API int (*zend_printf)(const char *format, ...);
485dba4774SZeev SuraskiZEND_API zend_write_func_t zend_write;
495463dd5bSAndi GutmansZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
5093536507SStig S. BakkenZEND_API void (*zend_block_interruptions)(void);
5193536507SStig S. BakkenZEND_API void (*zend_unblock_interruptions)(void);
52f1a2ee55SAndi GutmansZEND_API void (*zend_ticks_function)(int ticks);
53536221beSStanislav MalyshevZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
54536221beSStanislav Malyshev
55bd115087SZeev Suraskivoid (*zend_on_timeout)(int seconds TSRMLS_DC);
56bd115087SZeev Suraski
5756251a72SZeev Suraskistatic void (*zend_message_dispatcher_p)(long message, void *data);
58903018efSZeev Suraskistatic int (*zend_get_configuration_directive_p)(char *name, uint name_length, zval *contents);
59d035af4aSZeev Suraski
6067f69743SZeev Suraski
614be862b0SZeev Suraskistatic ZEND_INI_MH(OnUpdateErrorReporting)
624be862b0SZeev Suraski{
634be862b0SZeev Suraski	if (!new_value) {
644be862b0SZeev Suraski		EG(error_reporting) = E_ALL & ~E_NOTICE;
654be862b0SZeev Suraski	} else {
664be862b0SZeev Suraski		EG(error_reporting) = atoi(new_value);
674be862b0SZeev Suraski	}
684be862b0SZeev Suraski	return SUCCESS;
694be862b0SZeev Suraski}
704be862b0SZeev Suraski
714be862b0SZeev Suraski
72424e98f4SZeev Suraskistatic ZEND_INI_MH(OnUpdateImplicitClone)
73424e98f4SZeev Suraski{
74424e98f4SZeev Suraski	if (!new_value) {
75424e98f4SZeev Suraski		EG(implicit_clone) = 0;
76424e98f4SZeev Suraski	} else {
77424e98f4SZeev Suraski		EG(implicit_clone) = atoi(new_value) ? 1 : 0;
78424e98f4SZeev Suraski	}
79424e98f4SZeev Suraski	return SUCCESS;
80424e98f4SZeev Suraski}
81424e98f4SZeev Suraski
82424e98f4SZeev Suraski
834be862b0SZeev SuraskiZEND_INI_BEGIN()
844be862b0SZeev Suraski	ZEND_INI_ENTRY("error_reporting",			NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
85424e98f4SZeev Suraski	ZEND_INI_ENTRY("zend2.implicit_clone",		NULL,		ZEND_INI_ALL,		OnUpdateImplicitClone)
864be862b0SZeev SuraskiZEND_INI_END()
874be862b0SZeev Suraski
884be862b0SZeev Suraski
897a87fcbbSZeev Suraski#ifdef ZTS
90e06a1ed2SZeev SuraskiZEND_API int compiler_globals_id;
91e06a1ed2SZeev SuraskiZEND_API int executor_globals_id;
925864b57eSZeev SuraskiZEND_API int alloc_globals_id;
93ce98c73fSAndi Gutmanszend_class_entry global_main_class;
949d11db12SAndi GutmansHashTable *global_auto_globals_table;
957a87fcbbSZeev Suraski#endif
96573b4602SAndi Gutmans
97e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
98573b4602SAndi Gutmans
995ba5f00fSZeev SuraskiZEND_API zval zval_used_for_init; /* True global variable */
100213d0e2fSAndi Gutmans
101573b4602SAndi Gutmans/* version information */
102573b4602SAndi Gutmansstatic char *zend_version_info;
103573b4602SAndi Gutmansstatic uint zend_version_info_length;
1042c5d4b8cSSebastian Bergmann#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2003 Zend Technologies\n"
105573b4602SAndi Gutmans
106573b4602SAndi Gutmans
10780bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
108573b4602SAndi Gutmans
109573b4602SAndi Gutmansstatic void print_hash(HashTable *ht, int indent)
110573b4602SAndi Gutmans{
111573b4602SAndi Gutmans	zval **tmp;
112573b4602SAndi Gutmans	char *string_key;
11363873abaSStanislav Malyshev	HashPosition iterator;
1144757104eSZeev Suraski	ulong num_key;
1154757104eSZeev Suraski	uint str_len;
116573b4602SAndi Gutmans	int i;
117573b4602SAndi Gutmans
118573b4602SAndi Gutmans	for (i=0; i<indent; i++) {
119573b4602SAndi Gutmans		ZEND_PUTS(" ");
120573b4602SAndi Gutmans	}
121573b4602SAndi Gutmans	ZEND_PUTS("(\n");
12280bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
12363873abaSStanislav Malyshev	zend_hash_internal_pointer_reset_ex(ht, &iterator);
12463873abaSStanislav Malyshev	while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
125573b4602SAndi Gutmans		for (i=0; i<indent; i++) {
126573b4602SAndi Gutmans			ZEND_PUTS(" ");
127573b4602SAndi Gutmans		}
128573b4602SAndi Gutmans		ZEND_PUTS("[");
12936eaad25SZeev Suraski		switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
130573b4602SAndi Gutmans			case HASH_KEY_IS_STRING:
131573b4602SAndi Gutmans				ZEND_PUTS(string_key);
132573b4602SAndi Gutmans				break;
133573b4602SAndi Gutmans			case HASH_KEY_IS_LONG:
1344f6c95d1SZeev Suraski				zend_printf("%ld", num_key);
135573b4602SAndi Gutmans				break;
136573b4602SAndi Gutmans		}
137573b4602SAndi Gutmans		ZEND_PUTS("] => ");
13880bab9d9SAndrei Zmievski		zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT);
139573b4602SAndi Gutmans		ZEND_PUTS("\n");
14063873abaSStanislav Malyshev		zend_hash_move_forward_ex(ht, &iterator);
141573b4602SAndi Gutmans	}
14280bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
143573b4602SAndi Gutmans	for (i=0; i<indent; i++) {
144573b4602SAndi Gutmans		ZEND_PUTS(" ");
145573b4602SAndi Gutmans	}
146573b4602SAndi Gutmans	ZEND_PUTS(")\n");
147573b4602SAndi Gutmans}
148573b4602SAndi Gutmans
14927de54b0SAndi Gutmansstatic void print_flat_hash(HashTable *ht)
15027de54b0SAndi Gutmans{
15127de54b0SAndi Gutmans    zval **tmp;
15227de54b0SAndi Gutmans    char *string_key;
15327de54b0SAndi Gutmans    HashPosition iterator;
15427de54b0SAndi Gutmans    ulong num_key;
15527de54b0SAndi Gutmans    uint str_len;
15627de54b0SAndi Gutmans    int i = 0;
15727de54b0SAndi Gutmans
15827de54b0SAndi Gutmans    zend_hash_internal_pointer_reset_ex(ht, &iterator);
15927de54b0SAndi Gutmans    while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
16027de54b0SAndi Gutmans	if (i++ > 0) {
16127de54b0SAndi Gutmans	    ZEND_PUTS(",");
16227de54b0SAndi Gutmans	}
16327de54b0SAndi Gutmans	ZEND_PUTS("[");
16427de54b0SAndi Gutmans	switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
16527de54b0SAndi Gutmans	    case HASH_KEY_IS_STRING:
16627de54b0SAndi Gutmans		ZEND_PUTS(string_key);
16727de54b0SAndi Gutmans		break;
16827de54b0SAndi Gutmans	    case HASH_KEY_IS_LONG:
16927de54b0SAndi Gutmans		zend_printf("%ld", num_key);
17027de54b0SAndi Gutmans		break;
17127de54b0SAndi Gutmans	}
17227de54b0SAndi Gutmans	ZEND_PUTS("] => ");
17327de54b0SAndi Gutmans	zend_print_flat_zval_r(*tmp);
17427de54b0SAndi Gutmans	zend_hash_move_forward_ex(ht, &iterator);
17527de54b0SAndi Gutmans    }
17627de54b0SAndi Gutmans}
1777a87fcbbSZeev Suraski
178da9faa2cSZeev SuraskiZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy)
179573b4602SAndi Gutmans{
180da9faa2cSZeev Suraski	if (expr->type==IS_STRING) {
181da9faa2cSZeev Suraski		*use_copy = 0;
182da9faa2cSZeev Suraski		return;
183da9faa2cSZeev Suraski	}
184da9faa2cSZeev Suraski	switch (expr->type) {
185bdefd5daSAndi Gutmans		case IS_NULL:
186f2d703e9SZeev Suraski			expr_copy->value.str.len = 0;
187f2d703e9SZeev Suraski			expr_copy->value.str.val = empty_string;
1888c4ab98eSThies C. Arntzen			break;
189da9faa2cSZeev Suraski		case IS_BOOL:
19091d7ba76SAndi Gutmans			if (expr->value.lval) {
19191d7ba76SAndi Gutmans				expr_copy->value.str.len = 1;
19291d7ba76SAndi Gutmans				expr_copy->value.str.val = estrndup("1", 1);
19391d7ba76SAndi Gutmans			} else {
19491d7ba76SAndi Gutmans				expr_copy->value.str.len = 0;
19591d7ba76SAndi Gutmans				expr_copy->value.str.val = empty_string;
19691d7ba76SAndi Gutmans			}
197da9faa2cSZeev Suraski			break;
198da9faa2cSZeev Suraski		case IS_RESOURCE:
199da9faa2cSZeev Suraski			expr_copy->value.str.val = (char *) emalloc(sizeof("Resource id #")-1 + MAX_LENGTH_OF_LONG);
200da9faa2cSZeev Suraski			expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Resource id #%ld", expr->value.lval);
201da9faa2cSZeev Suraski			break;
202da9faa2cSZeev Suraski		case IS_ARRAY:
203da9faa2cSZeev Suraski			expr_copy->value.str.len = sizeof("Array")-1;
204da9faa2cSZeev Suraski			expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len);
205da9faa2cSZeev Suraski			break;
2061b282b35SAndi Gutmans		case IS_OBJECT:
207b04acdadSAndi Gutmans			expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
20892dd5e61SStanislav Malyshev			expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle);
209b04acdadSAndi Gutmans#if 0
210b04acdadSAndi Gutmans			/* FIXME: This might break BC for some people */
2111b282b35SAndi Gutmans			expr_copy->value.str.len = sizeof("Object")-1;
2121b282b35SAndi Gutmans			expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len);
213b04acdadSAndi Gutmans#endif
214da9faa2cSZeev Suraski			break;
215e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
216e842ef9fSIlia Alshanetsky			*expr_copy = *expr;
217e842ef9fSIlia Alshanetsky			zval_copy_ctor(expr_copy);
218e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
219e842ef9fSIlia Alshanetsky			break;
220da9faa2cSZeev Suraski		default:
221da9faa2cSZeev Suraski			*expr_copy = *expr;
222da9faa2cSZeev Suraski			zval_copy_ctor(expr_copy);
223da9faa2cSZeev Suraski			convert_to_string(expr_copy);
224da9faa2cSZeev Suraski			break;
225da9faa2cSZeev Suraski	}
226da9faa2cSZeev Suraski	expr_copy->type = IS_STRING;
227da9faa2cSZeev Suraski	*use_copy = 1;
228da9faa2cSZeev Suraski}
229da9faa2cSZeev Suraski
230da9faa2cSZeev Suraski
231da9faa2cSZeev SuraskiZEND_API int zend_print_zval(zval *expr, int indent)
232da9faa2cSZeev Suraski{
2335dba4774SZeev Suraski	return zend_print_zval_ex(zend_write, expr, indent);
2345dba4774SZeev Suraski}
2355dba4774SZeev Suraski
2365dba4774SZeev Suraski
2375dba4774SZeev SuraskiZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent)
2385dba4774SZeev Suraski{
239da9faa2cSZeev Suraski	zval expr_copy;
240da9faa2cSZeev Suraski	int use_copy;
241da9faa2cSZeev Suraski
242da9faa2cSZeev Suraski	zend_make_printable_zval(expr, &expr_copy, &use_copy);
243da9faa2cSZeev Suraski	if (use_copy) {
244573b4602SAndi Gutmans		expr = &expr_copy;
245573b4602SAndi Gutmans	}
246573b4602SAndi Gutmans	if (expr->value.str.len==0) { /* optimize away empty strings */
247da9faa2cSZeev Suraski		if (use_copy) {
248da9faa2cSZeev Suraski			zval_dtor(expr);
249da9faa2cSZeev Suraski		}
250573b4602SAndi Gutmans		return 0;
251573b4602SAndi Gutmans	}
2524f6c95d1SZeev Suraski	write_func(expr->value.str.val, expr->value.str.len);
253da9faa2cSZeev Suraski	if (use_copy) {
254573b4602SAndi Gutmans		zval_dtor(expr);
255573b4602SAndi Gutmans	}
256573b4602SAndi Gutmans	return expr->value.str.len;
257573b4602SAndi Gutmans}
258573b4602SAndi Gutmans
25927de54b0SAndi GutmansZEND_API void zend_print_flat_zval_r(zval *expr)
26027de54b0SAndi Gutmans{
26127de54b0SAndi Gutmans    zend_write_func_t write_func = zend_write;
26227de54b0SAndi Gutmans
26327de54b0SAndi Gutmans    switch (expr->type) {
26427de54b0SAndi Gutmans	case IS_ARRAY:
26527de54b0SAndi Gutmans	    ZEND_PUTS("Array (");
26627de54b0SAndi Gutmans	    if (++expr->value.ht->nApplyCount>1) {
26727de54b0SAndi Gutmans		ZEND_PUTS(" *RECURSION*");
26827de54b0SAndi Gutmans		expr->value.ht->nApplyCount--;
26927de54b0SAndi Gutmans		return;
27027de54b0SAndi Gutmans	    }
27127de54b0SAndi Gutmans	    print_flat_hash(expr->value.ht);
27227de54b0SAndi Gutmans	    ZEND_PUTS(")");
27327de54b0SAndi Gutmans	    expr->value.ht->nApplyCount--;
27427de54b0SAndi Gutmans	    break;
27527de54b0SAndi Gutmans	case IS_OBJECT:
27627de54b0SAndi Gutmans	    {
2779bba373aSStanislav Malyshev			HashTable *properties = NULL;
2789bba373aSStanislav Malyshev			char *class_name = NULL;
2799bba373aSStanislav Malyshev			zend_uint clen;
2809bba373aSStanislav Malyshev
2819bba373aSStanislav Malyshev			if(Z_OBJ_HANDLER_P(expr, get_class_name)) {
2829bba373aSStanislav Malyshev				Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
2839bba373aSStanislav Malyshev			}
2849bba373aSStanislav Malyshev			if(class_name == NULL) {
2859bba373aSStanislav Malyshev				class_name = "Unknown Class";
2869bba373aSStanislav Malyshev			}
2879bba373aSStanislav Malyshev			zend_printf("%s Object (", class_name);
2889bba373aSStanislav Malyshev			if(Z_OBJ_HANDLER_P(expr, get_properties)) {
2899bba373aSStanislav Malyshev				properties = Z_OBJPROP_P(expr);
2909bba373aSStanislav Malyshev			}
2919bba373aSStanislav Malyshev			if(properties) {
2929bba373aSStanislav Malyshev				if (++properties->nApplyCount>1) {
2939bba373aSStanislav Malyshev					ZEND_PUTS(" *RECURSION*");
2949bba373aSStanislav Malyshev					properties->nApplyCount--;
2959bba373aSStanislav Malyshev					return;
2969bba373aSStanislav Malyshev				}
2979bba373aSStanislav Malyshev				print_flat_hash(properties);
2989bba373aSStanislav Malyshev				properties->nApplyCount--;
2999bba373aSStanislav Malyshev			}
3009bba373aSStanislav Malyshev			ZEND_PUTS(")");
3019bba373aSStanislav Malyshev			break;
30227de54b0SAndi Gutmans	    }
30327de54b0SAndi Gutmans	default:
30427de54b0SAndi Gutmans	    zend_print_variable(expr);
30527de54b0SAndi Gutmans	    break;
30627de54b0SAndi Gutmans    }
30727de54b0SAndi Gutmans}
308573b4602SAndi Gutmans
3095dba4774SZeev SuraskiZEND_API void zend_print_zval_r(zval *expr, int indent)
3105dba4774SZeev Suraski{
3115dba4774SZeev Suraski	zend_print_zval_r_ex(zend_write, expr, indent);
3125dba4774SZeev Suraski}
3135dba4774SZeev Suraski
3145dba4774SZeev Suraski
315424e98f4SZeev SuraskiZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent)
316573b4602SAndi Gutmans{
317671fff2fSAndi Gutmans	switch (expr->type) {
318573b4602SAndi Gutmans		case IS_ARRAY:
319573b4602SAndi Gutmans			ZEND_PUTS("Array\n");
3206053f2a1SZeev Suraski			if (++expr->value.ht->nApplyCount>1) {
3216053f2a1SZeev Suraski				ZEND_PUTS(" *RECURSION*");
322a9d81981SDerick Rethans				expr->value.ht->nApplyCount--;
3236053f2a1SZeev Suraski				return;
3246053f2a1SZeev Suraski			}
3254f6c95d1SZeev Suraski			print_hash(expr->value.ht, indent);
3266053f2a1SZeev Suraski			expr->value.ht->nApplyCount--;
327573b4602SAndi Gutmans			break;
328573b4602SAndi Gutmans		case IS_OBJECT:
329c259cb7cSAndi Gutmans			{
3309bba373aSStanislav Malyshev				HashTable *properties = NULL;
3319bba373aSStanislav Malyshev				char *class_name = NULL;
3329bba373aSStanislav Malyshev				zend_uint clen;
3339bba373aSStanislav Malyshev
3349bba373aSStanislav Malyshev				if(Z_OBJ_HANDLER_P(expr, get_class_name)) {
3359bba373aSStanislav Malyshev					Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
3369bba373aSStanislav Malyshev				}
3379bba373aSStanislav Malyshev				if(class_name == NULL) {
3389bba373aSStanislav Malyshev					class_name = "Unknown Class";
3399bba373aSStanislav Malyshev				}
3409bba373aSStanislav Malyshev				zend_printf("%s Object\n", class_name);
3419bba373aSStanislav Malyshev				if(Z_OBJ_HANDLER_P(expr, get_properties)) {
3429bba373aSStanislav Malyshev					properties = Z_OBJPROP_P(expr);
3439bba373aSStanislav Malyshev				}
3449bba373aSStanislav Malyshev				if(properties) {
3459bba373aSStanislav Malyshev					if (++properties->nApplyCount>1) {
3469bba373aSStanislav Malyshev						ZEND_PUTS(" *RECURSION*");
3479bba373aSStanislav Malyshev						properties->nApplyCount--;
3489bba373aSStanislav Malyshev						return;
3499bba373aSStanislav Malyshev					}
3509bba373aSStanislav Malyshev					print_hash(properties, indent);
3519bba373aSStanislav Malyshev					properties->nApplyCount--;
352c259cb7cSAndi Gutmans				}
353c259cb7cSAndi Gutmans				break;
3546053f2a1SZeev Suraski			}
355573b4602SAndi Gutmans		default:
356573b4602SAndi Gutmans			zend_print_variable(expr);
357573b4602SAndi Gutmans			break;
358573b4602SAndi Gutmans	}
359573b4602SAndi Gutmans}
360573b4602SAndi Gutmans
361573b4602SAndi Gutmans
3625463dd5bSAndi Gutmansstatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path)
363573b4602SAndi Gutmans{
3645463dd5bSAndi Gutmans	if (opened_path) {
36527de5001SAndi Gutmans		*opened_path = estrdup(filename);
3665463dd5bSAndi Gutmans	}
367f311ab16SAndi Gutmans	return fopen(filename, "rb");
368573b4602SAndi Gutmans}
369573b4602SAndi Gutmans
370573b4602SAndi Gutmans
37193536507SStig S. Bakkenstatic void register_standard_class(void)
372573b4602SAndi Gutmans{
37392dd5e61SStanislav Malyshev	zend_standard_class_def = malloc(sizeof(zend_class_entry));
374424e98f4SZeev Suraski
37592dd5e61SStanislav Malyshev	zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
37692dd5e61SStanislav Malyshev	zend_standard_class_def->name_length = sizeof("stdClass") - 1;
37792dd5e61SStanislav Malyshev	zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
37892dd5e61SStanislav Malyshev	zend_standard_class_def->parent = NULL;
37992dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
38092dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
381bc5ea87eSAndi Gutmans	zend_hash_init_ex(&zend_standard_class_def->protected_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
38292dd5e61SStanislav Malyshev	zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
38392dd5e61SStanislav Malyshev	zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
38492dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
38592dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
38692dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
38792dd5e61SStanislav Malyshev	zend_standard_class_def->constructor = NULL;
38892dd5e61SStanislav Malyshev	zend_standard_class_def->destructor = NULL;
38992dd5e61SStanislav Malyshev	zend_standard_class_def->clone = NULL;
39092dd5e61SStanislav Malyshev	zend_standard_class_def->handle_function_call = NULL;
39192dd5e61SStanislav Malyshev	zend_standard_class_def->handle_property_get = NULL;
39292dd5e61SStanislav Malyshev	zend_standard_class_def->handle_property_set = NULL;
393fb6976e4SAndi Gutmans	zend_standard_class_def->refcount = 1;
3942de45becSAndi Gutmans	zend_standard_class_def->constants_updated = 0;
395e062dffeSZeev Suraski	zend_standard_class_def->ce_flags = 0;
3962de45becSAndi Gutmans
39792dd5e61SStanislav Malyshev	zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
398573b4602SAndi Gutmans}
399573b4602SAndi Gutmans
400573b4602SAndi Gutmans
401b4f3b9d3SZeev Suraskistatic void zend_set_default_compile_time_values(TSRMLS_D)
4028b794bb1SZeev Suraski{
4038b794bb1SZeev Suraski	/* default compile-time values */
4048b794bb1SZeev Suraski	CG(asp_tags) = 0;
4058b794bb1SZeev Suraski	CG(short_tags) = 1;
4068b794bb1SZeev Suraski	CG(allow_call_time_pass_reference) = 1;
4078b794bb1SZeev Suraski	CG(extended_info) = 0;
4088b794bb1SZeev Suraski}
4098b794bb1SZeev Suraski
4108b794bb1SZeev Suraski
4117a87fcbbSZeev Suraski#ifdef ZTS
4122c254ba7SZeev Suraskistatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC)
4137a87fcbbSZeev Suraski{
4147c4a0838SZeev Suraski	zend_function tmp_func;
4157c4a0838SZeev Suraski	zend_class_entry tmp_class;
4167c4a0838SZeev Suraski
4177f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
4187f4909d9SThies C. Arntzen
419ce98c73fSAndi Gutmans	compiler_globals->function_table = &compiler_globals->main_class.function_table;
4201263932aSZeev Suraski	zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
421ce98c73fSAndi Gutmans	zend_hash_copy(compiler_globals->function_table, GLOBAL_FUNCTION_TABLE, NULL, &tmp_func, sizeof(zend_function));
4227a87fcbbSZeev Suraski
423ce98c73fSAndi Gutmans	compiler_globals->class_table = &compiler_globals->main_class.class_table;
4241263932aSZeev Suraski	zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
425c29f5d6eSZeev Suraski	zend_hash_copy(compiler_globals->class_table, GLOBAL_CLASS_TABLE, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *));
4269cf1a98dSThies C. Arntzen
427b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
42885b4df53SZeev Suraski
42985b4df53SZeev Suraski	CG(interactive) = 0;
4309d11db12SAndi Gutmans
4319d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
4329d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
4339d11db12SAndi Gutmans	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(void *) /* empty element */);
4347a87fcbbSZeev Suraski}
4357a87fcbbSZeev Suraski
4367a87fcbbSZeev Suraski
4372c254ba7SZeev Suraskistatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC)
4387a87fcbbSZeev Suraski{
439ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
44074a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
44174a9ed7bSZeev Suraski	}
442ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
44374a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
44474a9ed7bSZeev Suraski	}
4459d11db12SAndi Gutmans	if (compiler_globals->auto_globals != global_auto_globals_table) {
4469d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
4479d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
4489d11db12SAndi Gutmans	}
4497a87fcbbSZeev Suraski}
450a9f9ae79SZeev Suraski
451a9f9ae79SZeev Suraski
4522c254ba7SZeev Suraskistatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC)
453a9f9ae79SZeev Suraski{
4545fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
4555fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
4562c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
4570b7a9ceaSZeev Suraski	EG(lambda_count)=0;
4581f23e507SZeev Suraski	EG(user_error_handler) = NULL;
45904788f95SStig Bakken	EG(user_exception_handler) = NULL;
460ab30c8ccSZeev Suraski	EG(in_execution) = 0;
461e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
462a9f9ae79SZeev Suraski}
463a9f9ae79SZeev Suraski
464a9f9ae79SZeev Suraski
4652c254ba7SZeev Suraskistatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC)
466a9f9ae79SZeev Suraski{
4672c254ba7SZeev Suraski	zend_shutdown_constants(TSRMLS_C);
4687deb44e3SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
4692c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
470a9f9ae79SZeev Suraski}
471a9f9ae79SZeev Suraski
472a9f9ae79SZeev Suraski
473609d58a4SZeev Suraskistatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC)
474609d58a4SZeev Suraski{
475609d58a4SZeev Suraski	zend_copy_ini_directives(TSRMLS_C);
476609d58a4SZeev Suraski	zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
477609d58a4SZeev Suraski}
478609d58a4SZeev Suraski
47966d9314bSZeev Suraski#endif
48066d9314bSZeev Suraski
48166d9314bSZeev Suraski
482b4f3b9d3SZeev Suraskistatic void alloc_globals_ctor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
4837c4a0838SZeev Suraski{
484b4f3b9d3SZeev Suraski	start_memory_manager(TSRMLS_C);
4857c4a0838SZeev Suraski}
4867c4a0838SZeev Suraski
4877a87fcbbSZeev Suraski
488fcc03510SZeev Suraskistatic void alloc_globals_dtor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
489fcc03510SZeev Suraski{
4907df16012SAndi Gutmans	shutdown_memory_manager(0, 1 TSRMLS_CC);
491fcc03510SZeev Suraski}
492fcc03510SZeev Suraski
493fcc03510SZeev Suraski
4941f5ee72eSAndi Gutmans#ifdef __FreeBSD__
4955928970dSAndi Gutmans/* FreeBSD floating point precision fix */
4965928970dSAndi Gutmans#include <floatingpoint.h>
4975928970dSAndi Gutmans#endif
4987a87fcbbSZeev Suraski
499609d58a4SZeev Suraski
500609d58a4SZeev Suraskistatic void scanner_globals_ctor(zend_scanner_globals *scanner_globals_p TSRMLS_DC)
50154d53055SZeev Suraski{
502609d58a4SZeev Suraski	scanner_globals_p->c_buf_p = (char *) 0;
503609d58a4SZeev Suraski	scanner_globals_p->init = 1;
504609d58a4SZeev Suraski	scanner_globals_p->start = 0;
505609d58a4SZeev Suraski	scanner_globals_p->current_buffer = NULL;
506483fc4c7SZeev Suraski	scanner_globals_p->yy_in = NULL;
507483fc4c7SZeev Suraski	scanner_globals_p->yy_out = NULL;
50817352812SZeev Suraski	scanner_globals_p->_yy_more_flag = 0;
50917352812SZeev Suraski	scanner_globals_p->_yy_more_len = 0;
5100bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack_ptr = 0;
5110bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack_depth = 0;
5120bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack = 0;
51354d53055SZeev Suraski}
51454d53055SZeev Suraski
515cf36abb2SAndi Gutmansvoid zend_init_opcodes_handlers();
51654d53055SZeev Suraski
51713e74131SAndi Gutmansint zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions)
518573b4602SAndi Gutmans{
519a9f9ae79SZeev Suraski#ifdef ZTS
5207c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
521a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
5222c254ba7SZeev Suraski	void ***tsrm_ls;
523609d58a4SZeev Suraski#ifdef ZTS
524609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
525609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
526609d58a4SZeev Suraski#else
527609d58a4SZeev Suraski	extern zend_scanner_globals ini_scanner_globals;
528609d58a4SZeev Suraski	extern zend_scanner_globals language_scanner_globals;
529609d58a4SZeev Suraski#endif
530a9f9ae79SZeev Suraski
531fcc03510SZeev Suraski	ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
53299947a25SAndi Gutmans#else
53366d9314bSZeev Suraski	alloc_globals_ctor(&alloc_globals TSRMLS_CC);
534a9f9ae79SZeev Suraski#endif
535a9f9ae79SZeev Suraski
5361f5ee72eSAndi Gutmans#ifdef __FreeBSD__
537c3340584SSascha Schumann	/* FreeBSD floating point precision fix */
538c3340584SSascha Schumann	fpsetmask(0);
5395928970dSAndi Gutmans#endif
540309827ecSZeev Suraski
541309827ecSZeev Suraski	zend_startup_extensions_mechanism();
542309827ecSZeev Suraski
543573b4602SAndi Gutmans	/* Set up utility functions and values */
54467f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
545573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
5465dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
547573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
548573b4602SAndi Gutmans	if (!zend_fopen) {
549573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
550573b4602SAndi Gutmans	}
55156251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
552573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
553573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
554903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
555fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
556bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
557d035af4aSZeev Suraski
558c06692e9SZeev Suraski	zend_compile_file = compile_file;
559573b4602SAndi Gutmans	zend_execute = execute;
5602c44fab3SDerick Rethans	zend_execute_internal = NULL;
561573b4602SAndi Gutmans
562cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
563cf36abb2SAndi Gutmans
564573b4602SAndi Gutmans	/* set up version */
565573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
566573b4602SAndi Gutmans	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;
567573b4602SAndi Gutmans
568ce98c73fSAndi Gutmans#ifndef ZTS
569ce98c73fSAndi Gutmans	GLOBAL_FUNCTION_TABLE = &compiler_globals.main_class.function_table;
570ce98c73fSAndi Gutmans	GLOBAL_CLASS_TABLE = &compiler_globals.main_class.class_table;
571ce98c73fSAndi Gutmans#endif
5729d11db12SAndi Gutmans	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
5731263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
5741263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
5752eabb14dSAndi Gutmans
576573b4602SAndi Gutmans	register_standard_class();
5771263932aSZeev Suraski	zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
5784cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
579573b4602SAndi Gutmans
58004788f95SStig Bakken
581213d0e2fSAndi Gutmans	/* This zval can be used to initialize allocate zval's to an uninit'ed value */
582213d0e2fSAndi Gutmans	zval_used_for_init.is_ref = 0;
583213d0e2fSAndi Gutmans	zval_used_for_init.refcount = 1;
584bdefd5daSAndi Gutmans	zval_used_for_init.type = IS_NULL;
585213d0e2fSAndi Gutmans
5867a87fcbbSZeev Suraski#ifdef ZTS
5878a003f80SZeev Suraski	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
5888a003f80SZeev Suraski	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0);
5892c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
5902c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
591609d58a4SZeev Suraski	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
592609d58a4SZeev Suraski	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
5937c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
594a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
5952c254ba7SZeev Suraski	tsrm_ls = ts_resource_ex(0, NULL);
5965fcae67eSZeev Suraski
5972c254ba7SZeev Suraski	compiler_globals_dtor(compiler_globals, tsrm_ls);
598f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
599f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
6009d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
6015fcae67eSZeev Suraski
6025fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
6035fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
604762158aaSAndi Gutmans#else
60580b870e5SAndi Gutmans	zend_hash_init_ex(CG(auto_globals), 8, NULL, NULL, 1, 0);
606609d58a4SZeev Suraski	scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
607609d58a4SZeev Suraski	scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
6086313238cSZeev Suraski	zend_startup_constants();
609b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
6101f23e507SZeev Suraski	EG(user_error_handler) = NULL;
61104788f95SStig Bakken	EG(user_exception_handler) = NULL;
6127a87fcbbSZeev Suraski#endif
6132c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
6147a87fcbbSZeev Suraski
615bfbe8618SZeev Suraski#ifndef ZTS
6162c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
617bfbe8618SZeev Suraski#endif
618a9f9ae79SZeev Suraski
61913e74131SAndi Gutmans	if (start_builtin_functions) {
620b5770382SZeev Suraski		zend_startup_builtin_functions(TSRMLS_C);
62113e74131SAndi Gutmans	}
62213d840bcSZeev Suraski
6232c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
62454d53055SZeev Suraski
62554d53055SZeev Suraski#ifdef ZTS
62654d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
62754d53055SZeev Suraski#endif
62854d53055SZeev Suraski
629573b4602SAndi Gutmans	return SUCCESS;
630573b4602SAndi Gutmans}
631573b4602SAndi Gutmans
632573b4602SAndi Gutmans
6334be862b0SZeev Suraskivoid zend_register_standard_ini_entries(TSRMLS_D)
6344be862b0SZeev Suraski{
6354be862b0SZeev Suraski	int module_number = 0;
6364be862b0SZeev Suraski
6374be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
6384be862b0SZeev Suraski}
6394be862b0SZeev Suraski
6404be862b0SZeev Suraski
641711be83dSZeev Suraski#ifdef ZTS
642711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
643711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
644711be83dSZeev Suraski */
645711be83dSZeev Suraskivoid zend_post_startup(TSRMLS_D)
646711be83dSZeev Suraski{
647711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
6485fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
649711be83dSZeev Suraski
6505fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
6515fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
6525fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
653b817dab2SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
654711be83dSZeev Suraski	compiler_globals_ctor(compiler_globals, tsrm_ls);
6555fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
656711be83dSZeev Suraski}
657711be83dSZeev Suraski#endif
658711be83dSZeev Suraski
659711be83dSZeev Suraski
660d76cf1daSZeev Suraskivoid zend_shutdown(TSRMLS_D)
661573b4602SAndi Gutmans{
66284eb48f0SZeev Suraski#ifdef ZEND_WIN32
66384eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
66484eb48f0SZeev Suraski#endif
665bfbe8618SZeev Suraski#ifndef ZTS
6667deb44e3SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
667bfbe8618SZeev Suraski#endif
6684cb9a483SZeev Suraski	zend_destroy_rsrc_list_dtors();
669d4acdd34SDerick Rethans	zend_hash_graceful_reverse_destroy(&module_registry);
6703458373eSAndi Gutmans
67176b9acc1SAndi Gutmans#ifndef ZTS
67276b9acc1SAndi Gutmans	/* In ZTS mode these are freed by compiler_globals_dtor() */
6737a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
67476b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
67576b9acc1SAndi Gutmans#endif
6763458373eSAndi Gutmans
6779d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
6789d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
679d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
680573b4602SAndi Gutmans	free(zend_version_info);
6817a87fcbbSZeev Suraski#ifndef ZTS
682ee08b81aSZeev Suraski	zend_shutdown_constants();
6837a87fcbbSZeev Suraski#endif
684573b4602SAndi Gutmans}
685573b4602SAndi Gutmans
686573b4602SAndi Gutmans
6877656c77cSZeev Suraskivoid zend_set_utility_values(zend_utility_values *utility_values)
6887656c77cSZeev Suraski{
6897656c77cSZeev Suraski	zend_uv = *utility_values;
6909baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
6917656c77cSZeev Suraski}
6927656c77cSZeev Suraski
6937656c77cSZeev Suraski
694573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
695573b4602SAndi Gutmansvoid zenderror(char *error)
696573b4602SAndi Gutmans{
697573b4602SAndi Gutmans	zend_error(E_PARSE, error);
698573b4602SAndi Gutmans}
699573b4602SAndi Gutmans
700573b4602SAndi Gutmans
701b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
702ef4fe54fSZeev SuraskiZEND_API void _zend_bailout(char *filename, uint lineno)
703573b4602SAndi Gutmans{
7042c254ba7SZeev Suraski	TSRMLS_FETCH();
705573b4602SAndi Gutmans
706931ebe08SZeev Suraski	if (!EG(bailout_set)) {
707ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
708931ebe08SZeev Suraski		exit(-1);
709931ebe08SZeev Suraski	}
7106bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
711b23d83cfSZeev Suraski	CG(in_compilation) = EG(in_execution) = 0;
712bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
713573b4602SAndi Gutmans	longjmp(EG(bailout), FAILURE);
714573b4602SAndi Gutmans}
715b0bfa458SZeev SuraskiEND_EXTERN_C()
716573b4602SAndi Gutmans
717573b4602SAndi Gutmans
718573b4602SAndi Gutmansvoid zend_append_version_info(zend_extension *extension)
719573b4602SAndi Gutmans{
720573b4602SAndi Gutmans	char *new_info;
721573b4602SAndi Gutmans	uint new_info_length;
722573b4602SAndi Gutmans
723573b4602SAndi Gutmans	new_info_length = sizeof("    with  v,  by \n")
724573b4602SAndi Gutmans						+ strlen(extension->name)
725573b4602SAndi Gutmans						+ strlen(extension->version)
726573b4602SAndi Gutmans						+ strlen(extension->copyright)
727573b4602SAndi Gutmans						+ strlen(extension->author);
728573b4602SAndi Gutmans
729573b4602SAndi Gutmans	new_info = (char *) malloc(new_info_length+1);
730573b4602SAndi Gutmans
731573b4602SAndi Gutmans	sprintf(new_info, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
732573b4602SAndi Gutmans
733573b4602SAndi Gutmans	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length+1);
734573b4602SAndi Gutmans	strcat(zend_version_info, new_info);
735573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
736573b4602SAndi Gutmans	free(new_info);
737573b4602SAndi Gutmans}
738573b4602SAndi Gutmans
739573b4602SAndi Gutmans
740573b4602SAndi GutmansZEND_API char *get_zend_version()
741573b4602SAndi Gutmans{
742573b4602SAndi Gutmans	return zend_version_info;
743573b4602SAndi Gutmans}
744ed06a70fSZeev Suraski
745ed06a70fSZeev Suraski
746b4f3b9d3SZeev Suraskivoid zend_activate(TSRMLS_D)
747ed06a70fSZeev Suraski{
748b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
749b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
750b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
751ed06a70fSZeev Suraski}
752ed06a70fSZeev Suraski
753dc0e6632SZeev Suraski
754d76cf1daSZeev Suraskivoid zend_activate_modules(TSRMLS_D)
755dc0e6632SZeev Suraski{
756d76cf1daSZeev Suraski	zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
757dc0e6632SZeev Suraski}
758dc0e6632SZeev Suraski
759b5770382SZeev Suraskivoid zend_deactivate_modules(TSRMLS_D)
760a8b0d960SAndi Gutmans{
761a8b0d960SAndi Gutmans	EG(opline_ptr) = NULL; /* we're no longer executing anything */
762a8b0d960SAndi Gutmans
763931ebe08SZeev Suraski	zend_try {
764d76cf1daSZeev Suraski		zend_hash_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
765931ebe08SZeev Suraski	} zend_end_try();
766a8b0d960SAndi Gutmans}
767dc0e6632SZeev Suraski
768b4f3b9d3SZeev Suraskivoid zend_deactivate(TSRMLS_D)
769ed06a70fSZeev Suraski{
770372f71ebSThies C. Arntzen	/* we're no longer executing anything */
771424e98f4SZeev Suraski	EG(opline_ptr) = NULL;
772372f71ebSThies C. Arntzen	EG(active_symbol_table) = NULL;
773f4c9d96fSThies C. Arntzen
774931ebe08SZeev Suraski	zend_try {
775b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
776931ebe08SZeev Suraski	} zend_end_try();
777931ebe08SZeev Suraski
7788084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
7792c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
780931ebe08SZeev Suraski
781931ebe08SZeev Suraski	zend_try {
782b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
783931ebe08SZeev Suraski	} zend_end_try();
784931ebe08SZeev Suraski
785931ebe08SZeev Suraski	zend_try {
7862c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
787931ebe08SZeev Suraski	} zend_end_try();
788ed06a70fSZeev Suraski}
78956251a72SZeev Suraski
79056251a72SZeev Suraski
791fc173b6aSSam RubyBEGIN_EXTERN_C()
79256251a72SZeev SuraskiZEND_API void zend_message_dispatcher(long message, void *data)
79356251a72SZeev Suraski{
79456251a72SZeev Suraski	if (zend_message_dispatcher_p) {
79556251a72SZeev Suraski		zend_message_dispatcher_p(message, data);
79656251a72SZeev Suraski	}
79756251a72SZeev Suraski}
798fc173b6aSSam RubyEND_EXTERN_C()
79956251a72SZeev Suraski
80056251a72SZeev Suraski
801903018efSZeev SuraskiZEND_API int zend_get_configuration_directive(char *name, uint name_length, zval *contents)
80256251a72SZeev Suraski{
803903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
804903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
80556251a72SZeev Suraski	} else {
80656251a72SZeev Suraski		return FAILURE;
80756251a72SZeev Suraski	}
80856251a72SZeev Suraski}
80967f69743SZeev Suraski
81067f69743SZeev Suraski
81167f69743SZeev Suraski#define ZEND_ERROR_BUFFER_SIZE 1024
81267f69743SZeev Suraski
81367f69743SZeev SuraskiZEND_API void zend_error(int type, const char *format, ...)
81467f69743SZeev Suraski{
81567f69743SZeev Suraski	va_list args;
8163cda6a75SZeev Suraski	zval ***params;
8173cda6a75SZeev Suraski	zval *retval;
818f34b9d41SZeev Suraski	zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
819b80b8381SZeev Suraski	char *error_filename;
820b80b8381SZeev Suraski	uint error_lineno;
821a31dc47aSZeev Suraski	zval *orig_user_error_handler;
8222c254ba7SZeev Suraski	TSRMLS_FETCH();
82367f69743SZeev Suraski
824b80b8381SZeev Suraski	/* Obtain relevant filename and lineno */
825b80b8381SZeev Suraski	switch (type) {
826b80b8381SZeev Suraski		case E_CORE_ERROR:
827b80b8381SZeev Suraski		case E_CORE_WARNING:
828b80b8381SZeev Suraski			error_filename = NULL;
829b80b8381SZeev Suraski			error_lineno = 0;
830b80b8381SZeev Suraski			break;
831b80b8381SZeev Suraski		case E_PARSE:
832b80b8381SZeev Suraski		case E_COMPILE_ERROR:
833b80b8381SZeev Suraski		case E_COMPILE_WARNING:
834b80b8381SZeev Suraski		case E_ERROR:
835b80b8381SZeev Suraski		case E_NOTICE:
836b80b8381SZeev Suraski		case E_WARNING:
837b80b8381SZeev Suraski		case E_USER_ERROR:
838b80b8381SZeev Suraski		case E_USER_WARNING:
839b80b8381SZeev Suraski		case E_USER_NOTICE:
8404187439cSZeev Suraski			if (zend_is_compiling(TSRMLS_C)) {
841b4f3b9d3SZeev Suraski				error_filename = zend_get_compiled_filename(TSRMLS_C);
842b4f3b9d3SZeev Suraski				error_lineno = zend_get_compiled_lineno(TSRMLS_C);
8434187439cSZeev Suraski			} else if (zend_is_executing(TSRMLS_C)) {
8442c254ba7SZeev Suraski				error_filename = zend_get_executed_filename(TSRMLS_C);
8452c254ba7SZeev Suraski				error_lineno = zend_get_executed_lineno(TSRMLS_C);
846b80b8381SZeev Suraski			} else {
847b80b8381SZeev Suraski				error_filename = NULL;
848b80b8381SZeev Suraski				error_lineno = 0;
849b80b8381SZeev Suraski			}
850b80b8381SZeev Suraski			break;
851b80b8381SZeev Suraski		default:
852b80b8381SZeev Suraski			error_filename = NULL;
853b80b8381SZeev Suraski			error_lineno = 0;
854b80b8381SZeev Suraski			break;
855b80b8381SZeev Suraski	}
856b80b8381SZeev Suraski	if (!error_filename) {
857b80b8381SZeev Suraski		error_filename = "Unknown";
858b80b8381SZeev Suraski	}
85967f69743SZeev Suraski
86067f69743SZeev Suraski
861b80b8381SZeev Suraski	va_start(args, format);
8628a8c3eafSZeev Suraski
86367f69743SZeev Suraski	/* if we don't have a user defined error handler */
86467f69743SZeev Suraski	if (!EG(user_error_handler)) {
865b80b8381SZeev Suraski		zend_error_cb(type, error_filename, error_lineno, format, args);
866b80b8381SZeev Suraski	} else switch (type) {
86767f69743SZeev Suraski		case E_ERROR:
86867f69743SZeev Suraski		case E_PARSE:
86967f69743SZeev Suraski		case E_CORE_ERROR:
87067f69743SZeev Suraski		case E_CORE_WARNING:
87167f69743SZeev Suraski		case E_COMPILE_ERROR:
87267f69743SZeev Suraski		case E_COMPILE_WARNING:
873b80b8381SZeev Suraski			/* The error may not be safe to handle in user-space */
874b80b8381SZeev Suraski			zend_error_cb(type, error_filename, error_lineno, format, args);
875b80b8381SZeev Suraski			break;
876b80b8381SZeev Suraski		default:
877b80b8381SZeev Suraski			/* Handle the error in user space */
878f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_error_message);
879f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_error_type);
880a31dc47aSZeev Suraski			ALLOC_INIT_ZVAL(z_error_filename);
881a31dc47aSZeev Suraski			ALLOC_INIT_ZVAL(z_error_lineno);
882f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_context);
883f34b9d41SZeev Suraski			z_error_message->value.str.val = (char *) emalloc(ZEND_ERROR_BUFFER_SIZE);
88467f69743SZeev Suraski
8858a8c3eafSZeev Suraski#ifdef HAVE_VSNPRINTF
886f34b9d41SZeev Suraski			z_error_message->value.str.len = vsnprintf(z_error_message->value.str.val, ZEND_ERROR_BUFFER_SIZE, format, args);
8874acff8f3SZeev Suraski			if (z_error_message->value.str.len > ZEND_ERROR_BUFFER_SIZE-1) {
888d10336ecSStanislav Malyshev				z_error_message->value.str.len = ZEND_ERROR_BUFFER_SIZE-1;
889d10336ecSStanislav Malyshev			}
8908a8c3eafSZeev Suraski#else
8914acff8f3SZeev Suraski			strncpy(z_error_message->value.str.val, format, ZEND_ERROR_BUFFER_SIZE);
8928a8c3eafSZeev Suraski			/* This is risky... */
8934acff8f3SZeev Suraski			/* z_error_message->value.str.len = vsprintf(z_error_message->value.str.val, format, args); */
8948a8c3eafSZeev Suraski#endif
895f34b9d41SZeev Suraski			z_error_message->type = IS_STRING;
89667f69743SZeev Suraski
897f34b9d41SZeev Suraski			z_error_type->value.lval = type;
898f34b9d41SZeev Suraski			z_error_type->type = IS_LONG;
89967f69743SZeev Suraski
900a31dc47aSZeev Suraski			if (error_filename) {
901a31dc47aSZeev Suraski				z_error_filename->value.str.len = strlen(error_filename);
902a31dc47aSZeev Suraski				z_error_filename->value.str.val = estrndup(error_filename, z_error_filename->value.str.len);
903a31dc47aSZeev Suraski				z_error_filename->type = IS_STRING;
904a31dc47aSZeev Suraski			}
905424e98f4SZeev Suraski
906a31dc47aSZeev Suraski			z_error_lineno->value.lval = error_lineno;
907a31dc47aSZeev Suraski			z_error_lineno->type = IS_LONG;
908a31dc47aSZeev Suraski
909f34b9d41SZeev Suraski			z_context->value.ht = EG(active_symbol_table);
910f34b9d41SZeev Suraski			z_context->type = IS_ARRAY;
911f34b9d41SZeev Suraski			ZVAL_ADDREF(z_context);  /* we don't want this one to be freed */
912f34b9d41SZeev Suraski
913f34b9d41SZeev Suraski			params = (zval ***) emalloc(sizeof(zval **)*5);
914f34b9d41SZeev Suraski			params[0] = &z_error_type;
915f34b9d41SZeev Suraski			params[1] = &z_error_message;
916a31dc47aSZeev Suraski			params[2] = &z_error_filename;
917a31dc47aSZeev Suraski			params[3] = &z_error_lineno;
918f34b9d41SZeev Suraski			params[4] = &z_context;
91967f69743SZeev Suraski
920a31dc47aSZeev Suraski			orig_user_error_handler = EG(user_error_handler);
921a31dc47aSZeev Suraski			EG(user_error_handler) = NULL;
9224187439cSZeev Suraski			if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC)==SUCCESS) {
9235cb8fabbSAndi Gutmans				if (retval) {
9245cb8fabbSAndi Gutmans					zval_ptr_dtor(&retval);
9255cb8fabbSAndi Gutmans				}
926b80b8381SZeev Suraski			} else {
927b80b8381SZeev Suraski				/* The user error handler failed, use built-in error handler */
928b80b8381SZeev Suraski				zend_error_cb(type, error_filename, error_lineno, format, args);
929b80b8381SZeev Suraski			}
930a31dc47aSZeev Suraski			EG(user_error_handler) = orig_user_error_handler;
931a31dc47aSZeev Suraski
932b80b8381SZeev Suraski			efree(params);
933f34b9d41SZeev Suraski			zval_ptr_dtor(&z_error_message);
934f34b9d41SZeev Suraski			zval_ptr_dtor(&z_error_type);
935a31dc47aSZeev Suraski			zval_ptr_dtor(&z_error_filename);
936a31dc47aSZeev Suraski			zval_ptr_dtor(&z_error_lineno);
9377cba0254SAndi Gutmans			if (ZVAL_REFCOUNT(z_context) == 2) {
938f34b9d41SZeev Suraski				FREE_ZVAL(z_context);
939f34b9d41SZeev Suraski			}
940b80b8381SZeev Suraski			break;
94167f69743SZeev Suraski	}
942b80b8381SZeev Suraski
943b80b8381SZeev Suraski	va_end(args);
944bda9c83aSZeev Suraski
9457cba0254SAndi Gutmans	if (type == E_PARSE) {
9461074fca0SIlia Alshanetsky		EG(exit_status) = 255;
947b4f3b9d3SZeev Suraski		zend_init_compiler_data_structures(TSRMLS_C);
948bda9c83aSZeev Suraski	}
94967f69743SZeev Suraski}
95067f69743SZeev Suraski
9510b7a9ceaSZeev Suraski
9520b7a9ceaSZeev SuraskiZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...)
9530b7a9ceaSZeev Suraski{
9540b7a9ceaSZeev Suraski#if ZEND_DEBUG
9550b7a9ceaSZeev Suraski	va_list args;
9560b7a9ceaSZeev Suraski
9570b7a9ceaSZeev Suraski	va_start(args, format);
95801d478baSAndi Gutmans#	ifdef ZEND_WIN32
9590b7a9ceaSZeev Suraski	{
9600b7a9ceaSZeev Suraski		char output_buf[1024];
9610b7a9ceaSZeev Suraski
9620b7a9ceaSZeev Suraski		vsnprintf(output_buf, 1024, format, args);
9630b7a9ceaSZeev Suraski		OutputDebugString(output_buf);
9640b7a9ceaSZeev Suraski		OutputDebugString("\n");
9650b7a9ceaSZeev Suraski		if (trigger_break && IsDebuggerPresent()) {
9660b7a9ceaSZeev Suraski			DebugBreak();
9670b7a9ceaSZeev Suraski		}
9680b7a9ceaSZeev Suraski	}
9690b7a9ceaSZeev Suraski#	else
9700b7a9ceaSZeev Suraski	vfprintf(stderr, format, args);
9710b7a9ceaSZeev Suraski	fprintf(stderr, "\n");
9720b7a9ceaSZeev Suraski#	endif
9730b7a9ceaSZeev Suraski	va_end(args);
9740b7a9ceaSZeev Suraski#endif
9750b7a9ceaSZeev Suraski}
976c06692e9SZeev Suraski
977c06692e9SZeev Suraski
978819ea51dSZeev SuraskiZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...)
979c06692e9SZeev Suraski{
980c06692e9SZeev Suraski	va_list files;
981c06692e9SZeev Suraski	int i;
982c06692e9SZeev Suraski	zend_file_handle *file_handle;
9830eadc7e4SZeev Suraski	zend_op_array *orig_op_array = EG(active_op_array);
984b06440bcSZeev Suraski	zval *local_retval=NULL;
985424e98f4SZeev Suraski
986c06692e9SZeev Suraski	va_start(files, file_count);
987c06692e9SZeev Suraski	for (i=0; i<file_count; i++) {
988c06692e9SZeev Suraski		file_handle = va_arg(files, zend_file_handle *);
989c06692e9SZeev Suraski		if (!file_handle) {
990c06692e9SZeev Suraski			continue;
991c06692e9SZeev Suraski		}
992b4f3b9d3SZeev Suraski		EG(active_op_array) = zend_compile_file(file_handle, ZEND_INCLUDE TSRMLS_CC);
993b4f3b9d3SZeev Suraski		zend_destroy_file_handle(file_handle TSRMLS_CC);
994c06692e9SZeev Suraski		if (EG(active_op_array)) {
995b06440bcSZeev Suraski			EG(return_value_ptr_ptr) = retval ? retval : &local_retval;
9962c254ba7SZeev Suraski			zend_execute(EG(active_op_array) TSRMLS_CC);
99784603723SAndi Gutmans			if (EG(exception)) {
99804788f95SStig Bakken#if 1 /* support set_exception_handler() */
99904788f95SStig Bakken				if (EG(user_exception_handler)) {
100004788f95SStig Bakken					zval *orig_user_exception_handler;
100104788f95SStig Bakken					zval ***params, *retval2;
100204788f95SStig Bakken					params = (zval ***)emalloc(sizeof(zval **));
100304788f95SStig Bakken					params[0] = &EG(exception);
100404788f95SStig Bakken					orig_user_exception_handler = EG(user_exception_handler);
100504788f95SStig Bakken					if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
1006b899f9bfSStig Bakken						if (retval2 != NULL) {
1007b899f9bfSStig Bakken							zval_ptr_dtor(&retval2);
1008b899f9bfSStig Bakken						}
1009b899f9bfSStig Bakken					} else {
1010b899f9bfSStig Bakken						zval_ptr_dtor(&EG(exception));
1011b899f9bfSStig Bakken						EG(exception) = NULL;
1012b899f9bfSStig Bakken						zend_error(E_ERROR, "Uncaught exception!");
101304788f95SStig Bakken					}
101438eea2e8SAndi Gutmans					efree(params);
101504788f95SStig Bakken					zval_ptr_dtor(&EG(exception));
101604788f95SStig Bakken					EG(exception) = NULL;
101704788f95SStig Bakken				} else {
101804788f95SStig Bakken					zval_ptr_dtor(&EG(exception));
101904788f95SStig Bakken					EG(exception) = NULL;
102004788f95SStig Bakken					zend_error(E_ERROR, "Uncaught exception!");
102104788f95SStig Bakken				}
1022b899f9bfSStig Bakken				if (retval == NULL && *EG(return_value_ptr_ptr) != NULL) {
102338eea2e8SAndi Gutmans					zval_ptr_dtor(EG(return_value_ptr_ptr));
102438eea2e8SAndi Gutmans					local_retval = NULL;
102538eea2e8SAndi Gutmans				}
102604788f95SStig Bakken#else
102784603723SAndi Gutmans				zval_ptr_dtor(&EG(exception));
1028b9355b9aSAndi Gutmans				zend_error(E_ERROR, "Uncaught exception!");
102904788f95SStig Bakken#endif
103084603723SAndi Gutmans			} else if (!retval) {
1031b06440bcSZeev Suraski				zval_ptr_dtor(EG(return_value_ptr_ptr));
1032b06440bcSZeev Suraski				local_retval = NULL;
1033819ea51dSZeev Suraski			}
1034c06692e9SZeev Suraski			destroy_op_array(EG(active_op_array));
1035c06692e9SZeev Suraski			efree(EG(active_op_array));
1036c06692e9SZeev Suraski		} else if (type==ZEND_REQUIRE) {
1037c06692e9SZeev Suraski			va_end(files);
10380eadc7e4SZeev Suraski			EG(active_op_array) = orig_op_array;
1039c06692e9SZeev Suraski			return FAILURE;
1040c06692e9SZeev Suraski		}
1041c06692e9SZeev Suraski	}
1042c06692e9SZeev Suraski	va_end(files);
10430eadc7e4SZeev Suraski	EG(active_op_array) = orig_op_array;
1044c06692e9SZeev Suraski
1045c06692e9SZeev Suraski	return SUCCESS;
1046c06692e9SZeev Suraski}
1047c06692e9SZeev Suraski
10485286b397SZeev Suraski#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
10495286b397SZeev Suraski
1050b5770382SZeev SuraskiZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC)
10515286b397SZeev Suraski{
10525286b397SZeev Suraski	char *cur_filename;
10535286b397SZeev Suraski	int cur_lineno;
10545286b397SZeev Suraski	char *compiled_string_description;
10555286b397SZeev Suraski
10564187439cSZeev Suraski	if (zend_is_compiling(TSRMLS_C)) {
1057b4f3b9d3SZeev Suraski		cur_filename = zend_get_compiled_filename(TSRMLS_C);
1058b4f3b9d3SZeev Suraski		cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
10594187439cSZeev Suraski	} else if (zend_is_executing(TSRMLS_C)) {
10602c254ba7SZeev Suraski		cur_filename = zend_get_executed_filename(TSRMLS_C);
10612c254ba7SZeev Suraski		cur_lineno = zend_get_executed_lineno(TSRMLS_C);
10625286b397SZeev Suraski	} else {
10635286b397SZeev Suraski		cur_filename = "Unknown";
10645286b397SZeev Suraski		cur_lineno = 0;
10655286b397SZeev Suraski	}
10665286b397SZeev Suraski
10675286b397SZeev Suraski	compiled_string_description = emalloc(sizeof(COMPILED_STRING_DESCRIPTION_FORMAT)+strlen(name)+strlen(cur_filename)+MAX_LENGTH_OF_LONG);
10685286b397SZeev Suraski	sprintf(compiled_string_description, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
10695286b397SZeev Suraski	return compiled_string_description;
10705286b397SZeev Suraski}
10715286b397SZeev Suraski
10720e08845eSZeev Suraski
10730e08845eSZeev Suraskivoid free_estring(char **str_p)
10740e08845eSZeev Suraski{
10750e08845eSZeev Suraski	efree(*str_p);
10760e08845eSZeev Suraski}
10775a41ced0SStig Bakken
10785a41ced0SStig Bakken/*
10795a41ced0SStig Bakken * Local variables:
10805a41ced0SStig Bakken * tab-width: 4
10815a41ced0SStig Bakken * c-basic-offset: 4
10825a41ced0SStig Bakken * indent-tabs-mode: t
10835a41ced0SStig Bakken * End:
10845a41ced0SStig Bakken */
1085