Permalink
Browse files

Add infrastructure for JIT initialization of auto globals

  • Loading branch information...
1 parent da0d5a1 commit f7b7800479ba43c2361ce2be981b7a59a0c9c1e1 @zsuraski zsuraski committed Mar 2, 2003
Showing with 40 additions and 8 deletions.
  1. +4 −3 Zend/zend.c
  2. +27 −4 Zend/zend_compile.c
  3. +9 −1 Zend/zend_compile.h
View
@@ -417,7 +417,7 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS
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 */);
+ zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */);
}
@@ -573,7 +573,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
#ifdef ZTS
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);
+ zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, (dtor_func_t) zend_auto_global_dtor, 1, 0);
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);
@@ -590,7 +590,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
zend_hash_destroy(executor_globals->zend_constants);
*executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
#else
- zend_hash_init_ex(CG(auto_globals), 8, NULL, NULL, 1, 0);
+ zend_hash_init_ex(CG(auto_globals), 8, NULL, (dtor_func_t) zend_auto_global_dtor, 1, 0);
scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC);
scanner_globals_ctor(&language_scanner_globals TSRMLS_CC);
zend_startup_constants();
@@ -600,6 +600,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i
#endif
register_standard_class(TSRMLS_C);
zend_register_standard_constants(TSRMLS_C);
+ zend_register_auto_global("GLOBALS", sizeof("GLOBALS")-1, NULL TSRMLS_CC);
#ifndef ZTS
zend_init_rsrc_plist(TSRMLS_C);
View
@@ -58,6 +58,13 @@ static void build_runtime_defined_function_key(zval *result, char *name, int nam
}
+int zend_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC)
+{
+ auto_global->armed = (auto_global->auto_global_callback ? 1 : 0);
+ return 0;
+}
+
+
static void init_compiler_declarables(TSRMLS_D)
{
CG(declarables).ticks.type = IS_LONG;
@@ -84,8 +91,8 @@ void zend_init_compiler_data_structures(TSRMLS_D)
CG(start_lineno) = 0;
init_compiler_declarables(TSRMLS_C);
CG(throw_list) = NULL;
- zend_register_auto_global("GLOBALS", sizeof("GLOBALS")-1 TSRMLS_CC);
CG(in_clone_method) = 0;
+ zend_hash_apply(CG(auto_globals), (apply_func_t) zend_auto_global_arm TSRMLS_CC);
}
@@ -277,8 +284,13 @@ void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar
opline_ptr->op2.u.EA.type = ZEND_FETCH_LOCAL;
if (varname->op_type == IS_CONST && varname->u.constant.type == IS_STRING) {
- if (zend_hash_exists(CG(auto_globals), varname->u.constant.value.str.val, varname->u.constant.value.str.len+1)) {
+ zend_auto_global *auto_global;
+
+ if (zend_hash_find(CG(auto_globals), varname->u.constant.value.str.val, varname->u.constant.value.str.len+1, (void **) &auto_global)==SUCCESS) {
opline_ptr->op2.u.EA.type = ZEND_FETCH_GLOBAL;
+ if (auto_global->armed) {
+ auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
+ }
} else {
/* if (CG(active_op_array)->static_variables && zend_hash_exists(CG(active_op_array)->static_variables, varname->u.constant.value.str.val, varname->u.constant.value.str.len+1)) {
opline_ptr->op2.u.EA.type = ZEND_FETCH_STATIC;
@@ -3152,9 +3164,20 @@ void zend_do_ticks(TSRMLS_D)
}
-int zend_register_auto_global(char *name, uint name_len TSRMLS_DC)
+void zend_auto_global_dtor(zend_auto_global *auto_global)
+{
+ free(auto_global->name);
+}
+
+int zend_register_auto_global(char *name, uint name_len, zend_auto_global_callback auto_global_callback TSRMLS_DC)
{
- return zend_hash_add_empty_element(CG(auto_globals), name, name_len+1);
+ zend_auto_global auto_global;
+
+ auto_global.name = zend_strndup(name, name_len);
+ auto_global.name_len = name_len;
+ auto_global.auto_global_callback = auto_global_callback;
+
+ return zend_hash_add(CG(auto_globals), name, name_len+1, &auto_global, sizeof(zend_auto_global), NULL);
}
View
@@ -462,8 +462,16 @@ ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
ZEND_API char *zend_make_compiled_string_description(char *name TSRMLS_DC);
void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
+typedef zend_bool (*zend_auto_global_callback)(char *name, uint name_len TSRMLS_DC);
+typedef struct _zend_auto_global {
+ char *name;
+ uint name_len;
+ zend_auto_global_callback auto_global_callback;
+ zend_bool armed;
+} zend_auto_global;
-int zend_register_auto_global(char *name, uint name_len TSRMLS_DC);
+void zend_auto_global_dtor(zend_auto_global *auto_global);
+int zend_register_auto_global(char *name, uint name_len, zend_auto_global_callback auto_global_callback TSRMLS_DC);
int zendlex(znode *zendlval TSRMLS_DC);

0 comments on commit f7b7800

Please sign in to comment.