Cleanup globals initialization

No needs explicit inititlize zero for globals in no-zts build.
executor_globals should be initialized in zend side.
This commit is contained in:
Xinchen Hui 2015-02-21 11:35:16 +08:00
parent 2a724becc1
commit 4629f8978e
3 changed files with 31 additions and 53 deletions

View file

@ -466,22 +466,28 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */
{ {
ZEND_TSRMLS_CACHE_UPDATE(); ZEND_TSRMLS_CACHE_UPDATE();
zend_startup_constants(); zend_startup_constants();
zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE); zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
zend_init_rsrc_plist(); zend_init_rsrc_plist();
zend_init_exception_op(); zend_init_exception_op();
EG(lambda_count) = 0; executor_globals->lambda_count = 0;
ZVAL_UNDEF(&EG(user_error_handler)); ZVAL_UNDEF(&executor_globals->user_error_handler);
ZVAL_UNDEF(&EG(user_exception_handler)); ZVAL_UNDEF(&executor_globals->user_exception_handler);
EG(in_autoload) = NULL; executor_globals->in_autoload = NULL;
EG(current_execute_data) = NULL; executor_globals->current_execute_data = NULL;
EG(current_module) = NULL; executor_globals->current_module = NULL;
EG(exit_status) = 0; executor_globals->exit_status = 0;
#if XPFPA_HAVE_CW #if XPFPA_HAVE_CW
EG(saved_fpu_cw) = 0; executor_globals->saved_fpu_cw = 0;
#endif #endif
EG(saved_fpu_cw_ptr) = NULL; executor_globals->saved_fpu_cw_ptr = NULL;
EG(active) = 0; executor_globals->active = 0;
executor_globals->bailout = NULL;
executor_globals->error_handling = EH_NORMAL;
executor_globals->exception_class = NULL;
executor_globals->exception = NULL;
executor_globals->objects_store.object_buckets = NULL;
} }
/* }}} */ /* }}} */
@ -662,9 +668,8 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) /
ini_scanner_globals_ctor(&ini_scanner_globals); ini_scanner_globals_ctor(&ini_scanner_globals);
php_scanner_globals_ctor(&language_scanner_globals); php_scanner_globals_ctor(&language_scanner_globals);
zend_set_default_compile_time_values(); zend_set_default_compile_time_values();
ZVAL_UNDEF(&EG(user_error_handler));
ZVAL_UNDEF(&EG(user_exception_handler));
#endif #endif
EG(error_reporting) = E_ALL & ~E_NOTICE;
zend_interned_strings_init(); zend_interned_strings_init();
zend_startup_builtin_functions(); zend_startup_builtin_functions();

View file

@ -311,8 +311,7 @@ PHP_MINIT_FUNCTION(browscap) /* {{{ */
char *browscap = INI_STR("browscap"); char *browscap = INI_STR("browscap");
#ifdef ZTS #ifdef ZTS
ts_allocate_id(&browscap_globals_id, sizeof(browser_data), ts_allocate_id(&browscap_globals_id, sizeof(browser_data), (ts_allocate_ctor) browscap_globals_ctor, NULL);
(ts_allocate_ctor) browscap_globals_ctor, NULL);
#endif #endif
/* ctor call not really needed for non-ZTS */ /* ctor call not really needed for non-ZTS */

View file

@ -1919,8 +1919,6 @@ static size_t php_output_wrapper(const char *str, size_t str_length)
static void core_globals_ctor(php_core_globals *core_globals) static void core_globals_ctor(php_core_globals *core_globals)
{ {
memset(core_globals, 0, sizeof(*core_globals)); memset(core_globals, 0, sizeof(*core_globals));
php_startup_ticks();
} }
/* }}} */ /* }}} */
#endif #endif
@ -2034,11 +2032,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */ int retval = SUCCESS, module_number=0; /* for REGISTER_INI_ENTRIES() */
char *php_os; char *php_os;
zend_module_entry *module; zend_module_entry *module;
#ifdef ZTS
zend_executor_globals *executor_globals;
void ***tsrm_ls;
php_core_globals *core_globals;
#endif
#if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK)) #if defined(PHP_WIN32) || (defined(NETWARE) && defined(USE_WINSOCK))
WORD wVersionRequested = MAKEWORD(2, 0); WORD wVersionRequested = MAKEWORD(2, 0);
@ -2057,11 +2050,11 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
_CrtSetReportMode(_CRT_ASSERT, 0); _CrtSetReportMode(_CRT_ASSERT, 0);
#endif #endif
#else #else
php_os=PHP_OS; php_os = PHP_OS;
#endif #endif
#ifdef ZTS #ifdef ZTS
tsrm_ls = ts_resource(0); (void)ts_resource(0);
#endif #endif
#ifdef PHP_WIN32 #ifdef PHP_WIN32
@ -2081,6 +2074,17 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
php_output_startup(); php_output_startup();
#ifdef ZTS
ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
php_startup_ticks();
#ifdef PHP_WIN32
ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
#else
php_startup_ticks();
#endif
gc_globals_ctor();
zuf.error_function = php_error_cb; zuf.error_function = php_error_cb;
zuf.printf_function = php_printf; zuf.printf_function = php_printf;
zuf.write_function = php_output_wrapper; zuf.write_function = php_output_wrapper;
@ -2098,18 +2102,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
zuf.resolve_path_function = php_resolve_path_for_zend; zuf.resolve_path_function = php_resolve_path_for_zend;
zend_startup(&zuf, NULL); zend_startup(&zuf, NULL);
#ifdef ZTS
executor_globals = ts_resource(executor_globals_id);
ts_allocate_id(&core_globals_id, sizeof(php_core_globals), (ts_allocate_ctor) core_globals_ctor, (ts_allocate_dtor) core_globals_dtor);
core_globals = ts_resource(core_globals_id);
#ifdef PHP_WIN32
ts_allocate_id(&php_win32_core_globals_id, sizeof(php_win32_core_globals), (ts_allocate_ctor) php_win32_core_globals_ctor, (ts_allocate_dtor) php_win32_core_globals_dtor);
#endif
#else
php_startup_ticks();
#endif
gc_globals_ctor();
#ifdef PHP_WIN32 #ifdef PHP_WIN32
{ {
OSVERSIONINFOEX *osvi = &EG(windows_version_info); OSVERSIONINFOEX *osvi = &EG(windows_version_info);
@ -2122,24 +2114,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
} }
} }
#endif #endif
EG(bailout) = NULL;
EG(error_reporting) = E_ALL & ~E_NOTICE;
PG(header_is_being_sent) = 0;
SG(request_info).headers_only = 0;
SG(request_info).argv0 = NULL;
SG(request_info).argc=0;
SG(request_info).argv=(char **)NULL;
PG(connection_status) = PHP_CONNECTION_NORMAL;
PG(during_request_startup) = 0;
PG(last_error_message) = NULL;
PG(last_error_file) = NULL;
PG(last_error_lineno) = 0;
EG(error_handling) = EH_NORMAL;
EG(exception_class) = NULL;
PG(disable_functions) = NULL;
PG(disable_classes) = NULL;
EG(exception) = NULL;
EG(objects_store).object_buckets = NULL;
#if HAVE_SETLOCALE #if HAVE_SETLOCALE
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");