1999-04-08 02:10:10 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 13:26:39 +08:00
|
|
|
| Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
|
1999-04-08 02:10:10 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-03-06 13:26:39 +08:00
|
|
|
| This source file is subject to version 0.92 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 |
|
2000-03-06 13:26:39 +08:00
|
|
|
| http://www.zend.com/license/0_92.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"
|
|
|
|
#include "modules.h"
|
|
|
|
#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"
|
1999-04-08 02:10:10 +08:00
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
# define GLOBAL_FUNCTION_TABLE global_function_table
|
|
|
|
# define GLOBAL_CLASS_TABLE global_class_table
|
1999-07-15 00:00:47 +08:00
|
|
|
# define GLOBAL_CONSTANTS_TABLE global_constants_table
|
1999-04-21 11:49:09 +08:00
|
|
|
#else
|
|
|
|
# define GLOBAL_FUNCTION_TABLE CG(function_table)
|
|
|
|
# define GLOBAL_CLASS_TABLE CG(class_table)
|
1999-07-15 00:00:47 +08:00
|
|
|
# define GLOBAL_CONSTANTS_TABLE CG(zend_constants)
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-03 15:34:20 +08:00
|
|
|
#ifdef ZEND_WIN32
|
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 */
|
1999-06-04 19:44:02 +08:00
|
|
|
ZEND_API zend_class_entry zend_standard_class_def;
|
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-03-06 03:50:10 +08:00
|
|
|
static void (*zend_message_dispatcher_p)(long message, void *data);
|
|
|
|
static int (*zend_get_ini_entry_p)(char *name, uint name_length, zval *contents);
|
1999-06-20 04:42:15 +08:00
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
static void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
|
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;
|
1999-04-21 11:49:09 +08:00
|
|
|
HashTable *global_function_table;
|
|
|
|
HashTable *global_class_table;
|
1999-07-15 00:00:47 +08:00
|
|
|
HashTable *global_constants_table;
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
zend_utility_values zend_uv;
|
|
|
|
|
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;
|
2000-05-23 00:55:56 +08:00
|
|
|
#define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2000 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;
|
|
|
|
unsigned long num_key;
|
|
|
|
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;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_hash_internal_pointer_reset(ht);
|
|
|
|
while (zend_hash_get_current_data(ht, (void **) &tmp) == SUCCESS) {
|
|
|
|
for (i=0; i<indent; i++) {
|
|
|
|
ZEND_PUTS(" ");
|
|
|
|
}
|
|
|
|
ZEND_PUTS("[");
|
|
|
|
switch (zend_hash_get_current_key(ht, &string_key, &num_key)) {
|
|
|
|
case HASH_KEY_IS_STRING:
|
|
|
|
ZEND_PUTS(string_key);
|
1999-07-11 00:56:56 +08:00
|
|
|
efree(string_key);
|
1999-04-08 02:10:10 +08:00
|
|
|
break;
|
|
|
|
case HASH_KEY_IS_LONG:
|
|
|
|
zend_printf("%ld",num_key);
|
|
|
|
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");
|
|
|
|
zend_hash_move_forward(ht);
|
|
|
|
}
|
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;
|
|
|
|
case IS_OBJECT: {
|
|
|
|
zval function_name;
|
2000-03-18 22:55:29 +08:00
|
|
|
ZVAL_STRING(&function_name,"__string_value",1);
|
1999-06-11 18:44:26 +08:00
|
|
|
|
|
|
|
if (call_user_function(NULL, expr, &function_name, expr_copy, 0, NULL)==FAILURE) {
|
|
|
|
expr_copy->value.str.len = sizeof("Object")-1;
|
|
|
|
expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len);
|
|
|
|
}
|
|
|
|
efree(function_name.value.str.val);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2000-03-26 03:10:07 +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");
|
|
|
|
print_hash(expr->value.ht,indent);
|
|
|
|
break;
|
|
|
|
case IS_OBJECT:
|
|
|
|
zend_printf("%s Object\n", expr->value.obj.ce->name);
|
|
|
|
print_hash(expr->value.obj.properties, indent);
|
|
|
|
break;
|
|
|
|
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) {
|
|
|
|
*opened_path = strdup(filename);
|
|
|
|
}
|
1999-04-08 02:10:10 +08:00
|
|
|
return fopen(filename, "r");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-02 06:55:20 +08:00
|
|
|
static void register_standard_class(void)
|
1999-04-08 02:10:10 +08:00
|
|
|
{
|
1999-06-04 19:44:02 +08:00
|
|
|
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;
|
1999-12-22 01:14:31 +08:00
|
|
|
zend_hash_init(&zend_standard_class_def.default_properties, 0, NULL, ZVAL_PTR_DTOR, 1);
|
1999-07-10 01:24:47 +08:00
|
|
|
zend_hash_init(&zend_standard_class_def.function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1);
|
1999-06-04 19:44:02 +08:00
|
|
|
zend_standard_class_def.handle_function_call = NULL;
|
|
|
|
zend_standard_class_def.handle_property_get = NULL;
|
|
|
|
zend_standard_class_def.handle_property_set = NULL;
|
|
|
|
zend_standard_class_def.refcount = (int *) malloc(sizeof(int));
|
|
|
|
*zend_standard_class_def.refcount = 1;
|
1999-09-13 03:27:50 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
static void compiler_globals_ctor(zend_compiler_globals *compiler_globals)
|
|
|
|
{
|
1999-04-26 22:10:42 +08:00
|
|
|
zend_function tmp_func;
|
|
|
|
zend_class_entry tmp_class;
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
|
1999-07-10 01:24:47 +08:00
|
|
|
zend_hash_init(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1);
|
1999-04-26 22:10:42 +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
|
|
|
|
|
|
|
compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
|
1999-07-10 01:24:47 +08:00
|
|
|
zend_hash_init(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1);
|
2000-02-05 23:11:24 +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
|
|
|
|
|
|
|
compiler_globals->extended_info = 0;
|
2000-06-07 03:13:54 +08:00
|
|
|
|
|
|
|
/* default compile-time values */
|
|
|
|
compiler_globals->asp_tags = 0;
|
|
|
|
compiler_globals->short_tags = 1;
|
|
|
|
compiler_globals->allow_call_time_pass_reference = 1;
|
1999-04-21 11:49:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void compiler_globals_dtor(zend_compiler_globals *compiler_globals)
|
|
|
|
{
|
1999-05-11 04:46:42 +08:00
|
|
|
if (compiler_globals->function_table != global_function_table) {
|
|
|
|
zend_hash_destroy(compiler_globals->function_table);
|
|
|
|
free(compiler_globals->function_table);
|
|
|
|
}
|
|
|
|
if (compiler_globals->class_table != global_class_table) {
|
|
|
|
zend_hash_destroy(compiler_globals->class_table);
|
|
|
|
free(compiler_globals->class_table);
|
|
|
|
}
|
1999-04-21 11:49:09 +08:00
|
|
|
}
|
1999-04-22 01:26:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void executor_globals_ctor(zend_executor_globals *executor_globals)
|
|
|
|
{
|
1999-07-15 00:00:47 +08:00
|
|
|
if (global_constants_table) {
|
1999-08-21 01:02:11 +08:00
|
|
|
zend_startup_constants(ELS_C);
|
1999-07-15 00:00:47 +08:00
|
|
|
zend_copy_constants(executor_globals->zend_constants, global_constants_table);
|
|
|
|
}
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_init_rsrc_plist(ELS_C);
|
2000-06-03 09:49:49 +08:00
|
|
|
EG(lambda_count)=0;
|
1999-04-22 01:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void executor_globals_dtor(zend_executor_globals *executor_globals)
|
|
|
|
{
|
|
|
|
zend_shutdown_constants(ELS_C);
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_destroy_rsrc_plist(ELS_C);
|
1999-04-22 01:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-26 22:10:42 +08:00
|
|
|
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
|
|
|
|
{
|
1999-09-06 03:03:35 +08:00
|
|
|
start_memory_manager(ALS_C);
|
1999-04-26 22:10:42 +08:00
|
|
|
}
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
1999-12-06 00:23:45 +08:00
|
|
|
alloc_globals_id = ts_allocate_id(sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, NULL);
|
1999-09-06 03:03:35 +08:00
|
|
|
#else
|
|
|
|
start_memory_manager(ALS_C);
|
1999-04-22 01:26:37 +08:00
|
|
|
#endif
|
|
|
|
|
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;
|
2000-03-06 03:50:10 +08:00
|
|
|
zend_get_ini_entry_p = utility_functions->get_ini_entry;
|
2000-01-25 03:00:30 +08:00
|
|
|
zend_ticks_function = utility_functions->ticks_function;
|
1999-06-20 04:42:15 +08:00
|
|
|
|
2000-04-28 05:48:47 +08:00
|
|
|
zend_v_compile_files = v_compile_files;
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_execute = execute;
|
|
|
|
|
2000-04-28 23:52:02 +08:00
|
|
|
zend_startup_extensions();
|
1999-04-08 02:10:10 +08:00
|
|
|
|
|
|
|
/* set up version */
|
|
|
|
zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
|
|
|
|
zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;
|
|
|
|
|
1999-04-21 11:49:09 +08:00
|
|
|
GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
|
|
|
|
GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
|
1999-07-10 01:24:47 +08:00
|
|
|
zend_hash_init(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1);
|
|
|
|
zend_hash_init(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1);
|
1999-04-08 02:10:10 +08:00
|
|
|
register_standard_class();
|
1999-07-10 01:24:47 +08:00
|
|
|
zend_hash_init(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1);
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_init_rsrc_list_dtors();
|
1999-04-08 02:10:10 +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
|
1999-07-15 00:00:47 +08:00
|
|
|
global_constants_table = NULL;
|
1999-04-21 11:49:09 +08:00
|
|
|
compiler_globals_id = ts_allocate_id(sizeof(zend_compiler_globals), (void (*)(void *)) compiler_globals_ctor, (void (*)(void *)) compiler_globals_dtor);
|
1999-04-22 01:26:37 +08:00
|
|
|
executor_globals_id = ts_allocate_id(sizeof(zend_executor_globals), (void (*)(void *)) executor_globals_ctor, (void (*)(void *)) executor_globals_dtor);
|
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);
|
1999-05-11 04:46:42 +08:00
|
|
|
compiler_globals_dtor(compiler_globals);
|
1999-04-26 22:10:42 +08:00
|
|
|
compiler_globals->function_table = GLOBAL_FUNCTION_TABLE;
|
|
|
|
compiler_globals->class_table = GLOBAL_CLASS_TABLE;
|
1999-08-21 01:02:11 +08:00
|
|
|
zend_startup_constants(executor_globals);
|
1999-07-15 03:49:19 +08:00
|
|
|
GLOBAL_CONSTANTS_TABLE = EG(zend_constants);
|
|
|
|
#else
|
1999-08-21 01:02:11 +08:00
|
|
|
zend_startup_constants();
|
1999-04-21 11:49:09 +08:00
|
|
|
#endif
|
1999-07-15 03:49:19 +08:00
|
|
|
zend_register_standard_constants(ELS_C);
|
1999-04-21 11:49:09 +08:00
|
|
|
|
1999-05-09 20:24:21 +08:00
|
|
|
#ifndef ZTS
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_init_rsrc_plist(ELS_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) {
|
|
|
|
zend_startup_builtin_functions();
|
|
|
|
}
|
1999-09-20 20:24:39 +08:00
|
|
|
|
1999-04-08 02:10:10 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zend_shutdown()
|
|
|
|
{
|
1999-05-09 20:24:21 +08:00
|
|
|
#ifndef ZTS
|
2000-04-15 22:17:18 +08:00
|
|
|
zend_destroy_rsrc_plist();
|
1999-05-09 20:24:21 +08:00
|
|
|
#endif
|
2000-04-15 21:02:22 +08:00
|
|
|
zend_destroy_rsrc_list_dtors();
|
1999-04-08 02:10:10 +08:00
|
|
|
zend_hash_destroy(&module_registry);
|
1999-04-21 11:49:09 +08:00
|
|
|
zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
|
|
|
|
free(GLOBAL_FUNCTION_TABLE);
|
|
|
|
zend_hash_destroy(GLOBAL_CLASS_TABLE);
|
|
|
|
free(GLOBAL_CLASS_TABLE);
|
1999-04-18 23:11:52 +08:00
|
|
|
zend_shutdown_extensions();
|
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()
|
1999-04-08 02:10:10 +08:00
|
|
|
ZEND_API void zend_bailout()
|
|
|
|
{
|
1999-05-12 05:39:48 +08:00
|
|
|
CLS_FETCH();
|
1999-04-08 02:10:10 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
|
1999-05-12 05:39:48 +08:00
|
|
|
CG(unclean_shutdown) = 1;
|
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
|
|
|
|
|
|
|
|
|
|
|
void zend_activate(CLS_D ELS_DC)
|
|
|
|
{
|
|
|
|
init_compiler(CLS_C ELS_CC);
|
|
|
|
init_executor(CLS_C ELS_CC);
|
|
|
|
startup_scanner(CLS_C);
|
|
|
|
}
|
|
|
|
|
2000-01-17 03:41:15 +08:00
|
|
|
|
|
|
|
void zend_activate_modules()
|
|
|
|
{
|
|
|
|
zend_hash_apply(&module_registry, (int (*)(void *)) module_registry_request_startup);
|
|
|
|
}
|
|
|
|
|
2000-05-22 01:41:16 +08:00
|
|
|
void zend_deactivate_modules()
|
|
|
|
{
|
2000-05-22 03:26:50 +08:00
|
|
|
ELS_FETCH();
|
2000-05-22 01:41:16 +08:00
|
|
|
EG(opline_ptr) = NULL; /* we're no longer executing anything */
|
|
|
|
|
|
|
|
zend_hash_apply(&module_registry, (int (*)(void *)) module_registry_cleanup);
|
|
|
|
}
|
2000-01-17 03:41:15 +08:00
|
|
|
|
1999-06-06 04:00:00 +08:00
|
|
|
void zend_deactivate(CLS_D ELS_DC)
|
|
|
|
{
|
2000-04-24 20:47:07 +08:00
|
|
|
EG(opline_ptr) = NULL; /* we're no longer executing anything */
|
|
|
|
|
1999-06-06 04:00:00 +08:00
|
|
|
shutdown_scanner(CLS_C);
|
|
|
|
shutdown_executor(ELS_C);
|
|
|
|
shutdown_compiler(CLS_C);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
ZEND_API int zend_get_ini_entry(char *name, uint name_length, zval *contents)
|
|
|
|
{
|
|
|
|
if (zend_get_ini_entry_p) {
|
|
|
|
return zend_get_ini_entry_p(name, name_length, contents);
|
|
|
|
} 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;
|
|
|
|
zval **params;
|
|
|
|
zval retval;
|
|
|
|
zval error_type, error_message;
|
2000-04-28 03:38:11 +08:00
|
|
|
char *error_filename;
|
|
|
|
uint error_lineno;
|
2000-04-19 23:08:06 +08:00
|
|
|
ELS_FETCH();
|
|
|
|
CLS_FETCH();
|
|
|
|
|
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:
|
|
|
|
if (zend_is_compiling()) {
|
|
|
|
error_filename = zend_get_compiled_filename(CLS_C);
|
|
|
|
error_lineno = zend_get_compiled_lineno(CLS_C);
|
|
|
|
} else if (zend_is_executing()) {
|
|
|
|
error_filename = zend_get_executed_filename(ELS_C);
|
|
|
|
error_lineno = zend_get_executed_lineno(ELS_C);
|
|
|
|
} 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 */
|
|
|
|
INIT_PZVAL(&error_message);
|
|
|
|
INIT_PZVAL(&error_type);
|
|
|
|
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
|
|
|
|
error_message.value.str.len = vsnprintf(error_message.value.str.val, ZEND_ERROR_BUFFER_SIZE, format, args);
|
|
|
|
#else
|
|
|
|
/* This is risky... */
|
2000-04-28 03:38:11 +08:00
|
|
|
error_message.value.str.len = vsprintf(error_message.value.str.val, format, args);
|
2000-06-02 20:21:49 +08:00
|
|
|
#endif
|
2000-04-28 03:38:11 +08:00
|
|
|
error_message.type = IS_STRING;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
error_type.value.lval = type;
|
|
|
|
error_type.type = IS_LONG;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
params = (zval **) emalloc(sizeof(zval *)*2);
|
|
|
|
params[0] = &error_type;
|
|
|
|
params[1] = &error_message;
|
2000-04-19 23:08:06 +08:00
|
|
|
|
2000-04-28 03:38:11 +08:00
|
|
|
if (call_user_function(CG(function_table), NULL, EG(user_error_handler), &retval, 2, params)==SUCCESS) {
|
|
|
|
zval_dtor(&retval);
|
|
|
|
} else {
|
|
|
|
/* The user error handler failed, use built-in error handler */
|
|
|
|
zend_error_cb(type, error_filename, error_lineno, format, args);
|
|
|
|
}
|
|
|
|
efree(params);
|
|
|
|
efree(error_message.value.str.val);
|
|
|
|
break;
|
2000-04-19 23:08:06 +08:00
|
|
|
}
|
2000-04-28 03:38:11 +08:00
|
|
|
|
|
|
|
va_end(args);
|
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
|
|
|
|
}
|