cvs: ZendEngine2(PHP_5_3) / zend.c zend_exceptions.c zend_exceptions.h zend_execute_API.c zend_globals.h zend_objects.c zend_vm_def.h
zend_vm_execute.h php-src/ext/spl php_spl.c
| From: | Marcus Boerger | Date: | Thu, 14 Aug 2008 10:24:58 +0000 |
| Subject: | cvs: ZendEngine2(PHP_5_3) / zend.c zend_exceptions.c zend_exceptions.h zend_execute_API.c zend_globals.h zend_objects.c zend_vm_def.h zend_vm_execute.h php-src/ext/spl php_spl.c |
||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-7050@lists.php.net to get a copy of this message | ||
helly Thu Aug 14 10:24:58 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/spl php_spl.c
/ZendEngine2 zend.c zend_exceptions.c zend_exceptions.h
zend_execute_API.c zend_globals.h zend_objects.c
zend_vm_def.h zend_vm_execute.h
Log:
- MFH Improve exception linking
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.52.2.28.2.17.2.25&r2=1.52.2.28.2.17.2.26&diff_format=u Index: php-src/ext/spl/php_spl.c diff -u php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.25 php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.26 --- php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.25 Sat Jul 26 13:14:03 2008 +++ php-src/ext/spl/php_spl.c Thu Aug 14 10:24:51 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.17.2.25 2008/07/26 13:14:03 dmitry Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.17.2.26 2008/08/14 10:24:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -381,7 +381,6 @@ if (SPL_G(autoload_functions)) { int l_autoload_running = SPL_G(autoload_running); - zval *exception = NULL; SPL_G(autoload_running) = 1; class_name_len = Z_STRLEN_P(class_name); lc_name = zend_str_tolower_dup(Z_STRVAL_P(class_name), class_name_len); @@ -390,12 +389,7 @@ zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &func_name_len, &dummy, 0, &function_pos); zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos); zend_call_method(alfi->obj ? &alfi->obj : NULL, alfi->ce, &alfi->func_ptr, func_name, func_name_len, &retval, 1, class_name, NULL TSRMLS_CC); - zend_exception_set_previous(exception TSRMLS_CC); - if (EG(exception)) { - zend_exception_set_previous(exception TSRMLS_CC); - exception = EG(exception); - EG(exception) = NULL; - } + zend_exception_save(TSRMLS_C); if (retval) { zval_ptr_dtor(&retval); } @@ -404,7 +398,7 @@ } zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); } - EG(exception) = exception; + zend_exception_restore(TSRMLS_C); efree(lc_name); SPL_G(autoload_running) = l_autoload_running; } else { http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.c?r1=1.308.2.12.2.35.2.21&r2=1.308.2.12.2.35.2.22&diff_format=u Index: ZendEngine2/zend.c diff -u ZendEngine2/zend.c:1.308.2.12.2.35.2.21 ZendEngine2/zend.c:1.308.2.12.2.35.2.22 --- ZendEngine2/zend.c:1.308.2.12.2.35.2.21 Tue Aug 12 17:20:23 2008 +++ ZendEngine2/zend.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.c,v 1.308.2.12.2.35.2.21 2008/08/12 17:20:23 felipe Exp $ */ +/* $Id: zend.c,v 1.308.2.12.2.35.2.22 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_extensions.h" @@ -1197,31 +1197,28 @@ if (EG(active_op_array)) { EG(return_value_ptr_ptr) = retval ? retval : NULL; zend_execute(EG(active_op_array) TSRMLS_CC); + zend_exception_restore(TSRMLS_C); if (EG(exception)) { if (EG(user_exception_handler)) { zval *orig_user_exception_handler; - zval ***params, *retval2, *old_exception; - params = (zval ***)emalloc(sizeof(zval **)); + zval **params[1], *retval2, *old_exception; old_exception = EG(exception); - EG(exception) = NULL; + zend_exception_save(TSRMLS_C); params[0] = &old_exception; orig_user_exception_handler = EG(user_exception_handler); if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) { if (retval2 != NULL) { zval_ptr_dtor(&retval2); } - } else { - if (!EG(exception)) { - EG(exception) = old_exception; + zend_exception_restore(TSRMLS_C); + if (EG(exception)) { + zval_ptr_dtor(&EG(exception)); + EG(exception) = NULL; } + } else { + zend_exception_restore(TSRMLS_C); zend_exception_error(EG(exception) TSRMLS_CC); } - efree(params); - zval_ptr_dtor(&old_exception); - if (EG(exception)) { - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; - } } else { zend_exception_error(EG(exception) TSRMLS_CC); } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.c?r1=1.79.2.6.2.9.2.13&r2=1.79.2.6.2.9.2.14&diff_format=u Index: ZendEngine2/zend_exceptions.c diff -u ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.13 ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.14 --- ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.13 Tue Jul 29 14:28:11 2008 +++ ZendEngine2/zend_exceptions.c Thu Aug 14 10:24:51 2008 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.c,v 1.79.2.6.2.9.2.13 2008/07/29 14:28:11 dmitry Exp $ */ +/* $Id: zend_exceptions.c,v 1.79.2.6.2.9.2.14 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -33,21 +33,17 @@ static zend_object_handlers default_exception_handlers; ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC); -void zend_exception_set_previous(zval *add_previous TSRMLS_DC) +void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC) { - zval *exception = EG(exception), *previous; + zval *previous; - if (exception == add_previous || !add_previous) { + if (exception == add_previous || !add_previous || !exception) { return; } if (Z_TYPE_P(add_previous) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) { zend_error(E_ERROR, "Cannot set non exception as previous exception"); return; } - if (!exception) { - EG(exception) = add_previous; - return; - } while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) { previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC); if (Z_TYPE_P(previous) == IS_NULL) { @@ -59,12 +55,40 @@ } } +void zend_exception_save(TSRMLS_D) /* {{{ */ +{ + if (EG(prev_exception)) { + zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC); + } + if (EG(exception)) { + EG(prev_exception) = EG(exception); + } + EG(exception) = NULL; +} +/* }}} */ + +void zend_exception_restore(TSRMLS_D) /* {{{ */ +{ + if (EG(prev_exception)) { + if (EG(exception)) { + zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC); + } else { + EG(exception) = EG(prev_exception); + } + EG(prev_exception) = NULL; + } +} +/* }}} */ + void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { if (exception != NULL) { zval *previous = EG(exception); + zend_exception_set_previous(exception, EG(exception) TSRMLS_CC); EG(exception) = exception; - zend_exception_set_previous(previous TSRMLS_CC); + if (previous) { + return; + } } if (!EG(current_execute_data)) { zend_error(E_ERROR, "Exception thrown without a stack frame"); @@ -86,6 +110,10 @@ ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */ { + if (EG(prev_exception)) { + zval_ptr_dtor(&EG(prev_exception)); + EG(prev_exception) = NULL; + } if (!EG(exception)) { return; } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.h?r1=1.21.2.1.2.2.2.2&r2=1.21.2.1.2.2.2.3&diff_format=u Index: ZendEngine2/zend_exceptions.h diff -u ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.2 ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.3 --- ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.2 Sun Jul 13 21:42:49 2008 +++ ZendEngine2/zend_exceptions.h Thu Aug 14 10:24:51 2008 @@ -19,14 +19,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.h,v 1.21.2.1.2.2.2.2 2008/07/13 21:42:49 helly Exp $ */ +/* $Id: zend_exceptions.h,v 1.21.2.1.2.2.2.3 2008/08/14 10:24:51 helly Exp $ */ #ifndef ZEND_EXCEPTIONS_H #define ZEND_EXCEPTIONS_H BEGIN_EXTERN_C() -ZEND_API void zend_exception_set_previous(zval *add_previous TSRMLS_DC); +ZEND_API void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC); +ZEND_API void zend_exception_save(TSRMLS_D); +ZEND_API void zend_exception_restore(TSRMLS_D); void zend_throw_exception_internal(zval *exception TSRMLS_DC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.24.2.54&r2=1.331.2.20.2.24.2.55&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.54 ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.55 --- ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.54 Tue Aug 12 21:45:52 2008 +++ ZendEngine2/zend_execute_API.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.54 2008/08/12 21:45:52 nlopess Exp $ */ +/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.55 2008/08/14 10:24:51 helly Exp $ */ #include <stdio.h> #include <signal.h> @@ -186,6 +186,7 @@ #endif EG(exception) = NULL; + EG(prev_exception) = NULL; EG(scope) = NULL; EG(called_scope) = NULL; @@ -1029,7 +1030,7 @@ fcall_cache.object_pp = NULL; exception = EG(exception); - EG(exception) = NULL; + zend_exception_save(TSRMLS_C); retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC); EG(autoload_func) = fcall_cache.function_handler; @@ -1038,19 +1039,18 @@ zend_hash_del(EG(in_autoload), lc_name, name_length + 1); if (retval == FAILURE) { - EG(exception) = exception; + zend_exception_restore(TSRMLS_C); free_alloca(lc_free, use_heap); return FAILURE; } if (EG(exception) && exception) { + zend_exception_restore(TSRMLS_C); free_alloca(lc_free, use_heap); zend_error(E_ERROR, "Function %s(%s) threw an exception of type '%s'", ZEND_AUTOLOAD_FUNC_NAME, name, Z_OBJCE_P(EG(exception))->name); return FAILURE; } - if (!EG(exception)) { - EG(exception) = exception; - } + zend_exception_restore(TSRMLS_C); if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_globals.h?r1=1.141.2.3.2.7.2.18&r2=1.141.2.3.2.7.2.19&diff_format=u Index: ZendEngine2/zend_globals.h diff -u ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.18 ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.19 --- ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.18 Mon Aug 11 17:19:20 2008 +++ ZendEngine2/zend_globals.h Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.18 2008/08/11 17:19:20 helly Exp $ */ +/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.19 2008/08/14 10:24:51 helly Exp $ */ #ifndef ZEND_GLOBALS_H #define ZEND_GLOBALS_H @@ -239,7 +239,7 @@ HashTable *modified_ini_directives; zend_objects_store objects_store; - zval *exception; + zval *exception, *prev_exception; zend_op *opline_before_exception; zend_op exception_op[3]; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_objects.c?r1=1.56.2.3.2.6.2.5&r2=1.56.2.3.2.6.2.6&diff_format=u Index: ZendEngine2/zend_objects.c diff -u ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.5 ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.6 --- ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.5 Tue Aug 12 17:20:24 2008 +++ ZendEngine2/zend_objects.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects.c,v 1.56.2.3.2.6.2.5 2008/08/12 17:20:24 felipe Exp $ */ +/* $Id: zend_objects.c,v 1.56.2.3.2.6.2.6 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -53,7 +53,6 @@ if (destructor) { zval *obj; - zval *old_exception; if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) { if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { @@ -96,10 +95,12 @@ * For example, if an exception was thrown in a function and when the function's * local variable destruction results in a destructor being called. */ - old_exception = EG(exception); - EG(exception) = NULL; + if (EG(exception) && Z_OBJ_HANDLE_P(EG(exception)) == handle) { + zend_error(E_ERROR, "Attempt to destruct pending exception"); + } + zend_exception_save(TSRMLS_C); zend_call_method_with_0_params(&obj, object->ce, &destructor, ZEND_DESTRUCTOR_FUNC_NAME, NULL); - zend_exception_set_previous(old_exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); zval_ptr_dtor(&obj); } } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.59.2.29.2.48.2.67&r2=1.59.2.29.2.48.2.68&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.67 ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.68 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.67 Wed Aug 13 07:21:23 2008 +++ ZendEngine2/zend_vm_def.h Thu Aug 14 10:24:51 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.67 2008/08/13 07:21:23 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.68 2008/08/14 10:24:51 helly Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -2515,6 +2515,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -2523,6 +2524,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); FREE_OP1_IF_VAR(); ZEND_VM_NEXT_OPCODE(); } @@ -2533,6 +2535,7 @@ zend_class_entry *ce; /* Check whether an exception has been thrown, if not, jump over code */ + zend_exception_restore(TSRMLS_C); if (EG(exception) == NULL) { ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]); ZEND_VM_CONTINUE(); /* CHECK_ME */ http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.62.2.30.2.49.2.67&r2=1.62.2.30.2.49.2.68&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.67 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.68 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.67 Wed Aug 13 07:21:23 2008 +++ ZendEngine2/zend_vm_execute.h Thu Aug 14 10:24:52 2008 @@ -1228,6 +1228,7 @@ zend_class_entry *ce; /* Check whether an exception has been thrown, if not, jump over code */ + zend_exception_restore(TSRMLS_C); if (EG(exception) == NULL) { ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]); ZEND_VM_CONTINUE(); /* CHECK_ME */ @@ -1655,6 +1656,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -1663,6 +1665,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); } @@ -4936,6 +4939,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -4944,6 +4948,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); } @@ -8121,6 +8126,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -8129,6 +8135,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); } @@ -22193,6 +22200,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -22201,6 +22209,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); }
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.52.2.28.2.17.2.25&r2=1.52.2.28.2.17.2.26&diff_format=u Index: php-src/ext/spl/php_spl.c diff -u php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.25 php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.26 --- php-src/ext/spl/php_spl.c:1.52.2.28.2.17.2.25 Sat Jul 26 13:14:03 2008 +++ php-src/ext/spl/php_spl.c Thu Aug 14 10:24:51 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.17.2.25 2008/07/26 13:14:03 dmitry Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.17.2.26 2008/08/14 10:24:51 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -381,7 +381,6 @@ if (SPL_G(autoload_functions)) { int l_autoload_running = SPL_G(autoload_running); - zval *exception = NULL; SPL_G(autoload_running) = 1; class_name_len = Z_STRLEN_P(class_name); lc_name = zend_str_tolower_dup(Z_STRVAL_P(class_name), class_name_len); @@ -390,12 +389,7 @@ zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &func_name_len, &dummy, 0, &function_pos); zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos); zend_call_method(alfi->obj ? &alfi->obj : NULL, alfi->ce, &alfi->func_ptr, func_name, func_name_len, &retval, 1, class_name, NULL TSRMLS_CC); - zend_exception_set_previous(exception TSRMLS_CC); - if (EG(exception)) { - zend_exception_set_previous(exception TSRMLS_CC); - exception = EG(exception); - EG(exception) = NULL; - } + zend_exception_save(TSRMLS_C); if (retval) { zval_ptr_dtor(&retval); } @@ -404,7 +398,7 @@ } zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); } - EG(exception) = exception; + zend_exception_restore(TSRMLS_C); efree(lc_name); SPL_G(autoload_running) = l_autoload_running; } else { http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.c?r1=1.308.2.12.2.35.2.21&r2=1.308.2.12.2.35.2.22&diff_format=u Index: ZendEngine2/zend.c diff -u ZendEngine2/zend.c:1.308.2.12.2.35.2.21 ZendEngine2/zend.c:1.308.2.12.2.35.2.22 --- ZendEngine2/zend.c:1.308.2.12.2.35.2.21 Tue Aug 12 17:20:23 2008 +++ ZendEngine2/zend.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.c,v 1.308.2.12.2.35.2.21 2008/08/12 17:20:23 felipe Exp $ */ +/* $Id: zend.c,v 1.308.2.12.2.35.2.22 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_extensions.h" @@ -1197,31 +1197,28 @@ if (EG(active_op_array)) { EG(return_value_ptr_ptr) = retval ? retval : NULL; zend_execute(EG(active_op_array) TSRMLS_CC); + zend_exception_restore(TSRMLS_C); if (EG(exception)) { if (EG(user_exception_handler)) { zval *orig_user_exception_handler; - zval ***params, *retval2, *old_exception; - params = (zval ***)emalloc(sizeof(zval **)); + zval **params[1], *retval2, *old_exception; old_exception = EG(exception); - EG(exception) = NULL; + zend_exception_save(TSRMLS_C); params[0] = &old_exception; orig_user_exception_handler = EG(user_exception_handler); if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) { if (retval2 != NULL) { zval_ptr_dtor(&retval2); } - } else { - if (!EG(exception)) { - EG(exception) = old_exception; + zend_exception_restore(TSRMLS_C); + if (EG(exception)) { + zval_ptr_dtor(&EG(exception)); + EG(exception) = NULL; } + } else { + zend_exception_restore(TSRMLS_C); zend_exception_error(EG(exception) TSRMLS_CC); } - efree(params); - zval_ptr_dtor(&old_exception); - if (EG(exception)) { - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; - } } else { zend_exception_error(EG(exception) TSRMLS_CC); } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.c?r1=1.79.2.6.2.9.2.13&r2=1.79.2.6.2.9.2.14&diff_format=u Index: ZendEngine2/zend_exceptions.c diff -u ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.13 ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.14 --- ZendEngine2/zend_exceptions.c:1.79.2.6.2.9.2.13 Tue Jul 29 14:28:11 2008 +++ ZendEngine2/zend_exceptions.c Thu Aug 14 10:24:51 2008 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.c,v 1.79.2.6.2.9.2.13 2008/07/29 14:28:11 dmitry Exp $ */ +/* $Id: zend_exceptions.c,v 1.79.2.6.2.9.2.14 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -33,21 +33,17 @@ static zend_object_handlers default_exception_handlers; ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC); -void zend_exception_set_previous(zval *add_previous TSRMLS_DC) +void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC) { - zval *exception = EG(exception), *previous; + zval *previous; - if (exception == add_previous || !add_previous) { + if (exception == add_previous || !add_previous || !exception) { return; } if (Z_TYPE_P(add_previous) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) { zend_error(E_ERROR, "Cannot set non exception as previous exception"); return; } - if (!exception) { - EG(exception) = add_previous; - return; - } while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) { previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC); if (Z_TYPE_P(previous) == IS_NULL) { @@ -59,12 +55,40 @@ } } +void zend_exception_save(TSRMLS_D) /* {{{ */ +{ + if (EG(prev_exception)) { + zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC); + } + if (EG(exception)) { + EG(prev_exception) = EG(exception); + } + EG(exception) = NULL; +} +/* }}} */ + +void zend_exception_restore(TSRMLS_D) /* {{{ */ +{ + if (EG(prev_exception)) { + if (EG(exception)) { + zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC); + } else { + EG(exception) = EG(prev_exception); + } + EG(prev_exception) = NULL; + } +} +/* }}} */ + void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { if (exception != NULL) { zval *previous = EG(exception); + zend_exception_set_previous(exception, EG(exception) TSRMLS_CC); EG(exception) = exception; - zend_exception_set_previous(previous TSRMLS_CC); + if (previous) { + return; + } } if (!EG(current_execute_data)) { zend_error(E_ERROR, "Exception thrown without a stack frame"); @@ -86,6 +110,10 @@ ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */ { + if (EG(prev_exception)) { + zval_ptr_dtor(&EG(prev_exception)); + EG(prev_exception) = NULL; + } if (!EG(exception)) { return; } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.h?r1=1.21.2.1.2.2.2.2&r2=1.21.2.1.2.2.2.3&diff_format=u Index: ZendEngine2/zend_exceptions.h diff -u ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.2 ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.3 --- ZendEngine2/zend_exceptions.h:1.21.2.1.2.2.2.2 Sun Jul 13 21:42:49 2008 +++ ZendEngine2/zend_exceptions.h Thu Aug 14 10:24:51 2008 @@ -19,14 +19,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.h,v 1.21.2.1.2.2.2.2 2008/07/13 21:42:49 helly Exp $ */ +/* $Id: zend_exceptions.h,v 1.21.2.1.2.2.2.3 2008/08/14 10:24:51 helly Exp $ */ #ifndef ZEND_EXCEPTIONS_H #define ZEND_EXCEPTIONS_H BEGIN_EXTERN_C() -ZEND_API void zend_exception_set_previous(zval *add_previous TSRMLS_DC); +ZEND_API void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC); +ZEND_API void zend_exception_save(TSRMLS_D); +ZEND_API void zend_exception_restore(TSRMLS_D); void zend_throw_exception_internal(zval *exception TSRMLS_DC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.24.2.54&r2=1.331.2.20.2.24.2.55&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.54 ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.55 --- ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.54 Tue Aug 12 21:45:52 2008 +++ ZendEngine2/zend_execute_API.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.54 2008/08/12 21:45:52 nlopess Exp $ */ +/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.55 2008/08/14 10:24:51 helly Exp $ */ #include <stdio.h> #include <signal.h> @@ -186,6 +186,7 @@ #endif EG(exception) = NULL; + EG(prev_exception) = NULL; EG(scope) = NULL; EG(called_scope) = NULL; @@ -1029,7 +1030,7 @@ fcall_cache.object_pp = NULL; exception = EG(exception); - EG(exception) = NULL; + zend_exception_save(TSRMLS_C); retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC); EG(autoload_func) = fcall_cache.function_handler; @@ -1038,19 +1039,18 @@ zend_hash_del(EG(in_autoload), lc_name, name_length + 1); if (retval == FAILURE) { - EG(exception) = exception; + zend_exception_restore(TSRMLS_C); free_alloca(lc_free, use_heap); return FAILURE; } if (EG(exception) && exception) { + zend_exception_restore(TSRMLS_C); free_alloca(lc_free, use_heap); zend_error(E_ERROR, "Function %s(%s) threw an exception of type '%s'", ZEND_AUTOLOAD_FUNC_NAME, name, Z_OBJCE_P(EG(exception))->name); return FAILURE; } - if (!EG(exception)) { - EG(exception) = exception; - } + zend_exception_restore(TSRMLS_C); if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_globals.h?r1=1.141.2.3.2.7.2.18&r2=1.141.2.3.2.7.2.19&diff_format=u Index: ZendEngine2/zend_globals.h diff -u ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.18 ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.19 --- ZendEngine2/zend_globals.h:1.141.2.3.2.7.2.18 Mon Aug 11 17:19:20 2008 +++ ZendEngine2/zend_globals.h Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.18 2008/08/11 17:19:20 helly Exp $ */ +/* $Id: zend_globals.h,v 1.141.2.3.2.7.2.19 2008/08/14 10:24:51 helly Exp $ */ #ifndef ZEND_GLOBALS_H #define ZEND_GLOBALS_H @@ -239,7 +239,7 @@ HashTable *modified_ini_directives; zend_objects_store objects_store; - zval *exception; + zval *exception, *prev_exception; zend_op *opline_before_exception; zend_op exception_op[3]; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_objects.c?r1=1.56.2.3.2.6.2.5&r2=1.56.2.3.2.6.2.6&diff_format=u Index: ZendEngine2/zend_objects.c diff -u ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.5 ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.6 --- ZendEngine2/zend_objects.c:1.56.2.3.2.6.2.5 Tue Aug 12 17:20:24 2008 +++ ZendEngine2/zend_objects.c Thu Aug 14 10:24:51 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_objects.c,v 1.56.2.3.2.6.2.5 2008/08/12 17:20:24 felipe Exp $ */ +/* $Id: zend_objects.c,v 1.56.2.3.2.6.2.6 2008/08/14 10:24:51 helly Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -53,7 +53,6 @@ if (destructor) { zval *obj; - zval *old_exception; if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) { if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) { @@ -96,10 +95,12 @@ * For example, if an exception was thrown in a function and when the function's * local variable destruction results in a destructor being called. */ - old_exception = EG(exception); - EG(exception) = NULL; + if (EG(exception) && Z_OBJ_HANDLE_P(EG(exception)) == handle) { + zend_error(E_ERROR, "Attempt to destruct pending exception"); + } + zend_exception_save(TSRMLS_C); zend_call_method_with_0_params(&obj, object->ce, &destructor, ZEND_DESTRUCTOR_FUNC_NAME, NULL); - zend_exception_set_previous(old_exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); zval_ptr_dtor(&obj); } } http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.59.2.29.2.48.2.67&r2=1.59.2.29.2.48.2.68&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.67 ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.68 --- ZendEngine2/zend_vm_def.h:1.59.2.29.2.48.2.67 Wed Aug 13 07:21:23 2008 +++ ZendEngine2/zend_vm_def.h Thu Aug 14 10:24:51 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.67 2008/08/13 07:21:23 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.59.2.29.2.48.2.68 2008/08/14 10:24:51 helly Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -2515,6 +2515,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -2523,6 +2524,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); FREE_OP1_IF_VAR(); ZEND_VM_NEXT_OPCODE(); } @@ -2533,6 +2535,7 @@ zend_class_entry *ce; /* Check whether an exception has been thrown, if not, jump over code */ + zend_exception_restore(TSRMLS_C); if (EG(exception) == NULL) { ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]); ZEND_VM_CONTINUE(); /* CHECK_ME */ http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.62.2.30.2.49.2.67&r2=1.62.2.30.2.49.2.68&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.67 ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.68 --- ZendEngine2/zend_vm_execute.h:1.62.2.30.2.49.2.67 Wed Aug 13 07:21:23 2008 +++ ZendEngine2/zend_vm_execute.h Thu Aug 14 10:24:52 2008 @@ -1228,6 +1228,7 @@ zend_class_entry *ce; /* Check whether an exception has been thrown, if not, jump over code */ + zend_exception_restore(TSRMLS_C); if (EG(exception) == NULL) { ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[opline->extended_value]); ZEND_VM_CONTINUE(); /* CHECK_ME */ @@ -1655,6 +1656,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -1663,6 +1665,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); } @@ -4936,6 +4939,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -4944,6 +4948,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); } @@ -8121,6 +8126,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -8129,6 +8135,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; ZEND_VM_NEXT_OPCODE(); } @@ -22193,6 +22200,7 @@ if (Z_TYPE_P(value) != IS_OBJECT) { zend_error_noreturn(E_ERROR, "Can only throw objects"); } + zend_exception_save(TSRMLS_C); /* Not sure if a complete copy is what we want here */ ALLOC_ZVAL(exception); INIT_PZVAL_COPY(exception, value); @@ -22201,6 +22209,7 @@ } zend_throw_exception_object(exception TSRMLS_CC); + zend_exception_restore(TSRMLS_C); ZEND_VM_NEXT_OPCODE(); }