diff options
-rw-r--r-- | Zend/zend_exceptions.h | 8 | ||||
-rw-r--r-- | Zend/zend_execute_API.c | 10 | ||||
-rw-r--r-- | Zend/zend_generators.c | 16 | ||||
-rw-r--r-- | Zend/zend_vm_def.h | 22 | ||||
-rw-r--r-- | Zend/zend_vm_execute.h | 40 |
5 files changed, 50 insertions, 46 deletions
diff --git a/Zend/zend_exceptions.h b/Zend/zend_exceptions.h index 18caf35553..71dcc8d172 100644 --- a/Zend/zend_exceptions.h +++ b/Zend/zend_exceptions.h @@ -72,6 +72,14 @@ ZEND_API ZEND_COLD void zend_exception_error(zend_object *exception, int severit size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 3, 4); zend_string *zend_strpprintf(size_t max_len, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); +static zend_always_inline void zend_rethrow_exception(zend_execute_data *execute_data) +{ + if (EX(opline)->opcode != ZEND_HANDLE_EXCEPTION) { + EG(opline_before_exception) = EX(opline); + EX(opline) = EG(exception_op); + } +} + END_EXTERN_C() #endif diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index c01a807e55..a4a1d3f4da 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -899,9 +899,15 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / EG(current_execute_data) = dummy_execute_data.prev_execute_data; } - if (EG(exception)) { - zend_throw_exception_internal(NULL); + if (UNEXPECTED(EG(exception))) { + if (UNEXPECTED(!EG(current_execute_data))) { + zend_throw_exception_internal(NULL); + } else if (EG(current_execute_data)->func && + ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { + zend_rethrow_exception(EG(current_execute_data)); + } } + return SUCCESS; } /* }}} */ diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index ae55c3ec24..970e1d743f 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -425,7 +425,7 @@ static void zend_generator_throw_exception(zend_generator *generator, zval *exce if (exception) { zend_throw_exception_object(exception); } else { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(EG(current_execute_data)); } generator->execute_data->opline++; EG(current_execute_data) = original_execute_data; @@ -741,12 +741,8 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /* } return SUCCESS; -exception: { - zend_execute_data *ex = EG(current_execute_data); - EG(current_execute_data) = generator->execute_data; - zend_throw_exception_internal(NULL); - EG(current_execute_data) = ex; - } +exception: + zend_rethrow_exception(generator->execute_data); failure: zval_ptr_dtor(&generator->values); @@ -834,7 +830,11 @@ try_again: if (UNEXPECTED(EG(exception) != NULL)) { if (generator == orig_generator) { zend_generator_close(generator, 0); - zend_throw_exception_internal(NULL); + if (EG(current_execute_data) && + EG(current_execute_data)->func && + ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { + zend_rethrow_exception(EG(current_execute_data)); + } } else { generator = zend_generator_get_current(orig_generator); zend_generator_throw_exception(generator, NULL); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c1cb3022c7..e278abb0f5 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2452,7 +2452,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) execute_data = EX(prev_execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -2486,7 +2486,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) zend_vm_stack_free_call_frame_ex(call_info, old_execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -2502,7 +2502,7 @@ ZEND_VM_HELPER(zend_leave_helper, ANY, ANY) zend_attach_symbol_table(execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -3524,7 +3524,7 @@ ZEND_VM_HANDLER(129, ZEND_DO_ICALL, ANY, ANY, SPEC(RETVAL)) } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -3596,7 +3596,7 @@ ZEND_VM_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL)) if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && UNEXPECTED(!zend_verify_internal_arg_types(fbc, call))) { zend_vm_stack_free_call_frame(call); - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -3625,7 +3625,7 @@ ZEND_VM_HANDLER(131, ZEND_DO_FCALL_BY_NAME, ANY, ANY, SPEC(RETVAL)) } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } ZEND_VM_SET_OPCODE(opline + 1); @@ -3749,7 +3749,7 @@ ZEND_VM_C_LABEL(fcall_end): zend_vm_stack_free_call_frame(call); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -4116,7 +4116,7 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV, JMP_ADDR) if (ce != catch_ce) { if (!catch_ce || !instanceof_function(ce, catch_ce)) { if (opline->result.num) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); @@ -5343,7 +5343,7 @@ ZEND_VM_HANDLER(73, ZEND_INCLUDE_OR_EVAL, CONST|TMPVAR|CV, ANY, EVAL) destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -5662,7 +5662,6 @@ ZEND_VM_HANDLER(77, ZEND_FE_RESET_R, CONST|TMP|VAR|CV, JMP_ADDR) if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -5824,7 +5823,6 @@ ZEND_VM_HANDLER(125, ZEND_FE_RESET_RW, CONST|TMP|VAR|CV, JMP_ADDR) if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -7938,7 +7936,7 @@ ZEND_VM_C_LABEL(call_trampoline_end): zend_vm_stack_free_call_frame(call); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 6d1cd22028..35f0709355 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -502,7 +502,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_ execute_data = EX(prev_execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -536,7 +536,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_ zend_vm_stack_free_call_frame_ex(call_info, old_execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -552,7 +552,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper_SPEC(ZEND_OPCODE_ zend_attach_symbol_table(execute_data); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -636,7 +636,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HA } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -680,7 +680,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_ICALL_SPEC_RETVAL_USED_HAND } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -774,7 +774,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_U if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && UNEXPECTED(!zend_verify_internal_arg_types(fbc, call))) { zend_vm_stack_free_call_frame(call); - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -803,7 +803,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_U } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } ZEND_VM_SET_OPCODE(opline + 1); @@ -852,7 +852,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_U if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_HAS_TYPE_HINTS) && UNEXPECTED(!zend_verify_internal_arg_types(fbc, call))) { zend_vm_stack_free_call_frame(call); - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -881,7 +881,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_DO_FCALL_BY_NAME_SPEC_RETVAL_U } if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } ZEND_VM_SET_OPCODE(opline + 1); @@ -1005,7 +1005,7 @@ fcall_end: zend_vm_stack_free_call_frame(call); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -1130,7 +1130,7 @@ fcall_end: zend_vm_stack_free_call_frame(call); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } @@ -2048,7 +2048,7 @@ call_trampoline_end: zend_vm_stack_free_call_frame(call); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION_LEAVE(); } @@ -3463,7 +3463,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HAN destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -3545,7 +3545,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CONST_HANDLER( if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -3704,7 +3703,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CONST_HANDLER if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -9668,7 +9666,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CATCH_SPEC_CONST_CV_HANDLER(ZE if (ce != catch_ce) { if (!catch_ce || !instanceof_function(ce, catch_ce)) { if (opline->result.num) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); HANDLE_EXCEPTION(); } ZEND_VM_SET_RELATIVE_OPCODE(opline, opline->extended_value); @@ -12937,7 +12935,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_TMP_HANDLER(ZE if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -13097,7 +13094,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_TMP_HANDLER(Z if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -16550,7 +16546,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_VAR_HANDLER(ZE if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -16712,7 +16707,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_VAR_HANDLER(Z if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -33793,7 +33787,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLE destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } @@ -33875,7 +33869,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_R_SPEC_CV_HANDLER(ZEN if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -34034,7 +34027,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_RESET_RW_SPEC_CV_HANDLER(ZE if (!EG(exception)) { zend_throw_exception_ex(NULL, 0, "Object of type %s did not create an Iterator", ZSTR_VAL(ce->name)); } - zend_throw_exception_internal(NULL); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -48570,7 +48562,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INCLUDE_OR_EVAL_SPEC_TMPVAR_HA destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); if (UNEXPECTED(EG(exception) != NULL)) { - zend_throw_exception_internal(NULL); + zend_rethrow_exception(execute_data); UNDEF_RESULT(); HANDLE_EXCEPTION(); } |