1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-01-06 23:21:36 +08:00
|
|
|
| Copyright (c) 1998-2002 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:16:21 +08:00
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
1999-07-16 22:58:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2001-12-11 23:16:21 +08:00
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
1999-07-16 22:58:16 +08:00
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-04-08 02:18:16 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_extensions.h"
|
2001-02-27 02:18:34 +08:00
|
|
|
#include "zend_modules.h"
|
1999-04-08 02:10:10 +08:00
|
|
|
#include "zend_constants.h"
|
|
|
|
#include "zend_list.h"
|
1999-06-11 18:44:26 +08:00
|
|
|
#include "zend_API.h"
|
1999-09-20 20:24:39 +08:00
|
|
|
#include "zend_builtin_functions.h"
|
2000-12-27 23:43:15 +08:00
|
|
|
#include "zend_ini.h"
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
2001-12-13 04:45:38 +08:00
|
|
|
# define GLOBAL_FUNCTION_TABLE &global_main_class.function_table
|
|
|
|
# define GLOBAL_CLASS_TABLE &global_main_class.class_table
|
|
|
|
# define GLOBAL_CONSTANTS_TABLE &global_main_class.constants_table
|
2001-08-09 01:18:16 +08:00
|
|
|
# define GLOBAL_AUTO_GLOBALS_TABLE global_auto_globals_table
|
1999-04-21 11:49:09 +08:00
|
|
|
#else
|
|
|
|
# define GLOBAL_FUNCTION_TABLE CG(function_table)
|
|
|
|
# define GLOBAL_CLASS_TABLE CG(class_table)
|
2001-08-09 01:18:16 +08:00
|
|
|
# define GLOBAL_AUTO_GLOBALS_TABLE CG(auto_globals)
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-29 23:07:59 +08:00
|
|
|
#if defined(ZEND_WIN32) && ZEND_DEBUG
|
2000-06-03 12:14:31 +08:00
|
|
|
BOOL WINAPI IsDebuggerPresent(VOID);
|
|
|
|
#endif
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
/* true multithread-shared globals */
|
2002-03-12 18:08:47 +08:00
|
|
|
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API int (*zend_printf)(const char *format, ...);
|
2000-03-26 03:10:07 +08:00
|
|
|
ZEND_API zend_write_func_t zend_write;
|
1999-12-01 04:15:04 +08:00
|
|
|
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
|
1999-12-02 06:55:20 +08:00
|
|
|
ZEND_API void (*zend_block_interruptions)(void);
|
|
|
|
ZEND_API void (*zend_unblock_interruptions)(void);
|
2000-02-17 16:03:13 +08:00
|
|
|
ZEND_API void (*zend_ticks_function)(int ticks);
|
2000-06-19 00:02:32 +08:00
|
|
|
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
|
|
|
|
|
2000-03-06 03:50:10 +08:00
|
|
|
static void (*zend_message_dispatcher_p)(long message, void *data);
|
2001-01-08 02:39:11 +08:00
|
|
|
static int (*zend_get_configuration_directive_p)(char *name, uint name_length, zval *contents);
|
1999-06-20 04:42:15 +08:00
|
|
|
|
2000-04-19 23:08:06 +08:00
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
1999-04-25 00:16:11 +08:00
|
|
|
ZEND_API int compiler_globals_id;
|
|
|
|
ZEND_API int executor_globals_id;
|
1999-12-30 13:25:44 +08:00
|
|
|
ZEND_API int alloc_globals_id;
|
2001-12-13 04:45:38 +08:00
|
|
|
zend_class_entry global_main_class;
|
2001-08-09 01:18:16 +08:00
|
|
|
HashTable *global_auto_globals_table;
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2002-09-03 18:25:06 +08:00
|
|
|
ZEND_API zend_utility_values zend_uv;
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-12-23 04:24:52 +08:00
|
|
|
ZEND_API zval zval_used_for_init; /* True global variable */
|
1999-12-19 14:39:17 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
/* version information */
|
|
|
|
static char *zend_version_info;
|
|
|
|
static uint zend_version_info_length;
|
2002-01-06 23:21:36 +08:00
|
|
|
#define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2002 Zend Technologies\n"
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
|
1999-12-22 01:14:31 +08:00
|
|
|
#define PRINT_ZVAL_INDENT 4
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
static void print_hash(HashTable *ht, int indent)
|
|
|
|
{
|
|
|
|
zval **tmp;
|
|
|
|
char *string_key;
|
2000-12-18 23:06:03 +08:00
|
|
|
HashPosition iterator;
|
2001-08-21 20:29:12 +08:00
|
|
|
ulong num_key;
|
|
|
|
uint str_len;
|
1999-04-08 02:10:10 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<indent; i++) {
|
|
|
|
ZEND_PUTS(" ");
|
|
|
|
}
|
|
|
|
ZEND_PUTS("(\n");
|
1999-12-22 01:14:31 +08:00
|
|
|
indent += PRINT_ZVAL_INDENT;
|
2000-12-18 23:06:03 +08:00
|
|
|
zend_hash_internal_pointer_reset_ex(ht, &iterator);
|
|
|
|
while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
|
1999-04-08 02:10:10 +08:00
|
|
|
for (i=0; i<indent; i++) {
|
|
|
|
ZEND_PUTS(" ");
|
|
|
|
}
|
|
|
|
ZEND_PUTS("[");
|
2000-12-22 20:49:51 +08:00
|
|
|
switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
|
1999-04-08 02:10:10 +08:00
|
|
|
case HASH_KEY_IS_STRING:
|
|
|
|
ZEND_PUTS(string_key);
|
|
|
|
break;
|
|
|
|
case HASH_KEY_IS_LONG:
|
2001-08-11 23:56:40 +08:00
|
|
|
zend_printf("%ld", num_key);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ZEND_PUTS("] => ");
|
1999-12-22 01:14:31 +08:00
|
|
|
zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT);
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_PUTS("\n");
|
2000-12-18 23:06:03 +08:00
|
|
|
zend_hash_move_forward_ex(ht, &iterator);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
1999-12-22 01:14:31 +08:00
|
|
|
indent -= PRINT_ZVAL_INDENT;
|
1999-04-08 02:10:10 +08:00
|
|
|
for (i=0; i<indent; i++) {
|
|
|
|
ZEND_PUTS(" ");
|
|
|
|
}
|
|
|
|
ZEND_PUTS(")\n");
|
|
|
|
}
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
|
1999-06-11 18:44:26 +08:00
|
|
|
ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-06-11 18:44:26 +08:00
|
|
|
if (expr->type==IS_STRING) {
|
|
|
|
*use_copy = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (expr->type) {
|
2000-01-04 21:22:58 +08:00
|
|
|
case IS_NULL:
|
1999-12-31 21:56:59 +08:00
|
|
|
expr_copy->value.str.len = 0;
|
|
|
|
expr_copy->value.str.val = empty_string;
|
2000-02-01 19:37:33 +08:00
|
|
|
break;
|
1999-06-11 18:44:26 +08:00
|
|
|
case IS_BOOL:
|
1999-07-16 04:38:00 +08:00
|
|
|
if (expr->value.lval) {
|
|
|
|
expr_copy->value.str.len = 1;
|
|
|
|
expr_copy->value.str.val = estrndup("1", 1);
|
|
|
|
} else {
|
|
|
|
expr_copy->value.str.len = 0;
|
|
|
|
expr_copy->value.str.val = empty_string;
|
|
|
|
}
|
1999-06-11 18:44:26 +08:00
|
|
|
break;
|
|
|
|
case IS_RESOURCE:
|
|
|
|
expr_copy->value.str.val = (char *) emalloc(sizeof("Resource id #")-1 + MAX_LENGTH_OF_LONG);
|
|
|
|
expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Resource id #%ld", expr->value.lval);
|
|
|
|
break;
|
|
|
|
case IS_ARRAY:
|
|
|
|
expr_copy->value.str.len = sizeof("Array")-1;
|
|
|
|
expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len);
|
|
|
|
break;
|
2000-09-01 03:50:19 +08:00
|
|
|
case IS_OBJECT:
|
2001-12-27 04:06:06 +08:00
|
|
|
expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
|
2002-03-12 18:08:47 +08:00
|
|
|
expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle);
|
2001-12-27 04:06:06 +08:00
|
|
|
#if 0
|
|
|
|
/* FIXME: This might break BC for some people */
|
2000-09-01 03:50:19 +08:00
|
|
|
expr_copy->value.str.len = sizeof("Object")-1;
|
|
|
|
expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len);
|
2001-12-27 04:06:06 +08:00
|
|
|
#endif
|
1999-06-11 18:44:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*expr_copy = *expr;
|
|
|
|
zval_copy_ctor(expr_copy);
|
|
|
|
convert_to_string(expr_copy);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
expr_copy->type = IS_STRING;
|
|
|
|
*use_copy = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API int zend_print_zval(zval *expr, int indent)
|
2000-03-26 03:10:07 +08:00
|
|
|
{
|
|
|
|
return zend_print_zval_ex(zend_write, expr, indent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent)
|
1999-06-11 18:44:26 +08:00
|
|
|
{
|
|
|
|
zval expr_copy;
|
|
|
|
int use_copy;
|
|
|
|
|
|
|
|
zend_make_printable_zval(expr, &expr_copy, &use_copy);
|
|
|
|
if (use_copy) {
|
1999-04-08 02:10:10 +08:00
|
|
|
expr = &expr_copy;
|
|
|
|
}
|
|
|
|
if (expr->value.str.len==0) { /* optimize away empty strings */
|
1999-06-11 18:44:26 +08:00
|
|
|
if (use_copy) {
|
|
|
|
zval_dtor(expr);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-11 23:56:40 +08:00
|
|
|
write_func(expr->value.str.val, expr->value.str.len);
|
1999-06-11 18:44:26 +08:00
|
|
|
if (use_copy) {
|
1999-04-08 02:10:10 +08:00
|
|
|
zval_dtor(expr);
|
|
|
|
}
|
|
|
|
return expr->value.str.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-26 03:10:07 +08:00
|
|
|
ZEND_API void zend_print_zval_r(zval *expr, int indent)
|
|
|
|
{
|
|
|
|
zend_print_zval_r_ex(zend_write, expr, indent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
|
|
|
switch(expr->type) {
|
|
|
|
case IS_ARRAY:
|
|
|
|
ZEND_PUTS("Array\n");
|
2000-11-03 07:17:55 +08:00
|
|
|
if (++expr->value.ht->nApplyCount>1) {
|
|
|
|
ZEND_PUTS(" *RECURSION*");
|
2002-08-28 17:49:40 +08:00
|
|
|
expr->value.ht->nApplyCount--;
|
2000-11-03 07:17:55 +08:00
|
|
|
return;
|
|
|
|
}
|
2001-08-11 23:56:40 +08:00
|
|
|
print_hash(expr->value.ht, indent);
|
2000-11-03 07:17:55 +08:00
|
|
|
expr->value.ht->nApplyCount--;
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case IS_OBJECT:
|
2001-07-29 16:22:57 +08:00
|
|
|
{
|
|
|
|
zend_object *object = Z_OBJ_P(expr);
|
|
|
|
|
|
|
|
if (++object->properties->nApplyCount>1) {
|
|
|
|
ZEND_PUTS(" *RECURSION*");
|
2002-08-28 17:49:40 +08:00
|
|
|
object->properties->nApplyCount--;
|
2001-07-29 16:22:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
zend_printf("%s Object\n", object->ce->name);
|
|
|
|
print_hash(object->properties, indent);
|
|
|
|
object->properties->nApplyCount--;
|
|
|
|
break;
|
2000-11-03 07:17:55 +08:00
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
default:
|
|
|
|
zend_print_variable(expr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-01 04:15:04 +08:00
|
|
|
static FILE *zend_fopen_wrapper(const char *filename, char **opened_path)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-12-01 04:15:04 +08:00
|
|
|
if (opened_path) {
|
2000-09-01 06:24:20 +08:00
|
|
|
*opened_path = estrdup(filename);
|
1999-12-01 04:15:04 +08:00
|
|
|
}
|
2000-06-26 01:05:22 +08:00
|
|
|
return fopen(filename, "rb");
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-02 06:55:20 +08:00
|
|
|
static void register_standard_class(void)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_standard_class_def = malloc(sizeof(zend_class_entry));
|
|
|
|
|
|
|
|
zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
|
|
|
|
zend_standard_class_def->name_length = sizeof("stdClass") - 1;
|
|
|
|
zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
|
|
|
|
zend_standard_class_def->parent = NULL;
|
|
|
|
zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(&zend_standard_class_def->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
2002-07-16 02:09:56 +08:00
|
|
|
zend_hash_init_ex(&zend_standard_class_def->protected_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
|
|
|
|
zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(&zend_standard_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(&zend_standard_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
|
|
|
|
zend_standard_class_def->constructor = NULL;
|
|
|
|
zend_standard_class_def->destructor = NULL;
|
|
|
|
zend_standard_class_def->clone = NULL;
|
|
|
|
zend_standard_class_def->handle_function_call = NULL;
|
|
|
|
zend_standard_class_def->handle_property_get = NULL;
|
|
|
|
zend_standard_class_def->handle_property_set = NULL;
|
2002-03-13 03:22:29 +08:00
|
|
|
zend_standard_class_def->refcount = 1;
|
2002-03-12 18:08:47 +08:00
|
|
|
zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-28 18:51:54 +08:00
|
|
|
static void zend_set_default_compile_time_values(TSRMLS_D)
|
2000-06-16 03:18:57 +08:00
|
|
|
{
|
|
|
|
/* default compile-time values */
|
|
|
|
CG(asp_tags) = 0;
|
|
|
|
CG(short_tags) = 1;
|
|
|
|
CG(allow_call_time_pass_reference) = 1;
|
|
|
|
CG(extended_info) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
2001-07-27 18:10:39 +08:00
|
|
|
static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC)
|
1999-04-21 11:49:09 +08:00
|
|
|
{
|
1999-04-26 22:10:42 +08:00
|
|
|
zend_function tmp_func;
|
|
|
|
zend_class_entry tmp_class;
|
|
|
|
|
2000-07-13 00:37:46 +08:00
|
|
|
compiler_globals->compiled_filename = NULL;
|
|
|
|
|
2001-12-13 04:45:38 +08:00
|
|
|
compiler_globals->function_table = &compiler_globals->main_class.function_table;
|
2000-07-11 22:27:31 +08:00
|
|
|
zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
|
2001-12-13 04:45:38 +08:00
|
|
|
zend_hash_copy(compiler_globals->function_table, GLOBAL_FUNCTION_TABLE, NULL, &tmp_func, sizeof(zend_function));
|
1999-04-21 11:49:09 +08:00
|
|
|
|
2001-12-13 04:45:38 +08:00
|
|
|
compiler_globals->class_table = &compiler_globals->main_class.class_table;
|
2000-07-11 22:27:31 +08:00
|
|
|
zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
|
2002-09-19 23:12:20 +08:00
|
|
|
zend_hash_copy(compiler_globals->class_table, GLOBAL_CLASS_TABLE, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *));
|
1999-12-27 19:22:57 +08:00
|
|
|
|
2001-07-28 18:51:54 +08:00
|
|
|
zend_set_default_compile_time_values(TSRMLS_C);
|
2001-07-15 22:08:58 +08:00
|
|
|
|
|
|
|
CG(interactive) = 0;
|
2001-08-09 01:18:16 +08:00
|
|
|
|
|
|
|
compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
|
|
|
|
zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
|
|
|
|
zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(void *) /* empty element */);
|
1999-04-21 11:49:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC)
|
1999-04-21 11:49:09 +08:00
|
|
|
{
|
2001-12-13 04:45:38 +08:00
|
|
|
if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
|
1999-05-11 04:46:42 +08:00
|
|
|
zend_hash_destroy(compiler_globals->function_table);
|
|
|
|
}
|
2001-12-13 04:45:38 +08:00
|
|
|
if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
|
1999-05-11 04:46:42 +08:00
|
|
|
zend_hash_destroy(compiler_globals->class_table);
|
|
|
|
}
|
2001-08-09 01:18:16 +08:00
|
|
|
if (compiler_globals->auto_globals != global_auto_globals_table) {
|
|
|
|
zend_hash_destroy(compiler_globals->auto_globals);
|
|
|
|
free(compiler_globals->auto_globals);
|
|
|
|
}
|
1999-04-21 11:49:09 +08:00
|
|
|
}
|
1999-04-22 01:26:37 +08:00
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC)
|
1999-04-22 01:26:37 +08:00
|
|
|
{
|
2002-09-19 06:16:22 +08:00
|
|
|
zend_startup_constants(TSRMLS_C);
|
|
|
|
zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_init_rsrc_plist(TSRMLS_C);
|
2000-06-03 09:49:49 +08:00
|
|
|
EG(lambda_count)=0;
|
2001-01-07 10:47:32 +08:00
|
|
|
EG(user_error_handler) = NULL;
|
2002-08-16 08:41:37 +08:00
|
|
|
EG(user_exception_handler) = NULL;
|
2001-07-15 20:24:10 +08:00
|
|
|
EG(in_execution) = 0;
|
1999-04-22 01:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC)
|
1999-04-22 01:26:37 +08:00
|
|
|
{
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_shutdown_constants(TSRMLS_C);
|
2001-08-02 14:16:20 +08:00
|
|
|
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_ini_shutdown(TSRMLS_C);
|
1999-04-22 01:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-06 21:48:51 +08:00
|
|
|
static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC)
|
|
|
|
{
|
|
|
|
zend_copy_ini_directives(TSRMLS_C);
|
|
|
|
zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC);
|
|
|
|
}
|
|
|
|
|
2001-08-03 15:06:05 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-07-28 18:51:54 +08:00
|
|
|
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
|
1999-04-26 22:10:42 +08:00
|
|
|
{
|
2001-07-28 18:51:54 +08:00
|
|
|
start_memory_manager(TSRMLS_C);
|
1999-04-26 22:10:42 +08:00
|
|
|
}
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
|
2001-08-05 09:37:10 +08:00
|
|
|
static void alloc_globals_dtor(zend_alloc_globals *alloc_globals_p TSRMLS_DC)
|
|
|
|
{
|
2002-02-27 03:17:26 +08:00
|
|
|
shutdown_memory_manager(0, 1 TSRMLS_CC);
|
2001-08-05 09:37:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 02:07:14 +08:00
|
|
|
#ifdef __FreeBSD__
|
2000-06-12 01:45:19 +08:00
|
|
|
/* FreeBSD floating point precision fix */
|
|
|
|
#include <floatingpoint.h>
|
|
|
|
#endif
|
1999-04-21 11:49:09 +08:00
|
|
|
|
2001-08-06 21:48:51 +08:00
|
|
|
|
|
|
|
static void scanner_globals_ctor(zend_scanner_globals *scanner_globals_p TSRMLS_DC)
|
2000-12-27 23:43:15 +08:00
|
|
|
{
|
2001-08-06 21:48:51 +08:00
|
|
|
scanner_globals_p->c_buf_p = (char *) 0;
|
|
|
|
scanner_globals_p->init = 1;
|
|
|
|
scanner_globals_p->start = 0;
|
|
|
|
scanner_globals_p->current_buffer = NULL;
|
2001-09-20 06:34:11 +08:00
|
|
|
scanner_globals_p->yy_in = NULL;
|
|
|
|
scanner_globals_p->yy_out = NULL;
|
2001-09-22 08:09:24 +08:00
|
|
|
scanner_globals_p->_yy_more_flag = 0;
|
|
|
|
scanner_globals_p->_yy_more_len = 0;
|
2002-08-15 08:25:27 +08:00
|
|
|
scanner_globals_p->yy_start_stack_ptr = 0;
|
|
|
|
scanner_globals_p->yy_start_stack_depth = 0;
|
|
|
|
scanner_globals_p->yy_start_stack = 0;
|
2000-12-27 23:43:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-22 03:01:19 +08:00
|
|
|
int zend_startup(zend_utility_functions *utility_functions, char **extensions, int start_builtin_functions)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-04-22 01:26:37 +08:00
|
|
|
#ifdef ZTS
|
1999-04-26 22:10:42 +08:00
|
|
|
zend_compiler_globals *compiler_globals;
|
1999-04-22 01:26:37 +08:00
|
|
|
zend_executor_globals *executor_globals;
|
2001-07-27 18:10:39 +08:00
|
|
|
void ***tsrm_ls;
|
2001-08-06 21:48:51 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
|
|
|
|
extern ZEND_API ts_rsrc_id language_scanner_globals_id;
|
|
|
|
#else
|
|
|
|
extern zend_scanner_globals ini_scanner_globals;
|
|
|
|
extern zend_scanner_globals language_scanner_globals;
|
|
|
|
#endif
|
1999-04-22 01:26:37 +08:00
|
|
|
|
2001-08-05 09:37:10 +08:00
|
|
|
ts_allocate_id(&alloc_globals_id, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
|
1999-09-06 03:03:35 +08:00
|
|
|
#else
|
2001-08-03 15:06:05 +08:00
|
|
|
alloc_globals_ctor(&alloc_globals TSRMLS_CC);
|
1999-04-22 01:26:37 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-12 02:07:14 +08:00
|
|
|
#ifdef __FreeBSD__
|
2000-12-23 05:11:34 +08:00
|
|
|
/* FreeBSD floating point precision fix */
|
|
|
|
fpsetmask(0);
|
2000-06-12 01:45:19 +08:00
|
|
|
#endif
|
2000-09-26 02:10:45 +08:00
|
|
|
|
|
|
|
zend_startup_extensions_mechanism();
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
/* Set up utility functions and values */
|
2000-04-19 23:08:06 +08:00
|
|
|
zend_error_cb = utility_functions->error_function;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_printf = utility_functions->printf_function;
|
2000-03-26 03:10:07 +08:00
|
|
|
zend_write = (zend_write_func_t) utility_functions->write_function;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_fopen = utility_functions->fopen_function;
|
|
|
|
if (!zend_fopen) {
|
|
|
|
zend_fopen = zend_fopen_wrapper;
|
|
|
|
}
|
2000-03-06 03:50:10 +08:00
|
|
|
zend_message_dispatcher_p = utility_functions->message_handler;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_block_interruptions = utility_functions->block_interruptions;
|
|
|
|
zend_unblock_interruptions = utility_functions->unblock_interruptions;
|
2001-01-08 02:39:11 +08:00
|
|
|
zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
|
2000-01-25 03:00:30 +08:00
|
|
|
zend_ticks_function = utility_functions->ticks_function;
|
1999-06-20 04:42:15 +08:00
|
|
|
|
2000-08-10 03:22:35 +08:00
|
|
|
zend_compile_file = compile_file;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_execute = execute;
|
|
|
|
|
|
|
|
/* set up version */
|
|
|
|
zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
|
|
|
|
zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;
|
|
|
|
|
2001-12-13 04:45:38 +08:00
|
|
|
#ifndef ZTS
|
|
|
|
GLOBAL_FUNCTION_TABLE = &compiler_globals.main_class.function_table;
|
|
|
|
GLOBAL_CLASS_TABLE = &compiler_globals.main_class.class_table;
|
|
|
|
#endif
|
2001-08-09 01:18:16 +08:00
|
|
|
GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
|
2000-07-11 22:27:31 +08:00
|
|
|
zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
|
2001-10-01 01:29:55 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
register_standard_class();
|
2000-07-11 22:27:31 +08:00
|
|
|
zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0);
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_init_rsrc_list_dtors();
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2002-08-16 08:41:37 +08:00
|
|
|
|
1999-12-19 14:39:17 +08:00
|
|
|
/* This zval can be used to initialize allocate zval's to an uninit'ed value */
|
|
|
|
zval_used_for_init.is_ref = 0;
|
|
|
|
zval_used_for_init.refcount = 1;
|
2000-01-04 21:22:58 +08:00
|
|
|
zval_used_for_init.type = IS_NULL;
|
1999-12-19 14:39:17 +08:00
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
2002-09-19 23:15:39 +08:00
|
|
|
zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0);
|
|
|
|
zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0);
|
2001-07-27 18:10:39 +08:00
|
|
|
ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
|
|
|
|
ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
|
2001-08-06 21:48:51 +08:00
|
|
|
ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
|
|
|
|
ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
|
1999-04-26 22:10:42 +08:00
|
|
|
compiler_globals = ts_resource(compiler_globals_id);
|
1999-04-22 01:26:37 +08:00
|
|
|
executor_globals = ts_resource(executor_globals_id);
|
2001-07-27 18:10:39 +08:00
|
|
|
tsrm_ls = ts_resource_ex(0, NULL);
|
2002-09-19 06:16:22 +08:00
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
compiler_globals_dtor(compiler_globals, tsrm_ls);
|
2001-12-14 00:55:04 +08:00
|
|
|
*compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
|
|
|
|
*compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
|
2001-08-09 01:18:16 +08:00
|
|
|
compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
|
2002-09-19 06:16:22 +08:00
|
|
|
|
|
|
|
zend_hash_destroy(executor_globals->zend_constants);
|
|
|
|
*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
|
1999-07-15 03:49:19 +08:00
|
|
|
#else
|
2001-08-09 11:58:58 +08:00
|
|
|
zend_hash_init_ex(CG(auto_globals), 8, NULL, NULL, 1, 0);
|
2001-08-06 21:48:51 +08:00
|
|
|
scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
|
|
|
|
scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
|
1999-08-21 01:02:11 +08:00
|
|
|
zend_startup_constants();
|
2001-07-28 18:51:54 +08:00
|
|
|
zend_set_default_compile_time_values(TSRMLS_C);
|
2001-01-07 10:47:32 +08:00
|
|
|
EG(user_error_handler) = NULL;
|
2002-08-16 08:41:37 +08:00
|
|
|
EG(user_exception_handler) = NULL;
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_register_standard_constants(TSRMLS_C);
|
1999-04-21 11:49:09 +08:00
|
|
|
|
1999-05-09 20:24:21 +08:00
|
|
|
#ifndef ZTS
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_init_rsrc_plist(TSRMLS_C);
|
1999-05-09 20:24:21 +08:00
|
|
|
#endif
|
1999-04-22 01:26:37 +08:00
|
|
|
|
2000-03-22 03:01:19 +08:00
|
|
|
if (start_builtin_functions) {
|
2001-07-30 09:48:22 +08:00
|
|
|
zend_startup_builtin_functions(TSRMLS_C);
|
2000-03-22 03:01:19 +08:00
|
|
|
}
|
1999-09-20 20:24:39 +08:00
|
|
|
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_ini_startup(TSRMLS_C);
|
2000-12-27 23:43:15 +08:00
|
|
|
|
|
|
|
#ifdef ZTS
|
|
|
|
tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
|
|
|
|
#endif
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-17 20:42:11 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
/* Unlink the global (r/o) copies of the class, function and constant tables,
|
|
|
|
* and use a fresh r/w copy for the startup thread
|
|
|
|
*/
|
|
|
|
void zend_post_startup(TSRMLS_D)
|
|
|
|
{
|
|
|
|
zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
|
2002-09-19 06:16:22 +08:00
|
|
|
zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
|
2002-09-17 20:42:11 +08:00
|
|
|
|
2002-09-19 06:16:22 +08:00
|
|
|
*GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
|
|
|
|
*GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
|
|
|
|
*GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
|
2002-09-17 20:42:11 +08:00
|
|
|
compiler_globals_ctor(compiler_globals, tsrm_ls);
|
2002-09-19 06:16:22 +08:00
|
|
|
executor_globals_ctor(executor_globals, tsrm_ls);
|
2002-09-17 20:42:11 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
void zend_shutdown(TSRMLS_D)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2000-06-16 22:27:28 +08:00
|
|
|
#ifdef ZEND_WIN32
|
|
|
|
zend_shutdown_timeout_thread();
|
|
|
|
#endif
|
1999-05-09 20:24:21 +08:00
|
|
|
#ifndef ZTS
|
2001-08-02 14:16:20 +08:00
|
|
|
zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC);
|
1999-05-09 20:24:21 +08:00
|
|
|
#endif
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_destroy_rsrc_list_dtors();
|
2002-06-19 01:36:33 +08:00
|
|
|
zend_hash_graceful_reverse_destroy(&module_registry);
|
2001-12-24 02:39:52 +08:00
|
|
|
|
2001-12-26 19:18:00 +08:00
|
|
|
#ifndef ZTS
|
|
|
|
/* In ZTS mode these are freed by compiler_globals_dtor() */
|
1999-04-21 11:49:09 +08:00
|
|
|
zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
|
2001-12-26 19:18:00 +08:00
|
|
|
zend_hash_destroy(GLOBAL_CLASS_TABLE);
|
|
|
|
#endif
|
2001-12-24 02:39:52 +08:00
|
|
|
|
2001-08-09 01:18:16 +08:00
|
|
|
zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
|
|
|
|
free(GLOBAL_AUTO_GLOBALS_TABLE);
|
2001-07-31 12:53:54 +08:00
|
|
|
zend_shutdown_extensions(TSRMLS_C);
|
1999-04-08 02:10:10 +08:00
|
|
|
free(zend_version_info);
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifndef ZTS
|
2000-01-17 04:59:03 +08:00
|
|
|
zend_shutdown_constants();
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
1999-04-08 02:10:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-10 19:21:55 +08:00
|
|
|
void zend_set_utility_values(zend_utility_values *utility_values)
|
|
|
|
{
|
|
|
|
zend_uv = *utility_values;
|
1999-12-04 21:26:57 +08:00
|
|
|
zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension);
|
1999-04-10 19:21:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
/* this should be compatible with the standard zenderror */
|
|
|
|
void zenderror(char *error)
|
|
|
|
{
|
|
|
|
zend_error(E_PARSE, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-15 23:47:24 +08:00
|
|
|
BEGIN_EXTERN_C()
|
2001-07-22 00:21:22 +08:00
|
|
|
ZEND_API void _zend_bailout(char *filename, uint lineno)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
2001-07-27 18:10:39 +08:00
|
|
|
TSRMLS_FETCH();
|
1999-04-08 02:10:10 +08:00
|
|
|
|
2001-07-21 22:25:27 +08:00
|
|
|
if (!EG(bailout_set)) {
|
2001-07-22 00:21:22 +08:00
|
|
|
zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
|
2001-07-21 22:25:27 +08:00
|
|
|
exit(-1);
|
|
|
|
}
|
1999-05-12 05:39:48 +08:00
|
|
|
CG(unclean_shutdown) = 1;
|
2001-06-14 01:18:11 +08:00
|
|
|
CG(in_compilation) = EG(in_execution) = 0;
|
2002-08-28 22:43:32 +08:00
|
|
|
EG(current_execute_data) = NULL;
|
1999-04-08 02:10:10 +08:00
|
|
|
longjmp(EG(bailout), FAILURE);
|
|
|
|
}
|
1999-05-15 23:47:24 +08:00
|
|
|
END_EXTERN_C()
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
void zend_append_version_info(zend_extension *extension)
|
|
|
|
{
|
|
|
|
char *new_info;
|
|
|
|
uint new_info_length;
|
|
|
|
|
|
|
|
new_info_length = sizeof(" with v, by \n")
|
|
|
|
+ strlen(extension->name)
|
|
|
|
+ strlen(extension->version)
|
|
|
|
+ strlen(extension->copyright)
|
|
|
|
+ strlen(extension->author);
|
|
|
|
|
|
|
|
new_info = (char *) malloc(new_info_length+1);
|
|
|
|
|
|
|
|
sprintf(new_info, " with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
|
|
|
|
|
|
|
|
zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length+1);
|
|
|
|
strcat(zend_version_info, new_info);
|
|
|
|
zend_version_info_length += new_info_length;
|
|
|
|
free(new_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZEND_API char *get_zend_version()
|
|
|
|
{
|
|
|
|
return zend_version_info;
|
|
|
|
}
|
1999-06-06 04:00:00 +08:00
|
|
|
|
|
|
|
|
2001-07-28 18:51:54 +08:00
|
|
|
void zend_activate(TSRMLS_D)
|
1999-06-06 04:00:00 +08:00
|
|
|
{
|
2001-07-28 18:51:54 +08:00
|
|
|
init_compiler(TSRMLS_C);
|
|
|
|
init_executor(TSRMLS_C);
|
|
|
|
startup_scanner(TSRMLS_C);
|
1999-06-06 04:00:00 +08:00
|
|
|
}
|
|
|
|
|
2000-01-17 03:41:15 +08:00
|
|
|
|
2001-07-31 12:53:54 +08:00
|
|
|
void zend_activate_modules(TSRMLS_D)
|
2000-01-17 03:41:15 +08:00
|
|
|
{
|
2001-07-31 12:53:54 +08:00
|
|
|
zend_hash_apply(&module_registry, (apply_func_t) module_registry_request_startup TSRMLS_CC);
|
2000-01-17 03:41:15 +08:00
|
|
|
}
|
|
|
|
|
2001-07-30 09:48:22 +08:00
|
|
|
void zend_deactivate_modules(TSRMLS_D)
|
2000-05-22 01:41:16 +08:00
|
|
|
{
|
|
|
|
EG(opline_ptr) = NULL; /* we're no longer executing anything */
|
|
|
|
|
2001-07-21 22:25:27 +08:00
|
|
|
zend_try {
|
2001-07-31 12:53:54 +08:00
|
|
|
zend_hash_apply(&module_registry, (apply_func_t) module_registry_cleanup TSRMLS_CC);
|
2001-07-21 22:25:27 +08:00
|
|
|
} zend_end_try();
|
2000-05-22 01:41:16 +08:00
|
|
|
}
|
2000-01-17 03:41:15 +08:00
|
|
|
|
2001-07-28 18:51:54 +08:00
|
|
|
void zend_deactivate(TSRMLS_D)
|
1999-06-06 04:00:00 +08:00
|
|
|
{
|
2000-07-12 20:00:17 +08:00
|
|
|
/* we're no longer executing anything */
|
|
|
|
EG(opline_ptr) = NULL;
|
|
|
|
EG(active_symbol_table) = NULL;
|
2000-04-24 20:47:07 +08:00
|
|
|
|
2001-07-21 22:25:27 +08:00
|
|
|
zend_try {
|
2001-07-28 18:51:54 +08:00
|
|
|
shutdown_scanner(TSRMLS_C);
|
2001-07-21 22:25:27 +08:00
|
|
|
} zend_end_try();
|
|
|
|
|
2001-07-20 22:20:34 +08:00
|
|
|
/* shutdown_executor() takes care of its own bailout handling */
|
2001-07-27 18:10:39 +08:00
|
|
|
shutdown_executor(TSRMLS_C);
|
2001-07-21 22:25:27 +08:00
|
|
|
|
|
|
|
zend_try {
|
2001-07-28 18:51:54 +08:00
|
|
|
shutdown_compiler(TSRMLS_C);
|
2001-07-21 22:25:27 +08:00
|
|
|
} zend_end_try();
|
|
|
|
|
|
|
|
zend_try {
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_ini_deactivate(TSRMLS_C);
|
2001-07-21 22:25:27 +08:00
|
|
|
} zend_end_try();
|
1999-06-06 04:00:00 +08:00
|
|
|
}
|
2000-03-06 03:50:10 +08:00
|
|
|
|
|
|
|
|
2000-03-06 18:46:40 +08:00
|
|
|
BEGIN_EXTERN_C()
|
2000-03-06 03:50:10 +08:00
|
|
|
ZEND_API void zend_message_dispatcher(long message, void *data)
|
|
|
|
{
|
|
|
|
if (zend_message_dispatcher_p) {
|
|
|
|
zend_message_dispatcher_p(message, data);
|
|
|
|
}
|
|
|
|
}
|
2000-03-06 18:46:40 +08:00
|
|
|
END_EXTERN_C()
|
2000-03-06 03:50:10 +08:00
|
|
|
|
|
|
|
|
2001-01-08 02:39:11 +08:00
|
|
|
ZEND_API int zend_get_configuration_directive(char *name, uint name_length, zval *contents)
|
2000-03-06 03:50:10 +08:00
|
|
|
{
|
2001-01-08 02:39:11 +08:00
|
|
|
if (zend_get_configuration_directive_p) {
|
|
|
|
return zend_get_configuration_directive_p(name, name_length, contents);
|
2000-03-06 03:50:10 +08:00
|
|
|
} else {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-19 23:08:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define ZEND_ERROR_BUFFER_SIZE 1024
|
|
|
|
|
|
|
|
ZEND_API void zend_error(int type, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2000-06-18 00:50:38 +08:00
|
|
|
zval ***params;
|
|
|
|
zval *retval;
|
2000-06-29 23:07:59 +08:00
|
|
|
zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context;
|
2000-04-28 03:38:11 +08:00
|
|
|
char *error_filename;
|
|
|
|
uint error_lineno;
|
2000-06-29 06:08:47 +08:00
|
|
|
zval *orig_user_error_handler;
|
2001-07-27 18:10:39 +08:00
|
|
|
TSRMLS_FETCH();
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
/* Obtain relevant filename and lineno */
|
|
|
|
switch (type) {
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
case E_CORE_WARNING:
|
|
|
|
error_filename = NULL;
|
|
|
|
error_lineno = 0;
|
|
|
|
break;
|
|
|
|
case E_PARSE:
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
case E_COMPILE_WARNING:
|
|
|
|
case E_ERROR:
|
|
|
|
case E_NOTICE:
|
|
|
|
case E_WARNING:
|
|
|
|
case E_USER_ERROR:
|
|
|
|
case E_USER_WARNING:
|
|
|
|
case E_USER_NOTICE:
|
2001-07-30 15:43:02 +08:00
|
|
|
if (zend_is_compiling(TSRMLS_C)) {
|
2001-07-28 18:51:54 +08:00
|
|
|
error_filename = zend_get_compiled_filename(TSRMLS_C);
|
|
|
|
error_lineno = zend_get_compiled_lineno(TSRMLS_C);
|
2001-07-30 15:43:02 +08:00
|
|
|
} else if (zend_is_executing(TSRMLS_C)) {
|
2001-07-27 18:10:39 +08:00
|
|
|
error_filename = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
error_lineno = zend_get_executed_lineno(TSRMLS_C);
|
2000-04-28 03:38:11 +08:00
|
|
|
} else {
|
|
|
|
error_filename = NULL;
|
|
|
|
error_lineno = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_filename = NULL;
|
|
|
|
error_lineno = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!error_filename) {
|
|
|
|
error_filename = "Unknown";
|
|
|
|
}
|
2000-04-19 23:08:06 +08:00
|
|
|
|
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
va_start(args, format);
|
2000-06-02 20:21:49 +08:00
|
|
|
|
2000-04-19 23:08:06 +08:00
|
|
|
/* if we don't have a user defined error handler */
|
|
|
|
if (!EG(user_error_handler)) {
|
2000-04-28 03:38:11 +08:00
|
|
|
zend_error_cb(type, error_filename, error_lineno, format, args);
|
|
|
|
} else switch (type) {
|
2000-04-19 23:08:06 +08:00
|
|
|
case E_ERROR:
|
|
|
|
case E_PARSE:
|
|
|
|
case E_CORE_ERROR:
|
|
|
|
case E_CORE_WARNING:
|
|
|
|
case E_COMPILE_ERROR:
|
|
|
|
case E_COMPILE_WARNING:
|
2000-04-28 03:38:11 +08:00
|
|
|
/* The error may not be safe to handle in user-space */
|
|
|
|
zend_error_cb(type, error_filename, error_lineno, format, args);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Handle the error in user space */
|
2000-06-29 23:07:59 +08:00
|
|
|
ALLOC_INIT_ZVAL(z_error_message);
|
|
|
|
ALLOC_INIT_ZVAL(z_error_type);
|
2000-06-29 06:08:47 +08:00
|
|
|
ALLOC_INIT_ZVAL(z_error_filename);
|
|
|
|
ALLOC_INIT_ZVAL(z_error_lineno);
|
2000-06-29 23:07:59 +08:00
|
|
|
ALLOC_INIT_ZVAL(z_context);
|
|
|
|
z_error_message->value.str.val = (char *) emalloc(ZEND_ERROR_BUFFER_SIZE);
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-06-02 20:21:49 +08:00
|
|
|
#ifdef HAVE_VSNPRINTF
|
2000-06-29 23:07:59 +08:00
|
|
|
z_error_message->value.str.len = vsnprintf(z_error_message->value.str.val, ZEND_ERROR_BUFFER_SIZE, format, args);
|
2000-09-09 23:06:38 +08:00
|
|
|
if (z_error_message->value.str.len > ZEND_ERROR_BUFFER_SIZE-1) {
|
2000-09-08 21:19:51 +08:00
|
|
|
z_error_message->value.str.len = ZEND_ERROR_BUFFER_SIZE-1;
|
|
|
|
}
|
2000-06-02 20:21:49 +08:00
|
|
|
#else
|
2000-09-09 23:06:38 +08:00
|
|
|
strncpy(z_error_message->value.str.val, format, ZEND_ERROR_BUFFER_SIZE);
|
2000-06-02 20:21:49 +08:00
|
|
|
/* This is risky... */
|
2000-09-09 23:06:38 +08:00
|
|
|
/* z_error_message->value.str.len = vsprintf(z_error_message->value.str.val, format, args); */
|
2000-06-02 20:21:49 +08:00
|
|
|
#endif
|
2000-06-29 23:07:59 +08:00
|
|
|
z_error_message->type = IS_STRING;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-06-29 23:07:59 +08:00
|
|
|
z_error_type->value.lval = type;
|
|
|
|
z_error_type->type = IS_LONG;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-06-29 06:08:47 +08:00
|
|
|
if (error_filename) {
|
|
|
|
z_error_filename->value.str.len = strlen(error_filename);
|
|
|
|
z_error_filename->value.str.val = estrndup(error_filename, z_error_filename->value.str.len);
|
|
|
|
z_error_filename->type = IS_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
z_error_lineno->value.lval = error_lineno;
|
|
|
|
z_error_lineno->type = IS_LONG;
|
|
|
|
|
2000-06-29 23:07:59 +08:00
|
|
|
z_context->value.ht = EG(active_symbol_table);
|
|
|
|
z_context->type = IS_ARRAY;
|
|
|
|
ZVAL_ADDREF(z_context); /* we don't want this one to be freed */
|
|
|
|
|
|
|
|
params = (zval ***) emalloc(sizeof(zval **)*5);
|
|
|
|
params[0] = &z_error_type;
|
|
|
|
params[1] = &z_error_message;
|
2000-06-29 06:08:47 +08:00
|
|
|
params[2] = &z_error_filename;
|
|
|
|
params[3] = &z_error_lineno;
|
2000-06-29 23:07:59 +08:00
|
|
|
params[4] = &z_context;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-06-29 06:08:47 +08:00
|
|
|
orig_user_error_handler = EG(user_error_handler);
|
|
|
|
EG(user_error_handler) = NULL;
|
2001-07-30 15:43:02 +08:00
|
|
|
if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC)==SUCCESS) {
|
2000-06-18 00:50:38 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
2000-04-28 03:38:11 +08:00
|
|
|
} else {
|
|
|
|
/* The user error handler failed, use built-in error handler */
|
|
|
|
zend_error_cb(type, error_filename, error_lineno, format, args);
|
|
|
|
}
|
2000-06-29 06:08:47 +08:00
|
|
|
EG(user_error_handler) = orig_user_error_handler;
|
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
efree(params);
|
2000-06-29 23:07:59 +08:00
|
|
|
zval_ptr_dtor(&z_error_message);
|
|
|
|
zval_ptr_dtor(&z_error_type);
|
2000-06-29 06:08:47 +08:00
|
|
|
zval_ptr_dtor(&z_error_filename);
|
|
|
|
zval_ptr_dtor(&z_error_lineno);
|
2000-06-29 23:07:59 +08:00
|
|
|
if (ZVAL_REFCOUNT(z_context)==2) {
|
|
|
|
FREE_ZVAL(z_context);
|
|
|
|
}
|
2000-04-28 03:38:11 +08:00
|
|
|
break;
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
2000-04-28 03:38:11 +08:00
|
|
|
|
|
|
|
va_end(args);
|
2001-05-07 03:30:31 +08:00
|
|
|
|
|
|
|
if (type==E_PARSE) {
|
2002-09-16 07:34:03 +08:00
|
|
|
EG(exit_status) = 255;
|
2001-07-28 18:51:54 +08:00
|
|
|
zend_init_compiler_data_structures(TSRMLS_C);
|
2001-05-07 03:30:31 +08:00
|
|
|
}
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
|
|
|
|
2000-06-03 09:49:49 +08:00
|
|
|
|
|
|
|
ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, ...)
|
|
|
|
{
|
|
|
|
#if ZEND_DEBUG
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2000-06-03 15:34:20 +08:00
|
|
|
# ifdef ZEND_WIN32
|
2000-06-03 09:49:49 +08:00
|
|
|
{
|
|
|
|
char output_buf[1024];
|
|
|
|
|
|
|
|
vsnprintf(output_buf, 1024, format, args);
|
|
|
|
OutputDebugString(output_buf);
|
|
|
|
OutputDebugString("\n");
|
|
|
|
if (trigger_break && IsDebuggerPresent()) {
|
|
|
|
DebugBreak();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
# endif
|
|
|
|
va_end(args);
|
|
|
|
#endif
|
|
|
|
}
|
2000-08-10 03:22:35 +08:00
|
|
|
|
|
|
|
|
2001-08-31 21:11:52 +08:00
|
|
|
ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...)
|
2000-08-10 03:22:35 +08:00
|
|
|
{
|
|
|
|
va_list files;
|
|
|
|
int i;
|
|
|
|
zend_file_handle *file_handle;
|
2001-05-07 19:08:18 +08:00
|
|
|
zend_op_array *orig_op_array = EG(active_op_array);
|
2001-09-10 08:07:32 +08:00
|
|
|
zval *local_retval=NULL;
|
2002-07-26 18:38:25 +08:00
|
|
|
|
2000-08-10 03:22:35 +08:00
|
|
|
va_start(files, file_count);
|
|
|
|
for (i=0; i<file_count; i++) {
|
|
|
|
file_handle = va_arg(files, zend_file_handle *);
|
|
|
|
if (!file_handle) {
|
|
|
|
continue;
|
|
|
|
}
|
2001-07-28 18:51:54 +08:00
|
|
|
EG(active_op_array) = zend_compile_file(file_handle, ZEND_INCLUDE TSRMLS_CC);
|
|
|
|
zend_destroy_file_handle(file_handle TSRMLS_CC);
|
2000-08-10 03:22:35 +08:00
|
|
|
if (EG(active_op_array)) {
|
2001-09-10 08:07:32 +08:00
|
|
|
EG(return_value_ptr_ptr) = retval ? retval : &local_retval;
|
2001-07-27 18:10:39 +08:00
|
|
|
zend_execute(EG(active_op_array) TSRMLS_CC);
|
2001-12-09 04:58:20 +08:00
|
|
|
if (EG(exception)) {
|
2002-08-16 08:41:37 +08:00
|
|
|
#if 1 /* support set_exception_handler() */
|
|
|
|
if (EG(user_exception_handler)) {
|
|
|
|
zval *orig_user_exception_handler;
|
|
|
|
zval ***params, *retval2;
|
|
|
|
params = (zval ***)emalloc(sizeof(zval **));
|
|
|
|
params[0] = &EG(exception);
|
|
|
|
orig_user_exception_handler = EG(user_exception_handler);
|
|
|
|
if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) {
|
|
|
|
zval_ptr_dtor(&retval2);
|
|
|
|
}
|
2002-08-16 15:11:37 +08:00
|
|
|
efree(params);
|
2002-08-16 08:41:37 +08:00
|
|
|
zval_ptr_dtor(&EG(exception));
|
|
|
|
EG(exception) = NULL;
|
|
|
|
} else {
|
|
|
|
zval_ptr_dtor(&EG(exception));
|
|
|
|
EG(exception) = NULL;
|
|
|
|
zend_error(E_ERROR, "Uncaught exception!");
|
|
|
|
}
|
2002-08-16 15:11:37 +08:00
|
|
|
if (!retval) {
|
|
|
|
zval_ptr_dtor(EG(return_value_ptr_ptr));
|
|
|
|
local_retval = NULL;
|
|
|
|
}
|
2002-08-16 08:41:37 +08:00
|
|
|
#else
|
2001-12-09 04:58:20 +08:00
|
|
|
zval_ptr_dtor(&EG(exception));
|
2002-01-07 04:30:41 +08:00
|
|
|
zend_error(E_ERROR, "Uncaught exception!");
|
2002-08-16 08:41:37 +08:00
|
|
|
#endif
|
2001-12-09 04:58:20 +08:00
|
|
|
} else if (!retval) {
|
2001-09-10 08:07:32 +08:00
|
|
|
zval_ptr_dtor(EG(return_value_ptr_ptr));
|
|
|
|
local_retval = NULL;
|
2001-08-31 21:11:52 +08:00
|
|
|
}
|
2000-08-10 03:22:35 +08:00
|
|
|
destroy_op_array(EG(active_op_array));
|
|
|
|
efree(EG(active_op_array));
|
|
|
|
} else if (type==ZEND_REQUIRE) {
|
|
|
|
va_end(files);
|
2001-05-07 19:08:18 +08:00
|
|
|
EG(active_op_array) = orig_op_array;
|
2000-08-10 03:22:35 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(files);
|
2001-05-07 19:08:18 +08:00
|
|
|
EG(active_op_array) = orig_op_array;
|
2000-08-10 03:22:35 +08:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-09-13 03:47:25 +08:00
|
|
|
#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
|
|
|
|
|
2001-07-30 09:48:22 +08:00
|
|
|
ZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC)
|
2000-09-13 03:47:25 +08:00
|
|
|
{
|
|
|
|
char *cur_filename;
|
|
|
|
int cur_lineno;
|
|
|
|
char *compiled_string_description;
|
|
|
|
|
2001-07-30 15:43:02 +08:00
|
|
|
if (zend_is_compiling(TSRMLS_C)) {
|
2001-07-28 18:51:54 +08:00
|
|
|
cur_filename = zend_get_compiled_filename(TSRMLS_C);
|
|
|
|
cur_lineno = zend_get_compiled_lineno(TSRMLS_C);
|
2001-07-30 15:43:02 +08:00
|
|
|
} else if (zend_is_executing(TSRMLS_C)) {
|
2001-07-27 18:10:39 +08:00
|
|
|
cur_filename = zend_get_executed_filename(TSRMLS_C);
|
|
|
|
cur_lineno = zend_get_executed_lineno(TSRMLS_C);
|
2000-09-13 03:47:25 +08:00
|
|
|
} else {
|
|
|
|
cur_filename = "Unknown";
|
|
|
|
cur_lineno = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
compiled_string_description = emalloc(sizeof(COMPILED_STRING_DESCRIPTION_FORMAT)+strlen(name)+strlen(cur_filename)+MAX_LENGTH_OF_LONG);
|
|
|
|
sprintf(compiled_string_description, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
|
|
|
|
return compiled_string_description;
|
|
|
|
}
|
|
|
|
|
2001-01-15 18:52:06 +08:00
|
|
|
|
|
|
|
void free_estring(char **str_p)
|
|
|
|
{
|
|
|
|
efree(*str_p);
|
|
|
|
}
|
2002-08-16 18:12:17 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|