diff --git a/Library/Compiler.php b/Library/Compiler.php index b8e38b7dcd..a9022fcbba 100644 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -773,11 +773,24 @@ public function generate(CommandInterface $command) /** * Check if there are module/request/global destructors */ + $includes = ''; $destructors = $this->config->get('destructors'); if (is_array($destructors)) { - $invokeDestructors = $this->processCodeInjection($destructors); - $includes = $invokeDestructors[0]; - $destructors = $invokeDestructors[1]; + $invokeRequestDestructors = $this->processCodeInjection($destructors, 'request'); + $includes .= PHP_EOL . $invokeRequestDestructors[0]; + $reqDestructors = $invokeRequestDestructors[1]; + + $invokePostRequestDestructors = $this->processCodeInjection($destructors, 'post-request'); + $includes .= PHP_EOL . $invokePostRequestDestructors[0]; + $prqDestructors = $invokePostRequestDestructors[1]; + + $invokeModuleDestructors = $this->processCodeInjection($destructors, 'module'); + $includes .= PHP_EOL . $invokeModuleDestructors[0]; + $modDestructors = $invokeModuleDestructors[1]; + + $invokeGlobalsDestructors = $this->processCodeInjection($destructors, 'globals'); + $includes .= PHP_EOL . $invokeGlobalsDestructors[0]; + $glbDestructors = $invokeGlobalsDestructors[1]; } /** @@ -785,9 +798,17 @@ public function generate(CommandInterface $command) */ $initializers = $this->config->get('initializers'); if (is_array($initializers)) { - $invokeInitializers = $this->processCodeInjection($initializers); - $includes = $invokeInitializers[0]; - $initializers = $invokeInitializers[1]; + $invokeRequestInitializers = $this->processCodeInjection($initializers, 'request'); + $includes .= PHP_EOL . $invokeRequestInitializers[0]; + $reqInitializers = $invokeRequestInitializers[1]; + + $invokeModuleInitializers = $this->processCodeInjection($initializers, 'module'); + $includes .= PHP_EOL . $invokeModuleInitializers[0]; + $modInitializers = $invokeModuleInitializers[1]; + + $invokeGlobalsInitializers = $this->processCodeInjection($initializers, 'globals'); + $includes .= PHP_EOL . $invokeGlobalsInitializers[0]; + $glbInitializers = $invokeGlobalsInitializers[1]; } /** @@ -1687,15 +1708,19 @@ public function processExtensionInfo() * @param array $entries * @return array */ - public function processCodeInjection(array $entries) + public function processCodeInjection(array $entries, $section = 'request') { $codes = array(); $includes = array(); - if (isset($entries['request'])) { - foreach ($entries['request'] as $entry) { - $codes[] = $entry['code'] . ';'; - $includes[] = "#include \"" . $entry['include'] . "\""; + if (isset($entries[$section])) { + foreach ($entries[$section] as $entry) { + if (isset($entry['code']) && !empty($entry['code'])) { + $codes[] = $entry['code'] . ';'; + } + if (isset($entry['include']) && !empty($entry['include'])) { + $includes[] = "#include \"" . $entry['include'] . "\""; + } } } @@ -1770,7 +1795,13 @@ public function createProjectFiles($project) } $includes = ''; - $destructors = ''; + $reqInitializers = ''; + $reqDestructors = ''; + $prqDestructors = ''; + $modInitializers = ''; + $modDestructors = ''; + $glbInitializers = ''; + $glbDestructors = ''; $files = array_merge($this->files, $this->anonymousFiles); /** @@ -1872,9 +1903,21 @@ public function createProjectFiles($project) */ $destructors = $this->config->get('destructors'); if (is_array($destructors)) { - $invokeDestructors = $this->processCodeInjection($destructors); - $includes = $invokeDestructors[0]; - $destructors = $invokeDestructors[1]; + $invokeRequestDestructors = $this->processCodeInjection($destructors, 'request'); + $includes .= PHP_EOL . $invokeRequestDestructors[0]; + $reqDestructors = $invokeRequestDestructors[1]; + + $invokePostRequestDestructors = $this->processCodeInjection($destructors, 'post-request'); + $includes .= PHP_EOL . $invokePostRequestDestructors[0]; + $prqDestructors = $invokePostRequestDestructors[1]; + + $invokeModuleDestructors = $this->processCodeInjection($destructors, 'module'); + $includes .= PHP_EOL . $invokeModuleDestructors[0]; + $modDestructors = $invokeModuleDestructors[1]; + + $invokeGlobalsDestructors = $this->processCodeInjection($destructors, 'globals'); + $includes .= PHP_EOL . $invokeGlobalsDestructors[0]; + $glbDestructors = $invokeGlobalsDestructors[1]; } /** @@ -1882,9 +1925,17 @@ public function createProjectFiles($project) */ $initializers = $this->config->get('initializers'); if (is_array($initializers)) { - $invokeInitializers = $this->processCodeInjection($initializers); - $includes = $invokeInitializers[0]; - $initializers = $invokeInitializers[1]; + $invokeRequestInitializers = $this->processCodeInjection($initializers, 'request'); + $includes .= PHP_EOL . $invokeRequestInitializers[0]; + $reqInitializers = $invokeRequestInitializers[1]; + + $invokeModuleInitializers = $this->processCodeInjection($initializers, 'module'); + $includes .= PHP_EOL . $invokeModuleInitializers[0]; + $modInitializers = $invokeModuleInitializers[1]; + + $invokeGlobalsInitializers = $this->processCodeInjection($initializers, 'globals'); + $includes .= PHP_EOL . $invokeGlobalsInitializers[0]; + $glbInitializers = $invokeGlobalsInitializers[1]; } /** @@ -1916,14 +1967,36 @@ public function createProjectFiles($project) PHP_EOL . "\t", array_merge($completeInterfaceInits, $completeClassInits) ), - '%INIT_GLOBALS%' => $globalsDefault[0], + '%INIT_GLOBALS%' => implode( + PHP_EOL . "\t", + array_merge((array)$globalsDefault[0], array($glbInitializers)) + ), '%INIT_MODULE_GLOBALS%' => $globalsDefault[1], + '%DESTROY_GLOBALS%' => $glbDestructors, '%EXTENSION_INFO%' => $phpInfo, - '%EXTRA_INCLUDES%' => $includes, - '%DESTRUCTORS%' => $destructors, - '%INITIALIZERS%' => implode( + '%EXTRA_INCLUDES%' => implode( + PHP_EOL, + array_unique(explode(PHP_EOL, $includes)) + ), + '%MOD_INITIALIZERS%' => $modInitializers, + '%MOD_DESTRUCTORS%' => $modDestructors, + '%REQ_INITIALIZERS%' => implode( + PHP_EOL . "\t", + array_merge($this->internalInitializers, array($reqInitializers)) + ), + '%REQ_DESTRUCTORS%' => $reqDestructors, + '%POSTREQ_DESTRUCTORS%' => empty($prqDestructors) ? '' : implode( PHP_EOL, - array_merge($this->internalInitializers, array($initializers)) + array( + '#define ZEPHIR_POST_REQUEST 1', + 'static PHP_PRSHUTDOWN_FUNCTION(' . strtolower($project) . ')', + '{', + "\t" . implode( + PHP_EOL . "\t", + explode(PHP_EOL, $prqDestructors) + ), + '}' + ) ), '%FE_HEADER%' => $feHeader, '%FE_ENTRIES%' => $feEntries, @@ -2235,8 +2308,7 @@ public function generatePackageDependenciesM4($contentM4) */ protected function checkRequires() { - $extensionRequires = $this->config->get("requires"); - $extensionRequires = $extensionRequires["extensions"]; + $extensionRequires = $this->config->get("extensions", "requires"); if ($extensionRequires) { $collectionError = PHP_EOL . "\tCould not load extension : "; foreach ($extensionRequires as $key => $value) { diff --git a/templates/ZendEngine2/project.c b/templates/ZendEngine2/project.c index 0f755aa401..80fc9afc36 100644 --- a/templates/ZendEngine2/project.c +++ b/templates/ZendEngine2/project.c @@ -56,6 +56,7 @@ static PHP_MINIT_FUNCTION(%PROJECT_LOWER%) #endif REGISTER_INI_ENTRIES(); %CLASS_INITS% + %MOD_INITIALIZERS% // TODO: Deprecated. Will be removed in future #if PHP_VERSION_ID < 50500 @@ -68,7 +69,7 @@ static PHP_MINIT_FUNCTION(%PROJECT_LOWER%) #ifndef ZEPHIR_RELEASE static PHP_MSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { - + %MOD_DESTRUCTORS% zephir_deinitialize_memory(TSRMLS_C); UNREGISTER_INI_ENTRIES(); return SUCCESS; @@ -97,7 +98,7 @@ static void php_zephir_init_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER /* Static cache */ memset(%PROJECT_LOWER%_globals->scache, '\0', sizeof(zephir_fcall_cache_entry*) * ZEPHIR_MAX_CACHE_SLOTS); -%INIT_GLOBALS% + %INIT_GLOBALS% } /** @@ -105,32 +106,30 @@ static void php_zephir_init_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER */ static void php_zephir_init_module_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER%_globals TSRMLS_DC) { -%INIT_MODULE_GLOBALS% + %INIT_MODULE_GLOBALS% } static PHP_RINIT_FUNCTION(%PROJECT_LOWER%) { - zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER%_globals_ptr = ZEPHIR_VGLOBAL; php_zephir_init_globals(%PROJECT_LOWER%_globals_ptr TSRMLS_CC); //zephir_init_interned_strings(TSRMLS_C); - zephir_initialize_memory(%PROJECT_LOWER%_globals_ptr TSRMLS_CC); -%INITIALIZERS% + %REQ_INITIALIZERS% return SUCCESS; } static PHP_RSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { - - %DESTRUCTORS% - + %REQ_DESTRUCTORS% zephir_deinitialize_memory(TSRMLS_C); return SUCCESS; } +%POSTREQ_DESTRUCTORS% + static PHP_MINFO_FUNCTION(%PROJECT_LOWER%) { php_info_print_box_start(0); @@ -144,7 +143,7 @@ static PHP_MINFO_FUNCTION(%PROJECT_LOWER%) php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ ); php_info_print_table_row(2, "Powered by Zephir", "Version " PHP_%PROJECT_UPPER%_ZEPVERSION); php_info_print_table_end(); -%EXTENSION_INFO% + %EXTENSION_INFO% DISPLAY_INI_ENTRIES(); } @@ -156,12 +155,12 @@ static PHP_GINIT_FUNCTION(%PROJECT_LOWER%) static PHP_GSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { - + %DESTROY_GLOBALS% } %FE_HEADER% zend_function_entry php_%PROJECT_LOWER_SAFE%_functions[] = { -%FE_ENTRIES% + %FE_ENTRIES% }; zend_module_entry %PROJECT_LOWER_SAFE%_module_entry = { @@ -183,7 +182,11 @@ zend_module_entry %PROJECT_LOWER_SAFE%_module_entry = { ZEND_MODULE_GLOBALS(%PROJECT_LOWER%), PHP_GINIT(%PROJECT_LOWER%), PHP_GSHUTDOWN(%PROJECT_LOWER%), +#ifdef ZEPHIR_POST_REQUEST + PHP_PRSHUTDOWN(%PROJECT_LOWER%), +#else NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; diff --git a/templates/ZendEngine3/project.c b/templates/ZendEngine3/project.c index b123fd7259..6236c88234 100644 --- a/templates/ZendEngine3/project.c +++ b/templates/ZendEngine3/project.c @@ -36,12 +36,14 @@ static PHP_MINIT_FUNCTION(%PROJECT_LOWER%) REGISTER_INI_ENTRIES(); zephir_module_init(); %CLASS_INITS% + %MOD_INITIALIZERS% return SUCCESS; } #ifndef ZEPHIR_RELEASE static PHP_MSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { + %MOD_DESTRUCTORS% zephir_deinitialize_memory(TSRMLS_C); UNREGISTER_INI_ENTRIES(); return SUCCESS; @@ -70,7 +72,7 @@ static void php_zephir_init_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER /* Static cache */ memset(%PROJECT_LOWER%_globals->scache, '\0', sizeof(zephir_fcall_cache_entry*) * ZEPHIR_MAX_CACHE_SLOTS); -%INIT_GLOBALS% + %INIT_GLOBALS% } /** @@ -78,12 +80,11 @@ static void php_zephir_init_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER */ static void php_zephir_init_module_globals(zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER%_globals TSRMLS_DC) { -%INIT_MODULE_GLOBALS% + %INIT_MODULE_GLOBALS% } static PHP_RINIT_FUNCTION(%PROJECT_LOWER%) { - zend_%PROJECT_LOWER%_globals *%PROJECT_LOWER%_globals_ptr; #ifdef ZTS tsrm_ls = ts_resource(0); @@ -93,17 +94,19 @@ static PHP_RINIT_FUNCTION(%PROJECT_LOWER%) php_zephir_init_globals(%PROJECT_LOWER%_globals_ptr TSRMLS_CC); zephir_initialize_memory(%PROJECT_LOWER%_globals_ptr TSRMLS_CC); -%INITIALIZERS% + %REQ_INITIALIZERS% return SUCCESS; } static PHP_RSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { - %DESTRUCTORS% + %REQ_DESTRUCTORS% zephir_deinitialize_memory(TSRMLS_C); return SUCCESS; } +%POSTREQ_DESTRUCTORS% + static PHP_MINFO_FUNCTION(%PROJECT_LOWER%) { php_info_print_box_start(0); @@ -117,7 +120,7 @@ static PHP_MINFO_FUNCTION(%PROJECT_LOWER%) php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ ); php_info_print_table_row(2, "Powered by Zephir", "Version " PHP_%PROJECT_UPPER%_ZEPVERSION); php_info_print_table_end(); -%EXTENSION_INFO% + %EXTENSION_INFO% DISPLAY_INI_ENTRIES(); } @@ -129,12 +132,12 @@ static PHP_GINIT_FUNCTION(%PROJECT_LOWER%) static PHP_GSHUTDOWN_FUNCTION(%PROJECT_LOWER%) { - + %DESTROY_GLOBALS% } %FE_HEADER% zend_function_entry php_%PROJECT_LOWER_SAFE%_functions[] = { -%FE_ENTRIES% + %FE_ENTRIES% }; zend_module_entry %PROJECT_LOWER_SAFE%_module_entry = { @@ -156,7 +159,11 @@ zend_module_entry %PROJECT_LOWER_SAFE%_module_entry = { ZEND_MODULE_GLOBALS(%PROJECT_LOWER%), PHP_GINIT(%PROJECT_LOWER%), PHP_GSHUTDOWN(%PROJECT_LOWER%), +#ifdef ZEPHIR_POST_REQUEST + PHP_PRSHUTDOWN(%PROJECT_LOWER%), +#else NULL, +#endif STANDARD_MODULE_PROPERTIES_EX }; diff --git a/unit-tests/Zephir/Test/ConfigTest.php b/unit-tests/Zephir/Test/ConfigTest.php index b5a4ea5a8f..1096c0a354 100644 --- a/unit-tests/Zephir/Test/ConfigTest.php +++ b/unit-tests/Zephir/Test/ConfigTest.php @@ -39,7 +39,7 @@ public function setUp() */ public function testConstructWithBadConfigFile() { - chdir(__DIR__ . DIRECTORY_SEPARATOR . '_files'); + chdir(__DIR__ . DIRECTORY_SEPARATOR . '_files/badconfig'); $config = new Config(); } diff --git a/unit-tests/Zephir/Test/LifeCycleTest.php b/unit-tests/Zephir/Test/LifeCycleTest.php new file mode 100644 index 0000000000..e656e2a791 --- /dev/null +++ b/unit-tests/Zephir/Test/LifeCycleTest.php @@ -0,0 +1,84 @@ +pwd = getcwd(); + } + + public function testLifeCycleInjectionZend2() + { + chdir(__DIR__ . DIRECTORY_SEPARATOR . '_files/lifecycle'); + $config = new Config(); + $logger = new Logger($config); + $backend = new Zend2($config); + $parser = new Parser(); + $manager = new Manager($parser, $logger); + $compiler = new Compiler($config, $logger, $backend, $manager); + $compiler->createProjectFiles('lifecycle'); + $this->assertSame( + implode(PHP_EOL, file('ext/lifecycle.c', FILE_IGNORE_NEW_LINES)), + implode(PHP_EOL, file('expected2.c', FILE_IGNORE_NEW_LINES)) + ); + } + + public function testLifeCycleInjectionZend3() + { + chdir(__DIR__ . DIRECTORY_SEPARATOR . '_files/lifecycle'); + $config = new Config(); + $logger = new Logger($config); + $backend = new Zend3($config); + $parser = new Parser(); + $manager = new Manager($parser, $logger); + $compiler = new Compiler($config, $logger, $backend, $manager); + $compiler->createProjectFiles('lifecycle'); + $this->assertSame( + implode(PHP_EOL, file('ext/lifecycle.c', FILE_IGNORE_NEW_LINES)), + implode(PHP_EOL, file('expected3.c', FILE_IGNORE_NEW_LINES)) + ); + } + + /** + * Restore current directory, and clean config.json. + */ + public function tearDown() + { + if (file_exists('ext')) { + exec('rm -rf ext/'); + } + + if (getcwd() != $this->pwd) { + chdir($this->pwd); + } + } +} diff --git a/unit-tests/Zephir/Test/_files/config.json b/unit-tests/Zephir/Test/_files/badconfig/config.json similarity index 100% rename from unit-tests/Zephir/Test/_files/config.json rename to unit-tests/Zephir/Test/_files/badconfig/config.json diff --git a/unit-tests/Zephir/Test/_files/lifecycle/config.json b/unit-tests/Zephir/Test/_files/lifecycle/config.json new file mode 100644 index 0000000000..f82cea1b16 --- /dev/null +++ b/unit-tests/Zephir/Test/_files/lifecycle/config.json @@ -0,0 +1,63 @@ +{ + "namespace": "lifecycle", + "name": "Life Cycle Test", + "description": "Description: Life Cycle Test 'Extension'", + "author": "Zephir Team", + "version": "1.0.0", + "verbose": false, + "silent": true, + "initializers": { + "globals": [ + { + "include": "setup_funcs.h", + "code": "ext_setup_globals()" + } + ], + "module": [ + { + "include": "setup_funcs.h", + "code": "ext_setup_module()" + }, + { + "include": "prep_funcs.h", + "code": "ext_prep_module()" + } + ], + "request": [ + { + "include": "setup_funcs.h", + "code": "ext_setup_request()" + } + ] + }, + "destructors": { + "request": [ + { + "include": "takedown_funcs.h", + "code": "ext_takedown_request()" + } + ], + "post-request": [ + { + "include": "takedown_funcs.h", + "code": "ext_takedown_request()" + } + ], + "module": [ + { + "include": "takedown_funcs.h", + "code": "ext_takedown_module()" + }, + { + "include": "", + "code": "ext_kill_module()" + } + ], + "globals": [ + { + "include": "takedown_funcs.h", + "code": "ext_takedown_globals()" + } + ] + } +} diff --git a/unit-tests/Zephir/Test/_files/lifecycle/expected2.c b/unit-tests/Zephir/Test/_files/lifecycle/expected2.c new file mode 100644 index 0000000000..6115456c9c --- /dev/null +++ b/unit-tests/Zephir/Test/_files/lifecycle/expected2.c @@ -0,0 +1,206 @@ + +/* This file was generated automatically by Zephir do not modify it! */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +// TODO: Deprecated. Will be removed in future +#if PHP_VERSION_ID < 50500 +#include +#endif + +#include "php_ext.h" +#include "lifecycle.h" + +#include + +#include +#include +#include + +#include "kernel/globals.h" +#include "kernel/main.h" +#include "kernel/fcall.h" +#include "kernel/memory.h" + + +#include "takedown_funcs.h" +#include "setup_funcs.h" +#include "prep_funcs.h" + + + +ZEND_DECLARE_MODULE_GLOBALS(lifecycle) + +PHP_INI_BEGIN() + +PHP_INI_END() + +static PHP_MINIT_FUNCTION(lifecycle) +{ +// TODO: Deprecated. Will be removed in future +#if PHP_VERSION_ID < 50500 + char* old_lc_all = setlocale(LC_ALL, NULL); + if (old_lc_all) { + size_t len = strlen(old_lc_all); + char *tmp = calloc(len+1, 1); + if (UNEXPECTED(!tmp)) { + return FAILURE; + } + + memcpy(tmp, old_lc_all, len); + old_lc_all = tmp; + } + + setlocale(LC_ALL, "C"); +#endif + REGISTER_INI_ENTRIES(); + + ext_setup_module(); + ext_prep_module(); + +// TODO: Deprecated. Will be removed in future +#if PHP_VERSION_ID < 50500 + setlocale(LC_ALL, old_lc_all); + free(old_lc_all); +#endif + return SUCCESS; +} + +#ifndef ZEPHIR_RELEASE +static PHP_MSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_module(); + ext_kill_module(); + zephir_deinitialize_memory(TSRMLS_C); + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} +#endif + +/** + * Initialize globals on each request or each thread started + */ +static void php_zephir_init_globals(zend_lifecycle_globals *lifecycle_globals TSRMLS_DC) +{ + lifecycle_globals->initialized = 0; + + /* Memory options */ + lifecycle_globals->active_memory = NULL; + + /* Virtual Symbol Tables */ + lifecycle_globals->active_symbol_table = NULL; + + /* Cache Enabled */ + lifecycle_globals->cache_enabled = 1; + + /* Recursive Lock */ + lifecycle_globals->recursive_lock = 0; + + /* Static cache */ + memset(lifecycle_globals->scache, '\0', sizeof(zephir_fcall_cache_entry*) * ZEPHIR_MAX_CACHE_SLOTS); + + + ext_setup_globals(); +} + +/** + * Initialize globals only on each thread started + */ +static void php_zephir_init_module_globals(zend_lifecycle_globals *lifecycle_globals TSRMLS_DC) +{ + +} + +static PHP_RINIT_FUNCTION(lifecycle) +{ + zend_lifecycle_globals *lifecycle_globals_ptr = ZEPHIR_VGLOBAL; + + php_zephir_init_globals(lifecycle_globals_ptr TSRMLS_CC); + //zephir_init_interned_strings(TSRMLS_C); + zephir_initialize_memory(lifecycle_globals_ptr TSRMLS_CC); + + ext_setup_request(); + return SUCCESS; +} + +static PHP_RSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_request(); + zephir_deinitialize_memory(TSRMLS_C); + return SUCCESS; +} + +#define ZEPHIR_POST_REQUEST 1 +static PHP_PRSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_request(); +} + +static PHP_MINFO_FUNCTION(lifecycle) +{ + php_info_print_box_start(0); + php_printf("%s", PHP_LIFECYCLE_DESCRIPTION); + php_info_print_box_end(); + + php_info_print_table_start(); + php_info_print_table_header(2, PHP_LIFECYCLE_NAME, "enabled"); + php_info_print_table_row(2, "Author", PHP_LIFECYCLE_AUTHOR); + php_info_print_table_row(2, "Version", PHP_LIFECYCLE_VERSION); + php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ ); + php_info_print_table_row(2, "Powered by Zephir", "Version " PHP_LIFECYCLE_ZEPVERSION); + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); +} + +static PHP_GINIT_FUNCTION(lifecycle) +{ + php_zephir_init_globals(lifecycle_globals TSRMLS_CC); + php_zephir_init_module_globals(lifecycle_globals TSRMLS_CC); +} + +static PHP_GSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_globals(); +} + + +zend_function_entry php_lifecycle_functions[] = { + ZEND_FE_END + +}; + +zend_module_entry lifecycle_module_entry = { + STANDARD_MODULE_HEADER_EX, + NULL, + NULL, + PHP_LIFECYCLE_EXTNAME, + php_lifecycle_functions, + PHP_MINIT(lifecycle), +#ifndef ZEPHIR_RELEASE + PHP_MSHUTDOWN(lifecycle), +#else + NULL, +#endif + PHP_RINIT(lifecycle), + PHP_RSHUTDOWN(lifecycle), + PHP_MINFO(lifecycle), + PHP_LIFECYCLE_VERSION, + ZEND_MODULE_GLOBALS(lifecycle), + PHP_GINIT(lifecycle), + PHP_GSHUTDOWN(lifecycle), +#ifdef ZEPHIR_POST_REQUEST + PHP_PRSHUTDOWN(lifecycle), +#else + NULL, +#endif + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_LIFECYCLE +ZEND_GET_MODULE(lifecycle) +#endif diff --git a/unit-tests/Zephir/Test/_files/lifecycle/expected3.c b/unit-tests/Zephir/Test/_files/lifecycle/expected3.c new file mode 100644 index 0000000000..ddcd481ebc --- /dev/null +++ b/unit-tests/Zephir/Test/_files/lifecycle/expected3.c @@ -0,0 +1,183 @@ + +/* This file was generated automatically by Zephir do not modify it! */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "php_ext.h" +#include "lifecycle.h" + +#include + +#include +#include +#include + +#include "kernel/globals.h" +#include "kernel/main.h" +#include "kernel/fcall.h" +#include "kernel/memory.h" + + +#include "takedown_funcs.h" +#include "setup_funcs.h" +#include "prep_funcs.h" + + + +ZEND_DECLARE_MODULE_GLOBALS(lifecycle) + +PHP_INI_BEGIN() + +PHP_INI_END() + +static PHP_MINIT_FUNCTION(lifecycle) +{ + REGISTER_INI_ENTRIES(); + zephir_module_init(); + + ext_setup_module(); + ext_prep_module(); + return SUCCESS; +} + +#ifndef ZEPHIR_RELEASE +static PHP_MSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_module(); + ext_kill_module(); + zephir_deinitialize_memory(TSRMLS_C); + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} +#endif + +/** + * Initialize globals on each request or each thread started + */ +static void php_zephir_init_globals(zend_lifecycle_globals *lifecycle_globals TSRMLS_DC) +{ + lifecycle_globals->initialized = 0; + + /* Memory options */ + lifecycle_globals->active_memory = NULL; + + /* Virtual Symbol Tables */ + lifecycle_globals->active_symbol_table = NULL; + + /* Cache Enabled */ + lifecycle_globals->cache_enabled = 1; + + /* Recursive Lock */ + lifecycle_globals->recursive_lock = 0; + + /* Static cache */ + memset(lifecycle_globals->scache, '\0', sizeof(zephir_fcall_cache_entry*) * ZEPHIR_MAX_CACHE_SLOTS); + + + ext_setup_globals(); +} + +/** + * Initialize globals only on each thread started + */ +static void php_zephir_init_module_globals(zend_lifecycle_globals *lifecycle_globals TSRMLS_DC) +{ + +} + +static PHP_RINIT_FUNCTION(lifecycle) +{ + zend_lifecycle_globals *lifecycle_globals_ptr; +#ifdef ZTS + tsrm_ls = ts_resource(0); +#endif + lifecycle_globals_ptr = ZEPHIR_VGLOBAL; + + php_zephir_init_globals(lifecycle_globals_ptr TSRMLS_CC); + zephir_initialize_memory(lifecycle_globals_ptr TSRMLS_CC); + + ext_setup_request(); + return SUCCESS; +} + +static PHP_RSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_request(); + zephir_deinitialize_memory(TSRMLS_C); + return SUCCESS; +} + +#define ZEPHIR_POST_REQUEST 1 +static PHP_PRSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_request(); +} + +static PHP_MINFO_FUNCTION(lifecycle) +{ + php_info_print_box_start(0); + php_printf("%s", PHP_LIFECYCLE_DESCRIPTION); + php_info_print_box_end(); + + php_info_print_table_start(); + php_info_print_table_header(2, PHP_LIFECYCLE_NAME, "enabled"); + php_info_print_table_row(2, "Author", PHP_LIFECYCLE_AUTHOR); + php_info_print_table_row(2, "Version", PHP_LIFECYCLE_VERSION); + php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ ); + php_info_print_table_row(2, "Powered by Zephir", "Version " PHP_LIFECYCLE_ZEPVERSION); + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); +} + +static PHP_GINIT_FUNCTION(lifecycle) +{ + php_zephir_init_globals(lifecycle_globals TSRMLS_CC); + php_zephir_init_module_globals(lifecycle_globals TSRMLS_CC); +} + +static PHP_GSHUTDOWN_FUNCTION(lifecycle) +{ + ext_takedown_globals(); +} + + +zend_function_entry php_lifecycle_functions[] = { + ZEND_FE_END + +}; + +zend_module_entry lifecycle_module_entry = { + STANDARD_MODULE_HEADER_EX, + NULL, + NULL, + PHP_LIFECYCLE_EXTNAME, + php_lifecycle_functions, + PHP_MINIT(lifecycle), +#ifndef ZEPHIR_RELEASE + PHP_MSHUTDOWN(lifecycle), +#else + NULL, +#endif + PHP_RINIT(lifecycle), + PHP_RSHUTDOWN(lifecycle), + PHP_MINFO(lifecycle), + PHP_LIFECYCLE_VERSION, + ZEND_MODULE_GLOBALS(lifecycle), + PHP_GINIT(lifecycle), + PHP_GSHUTDOWN(lifecycle), +#ifdef ZEPHIR_POST_REQUEST + PHP_PRSHUTDOWN(lifecycle), +#else + NULL, +#endif + STANDARD_MODULE_PROPERTIES_EX +}; + +#ifdef COMPILE_DL_LIFECYCLE +ZEND_GET_MODULE(lifecycle) +#endif