]> granicus.if.org Git - php/commitdiff
Cleanup globals initialization
authorXinchen Hui <laruence@php.net>
Sat, 21 Feb 2015 03:35:16 +0000 (11:35 +0800)
committerXinchen Hui <laruence@php.net>
Sat, 21 Feb 2015 03:35:16 +0000 (11:35 +0800)
No needs explicit inititlize zero for globals in no-zts build.
executor_globals should be initialized in zend side.

Zend/zend.c
ext/standard/browscap.c
main/main.c

index 7609869a1a6bdb3bbfc17542386f5286f02a7ad4..b7a8784a69c3d4236f7c32d5931e467f212aa760 100644 (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) /* {{{ */
 {
        ZEND_TSRMLS_CACHE_UPDATE();
+
        zend_startup_constants();
        zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
        zend_init_rsrc_plist();
        zend_init_exception_op();
-       EG(lambda_count) = 0;
-       ZVAL_UNDEF(&EG(user_error_handler));
-       ZVAL_UNDEF(&EG(user_exception_handler));
-       EG(in_autoload) = NULL;
-       EG(current_execute_data) = NULL;
-       EG(current_module) = NULL;
-       EG(exit_status) = 0;
+       executor_globals->lambda_count = 0;
+       ZVAL_UNDEF(&executor_globals->user_error_handler);
+       ZVAL_UNDEF(&executor_globals->user_exception_handler);
+       executor_globals->in_autoload = NULL;
+       executor_globals->current_execute_data = NULL;
+       executor_globals->current_module = NULL;
+       executor_globals->exit_status = 0;
 #if XPFPA_HAVE_CW
-       EG(saved_fpu_cw) = 0;
+       executor_globals->saved_fpu_cw = 0;
 #endif
-       EG(saved_fpu_cw_ptr) = NULL;
-       EG(active) = 0;
+       executor_globals->saved_fpu_cw_ptr = NULL;
+       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);
        php_scanner_globals_ctor(&language_scanner_globals);
        zend_set_default_compile_time_values();
-       ZVAL_UNDEF(&EG(user_error_handler));
-       ZVAL_UNDEF(&EG(user_exception_handler));
 #endif
+       EG(error_reporting) = E_ALL & ~E_NOTICE;
 
        zend_interned_strings_init();
        zend_startup_builtin_functions();
index 123a79ea123c7d406a6f3f786a88e05164e92ba8..11eeb7c907f20969698219ad57188f710e12b65d 100644 (file)
@@ -311,8 +311,7 @@ PHP_MINIT_FUNCTION(browscap) /* {{{ */
        char *browscap = INI_STR("browscap");
 
 #ifdef ZTS
-       ts_allocate_id(&browscap_globals_id, sizeof(browser_data),
-               (ts_allocate_ctor) browscap_globals_ctor, NULL);
+       ts_allocate_id(&browscap_globals_id, sizeof(browser_data), (ts_allocate_ctor) browscap_globals_ctor, NULL);
 #endif
        /* ctor call not really needed for non-ZTS */
 
index 944a61f86bbdbeb9289f36b977bd76859683a049..35fbcb731dee92639d6620988e895ba302e9df99 100644 (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)
 {
        memset(core_globals, 0, sizeof(*core_globals));
-
-       php_startup_ticks();
 }
 /* }}} */
 #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() */
        char *php_os;
        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))
        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);
 #endif
 #else
-       php_os=PHP_OS;
+       php_os = PHP_OS;
 #endif
 
 #ifdef ZTS
-       tsrm_ls = ts_resource(0);
+       (void)ts_resource(0);
 #endif
 
 #ifdef PHP_WIN32
@@ -2081,6 +2074,17 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
 
        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.printf_function = php_printf;
        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;
        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
        {
                OSVERSIONINFOEX *osvi = &EG(windows_version_info);
@@ -2122,24 +2114,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
                }
        }
 #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
        setlocale(LC_CTYPE, "");