Calling symbol table patch
| From: | Andrei Zmievski | Date: | Mon, 20 Nov 2000 20:24:57 +0000 |
| Subject: | Calling symbol table patch | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-38667@lists.php.net to get a copy of this message | ||
Sorry, here it is.
-Andrei
* The great thing about standards is that there are so many to choose from. *
? .zend_builtin_functions.c.swp Index: zend_builtin_functions.c =================================================================== RCS file: /repository/Zend/zend_builtin_functions.c,v retrieving revision 1.76 diff -u -r1.76 zend_builtin_functions.c --- zend_builtin_functions.c 2000/10/17 18:25:10 1.76 +++ zend_builtin_functions.c 2000/11/20 20:22:05 @@ -60,6 +60,7 @@ static ZEND_FUNCTION(get_defined_vars); static ZEND_FUNCTION(create_function); static ZEND_FUNCTION(get_resource_type); +static ZEND_FUNCTION(get_calling_symbol_table); #if ZEND_DEBUG static ZEND_FUNCTION(zend_test_func); #endif @@ -107,6 +108,7 @@ ZEND_FE(get_defined_vars, NULL) ZEND_FE(create_function, NULL) ZEND_FE(get_resource_type, NULL) + ZEND_FE(get_calling_symbol_table, NULL) #if ZEND_DEBUG ZEND_FE(zend_test_func, NULL) #endif @@ -1037,5 +1039,22 @@ RETURN_STRING(resource_type, 1); } else { RETURN_STRING("Unknown", 1); + } +} + +ZEND_FUNCTION(get_calling_symbol_table) +{ + zval *tmp; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + if (!EG(calling_symbol_table)) { + RETURN_NULL(); + } else { + array_init(return_value); + zend_hash_copy(Z_ARRVAL_P(return_value), EG(calling_symbol_table), + (copy_ctor_func_t)zval_add_ref, &tmp, sizeof(zval *)); } } Index: zend_execute.c =================================================================== RCS file: /repository/Zend/zend_execute.c,v retrieving revision 1.238 diff -u -r1.238 zend_execute.c --- zend_execute.c 2000/11/20 05:09:21 1.238 +++ zend_execute.c 2000/11/20 20:22:06 @@ -1526,8 +1526,6 @@ zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); } } else if (function_state.function->type==ZEND_USER_FUNCTION) { - HashTable *calling_symbol_table; - Ts[opline->result.u.var].var.ptr = NULL; if (EG(symtable_cache_ptr)>=EG(symtable_cache)) { /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ @@ -1537,7 +1535,9 @@ zend_hash_init(function_state.function_symbol_table, 0, NULL, ZVAL_PTR_DTOR, 0); /*printf("Cache miss! Initialized %x\n", function_state.function_symbol_table);*/ } - calling_symbol_table = EG(active_symbol_table); + zend_ptr_stack_push(&EG(calling_symbol_table_stack), + EG(calling_symbol_table)); + EG(calling_symbol_table) = EG(active_symbol_table); EG(active_symbol_table) = function_state.function_symbol_table; if (opline->opcode==ZEND_DO_FCALL_BY_NAME && object.ptr @@ -1574,7 +1574,8 @@ *(++EG(symtable_cache_ptr)) = function_state.function_symbol_table; zend_hash_clean(*EG(symtable_cache_ptr)); } - EG(active_symbol_table) = calling_symbol_table; + EG(active_symbol_table) = EG(calling_symbol_table); + EG(calling_symbol_table) = zend_ptr_stack_pop(&EG(calling_symbol_table_stack)); } else { /* ZEND_OVERLOADED_FUNCTION */ ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); INIT_ZVAL(*(Ts[opline->result.u.var].var.ptr)); Index: zend_execute_API.c =================================================================== RCS file: /repository/Zend/zend_execute_API.c,v retrieving revision 1.107 diff -u -r1.107 zend_execute_API.c --- zend_execute_API.c 2000/10/11 18:51:52 1.107 +++ zend_execute_API.c 2000/11/20 20:22:07 @@ -131,6 +131,9 @@ zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0); EG(active_symbol_table) = &EG(symbol_table); + EG(calling_symbol_table) = NULL; + zend_ptr_stack_init(&EG(calling_symbol_table_stack)); + zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_activator); EG(opline_ptr) = NULL; EG(garbage_ptr) = 0; @@ -187,6 +190,8 @@ zend_hash_destroy(&EG(included_files)); + zend_ptr_stack_destroy(&EG(calling_symbol_table_stack)); + if (EG(user_error_handler)) { zval_dtor(EG(user_error_handler)); FREE_ZVAL(EG(user_error_handler)); @@ -337,7 +342,6 @@ { int i; zval **original_return_value; - HashTable *calling_symbol_table; zend_function_state function_state; zend_function_state *original_function_state_ptr; zend_op_array *original_op_array; @@ -415,7 +419,9 @@ zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long) param_count, NULL); if (function_state.function->type == ZEND_USER_FUNCTION) { - calling_symbol_table = EG(active_symbol_table); + zend_ptr_stack_push(&EG(calling_symbol_table_stack), + EG(calling_symbol_table)); + EG(calling_symbol_table) = EG(active_symbol_table); if (symbol_table) { EG(active_symbol_table) = symbol_table; } else { @@ -441,7 +447,8 @@ zend_hash_destroy(EG(active_symbol_table)); FREE_HASHTABLE(EG(active_symbol_table)); } - EG(active_symbol_table) = calling_symbol_table; + EG(active_symbol_table) = EG(calling_symbol_table); + EG(calling_symbol_table) = zend_ptr_stack_pop(&EG(calling_symbol_table_stack)); EG(active_op_array) = original_op_array; EG(return_value_ptr_ptr)=original_return_value; EG(opline_ptr) = original_opline_ptr; Index: zend_globals.h =================================================================== RCS file: /repository/Zend/zend_globals.h,v retrieving revision 1.58 diff -u -r1.58 zend_globals.h --- zend_globals.h 2000/10/30 23:19:48 1.58 +++ zend_globals.h 2000/11/20 20:22:07 @@ -143,7 +143,10 @@ zend_op **opline_ptr; HashTable *active_symbol_table; - HashTable symbol_table; /* main symbol table */ + HashTable symbol_table; /* main symbol table */ + HashTable *calling_symbol_table; /* symbol table of the calling function */ + + zend_ptr_stack calling_symbol_table_stack; HashTable included_files; /* files already included */
? .zend_builtin_functions.c.swp Index: zend_builtin_functions.c =================================================================== RCS file: /repository/Zend/zend_builtin_functions.c,v retrieving revision 1.76 diff -u -r1.76 zend_builtin_functions.c --- zend_builtin_functions.c 2000/10/17 18:25:10 1.76 +++ zend_builtin_functions.c 2000/11/20 20:22:05 @@ -60,6 +60,7 @@ static ZEND_FUNCTION(get_defined_vars); static ZEND_FUNCTION(create_function); static ZEND_FUNCTION(get_resource_type); +static ZEND_FUNCTION(get_calling_symbol_table); #if ZEND_DEBUG static ZEND_FUNCTION(zend_test_func); #endif @@ -107,6 +108,7 @@ ZEND_FE(get_defined_vars, NULL) ZEND_FE(create_function, NULL) ZEND_FE(get_resource_type, NULL) + ZEND_FE(get_calling_symbol_table, NULL) #if ZEND_DEBUG ZEND_FE(zend_test_func, NULL) #endif @@ -1037,5 +1039,22 @@ RETURN_STRING(resource_type, 1); } else { RETURN_STRING("Unknown", 1); + } +} + +ZEND_FUNCTION(get_calling_symbol_table) +{ + zval *tmp; + + if (ZEND_NUM_ARGS() != 0) { + WRONG_PARAM_COUNT; + } + + if (!EG(calling_symbol_table)) { + RETURN_NULL(); + } else { + array_init(return_value); + zend_hash_copy(Z_ARRVAL_P(return_value), EG(calling_symbol_table), + (copy_ctor_func_t)zval_add_ref, &tmp, sizeof(zval *)); } } Index: zend_execute.c =================================================================== RCS file: /repository/Zend/zend_execute.c,v retrieving revision 1.238 diff -u -r1.238 zend_execute.c --- zend_execute.c 2000/11/20 05:09:21 1.238 +++ zend_execute.c 2000/11/20 20:22:06 @@ -1526,8 +1526,6 @@ zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); } } else if (function_state.function->type==ZEND_USER_FUNCTION) { - HashTable *calling_symbol_table; - Ts[opline->result.u.var].var.ptr = NULL; if (EG(symtable_cache_ptr)>=EG(symtable_cache)) { /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ @@ -1537,7 +1535,9 @@ zend_hash_init(function_state.function_symbol_table, 0, NULL, ZVAL_PTR_DTOR, 0); /*printf("Cache miss! Initialized %x\n", function_state.function_symbol_table);*/ } - calling_symbol_table = EG(active_symbol_table); + zend_ptr_stack_push(&EG(calling_symbol_table_stack), + EG(calling_symbol_table)); + EG(calling_symbol_table) = EG(active_symbol_table); EG(active_symbol_table) = function_state.function_symbol_table; if (opline->opcode==ZEND_DO_FCALL_BY_NAME && object.ptr @@ -1574,7 +1574,8 @@ *(++EG(symtable_cache_ptr)) = function_state.function_symbol_table; zend_hash_clean(*EG(symtable_cache_ptr)); } - EG(active_symbol_table) = calling_symbol_table; + EG(active_symbol_table) = EG(calling_symbol_table); + EG(calling_symbol_table) = zend_ptr_stack_pop(&EG(calling_symbol_table_stack)); } else { /* ZEND_OVERLOADED_FUNCTION */ ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); INIT_ZVAL(*(Ts[opline->result.u.var].var.ptr)); Index: zend_execute_API.c =================================================================== RCS file: /repository/Zend/zend_execute_API.c,v retrieving revision 1.107 diff -u -r1.107 zend_execute_API.c --- zend_execute_API.c 2000/10/11 18:51:52 1.107 +++ zend_execute_API.c 2000/11/20 20:22:07 @@ -131,6 +131,9 @@ zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0); EG(active_symbol_table) = &EG(symbol_table); + EG(calling_symbol_table) = NULL; + zend_ptr_stack_init(&EG(calling_symbol_table_stack)); + zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_activator); EG(opline_ptr) = NULL; EG(garbage_ptr) = 0; @@ -187,6 +190,8 @@ zend_hash_destroy(&EG(included_files)); + zend_ptr_stack_destroy(&EG(calling_symbol_table_stack)); + if (EG(user_error_handler)) { zval_dtor(EG(user_error_handler)); FREE_ZVAL(EG(user_error_handler)); @@ -337,7 +342,6 @@ { int i; zval **original_return_value; - HashTable *calling_symbol_table; zend_function_state function_state; zend_function_state *original_function_state_ptr; zend_op_array *original_op_array; @@ -415,7 +419,9 @@ zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long) param_count, NULL); if (function_state.function->type == ZEND_USER_FUNCTION) { - calling_symbol_table = EG(active_symbol_table); + zend_ptr_stack_push(&EG(calling_symbol_table_stack), + EG(calling_symbol_table)); + EG(calling_symbol_table) = EG(active_symbol_table); if (symbol_table) { EG(active_symbol_table) = symbol_table; } else { @@ -441,7 +447,8 @@ zend_hash_destroy(EG(active_symbol_table)); FREE_HASHTABLE(EG(active_symbol_table)); } - EG(active_symbol_table) = calling_symbol_table; + EG(active_symbol_table) = EG(calling_symbol_table); + EG(calling_symbol_table) = zend_ptr_stack_pop(&EG(calling_symbol_table_stack)); EG(active_op_array) = original_op_array; EG(return_value_ptr_ptr)=original_return_value; EG(opline_ptr) = original_opline_ptr; Index: zend_globals.h =================================================================== RCS file: /repository/Zend/zend_globals.h,v retrieving revision 1.58 diff -u -r1.58 zend_globals.h --- zend_globals.h 2000/10/30 23:19:48 1.58 +++ zend_globals.h 2000/11/20 20:22:07 @@ -143,7 +143,10 @@ zend_op **opline_ptr; HashTable *active_symbol_table; - HashTable symbol_table; /* main symbol table */ + HashTable symbol_table; /* main symbol table */ + HashTable *calling_symbol_table; /* symbol table of the calling function */ + + zend_ptr_stack calling_symbol_table_stack; HashTable included_files; /* files already included */