From 2182822451c4459fdfefdc595ba049a84a395d0e Mon Sep 17 00:00:00 2001 From: longxinhui Date: Mon, 11 Jun 2018 14:22:49 +0800 Subject: [PATCH] fix #9 fix zts segment error --- extension/php_xhprof.h | 3 +-- extension/xhprof.c | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/extension/php_xhprof.h b/extension/php_xhprof.h index a04ce850..e7fca836 100644 --- a/extension/php_xhprof.h +++ b/extension/php_xhprof.h @@ -39,7 +39,7 @@ extern zend_module_entry xhprof_module_entry; */ /* XHProf version */ -#define XHPROF_VERSION "2.0.0" +#define XHPROF_VERSION "2.0.1" /* Fictitious function name to represent top of the call tree. The paranthesis * in the name is to ensure we don't conflict with user function names. */ @@ -293,7 +293,6 @@ PHP_MSHUTDOWN_FUNCTION(xhprof); PHP_RINIT_FUNCTION(xhprof); PHP_RSHUTDOWN_FUNCTION(xhprof); PHP_MINFO_FUNCTION(xhprof); -PHP_GINIT_FUNCTION(xhprof); PHP_FUNCTION(xhprof_enable); PHP_FUNCTION(xhprof_disable); diff --git a/extension/xhprof.c b/extension/xhprof.c index 62bdb978..2ed56d46 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -200,7 +200,7 @@ PHP_FUNCTION(xhprof_sample_disable) /* else null is returned */ } -PHP_GINIT_FUNCTION(xhprof) +static void php_xhprof_init_globals(zend_xhprof_globals *xhprof_globals) { xhprof_globals->enabled = 0; xhprof_globals->ever_enabled = 0; @@ -211,6 +211,21 @@ PHP_GINIT_FUNCTION(xhprof) xhprof_globals->ignored_functions = NULL; xhprof_globals->sampling_interval = XHPROF_DEFAULT_SAMPLING_INTERVAL; xhprof_globals->sampling_depth = INT_MAX; + + ZVAL_UNDEF(&xhprof_globals->stats_count); + + /* no free hp_entry_t structures to start with */ + xhprof_globals->entry_free_list = NULL; + + int i; + + for (i = 0; i < 256; i++) { + xhprof_globals->func_hash_counters[i] = 0; + } + + if (xhprof_globals->sampling_interval < XHPROF_MINIMAL_SAMPLING_INTERVAL) { + xhprof_globals->sampling_interval = XHPROF_MINIMAL_SAMPLING_INTERVAL; + } } /** @@ -220,24 +235,12 @@ PHP_GINIT_FUNCTION(xhprof) */ PHP_MINIT_FUNCTION(xhprof) { - int i; + ZEND_INIT_MODULE_GLOBALS(xhprof, php_xhprof_init_globals, NULL); REGISTER_INI_ENTRIES(); hp_register_constants(INIT_FUNC_ARGS_PASSTHRU); - ZVAL_UNDEF(&XHPROF_G(stats_count)); - - /* no free hp_entry_t structures to start with */ - XHPROF_G(entry_free_list) = NULL; - - for (i = 0; i < 256; i++) { - XHPROF_G(func_hash_counters[i]) = 0; - } - if (XHPROF_G(sampling_interval) < XHPROF_MINIMAL_SAMPLING_INTERVAL) { - XHPROF_G(sampling_interval) = XHPROF_MINIMAL_SAMPLING_INTERVAL; - } - /* Replace zend_compile with our proxy */ _zend_compile_file = zend_compile_file; zend_compile_file = hp_compile_file;