zend.c revision 27de54b0
1573b4602SAndi Gutmans/*
2573b4602SAndi Gutmans   +----------------------------------------------------------------------+
3573b4602SAndi Gutmans   | Zend Engine                                                          |
4573b4602SAndi Gutmans   +----------------------------------------------------------------------+
562dc854bSSebastian Bergmann   | Copyright (c) 1998-2002 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
724be862b0SZeev SuraskiZEND_INI_BEGIN()
734be862b0SZeev Suraski	ZEND_INI_ENTRY("error_reporting",			NULL,		ZEND_INI_ALL,		OnUpdateErrorReporting)
744be862b0SZeev SuraskiZEND_INI_END()
754be862b0SZeev Suraski
764be862b0SZeev Suraski
777a87fcbbSZeev Suraski#ifdef ZTS
78e06a1ed2SZeev SuraskiZEND_API int compiler_globals_id;
79e06a1ed2SZeev SuraskiZEND_API int executor_globals_id;
805864b57eSZeev SuraskiZEND_API int alloc_globals_id;
81ce98c73fSAndi Gutmanszend_class_entry global_main_class;
829d11db12SAndi GutmansHashTable *global_auto_globals_table;
837a87fcbbSZeev Suraski#endif
84573b4602SAndi Gutmans
85e801a99aSZeev SuraskiZEND_API zend_utility_values zend_uv;
86573b4602SAndi Gutmans
875ba5f00fSZeev SuraskiZEND_API zval zval_used_for_init; /* True global variable */
88213d0e2fSAndi Gutmans
89573b4602SAndi Gutmans/* version information */
90573b4602SAndi Gutmansstatic char *zend_version_info;
91573b4602SAndi Gutmansstatic uint zend_version_info_length;
9262dc854bSSebastian Bergmann#define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2002 Zend Technologies\n"
93573b4602SAndi Gutmans
94573b4602SAndi Gutmans
9580bab9d9SAndrei Zmievski#define PRINT_ZVAL_INDENT 4
96573b4602SAndi Gutmans
97573b4602SAndi Gutmansstatic void print_hash(HashTable *ht, int indent)
98573b4602SAndi Gutmans{
99573b4602SAndi Gutmans	zval **tmp;
100573b4602SAndi Gutmans	char *string_key;
10163873abaSStanislav Malyshev	HashPosition iterator;
1024757104eSZeev Suraski	ulong num_key;
1034757104eSZeev Suraski	uint str_len;
104573b4602SAndi Gutmans	int i;
105573b4602SAndi Gutmans
106573b4602SAndi Gutmans	for (i=0; i<indent; i++) {
107573b4602SAndi Gutmans		ZEND_PUTS(" ");
108573b4602SAndi Gutmans	}
109573b4602SAndi Gutmans	ZEND_PUTS("(\n");
11080bab9d9SAndrei Zmievski	indent += PRINT_ZVAL_INDENT;
11163873abaSStanislav Malyshev	zend_hash_internal_pointer_reset_ex(ht, &iterator);
11263873abaSStanislav Malyshev	while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
113573b4602SAndi Gutmans		for (i=0; i<indent; i++) {
114573b4602SAndi Gutmans			ZEND_PUTS(" ");
115573b4602SAndi Gutmans		}
116573b4602SAndi Gutmans		ZEND_PUTS("[");
11736eaad25SZeev Suraski		switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
118573b4602SAndi Gutmans			case HASH_KEY_IS_STRING:
119573b4602SAndi Gutmans				ZEND_PUTS(string_key);
120573b4602SAndi Gutmans				break;
121573b4602SAndi Gutmans			case HASH_KEY_IS_LONG:
1224f6c95d1SZeev Suraski				zend_printf("%ld", num_key);
123573b4602SAndi Gutmans				break;
124573b4602SAndi Gutmans		}
125573b4602SAndi Gutmans		ZEND_PUTS("] => ");
12680bab9d9SAndrei Zmievski		zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT);
127573b4602SAndi Gutmans		ZEND_PUTS("\n");
12863873abaSStanislav Malyshev		zend_hash_move_forward_ex(ht, &iterator);
129573b4602SAndi Gutmans	}
13080bab9d9SAndrei Zmievski	indent -= PRINT_ZVAL_INDENT;
131573b4602SAndi Gutmans	for (i=0; i<indent; i++) {
132573b4602SAndi Gutmans		ZEND_PUTS(" ");
133573b4602SAndi Gutmans	}
134573b4602SAndi Gutmans	ZEND_PUTS(")\n");
135573b4602SAndi Gutmans}
136573b4602SAndi Gutmans
13727de54b0SAndi Gutmansstatic void print_flat_hash(HashTable *ht)
13827de54b0SAndi Gutmans{
13927de54b0SAndi Gutmans    zval **tmp;
14027de54b0SAndi Gutmans    char *string_key;
14127de54b0SAndi Gutmans    HashPosition iterator;
14227de54b0SAndi Gutmans    ulong num_key;
14327de54b0SAndi Gutmans    uint str_len;
14427de54b0SAndi Gutmans    int i = 0;
14527de54b0SAndi Gutmans
14627de54b0SAndi Gutmans    zend_hash_internal_pointer_reset_ex(ht, &iterator);
14727de54b0SAndi Gutmans    while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
14827de54b0SAndi Gutmans	if (i++ > 0) {
14927de54b0SAndi Gutmans	    ZEND_PUTS(",");
15027de54b0SAndi Gutmans	}
15127de54b0SAndi Gutmans	ZEND_PUTS("[");
15227de54b0SAndi Gutmans	switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
15327de54b0SAndi Gutmans	    case HASH_KEY_IS_STRING:
15427de54b0SAndi Gutmans		ZEND_PUTS(string_key);
15527de54b0SAndi Gutmans		break;
15627de54b0SAndi Gutmans	    case HASH_KEY_IS_LONG:
15727de54b0SAndi Gutmans		zend_printf("%ld", num_key);
15827de54b0SAndi Gutmans		break;
15927de54b0SAndi Gutmans	}
16027de54b0SAndi Gutmans	ZEND_PUTS("] => ");
16127de54b0SAndi Gutmans	zend_print_flat_zval_r(*tmp);
16227de54b0SAndi Gutmans	zend_hash_move_forward_ex(ht, &iterator);
16327de54b0SAndi Gutmans    }
16427de54b0SAndi Gutmans}
1657a87fcbbSZeev Suraski
166da9faa2cSZeev SuraskiZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy)
167573b4602SAndi Gutmans{
168da9faa2cSZeev Suraski	if (expr->type==IS_STRING) {
169da9faa2cSZeev Suraski		*use_copy = 0;
170da9faa2cSZeev Suraski		return;
171da9faa2cSZeev Suraski	}
172da9faa2cSZeev Suraski	switch (expr->type) {
173bdefd5daSAndi Gutmans		case IS_NULL:
174f2d703e9SZeev Suraski			expr_copy->value.str.len = 0;
175f2d703e9SZeev Suraski			expr_copy->value.str.val = empty_string;
1768c4ab98eSThies C. Arntzen			break;
177da9faa2cSZeev Suraski		case IS_BOOL:
17891d7ba76SAndi Gutmans			if (expr->value.lval) {
17991d7ba76SAndi Gutmans				expr_copy->value.str.len = 1;
18091d7ba76SAndi Gutmans				expr_copy->value.str.val = estrndup("1", 1);
18191d7ba76SAndi Gutmans			} else {
18291d7ba76SAndi Gutmans				expr_copy->value.str.len = 0;
18391d7ba76SAndi Gutmans				expr_copy->value.str.val = empty_string;
18491d7ba76SAndi Gutmans			}
185da9faa2cSZeev Suraski			break;
186da9faa2cSZeev Suraski		case IS_RESOURCE:
187da9faa2cSZeev Suraski			expr_copy->value.str.val = (char *) emalloc(sizeof("Resource id #")-1 + MAX_LENGTH_OF_LONG);
188da9faa2cSZeev Suraski			expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Resource id #%ld", expr->value.lval);
189da9faa2cSZeev Suraski			break;
190da9faa2cSZeev Suraski		case IS_ARRAY:
191da9faa2cSZeev Suraski			expr_copy->value.str.len = sizeof("Array")-1;
192da9faa2cSZeev Suraski			expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len);
193da9faa2cSZeev Suraski			break;
1941b282b35SAndi Gutmans		case IS_OBJECT:
195b04acdadSAndi Gutmans			expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
19692dd5e61SStanislav Malyshev			expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle);
197b04acdadSAndi Gutmans#if 0
198b04acdadSAndi Gutmans			/* FIXME: This might break BC for some people */
1991b282b35SAndi Gutmans			expr_copy->value.str.len = sizeof("Object")-1;
2001b282b35SAndi Gutmans			expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len);
201b04acdadSAndi Gutmans#endif
202da9faa2cSZeev Suraski			break;
203e842ef9fSIlia Alshanetsky		case IS_DOUBLE:
204e842ef9fSIlia Alshanetsky			*expr_copy = *expr;
205e842ef9fSIlia Alshanetsky			zval_copy_ctor(expr_copy);
206e842ef9fSIlia Alshanetsky			zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC);
207e842ef9fSIlia Alshanetsky			break;
208da9faa2cSZeev Suraski		default:
209da9faa2cSZeev Suraski			*expr_copy = *expr;
210da9faa2cSZeev Suraski			zval_copy_ctor(expr_copy);
211da9faa2cSZeev Suraski			convert_to_string(expr_copy);
212da9faa2cSZeev Suraski			break;
213da9faa2cSZeev Suraski	}
214da9faa2cSZeev Suraski	expr_copy->type = IS_STRING;
215da9faa2cSZeev Suraski	*use_copy = 1;
216da9faa2cSZeev Suraski}
217da9faa2cSZeev Suraski
218da9faa2cSZeev Suraski
219da9faa2cSZeev SuraskiZEND_API int zend_print_zval(zval *expr, int indent)
220da9faa2cSZeev Suraski{
2215dba4774SZeev Suraski	return zend_print_zval_ex(zend_write, expr, indent);
2225dba4774SZeev Suraski}
2235dba4774SZeev Suraski
2245dba4774SZeev Suraski
2255dba4774SZeev SuraskiZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent)
2265dba4774SZeev Suraski{
227da9faa2cSZeev Suraski	zval expr_copy;
228da9faa2cSZeev Suraski	int use_copy;
229da9faa2cSZeev Suraski
230da9faa2cSZeev Suraski	zend_make_printable_zval(expr, &expr_copy, &use_copy);
231da9faa2cSZeev Suraski	if (use_copy) {
232573b4602SAndi Gutmans		expr = &expr_copy;
233573b4602SAndi Gutmans	}
234573b4602SAndi Gutmans	if (expr->value.str.len==0) { /* optimize away empty strings */
235da9faa2cSZeev Suraski		if (use_copy) {
236da9faa2cSZeev Suraski			zval_dtor(expr);
237da9faa2cSZeev Suraski		}
238573b4602SAndi Gutmans		return 0;
239573b4602SAndi Gutmans	}
2404f6c95d1SZeev Suraski	write_func(expr->value.str.val, expr->value.str.len);
241da9faa2cSZeev Suraski	if (use_copy) {
242573b4602SAndi Gutmans		zval_dtor(expr);
243573b4602SAndi Gutmans	}
244573b4602SAndi Gutmans	return expr->value.str.len;
245573b4602SAndi Gutmans}
246573b4602SAndi Gutmans
24727de54b0SAndi GutmansZEND_API void zend_print_flat_zval_r(zval *expr)
24827de54b0SAndi Gutmans{
24927de54b0SAndi Gutmans    zend_write_func_t write_func = zend_write;
25027de54b0SAndi Gutmans
25127de54b0SAndi Gutmans    switch (expr->type) {
25227de54b0SAndi Gutmans	case IS_ARRAY:
25327de54b0SAndi Gutmans	    ZEND_PUTS("Array (");
25427de54b0SAndi Gutmans	    if (++expr->value.ht->nApplyCount>1) {
25527de54b0SAndi Gutmans		ZEND_PUTS(" *RECURSION*");
25627de54b0SAndi Gutmans		expr->value.ht->nApplyCount--;
25727de54b0SAndi Gutmans		return;
25827de54b0SAndi Gutmans	    }
25927de54b0SAndi Gutmans	    print_flat_hash(expr->value.ht);
26027de54b0SAndi Gutmans	    ZEND_PUTS(")");
26127de54b0SAndi Gutmans	    expr->value.ht->nApplyCount--;
26227de54b0SAndi Gutmans	    break;
26327de54b0SAndi Gutmans	case IS_OBJECT:
26427de54b0SAndi Gutmans	    {
26527de54b0SAndi Gutmans		zend_object *object = Z_OBJ_P(expr);
26627de54b0SAndi Gutmans
26727de54b0SAndi Gutmans		if (++object->properties->nApplyCount>1) {
26827de54b0SAndi Gutmans		    ZEND_PUTS(" *RECURSION*");
26927de54b0SAndi Gutmans		    object->properties->nApplyCount--;
27027de54b0SAndi Gutmans		    return;
27127de54b0SAndi Gutmans		}
27227de54b0SAndi Gutmans		zend_printf("%s Object (", object->ce->name);
27327de54b0SAndi Gutmans		print_flat_hash(object->properties);
27427de54b0SAndi Gutmans		ZEND_PUTS(")");
27527de54b0SAndi Gutmans		object->properties->nApplyCount--;
27627de54b0SAndi Gutmans		break;
27727de54b0SAndi Gutmans	    }
27827de54b0SAndi Gutmans	default:
27927de54b0SAndi Gutmans	    zend_print_variable(expr);
28027de54b0SAndi Gutmans	    break;
28127de54b0SAndi Gutmans    }
28227de54b0SAndi Gutmans}
283573b4602SAndi Gutmans
2845dba4774SZeev SuraskiZEND_API void zend_print_zval_r(zval *expr, int indent)
2855dba4774SZeev Suraski{
2865dba4774SZeev Suraski	zend_print_zval_r_ex(zend_write, expr, indent);
2875dba4774SZeev Suraski}
2885dba4774SZeev Suraski
2895dba4774SZeev Suraski
2905dba4774SZeev SuraskiZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent)
291573b4602SAndi Gutmans{
292671fff2fSAndi Gutmans	switch (expr->type) {
293573b4602SAndi Gutmans		case IS_ARRAY:
294573b4602SAndi Gutmans			ZEND_PUTS("Array\n");
2956053f2a1SZeev Suraski			if (++expr->value.ht->nApplyCount>1) {
2966053f2a1SZeev Suraski				ZEND_PUTS(" *RECURSION*");
297a9d81981SDerick Rethans				expr->value.ht->nApplyCount--;
2986053f2a1SZeev Suraski				return;
2996053f2a1SZeev Suraski			}
3004f6c95d1SZeev Suraski			print_hash(expr->value.ht, indent);
3016053f2a1SZeev Suraski			expr->value.ht->nApplyCount--;
302573b4602SAndi Gutmans			break;
303573b4602SAndi Gutmans		case IS_OBJECT:
304c259cb7cSAndi Gutmans			{
305c259cb7cSAndi Gutmans				zend_object *object = Z_OBJ_P(expr);
306c259cb7cSAndi Gutmans
307c259cb7cSAndi Gutmans				if (++object->properties->nApplyCount>1) {
308c259cb7cSAndi Gutmans					ZEND_PUTS(" *RECURSION*");
309a9d81981SDerick Rethans					object->properties->nApplyCount--;
310c259cb7cSAndi Gutmans					return;
311c259cb7cSAndi Gutmans				}
312c259cb7cSAndi Gutmans				zend_printf("%s Object\n", object->ce->name);
313c259cb7cSAndi Gutmans				print_hash(object->properties, indent);
314c259cb7cSAndi Gutmans				object->properties->nApplyCount--;
315c259cb7cSAndi Gutmans				break;
3166053f2a1SZeev Suraski			}
317573b4602SAndi Gutmans		default:
318573b4602SAndi Gutmans			zend_print_variable(expr);
319573b4602SAndi Gutmans			break;
320573b4602SAndi Gutmans	}
321573b4602SAndi Gutmans}
322573b4602SAndi Gutmans
323573b4602SAndi Gutmans
3245463dd5bSAndi Gutmansstatic FILE *zend_fopen_wrapper(const char *filename, char **opened_path)
325573b4602SAndi Gutmans{
3265463dd5bSAndi Gutmans	if (opened_path) {
32727de5001SAndi Gutmans		*opened_path = estrdup(filename);
3285463dd5bSAndi Gutmans	}
329f311ab16SAndi Gutmans	return fopen(filename, "rb");
330573b4602SAndi Gutmans}
331573b4602SAndi Gutmans
332573b4602SAndi Gutmans
33393536507SStig S. Bakkenstatic void register_standard_class(void)
334573b4602SAndi Gutmans{
33592dd5e61SStanislav Malyshev	zend_standard_class_def = malloc(sizeof(zend_class_entry));
33692dd5e61SStanislav Malyshev
33792dd5e61SStanislav Malyshev	zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
33892dd5e61SStanislav Malyshev	zend_standard_class_def->name_length = sizeof("stdClass") - 1;
33992dd5e61SStanislav Malyshev	zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
34092dd5e61SStanislav Malyshev	zend_standard_class_def->parent = NULL;
34192dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
34292dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
343bc5ea87eSAndi Gutmans	zend_hash_init_ex(&zend_standard_class_def->protected_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
34492dd5e61SStanislav Malyshev	zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
34592dd5e61SStanislav Malyshev	zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
34692dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
34792dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
34892dd5e61SStanislav Malyshev	zend_hash_init_ex(&zend_standard_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
34992dd5e61SStanislav Malyshev	zend_standard_class_def->constructor = NULL;
35092dd5e61SStanislav Malyshev	zend_standard_class_def->destructor = NULL;
35192dd5e61SStanislav Malyshev	zend_standard_class_def->clone = NULL;
35292dd5e61SStanislav Malyshev	zend_standard_class_def->handle_function_call = NULL;
35392dd5e61SStanislav Malyshev	zend_standard_class_def->handle_property_get = NULL;
35492dd5e61SStanislav Malyshev	zend_standard_class_def->handle_property_set = NULL;
355fb6976e4SAndi Gutmans	zend_standard_class_def->refcount = 1;
3562de45becSAndi Gutmans	zend_standard_class_def->constants_updated = 0;
3572de45becSAndi Gutmans
35892dd5e61SStanislav Malyshev	zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
359573b4602SAndi Gutmans}
360573b4602SAndi Gutmans
361573b4602SAndi Gutmans
362b4f3b9d3SZeev Suraskistatic void zend_set_default_compile_time_values(TSRMLS_D)
3638b794bb1SZeev Suraski{
3648b794bb1SZeev Suraski	/* default compile-time values */
3658b794bb1SZeev Suraski	CG(asp_tags) = 0;
3668b794bb1SZeev Suraski	CG(short_tags) = 1;
3678b794bb1SZeev Suraski	CG(allow_call_time_pass_reference) = 1;
3688b794bb1SZeev Suraski	CG(extended_info) = 0;
3698b794bb1SZeev Suraski}
3708b794bb1SZeev Suraski
3718b794bb1SZeev Suraski
3727a87fcbbSZeev Suraski#ifdef ZTS
3732c254ba7SZeev Suraskistatic void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC)
3747a87fcbbSZeev Suraski{
3757c4a0838SZeev Suraski	zend_function tmp_func;
3767c4a0838SZeev Suraski	zend_class_entry tmp_class;
3777c4a0838SZeev Suraski
3787f4909d9SThies C. Arntzen	compiler_globals->compiled_filename = NULL;
3797f4909d9SThies C. Arntzen
380ce98c73fSAndi Gutmans	compiler_globals->function_table = &compiler_globals->main_class.function_table;
3811263932aSZeev Suraski	zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
382ce98c73fSAndi Gutmans	zend_hash_copy(compiler_globals->function_table, GLOBAL_FUNCTION_TABLE, NULL, &tmp_func, sizeof(zend_function));
3837a87fcbbSZeev Suraski
384ce98c73fSAndi Gutmans	compiler_globals->class_table = &compiler_globals->main_class.class_table;
3851263932aSZeev Suraski	zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
386c29f5d6eSZeev 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 *));
3879cf1a98dSThies C. Arntzen
388b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
38985b4df53SZeev Suraski
39085b4df53SZeev Suraski	CG(interactive) = 0;
3919d11db12SAndi Gutmans
3929d11db12SAndi Gutmans	compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
3939d11db12SAndi Gutmans	zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
3949d11db12SAndi Gutmans	zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(void *) /* empty element */);
3957a87fcbbSZeev Suraski}
3967a87fcbbSZeev Suraski
3977a87fcbbSZeev Suraski
3982c254ba7SZeev Suraskistatic void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC)
3997a87fcbbSZeev Suraski{
400ce98c73fSAndi Gutmans	if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
40174a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->function_table);
40274a9ed7bSZeev Suraski	}
403ce98c73fSAndi Gutmans	if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
40474a9ed7bSZeev Suraski		zend_hash_destroy(compiler_globals->class_table);
40574a9ed7bSZeev Suraski	}
4069d11db12SAndi Gutmans	if (compiler_globals->auto_globals != global_auto_globals_table) {
4079d11db12SAndi Gutmans		zend_hash_destroy(compiler_globals->auto_globals);
4089d11db12SAndi Gutmans		free(compiler_globals->auto_globals);
4099d11db12SAndi Gutmans	}
4107a87fcbbSZeev Suraski}
411a9f9ae79SZeev Suraski
412a9f9ae79SZeev Suraski
4132c254ba7SZeev Suraskistatic void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC)
414a9f9ae79SZeev Suraski{
4155fcae67eSZeev Suraski	zend_startup_constants(TSRMLS_C);
4165fcae67eSZeev Suraski	zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
4172c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
4180b7a9ceaSZeev Suraski	EG(lambda_count)=0;
4191f23e507SZeev Suraski	EG(user_error_handler) = NULL;
42004788f95SStig Bakken	EG(user_exception_handler) = NULL;
421ab30c8ccSZeev Suraski	EG(in_execution) = 0;
422e6054d28SDerick Rethans	EG(current_execute_data) = NULL;
423a9f9ae79SZeev Suraski}
424a9f9ae79SZeev Suraski
425a9f9ae79SZeev Suraski
4262c254ba7SZeev Suraskistatic void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC)
427a9f9ae79SZeev Suraski{
4282c254ba7SZeev Suraski	zend_shutdown_constants(TSRMLS_C);
4297deb44e3SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
4302c254ba7SZeev Suraski	zend_ini_shutdown(TSRMLS_C);
431a9f9ae79SZeev Suraski}
432a9f9ae79SZeev Suraski
433a9f9ae79SZeev Suraski
434609d58a4SZeev Suraskistatic void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC)
435609d58a4SZeev Suraski{
436609d58a4SZeev Suraski	zend_copy_ini_directives(TSRMLS_C);
437609d58a4SZeev Suraski	zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
438609d58a4SZeev Suraski}
439609d58a4SZeev Suraski
44066d9314bSZeev Suraski#endif
44166d9314bSZeev Suraski
44266d9314bSZeev Suraski
443b4f3b9d3SZeev Suraskistatic void alloc_globals_ctor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
4447c4a0838SZeev Suraski{
445b4f3b9d3SZeev Suraski	start_memory_manager(TSRMLS_C);
4467c4a0838SZeev Suraski}
4477c4a0838SZeev Suraski
4487a87fcbbSZeev Suraski
449fcc03510SZeev Suraskistatic void alloc_globals_dtor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
450fcc03510SZeev Suraski{
4517df16012SAndi Gutmans	shutdown_memory_manager(0, 1 TSRMLS_CC);
452fcc03510SZeev Suraski}
453fcc03510SZeev Suraski
454fcc03510SZeev Suraski
4551f5ee72eSAndi Gutmans#ifdef __FreeBSD__
4565928970dSAndi Gutmans/* FreeBSD floating point precision fix */
4575928970dSAndi Gutmans#include <floatingpoint.h>
4585928970dSAndi Gutmans#endif
4597a87fcbbSZeev Suraski
460609d58a4SZeev Suraski
461609d58a4SZeev Suraskistatic void scanner_globals_ctor(zend_scanner_globals *scanner_globals_p TSRMLS_DC)
46254d53055SZeev Suraski{
463609d58a4SZeev Suraski	scanner_globals_p->c_buf_p = (char *) 0;
464609d58a4SZeev Suraski	scanner_globals_p->init = 1;
465609d58a4SZeev Suraski	scanner_globals_p->start = 0;
466609d58a4SZeev Suraski	scanner_globals_p->current_buffer = NULL;
467483fc4c7SZeev Suraski	scanner_globals_p->yy_in = NULL;
468483fc4c7SZeev Suraski	scanner_globals_p->yy_out = NULL;
46917352812SZeev Suraski	scanner_globals_p->_yy_more_flag = 0;
47017352812SZeev Suraski	scanner_globals_p->_yy_more_len = 0;
4710bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack_ptr = 0;
4720bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack_depth = 0;
4730bb780b3SZeev Suraski	scanner_globals_p->yy_start_stack = 0;
47454d53055SZeev Suraski}
47554d53055SZeev Suraski
476cf36abb2SAndi Gutmansvoid zend_init_opcodes_handlers();
47754d53055SZeev Suraski
47813e74131SAndi Gutmansint zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions)
479573b4602SAndi Gutmans{
480a9f9ae79SZeev Suraski#ifdef ZTS
4817c4a0838SZeev Suraski	zend_compiler_globals *compiler_globals;
482a9f9ae79SZeev Suraski	zend_executor_globals *executor_globals;
4832c254ba7SZeev Suraski	void ***tsrm_ls;
484609d58a4SZeev Suraski#ifdef ZTS
485609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
486609d58a4SZeev Suraski	extern ZEND_API ts_rsrc_id language_scanner_globals_id;
487609d58a4SZeev Suraski#else
488609d58a4SZeev Suraski	extern zend_scanner_globals ini_scanner_globals;
489609d58a4SZeev Suraski	extern zend_scanner_globals language_scanner_globals;
490609d58a4SZeev Suraski#endif
491a9f9ae79SZeev Suraski
492fcc03510SZeev Suraski	ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
49399947a25SAndi Gutmans#else
49466d9314bSZeev Suraski	alloc_globals_ctor(&alloc_globals TSRMLS_CC);
495a9f9ae79SZeev Suraski#endif
496a9f9ae79SZeev Suraski
4971f5ee72eSAndi Gutmans#ifdef __FreeBSD__
498c3340584SSascha Schumann	/* FreeBSD floating point precision fix */
499c3340584SSascha Schumann	fpsetmask(0);
5005928970dSAndi Gutmans#endif
501309827ecSZeev Suraski
502309827ecSZeev Suraski	zend_startup_extensions_mechanism();
503309827ecSZeev Suraski
504573b4602SAndi Gutmans	/* Set up utility functions and values */
50567f69743SZeev Suraski	zend_error_cb = utility_functions->error_function;
506573b4602SAndi Gutmans	zend_printf = utility_functions->printf_function;
5075dba4774SZeev Suraski	zend_write = (zend_write_func_t) utility_functions->write_function;
508573b4602SAndi Gutmans	zend_fopen = utility_functions->fopen_function;
509573b4602SAndi Gutmans	if (!zend_fopen) {
510573b4602SAndi Gutmans		zend_fopen = zend_fopen_wrapper;
511573b4602SAndi Gutmans	}
51256251a72SZeev Suraski	zend_message_dispatcher_p = utility_functions->message_handler;
513573b4602SAndi Gutmans	zend_block_interruptions = utility_functions->block_interruptions;
514573b4602SAndi Gutmans	zend_unblock_interruptions = utility_functions->unblock_interruptions;
515903018efSZeev Suraski	zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
516fafbf6d8SZeev Suraski	zend_ticks_function = utility_functions->ticks_function;
517bd115087SZeev Suraski	zend_on_timeout = utility_functions->on_timeout;
518d035af4aSZeev Suraski
519c06692e9SZeev Suraski	zend_compile_file = compile_file;
520573b4602SAndi Gutmans	zend_execute = execute;
521573b4602SAndi Gutmans
522cf36abb2SAndi Gutmans	zend_init_opcodes_handlers();
523cf36abb2SAndi Gutmans
524573b4602SAndi Gutmans	/* set up version */
525573b4602SAndi Gutmans	zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
526573b4602SAndi Gutmans	zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;
527573b4602SAndi Gutmans
528ce98c73fSAndi Gutmans#ifndef ZTS
529ce98c73fSAndi Gutmans	GLOBAL_FUNCTION_TABLE = &compiler_globals.main_class.function_table;
530ce98c73fSAndi Gutmans	GLOBAL_CLASS_TABLE = &compiler_globals.main_class.class_table;
531ce98c73fSAndi Gutmans#endif
5329d11db12SAndi Gutmans	GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
5331263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
5341263932aSZeev Suraski	zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
5352eabb14dSAndi Gutmans
536573b4602SAndi Gutmans	register_standard_class();
5371263932aSZeev Suraski	zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
5384cb9a483SZeev Suraski	zend_init_rsrc_list_dtors();
539573b4602SAndi Gutmans
54004788f95SStig Bakken
541213d0e2fSAndi Gutmans	/* This zval can be used to initialize allocate zval's to an uninit'ed value */
542213d0e2fSAndi Gutmans	zval_used_for_init.is_ref = 0;
543213d0e2fSAndi Gutmans	zval_used_for_init.refcount = 1;
544bdefd5daSAndi Gutmans	zval_used_for_init.type = IS_NULL;
545213d0e2fSAndi Gutmans
5467a87fcbbSZeev Suraski#ifdef ZTS
5478a003f80SZeev Suraski	zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
5488a003f80SZeev Suraski	zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0);
5492c254ba7SZeev Suraski	ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
5502c254ba7SZeev Suraski	ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
551609d58a4SZeev Suraski	ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
552609d58a4SZeev Suraski	ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
5537c4a0838SZeev Suraski	compiler_globals = ts_resource(compiler_globals_id);
554a9f9ae79SZeev Suraski	executor_globals = ts_resource(executor_globals_id);
5552c254ba7SZeev Suraski	tsrm_ls = ts_resource_ex(0, NULL);
5565fcae67eSZeev Suraski
5572c254ba7SZeev Suraski	compiler_globals_dtor(compiler_globals, tsrm_ls);
558f4b832d2SAndi Gutmans	*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
559f4b832d2SAndi Gutmans	*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
5609d11db12SAndi Gutmans	compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
5615fcae67eSZeev Suraski
5625fcae67eSZeev Suraski	zend_hash_destroy(executor_globals->zend_constants);
5635fcae67eSZeev Suraski	*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
564762158aaSAndi Gutmans#else
56580b870e5SAndi Gutmans	zend_hash_init_ex(CG(auto_globals), 8, NULL, NULL, 1, 0);
566609d58a4SZeev Suraski	scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
567609d58a4SZeev Suraski	scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
5686313238cSZeev Suraski	zend_startup_constants();
569b4f3b9d3SZeev Suraski	zend_set_default_compile_time_values(TSRMLS_C);
5701f23e507SZeev Suraski	EG(user_error_handler) = NULL;
57104788f95SStig Bakken	EG(user_exception_handler) = NULL;
5727a87fcbbSZeev Suraski#endif
5732c254ba7SZeev Suraski	zend_register_standard_constants(TSRMLS_C);
5747a87fcbbSZeev Suraski
575bfbe8618SZeev Suraski#ifndef ZTS
5762c254ba7SZeev Suraski	zend_init_rsrc_plist(TSRMLS_C);
577bfbe8618SZeev Suraski#endif
578a9f9ae79SZeev Suraski
57913e74131SAndi Gutmans	if (start_builtin_functions) {
580b5770382SZeev Suraski		zend_startup_builtin_functions(TSRMLS_C);
58113e74131SAndi Gutmans	}
58213d840bcSZeev Suraski
5832c254ba7SZeev Suraski	zend_ini_startup(TSRMLS_C);
58454d53055SZeev Suraski
58554d53055SZeev Suraski#ifdef ZTS
58654d53055SZeev Suraski	tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
58754d53055SZeev Suraski#endif
58854d53055SZeev Suraski
589573b4602SAndi Gutmans	return SUCCESS;
590573b4602SAndi Gutmans}
591573b4602SAndi Gutmans
592573b4602SAndi Gutmans
5934be862b0SZeev Suraskivoid zend_register_standard_ini_entries(TSRMLS_D)
5944be862b0SZeev Suraski{
5954be862b0SZeev Suraski	int module_number = 0;
5964be862b0SZeev Suraski
5974be862b0SZeev Suraski	REGISTER_INI_ENTRIES();
5984be862b0SZeev Suraski}
5994be862b0SZeev Suraski
6004be862b0SZeev Suraski
601711be83dSZeev Suraski#ifdef ZTS
602711be83dSZeev Suraski/* Unlink the global (r/o) copies of the class, function and constant tables,
603711be83dSZeev Suraski * and use a fresh r/w copy for the startup thread
604711be83dSZeev Suraski */
605711be83dSZeev Suraskivoid zend_post_startup(TSRMLS_D)
606711be83dSZeev Suraski{
607711be83dSZeev Suraski	zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
6085fcae67eSZeev Suraski	zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
609711be83dSZeev Suraski
6105fcae67eSZeev Suraski	*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
6115fcae67eSZeev Suraski	*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
6125fcae67eSZeev Suraski	*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
613711be83dSZeev Suraski	compiler_globals_ctor(compiler_globals, tsrm_ls);
6145fcae67eSZeev Suraski	executor_globals_ctor(executor_globals, tsrm_ls);
615711be83dSZeev Suraski}
616711be83dSZeev Suraski#endif
617711be83dSZeev Suraski
618711be83dSZeev Suraski
619d76cf1daSZeev Suraskivoid zend_shutdown(TSRMLS_D)
620573b4602SAndi Gutmans{
62184eb48f0SZeev Suraski#ifdef ZEND_WIN32
62284eb48f0SZeev Suraski	zend_shutdown_timeout_thread();
62384eb48f0SZeev Suraski#endif
624bfbe8618SZeev Suraski#ifndef ZTS
6257deb44e3SZeev Suraski	zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
626bfbe8618SZeev Suraski#endif
6274cb9a483SZeev Suraski	zend_destroy_rsrc_list_dtors();
628d4acdd34SDerick Rethans	zend_hash_graceful_reverse_destroy(&module_registry);
6293458373eSAndi Gutmans
63076b9acc1SAndi Gutmans#ifndef ZTS
63176b9acc1SAndi Gutmans	/* In ZTS mode these are freed by compiler_globals_dtor() */
6327a87fcbbSZeev Suraski	zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
63376b9acc1SAndi Gutmans	zend_hash_destroy(GLOBAL_CLASS_TABLE);
63476b9acc1SAndi Gutmans#endif
6353458373eSAndi Gutmans
6369d11db12SAndi Gutmans	zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
6379d11db12SAndi Gutmans	free(GLOBAL_AUTO_GLOBALS_TABLE);
638d76cf1daSZeev Suraski	zend_shutdown_extensions(TSRMLS_C);
639573b4602SAndi Gutmans	free(zend_version_info);
6407a87fcbbSZeev Suraski#ifndef ZTS
641ee08b81aSZeev Suraski	zend_shutdown_constants();
6427a87fcbbSZeev Suraski#endif
643573b4602SAndi Gutmans}
644573b4602SAndi Gutmans
645573b4602SAndi Gutmans
6467656c77cSZeev Suraskivoid zend_set_utility_values(zend_utility_values *utility_values)
6477656c77cSZeev Suraski{
6487656c77cSZeev Suraski	zend_uv = *utility_values;
6499baad804SZeev Suraski	zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
6507656c77cSZeev Suraski}
6517656c77cSZeev Suraski
6527656c77cSZeev Suraski
653573b4602SAndi Gutmans/* this should be compatible with the standard zenderror */
654573b4602SAndi Gutmansvoid zenderror(char *error)
655573b4602SAndi Gutmans{
656573b4602SAndi Gutmans	zend_error(E_PARSE, error);
657573b4602SAndi Gutmans}
658573b4602SAndi Gutmans
659573b4602SAndi Gutmans
660b0bfa458SZeev SuraskiBEGIN_EXTERN_C()
661ef4fe54fSZeev SuraskiZEND_API void _zend_bailout(char *filename, uint lineno)
662573b4602SAndi Gutmans{
6632c254ba7SZeev Suraski	TSRMLS_FETCH();
664573b4602SAndi Gutmans
665931ebe08SZeev Suraski	if (!EG(bailout_set)) {
666ef4fe54fSZeev Suraski		zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
667931ebe08SZeev Suraski		exit(-1);
668931ebe08SZeev Suraski	}
6696bc6dacfSZeev Suraski	CG(unclean_shutdown) = 1;
670b23d83cfSZeev Suraski	CG(in_compilation) = EG(in_execution) = 0;
671bdc35c9fSThies C. Arntzen	EG(current_execute_data) = NULL;
672573b4602SAndi Gutmans	longjmp(EG(bailout), FAILURE);
673573b4602SAndi Gutmans}
674b0bfa458SZeev SuraskiEND_EXTERN_C()
675573b4602SAndi Gutmans
676573b4602SAndi Gutmans
677573b4602SAndi Gutmansvoid zend_append_version_info(zend_extension *extension)
678573b4602SAndi Gutmans{
679573b4602SAndi Gutmans	char *new_info;
680573b4602SAndi Gutmans	uint new_info_length;
681573b4602SAndi Gutmans
682573b4602SAndi Gutmans	new_info_length = sizeof("    with  v,  by \n")
683573b4602SAndi Gutmans						+ strlen(extension->name)
684573b4602SAndi Gutmans						+ strlen(extension->version)
685573b4602SAndi Gutmans						+ strlen(extension->copyright)
686573b4602SAndi Gutmans						+ strlen(extension->author);
687573b4602SAndi Gutmans
688573b4602SAndi Gutmans	new_info = (char *) malloc(new_info_length+1);
689573b4602SAndi Gutmans
690573b4602SAndi Gutmans	sprintf(new_info, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
691573b4602SAndi Gutmans
692573b4602SAndi Gutmans	zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length+1);
693573b4602SAndi Gutmans	strcat(zend_version_info, new_info);
694573b4602SAndi Gutmans	zend_version_info_length += new_info_length;
695573b4602SAndi Gutmans	free(new_info);
696573b4602SAndi Gutmans}
697573b4602SAndi Gutmans
698573b4602SAndi Gutmans
699573b4602SAndi GutmansZEND_API char *get_zend_version()
700573b4602SAndi Gutmans{
701573b4602SAndi Gutmans	return zend_version_info;
702573b4602SAndi Gutmans}
703ed06a70fSZeev Suraski
704ed06a70fSZeev Suraski
705b4f3b9d3SZeev Suraskivoid zend_activate(TSRMLS_D)
706ed06a70fSZeev Suraski{
707b4f3b9d3SZeev Suraski	init_compiler(TSRMLS_C);
708b4f3b9d3SZeev Suraski	init_executor(TSRMLS_C);
709b4f3b9d3SZeev Suraski	startup_scanner(TSRMLS_C);
710ed06a70fSZeev Suraski}
711ed06a70fSZeev Suraski
712dc0e6632SZeev Suraski
713d76cf1daSZeev Suraskivoid zend_activate_modules(TSRMLS_D)
714dc0e6632SZeev Suraski{
715d76cf1daSZeev Suraski	zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
716dc0e6632SZeev Suraski}
717dc0e6632SZeev Suraski
718b5770382SZeev Suraskivoid zend_deactivate_modules(TSRMLS_D)
719a8b0d960SAndi Gutmans{
720a8b0d960SAndi Gutmans	EG(opline_ptr) = NULL; /* we're no longer executing anything */
721a8b0d960SAndi Gutmans
722931ebe08SZeev Suraski	zend_try {
723d76cf1daSZeev Suraski		zend_hash_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
724931ebe08SZeev Suraski	} zend_end_try();
725a8b0d960SAndi Gutmans}
726dc0e6632SZeev Suraski
727b4f3b9d3SZeev Suraskivoid zend_deactivate(TSRMLS_D)
728ed06a70fSZeev Suraski{
729372f71ebSThies C. Arntzen	/* we're no longer executing anything */
730372f71ebSThies C. Arntzen	EG(opline_ptr) = NULL;
731372f71ebSThies C. Arntzen	EG(active_symbol_table) = NULL;
732f4c9d96fSThies C. Arntzen
733931ebe08SZeev Suraski	zend_try {
734b4f3b9d3SZeev Suraski		shutdown_scanner(TSRMLS_C);
735931ebe08SZeev Suraski	} zend_end_try();
736931ebe08SZeev Suraski
7378084d278SZeev Suraski	/* shutdown_executor() takes care of its own bailout handling */
7382c254ba7SZeev Suraski	shutdown_executor(TSRMLS_C);
739931ebe08SZeev Suraski
740931ebe08SZeev Suraski	zend_try {
741b4f3b9d3SZeev Suraski		shutdown_compiler(TSRMLS_C);
742931ebe08SZeev Suraski	} zend_end_try();
743931ebe08SZeev Suraski
744931ebe08SZeev Suraski	zend_try {
7452c254ba7SZeev Suraski		zend_ini_deactivate(TSRMLS_C);
746931ebe08SZeev Suraski	} zend_end_try();
747ed06a70fSZeev Suraski}
74856251a72SZeev Suraski
74956251a72SZeev Suraski
750fc173b6aSSam RubyBEGIN_EXTERN_C()
75156251a72SZeev SuraskiZEND_API void zend_message_dispatcher(long message, void *data)
75256251a72SZeev Suraski{
75356251a72SZeev Suraski	if (zend_message_dispatcher_p) {
75456251a72SZeev Suraski		zend_message_dispatcher_p(message, data);
75556251a72SZeev Suraski	}
75656251a72SZeev Suraski}
757fc173b6aSSam RubyEND_EXTERN_C()
75856251a72SZeev Suraski
75956251a72SZeev Suraski
760903018efSZeev SuraskiZEND_API int zend_get_configuration_directive(char *name, uint name_length, zval *contents)
76156251a72SZeev Suraski{
762903018efSZeev Suraski	if (zend_get_configuration_directive_p) {
763903018efSZeev Suraski		return zend_get_configuration_directive_p(name, name_length, contents);
76456251a72SZeev Suraski	} else {
76556251a72SZeev Suraski		return FAILURE;
76656251a72SZeev Suraski	}
76756251a72SZeev Suraski}
76867f69743SZeev Suraski
76967f69743SZeev Suraski
77067f69743SZeev Suraski#define ZEND_ERROR_BUFFER_SIZE 1024
77167f69743SZeev Suraski
77267f69743SZeev SuraskiZEND_API void zend_error(int type, const char *format, ...)
77367f69743SZeev Suraski{
77467f69743SZeev Suraski	va_list args;
7753cda6a75SZeev Suraski	zval ***params;
7763cda6a75SZeev Suraski	zval *retval;
777f34b9d41SZeev Suraski	zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
778b80b8381SZeev Suraski	char *error_filename;
779b80b8381SZeev Suraski	uint error_lineno;
780a31dc47aSZeev Suraski	zval *orig_user_error_handler;
7812c254ba7SZeev Suraski	TSRMLS_FETCH();
78267f69743SZeev Suraski
783b80b8381SZeev Suraski	/* Obtain relevant filename and lineno */
784b80b8381SZeev Suraski	switch (type) {
785b80b8381SZeev Suraski		case E_CORE_ERROR:
786b80b8381SZeev Suraski		case E_CORE_WARNING:
787b80b8381SZeev Suraski			error_filename = NULL;
788b80b8381SZeev Suraski			error_lineno = 0;
789b80b8381SZeev Suraski			break;
790b80b8381SZeev Suraski		case E_PARSE:
791b80b8381SZeev Suraski		case E_COMPILE_ERROR:
792b80b8381SZeev Suraski		case E_COMPILE_WARNING:
793b80b8381SZeev Suraski		case E_ERROR:
794b80b8381SZeev Suraski		case E_NOTICE:
795b80b8381SZeev Suraski		case E_WARNING:
796b80b8381SZeev Suraski		case E_USER_ERROR:
797b80b8381SZeev Suraski		case E_USER_WARNING:
798b80b8381SZeev Suraski		case E_USER_NOTICE:
7994187439cSZeev Suraski			if (zend_is_compiling(TSRMLS_C)) {
800b4f3b9d3SZeev Suraski				error_filename = zend_get_compiled_filename(TSRMLS_C);
801b4f3b9d3SZeev Suraski				error_lineno = zend_get_compiled_lineno(TSRMLS_C);
8024187439cSZeev Suraski			} else if (zend_is_executing(TSRMLS_C)) {
8032c254ba7SZeev Suraski				error_filename = zend_get_executed_filename(TSRMLS_C);
8042c254ba7SZeev Suraski				error_lineno = zend_get_executed_lineno(TSRMLS_C);
805b80b8381SZeev Suraski			} else {
806b80b8381SZeev Suraski				error_filename = NULL;
807b80b8381SZeev Suraski				error_lineno = 0;
808b80b8381SZeev Suraski			}
809b80b8381SZeev Suraski			break;
810b80b8381SZeev Suraski		default:
811b80b8381SZeev Suraski			error_filename = NULL;
812b80b8381SZeev Suraski			error_lineno = 0;
813b80b8381SZeev Suraski			break;
814b80b8381SZeev Suraski	}
815b80b8381SZeev Suraski	if (!error_filename) {
816b80b8381SZeev Suraski		error_filename = "Unknown";
817b80b8381SZeev Suraski	}
81867f69743SZeev Suraski
81967f69743SZeev Suraski
820b80b8381SZeev Suraski	va_start(args, format);
8218a8c3eafSZeev Suraski
82267f69743SZeev Suraski	/* if we don't have a user defined error handler */
82367f69743SZeev Suraski	if (!EG(user_error_handler)) {
824b80b8381SZeev Suraski		zend_error_cb(type, error_filename, error_lineno, format, args);
825b80b8381SZeev Suraski	} else switch (type) {
82667f69743SZeev Suraski		case E_ERROR:
82767f69743SZeev Suraski		case E_PARSE:
82867f69743SZeev Suraski		case E_CORE_ERROR:
82967f69743SZeev Suraski		case E_CORE_WARNING:
83067f69743SZeev Suraski		case E_COMPILE_ERROR:
83167f69743SZeev Suraski		case E_COMPILE_WARNING:
832b80b8381SZeev Suraski			/* The error may not be safe to handle in user-space */
833b80b8381SZeev Suraski			zend_error_cb(type, error_filename, error_lineno, format, args);
834b80b8381SZeev Suraski			break;
835b80b8381SZeev Suraski		default:
836b80b8381SZeev Suraski			/* Handle the error in user space */
837f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_error_message);
838f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_error_type);
839a31dc47aSZeev Suraski			ALLOC_INIT_ZVAL(z_error_filename);
840a31dc47aSZeev Suraski			ALLOC_INIT_ZVAL(z_error_lineno);
841f34b9d41SZeev Suraski			ALLOC_INIT_ZVAL(z_context);
842f34b9d41SZeev Suraski			z_error_message->value.str.val = (char *) emalloc(ZEND_ERROR_BUFFER_SIZE);
84367f69743SZeev Suraski
8448a8c3eafSZeev Suraski#ifdef HAVE_VSNPRINTF
845f34b9d41SZeev Suraski			z_error_message->value.str.len = vsnprintf(z_error_message->value.str.val, ZEND_ERROR_BUFFER_SIZE, format, args);
8464acff8f3SZeev Suraski			if (z_error_message->value.str.len > ZEND_ERROR_BUFFER_SIZE-1) {
847d10336ecSStanislav Malyshev				z_error_message->value.str.len = ZEND_ERROR_BUFFER_SIZE-1;
848d10336ecSStanislav Malyshev			}
8498a8c3eafSZeev Suraski#else
8504acff8f3SZeev Suraski			strncpy(z_error_message->value.str.val, format, ZEND_ERROR_BUFFER_SIZE);
8518a8c3eafSZeev Suraski			/* This is risky... */
8524acff8f3SZeev Suraski			/* z_error_message->value.str.len = vsprintf(z_error_message->value.str.val, format, args); */
8538a8c3eafSZeev Suraski#endif
854f34b9d41SZeev Suraski			z_error_message->type = IS_STRING;
85567f69743SZeev Suraski
856f34b9d41SZeev Suraski			z_error_type->value.lval = type;
857f34b9d41SZeev Suraski			z_error_type->type = IS_LONG;
85867f69743SZeev Suraski
859a31dc47aSZeev Suraski			if (error_filename) {
860a31dc47aSZeev Suraski				z_error_filename->value.str.len = strlen(error_filename);
861a31dc47aSZeev Suraski				z_error_filename->value.str.val = estrndup(error_filename, z_error_filename->value.str.len);
862a31dc47aSZeev Suraski				z_error_filename->type = IS_STRING;
863a31dc47aSZeev Suraski			}
864a31dc47aSZeev Suraski
865a31dc47aSZeev Suraski			z_error_lineno->value.lval = error_lineno;
866a31dc47aSZeev Suraski			z_error_lineno->type = IS_LONG;
867a31dc47aSZeev Suraski
868f34b9d41SZeev Suraski			z_context->value.ht = EG(active_symbol_table);
869f34b9d41SZeev Suraski			z_context->type = IS_ARRAY;
870f34b9d41SZeev Suraski			ZVAL_ADDREF(z_context);  /* we don't want this one to be freed */
871f34b9d41SZeev Suraski
872f34b9d41SZeev Suraski			params = (zval ***) emalloc(sizeof(zval **)*5);
873f34b9d41SZeev Suraski			params[0] = &z_error_type;
874f34b9d41SZeev Suraski			params[1] = &z_error_message;
875a31dc47aSZeev Suraski			params[2] = &z_error_filename;
876a31dc47aSZeev Suraski			params[3] = &z_error_lineno;
877f34b9d41SZeev Suraski			params[4] = &z_context;
87867f69743SZeev Suraski
879a31dc47aSZeev Suraski			orig_user_error_handler = EG(user_error_handler);
880a31dc47aSZeev Suraski			EG(user_error_handler) = NULL;
8814187439cSZeev Suraski			if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC)==SUCCESS) {
8825cb8fabbSAndi Gutmans				if (retval) {
8835cb8fabbSAndi Gutmans					zval_ptr_dtor(&retval);
8845cb8fabbSAndi Gutmans				}
885b80b8381SZeev Suraski			} else {
886b80b8381SZeev Suraski				/* The user error handler failed, use built-in error handler */
887b80b8381SZeev Suraski				zend_error_cb(type, error_filename, error_lineno, format, args);
888b80b8381SZeev Suraski			}
889a31dc47aSZeev Suraski			EG(user_error_handler) = orig_user_error_handler;
890a31dc47aSZeev Suraski
891b80b8381SZeev Suraski			efree(params);
892f34b9d41SZeev Suraski			zval_ptr_dtor(&z_error_message);
893f34b9d41SZeev Suraski			zval_ptr_dtor(&z_error_type);
894a31dc47aSZeev Suraski			zval_ptr_dtor(&z_error_filename);
895a31dc47aSZeev Suraski			zval_ptr_dtor(&z_error_lineno);
8967cba0254SAndi Gutmans			if (ZVAL_REFCOUNT(z_context) == 2) {
897f34b9d41SZeev Suraski				FREE_ZVAL(z_context);
898f34b9d41SZeev Suraski			}
899b80b8381SZeev Suraski			break;
90067f69743SZeev Suraski	}
901b80b8381SZeev Suraski
902b80b8381SZeev Suraski	va_end(args);
903bda9c83aSZeev Suraski
9047cba0254SAndi Gutmans	if (type == E_PARSE) {
9051074fca0SIlia Alshanetsky		EG(exit_status) = 255;
906b4f3b9d3SZeev Suraski		zend_init_compiler_data_structures(TSRMLS_C);
907bda9c83aSZeev Suraski	}
90867f69743SZeev Suraski}
90967f69743SZeev Suraski
9100b7a9ceaSZeev Suraski
9110b7a9ceaSZeev SuraskiZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...)
9120b7a9ceaSZeev Suraski{
9130b7a9ceaSZeev Suraski#if ZEND_DEBUG
9140b7a9ceaSZeev Suraski	va_list args;
9150b7a9ceaSZeev Suraski
9160b7a9ceaSZeev Suraski	va_start(args, format);
91701d478baSAndi Gutmans#	ifdef ZEND_WIN32
9180b7a9ceaSZeev Suraski	{
9190b7a9ceaSZeev Suraski		char output_buf[1024];
9200b7a9ceaSZeev Suraski
9210b7a9ceaSZeev Suraski		vsnprintf(output_buf, 1024, format, args);
9220b7a9ceaSZeev Suraski		OutputDebugString(output_buf);
9230b7a9ceaSZeev Suraski		OutputDebugString("\n");
9240b7a9ceaSZeev Suraski		if (trigger_break && IsDebuggerPresent()) {
9250b7a9ceaSZeev Suraski			DebugBreak();
9260b7a9ceaSZeev Suraski		}
9270b7a9ceaSZeev Suraski	}
9280b7a9ceaSZeev Suraski#	else
9290b7a9ceaSZeev Suraski	vfprintf(stderr, format, args);
9300b7a9ceaSZeev Suraski	fprintf(stderr, "\n");
9310b7a9ceaSZeev Suraski#	endif
9320b7a9ceaSZeev Suraski	va_end(args);
9330b7a9ceaSZeev Suraski#endif
9340b7a9ceaSZeev Suraski}
935c06692e9SZeev Suraski
936c06692e9SZeev Suraski
937819ea51dSZeev SuraskiZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...)
938c06692e9SZeev Suraski{
939c06692e9SZeev Suraski	va_list files;
940c06692e9SZeev Suraski	int i;
941c06692e9SZeev Suraski	zend_file_handle *file_handle;
9420eadc7e4SZeev Suraski	zend_op_array *orig_op_array = EG(active_op_array);
943b06440bcSZeev Suraski	zval *local_retval=NULL;
94441e3f4f0SAndi Gutmans
945c06692e9SZeev Suraski	va_start(files, file_count);
946c06692e9SZeev Suraski	for (i=0; i<file_count; i++) {
947c06692e9SZeev Suraski		file_handle = va_arg(files, zend_file_handle *);
948c06692e9SZeev Suraski		if (!file_handle) {
949c06692e9SZeev Suraski			continue;
950c06692e9SZeev Suraski		}
951b4f3b9d3SZeev Suraski		EG(active_op_array) = zend_compile_file(file_handle, ZEND_INCLUDE TSRMLS_CC);
952b4f3b9d3SZeev Suraski		zend_destroy_file_handle(file_handle TSRMLS_CC);
953c06692e9SZeev Suraski		if (EG(active_op_array)) {
954b06440bcSZeev Suraski			EG(return_value_ptr_ptr) = retval ? retval : &local_retval;
9552c254ba7SZeev Suraski			zend_execute(EG(active_op_array) TSRMLS_CC);
95684603723SAndi Gutmans			if (EG(exception)) {
95704788f95SStig Bakken#if 1 /* support set_exception_handler() */
95804788f95SStig Bakken				if (EG(user_exception_handler)) {
95904788f95SStig Bakken					zval *orig_user_exception_handler;
96004788f95SStig Bakken					zval ***params, *retval2;
96104788f95SStig Bakken					params = (zval ***)emalloc(sizeof(zval **));
96204788f95SStig Bakken					params[0] = &EG(exception);
96304788f95SStig Bakken					orig_user_exception_handler = EG(user_exception_handler);
96404788f95SStig Bakken					if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
965b899f9bfSStig Bakken						if (retval2 != NULL) {
966b899f9bfSStig Bakken							zval_ptr_dtor(&retval2);
967b899f9bfSStig Bakken						}
968b899f9bfSStig Bakken					} else {
969b899f9bfSStig Bakken						zval_ptr_dtor(&EG(exception));
970b899f9bfSStig Bakken						EG(exception) = NULL;
971b899f9bfSStig Bakken						zend_error(E_ERROR, "Uncaught exception!");
97204788f95SStig Bakken					}
97338eea2e8SAndi Gutmans					efree(params);
97404788f95SStig Bakken					zval_ptr_dtor(&EG(exception));
97504788f95SStig Bakken					EG(exception) = NULL;
97604788f95SStig Bakken				} else {
97704788f95SStig Bakken					zval_ptr_dtor(&EG(exception));
97804788f95SStig Bakken					EG(exception) = NULL;
97904788f95SStig Bakken					zend_error(E_ERROR, "Uncaught exception!");
98004788f95SStig Bakken				}
981b899f9bfSStig Bakken				if (retval == NULL && *EG(return_value_ptr_ptr) != NULL) {
98238eea2e8SAndi Gutmans					zval_ptr_dtor(EG(return_value_ptr_ptr));
98338eea2e8SAndi Gutmans					local_retval = NULL;
98438eea2e8SAndi Gutmans				}
98504788f95SStig Bakken#else
98684603723SAndi Gutmans				zval_ptr_dtor(&EG(exception));
987b9355b9aSAndi Gutmans				zend_error(E_ERROR, "Uncaught exception!");
98804788f95SStig Bakken#endif
98984603723SAndi Gutmans			} else if (!retval) {
990b06440bcSZeev Suraski				zval_ptr_dtor(EG(return_value_ptr_ptr));
991b06440bcSZeev Suraski				local_retval = NULL;
992819ea51dSZeev Suraski			}
993c06692e9SZeev Suraski			destroy_op_array(EG(active_op_array));
994c06692e9SZeev Suraski			efree(EG(active_op_array));
995c06692e9SZeev Suraski		} else if (type==ZEND_REQUIRE) {
996c06692e9SZeev Suraski			va_end(files);
9970eadc7e4SZeev Suraski			EG(active_op_array) = orig_op_array;
998c06692e9SZeev Suraski			return FAILURE;
999c06692e9SZeev Suraski		}
1000c06692e9SZeev Suraski	}
1001c06692e9SZeev Suraski	va_end(files);
10020eadc7e4SZeev Suraski	EG(active_op_array) = orig_op_array;
1003c06692e9SZeev Suraski
1004c06692e9SZeev Suraski	return SUCCESS;
1005c06692e9SZeev Suraski}
1006c06692e9SZeev Suraski
10075286b397SZeev Suraski#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
10085286b397SZeev Suraski
1009b5770382SZeev SuraskiZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC)
10105286b397SZeev Suraski{
10115286b397SZeev Suraski	char *cur_filename;
10125286b397SZeev Suraski	int cur_lineno;
10135286b397SZeev Suraski	char *compiled_string_description;
10145286b397SZeev Suraski
10154187439cSZeev Suraski	if (zend_is_compiling(TSRMLS_C)) {
1016b4f3b9d3SZeev Suraski		cur_filename = zend_get_compiled_filename(TSRMLS_C);
1017b4f3b9d3SZeev Suraski		cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
10184187439cSZeev Suraski	} else if (zend_is_executing(TSRMLS_C)) {
10192c254ba7SZeev Suraski		cur_filename = zend_get_executed_filename(TSRMLS_C);
10202c254ba7SZeev Suraski		cur_lineno = zend_get_executed_lineno(TSRMLS_C);
10215286b397SZeev Suraski	} else {
10225286b397SZeev Suraski		cur_filename = "Unknown";
10235286b397SZeev Suraski		cur_lineno = 0;
10245286b397SZeev Suraski	}
10255286b397SZeev Suraski
10265286b397SZeev Suraski	compiled_string_description = emalloc(sizeof(COMPILED_STRING_DESCRIPTION_FORMAT)+strlen(name)+strlen(cur_filename)+MAX_LENGTH_OF_LONG);
10275286b397SZeev Suraski	sprintf(compiled_string_description, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
10285286b397SZeev Suraski	return compiled_string_description;
10295286b397SZeev Suraski}
10305286b397SZeev Suraski
10310e08845eSZeev Suraski
10320e08845eSZeev Suraskivoid free_estring(char **str_p)
10330e08845eSZeev Suraski{
10340e08845eSZeev Suraski	efree(*str_p);
10350e08845eSZeev Suraski}
10365a41ced0SStig Bakken
10375a41ced0SStig Bakken/*
10385a41ced0SStig Bakken * Local variables:
10395a41ced0SStig Bakken * tab-width: 4
10405a41ced0SStig Bakken * c-basic-offset: 4
10415a41ced0SStig Bakken * indent-tabs-mode: t
10425a41ced0SStig Bakken * End:
10435a41ced0SStig Bakken */
1044