[PATCH] destructors called after module shutdown
| From: | Florian Schaper | Date: | Fri, 02 Jul 2004 21:51:44 +0000 |
| Subject: | [PATCH] destructors called after module shutdown | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-10879@lists.php.net to get a copy of this message | ||
Currently object's destructors are called in the zend_deactivate function in
main.c after the modules
request_shutdown_func has been called (main.c -
php_call_shutdown_functions(void); ) .
Since no code should be executed after module request shutdown unexpected
behaviour might
occur like the one descibed in bug#27555 affecting the session extension.
Maybe somebody can take a look.
./regards
Florian
<?php
// Short test which saves a session in the destructor
class TestSession {
public static $oSessionMap;
public function __construct() {
session_start();
if( empty($_SESSION['sessionObject']) ) {
TestSession::$oSessionMap = array();
} else if ( ! is_array(TestSession::$oSessionMap) ) {
TestSession::$oSessionMap = unserialize( $_SESSION['sessionObject'] );
} // if / else
} // public function __construct
public function add( $sKey, $sValue ) {
TestSession::$oSessionMap[ $sKey ] = $sValue;
} // public function add
public function get( $sKey ) {
return TestSession::$oSessionMap[ $sKey ];
} // public function get
public function __destruct() {
$_SESSION['sessionObject'] = serialize(TestSession::$oSessionMap);
} // public function __destruct
} // class Session
$oSes = new TestSession();
echo $oSes->get("test1","testval");
$oSes->add("test1","testval");
?>
Index: ZendEngine2/zend.c =================================================================== RCS file: /repository/ZendEngine2/zend.c,v retrieving revision 1.285 diff -u -r1.285 zend.c --- ZendEngine2/zend.c 1 Jun 2004 11:45:46 -0000 1.285 +++ ZendEngine2/zend.c 2 Jul 2004 18:32:10 -0000 @@ -805,6 +805,13 @@ } zend_end_try(); } +void zend_call_destructors(TSRMLS_D) +{ + zend_try { + shutdown_destructors(TSRMLS_C); + } zend_end_try(); +} + void zend_deactivate(TSRMLS_D) { /* we're no longer executing anything */ Index: ZendEngine2/zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.255 diff -u -r1.255 zend.h --- ZendEngine2/zend.h 7 Jun 2004 18:57:34 -0000 1.255 +++ ZendEngine2/zend.h 2 Jul 2004 18:32:11 -0000 @@ -450,6 +450,7 @@ void zend_activate(TSRMLS_D); void zend_deactivate(TSRMLS_D); +void zend_call_destructors(TSRMLS_D); void zend_activate_modules(TSRMLS_D); void zend_deactivate_modules(TSRMLS_D); void zend_post_deactivate_modules(TSRMLS_D); Index: ZendEngine2/zend_execute.h =================================================================== RCS file: /repository/ZendEngine2/zend_execute.h,v retrieving revision 1.72 diff -u -r1.72 zend_execute.h --- ZendEngine2/zend_execute.h 16 Mar 2004 10:14:52 -0000 1.72 +++ ZendEngine2/zend_execute.h 2 Jul 2004 18:32:11 -0000 @@ -49,6 +49,7 @@ void init_executor(TSRMLS_D); void shutdown_executor(TSRMLS_D); +void shutdown_destructors(TSRMLS_D); ZEND_API void execute(zend_op_array *op_array TSRMLS_DC); ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC); ZEND_API int zend_is_true(zval *op); Index: ZendEngine2/zend_execute_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute_API.c,v retrieving revision 1.287 diff -u -r1.287 zend_execute_API.c --- ZendEngine2/zend_execute_API.c 18 May 2004 20:14:54 -0000 1.287 +++ ZendEngine2/zend_execute_API.c 2 Jul 2004 18:32:11 -0000 @@ -187,6 +187,12 @@ EG(float_separator)[0] = '.'; } +void shutdown_destructors(TSRMLS_D) { + zend_try { + zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); + } zend_end_try(); +} + void shutdown_executor(TSRMLS_D) { zend_try { @@ -206,7 +212,6 @@ } */ zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC); - zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); zend_hash_graceful_reverse_destroy(&EG(symbol_table)); } zend_end_try(); Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.604 diff -u -r1.604 main.c --- main/main.c 28 May 2004 14:14:26 -0000 1.604 +++ main/main.c 2 Jul 2004 18:32:16 -0000 @@ -1190,6 +1190,10 @@ sapi_send_headers(TSRMLS_C); } zend_end_try(); + zend_try { + zend_call_destructors(TSRMLS_C); + } zend_end_try(); + if (PG(modules_activated)) zend_try { php_call_shutdown_functions(); } zend_end_try();
Index: ZendEngine2/zend.c =================================================================== RCS file: /repository/ZendEngine2/zend.c,v retrieving revision 1.285 diff -u -r1.285 zend.c --- ZendEngine2/zend.c 1 Jun 2004 11:45:46 -0000 1.285 +++ ZendEngine2/zend.c 2 Jul 2004 18:32:10 -0000 @@ -805,6 +805,13 @@ } zend_end_try(); } +void zend_call_destructors(TSRMLS_D) +{ + zend_try { + shutdown_destructors(TSRMLS_C); + } zend_end_try(); +} + void zend_deactivate(TSRMLS_D) { /* we're no longer executing anything */ Index: ZendEngine2/zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.255 diff -u -r1.255 zend.h --- ZendEngine2/zend.h 7 Jun 2004 18:57:34 -0000 1.255 +++ ZendEngine2/zend.h 2 Jul 2004 18:32:11 -0000 @@ -450,6 +450,7 @@ void zend_activate(TSRMLS_D); void zend_deactivate(TSRMLS_D); +void zend_call_destructors(TSRMLS_D); void zend_activate_modules(TSRMLS_D); void zend_deactivate_modules(TSRMLS_D); void zend_post_deactivate_modules(TSRMLS_D); Index: ZendEngine2/zend_execute.h =================================================================== RCS file: /repository/ZendEngine2/zend_execute.h,v retrieving revision 1.72 diff -u -r1.72 zend_execute.h --- ZendEngine2/zend_execute.h 16 Mar 2004 10:14:52 -0000 1.72 +++ ZendEngine2/zend_execute.h 2 Jul 2004 18:32:11 -0000 @@ -49,6 +49,7 @@ void init_executor(TSRMLS_D); void shutdown_executor(TSRMLS_D); +void shutdown_destructors(TSRMLS_D); ZEND_API void execute(zend_op_array *op_array TSRMLS_DC); ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC); ZEND_API int zend_is_true(zval *op); Index: ZendEngine2/zend_execute_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute_API.c,v retrieving revision 1.287 diff -u -r1.287 zend_execute_API.c --- ZendEngine2/zend_execute_API.c 18 May 2004 20:14:54 -0000 1.287 +++ ZendEngine2/zend_execute_API.c 2 Jul 2004 18:32:11 -0000 @@ -187,6 +187,12 @@ EG(float_separator)[0] = '.'; } +void shutdown_destructors(TSRMLS_D) { + zend_try { + zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); + } zend_end_try(); +} + void shutdown_executor(TSRMLS_D) { zend_try { @@ -206,7 +212,6 @@ } */ zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC); - zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); zend_hash_graceful_reverse_destroy(&EG(symbol_table)); } zend_end_try(); Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.604 diff -u -r1.604 main.c --- main/main.c 28 May 2004 14:14:26 -0000 1.604 +++ main/main.c 2 Jul 2004 18:32:16 -0000 @@ -1190,6 +1190,10 @@ sapi_send_headers(TSRMLS_C); } zend_end_try(); + zend_try { + zend_call_destructors(TSRMLS_C); + } zend_end_try(); + if (PG(modules_activated)) zend_try { php_call_shutdown_functions(); } zend_end_try();