Skip to content

Commit

Permalink
- Infrastructure changes for allowing to access the global scope from
Browse files Browse the repository at this point in the history
- within a class scope.
- Fix the Zend.dsp project a bit. It seems someone pretty much killed it
- when commiting their own personal configuration. Please be careful in
- future.
  • Loading branch information
Andi Gutmans committed Dec 12, 2001
1 parent 6bd6416 commit ce98c73
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
4 changes: 4 additions & 0 deletions Zend/Zend.dsp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 16 additions & 22 deletions Zend/zend.c
Expand Up @@ -28,9 +28,9 @@
#include "zend_ini.h"

#ifdef ZTS
# define GLOBAL_FUNCTION_TABLE global_function_table
# define GLOBAL_CLASS_TABLE global_class_table
# define GLOBAL_CONSTANTS_TABLE global_constants_table
# 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
# define GLOBAL_AUTO_GLOBALS_TABLE global_auto_globals_table
#else
# define GLOBAL_FUNCTION_TABLE CG(function_table)
Expand Down Expand Up @@ -61,9 +61,7 @@ static int (*zend_get_configuration_directive_p)(char *name, uint name_length, z
ZEND_API int compiler_globals_id;
ZEND_API int executor_globals_id;
ZEND_API int alloc_globals_id;
HashTable *global_function_table;
HashTable *global_class_table;
HashTable *global_constants_table;
zend_class_entry global_main_class;
HashTable *global_auto_globals_table;
#endif

Expand Down Expand Up @@ -280,13 +278,13 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS

compiler_globals->compiled_filename = NULL;

compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
compiler_globals->function_table = &compiler_globals->main_class.function_table;
zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0);
zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function));
zend_hash_copy(compiler_globals->function_table, GLOBAL_FUNCTION_TABLE, NULL, &tmp_func, sizeof(zend_function));

compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
compiler_globals->class_table = &compiler_globals->main_class.class_table;
zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry));
zend_hash_copy(compiler_globals->class_table, GLOBAL_CLASS_TABLE, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry));

zend_set_default_compile_time_values(TSRMLS_C);

Expand All @@ -300,13 +298,11 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS

static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC)
{
if (compiler_globals->function_table != global_function_table) {
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) {
if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
zend_hash_destroy(compiler_globals->class_table);
free(compiler_globals->class_table);
}
if (compiler_globals->auto_globals != global_auto_globals_table) {
zend_hash_destroy(compiler_globals->auto_globals);
Expand All @@ -317,9 +313,9 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS

static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC)
{
if (global_constants_table) {
if (GLOBAL_CONSTANTS_TABLE) {
zend_startup_constants(TSRMLS_C);
zend_copy_constants(EG(zend_constants), global_constants_table);
zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
}
zend_init_rsrc_plist(TSRMLS_C);
EG(lambda_count)=0;
Expand Down Expand Up @@ -424,8 +420,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1;

GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
#ifndef ZTS
GLOBAL_FUNCTION_TABLE = &compiler_globals.main_class.function_table;
GLOBAL_CLASS_TABLE = &compiler_globals.main_class.class_table;
#endif
GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
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);
Expand All @@ -441,7 +439,6 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
zval_used_for_init.type = IS_NULL;

#ifdef ZTS
global_constants_table = NULL;
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);
ts_allocate_id(&language_scanner_globals_id, sizeof(zend_scanner_globals), (ts_allocate_ctor) scanner_globals_ctor, NULL);
Expand All @@ -454,7 +451,6 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
compiler_globals->class_table = GLOBAL_CLASS_TABLE;
compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
zend_startup_constants(tsrm_ls);
GLOBAL_CONSTANTS_TABLE = EG(zend_constants);
#else
zend_hash_init_ex(CG(auto_globals), 8, NULL, NULL, 1, 0);
scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
Expand Down Expand Up @@ -494,9 +490,7 @@ void zend_shutdown(TSRMLS_D)
zend_destroy_rsrc_list_dtors();
zend_hash_destroy(&module_registry);
zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
free(GLOBAL_FUNCTION_TABLE);
zend_hash_destroy(GLOBAL_CLASS_TABLE);
free(GLOBAL_CLASS_TABLE);
zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
free(GLOBAL_AUTO_GLOBALS_TABLE);
zend_shutdown_extensions(TSRMLS_C);
Expand Down
3 changes: 1 addition & 2 deletions Zend/zend_constants.c
Expand Up @@ -90,7 +90,7 @@ int zend_startup_constants(TSRMLS_D)
DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
#endif

EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable));
EG(zend_constants) = &CG(main_class).constants_table;

if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) {
return FAILURE;
Expand Down Expand Up @@ -153,7 +153,6 @@ void zend_register_standard_constants(TSRMLS_D)
int zend_shutdown_constants(TSRMLS_D)
{
zend_hash_destroy(EG(zend_constants));
free(EG(zend_constants));
return SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions Zend/zend_globals.h
Expand Up @@ -85,6 +85,7 @@ struct _zend_compiler_globals {

zend_op_array *active_op_array;

zend_class_entry main_class;
HashTable *function_table; /* function symbol table */
HashTable *class_table; /* class table */

Expand Down

0 comments on commit ce98c73

Please sign in to comment.