author: goosman.lei(Lei Guoguo)
blog: http://blog.csdn.net/lgg201
mail: lgg860911@yahoo.com.cn
Related codes can be found in Chapter 12 of the book
, section "Extension Globals".
The global space code to register the extension is as follows:
#ifdef ZTS
ts_allocate_id(&sample_globals_id, sizeof(zend_sample_globals), (ts_allocate_ctor)ZEND_MODULE_GLOBALS_CTOR_N(sample), (ts_allocate_dtor)ZEND_MODULE_GLOBALS_DTOR_N(sample));
#else
sample_globals_ctor(&sample_globals TSRMLS_CC);
#endif
In the ts_allocate_id() function call, a record is written to the resource_types_table array.
In the process of tsrm_shutdown(), the registered dtor callback function will be called.
But after I finish coding according to the book, there will be coredump when running the test code.
After tracking, it was found that during the calling process of zend_shutdown(), DL_UNLOAD(module->handle); had been called on the module, causing the handle (dtor) registered at that time to be inaccessible when executing tsrm_shutdown().
At the same time, I saw that this registration method is also used in ext/standard/file.c in the standard extension. However, it should be statically compiled so there is no problem. My extension is compiled.so and dynamically linked.
The following is the calling path that traces zend_shutdown() to DL_UNLOAD().
zend_shutdown() => zend_desctroy_modules() => zend_hash_graceful_reverse_destroy() =>
http://www.bkjia.com/PHPjc/477806.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477806.htmlTechArticleauthor: goosman.lei (Lei Guo) blog: http://blog.csdn.net/lgg201 mail : lgg860911@yahoo.com.cn For relevant code, please refer to Chapter 12 of the book php extending and embedding, section Extension Globals...