@@ -1928,39 +1928,38 @@ ZEND_API ZEND_COLD void zend_output_debug_string(bool trigger_break, const char
19281928
19291929ZEND_API ZEND_COLD void zend_user_exception_handler (void ) /* {{{ */
19301930{
1931- zval orig_user_exception_handler ;
1932- zval params [1 ], retval2 ;
1933- zend_object * old_exception ;
1934-
19351931 if (zend_is_unwind_exit (EG (exception ))) {
19361932 return ;
19371933 }
19381934
1939- old_exception = EG (exception );
1935+ zend_object * old_exception = EG (exception );
19401936 EG (exception ) = NULL ;
1937+
1938+ zval params [1 ];
19411939 ZVAL_OBJ (& params [0 ], old_exception );
19421940
1943- ZVAL_COPY_VALUE ( & orig_user_exception_handler , & EG (user_exception_handler ) );
1944- zend_stack_push ( & EG ( user_exception_handlers ), & orig_user_exception_handler );
1945- ZVAL_UNDEF ( & EG (user_exception_handler ));
1941+ zend_fcall_info_cache fcc = EG (user_exception_handler );
1942+ /* Push the current handler on the stack and set the current one to the default handler to prevent recursion */
1943+ zend_stack_push ( & EG ( user_exception_handlers ), & EG (user_exception_handler ));
19461944
1947- if (call_user_function (CG (function_table ), NULL , & orig_user_exception_handler , & retval2 , 1 , params ) == SUCCESS ) {
1948- zval_ptr_dtor (& retval2 );
1949- if (EG (exception )) {
1950- OBJ_RELEASE (EG (exception ));
1951- EG (exception ) = NULL ;
1952- }
1953- OBJ_RELEASE (old_exception );
1954- } else {
1955- EG (exception ) = old_exception ;
1945+ int current_stack_position = zend_stack_count (& EG (user_exception_handlers ));
1946+
1947+ EG (user_exception_handler ) = empty_fcall_info_cache ;
1948+
1949+ zend_call_known_fcc (& fcc , NULL , 1 , params , NULL );
1950+ if (EG (exception )) {
1951+ OBJ_RELEASE (EG (exception ));
1952+ EG (exception ) = NULL ;
19561953 }
1954+ OBJ_RELEASE (old_exception );
19571955
1958- if (Z_TYPE (EG (user_exception_handler )) == IS_UNDEF ) {
1959- zval * tmp = zend_stack_top (& EG (user_exception_handlers ));
1960- if (tmp ) {
1961- ZVAL_COPY_VALUE (& EG (user_exception_handler ), tmp );
1962- zend_stack_del_top (& EG (user_exception_handlers ));
1963- }
1956+ if (
1957+ current_stack_position == zend_stack_count (& EG (user_exception_handlers ))
1958+ && !ZEND_FCC_INITIALIZED (EG (user_exception_handler ))
1959+ ) {
1960+ const zend_fcall_info_cache * tmp = zend_stack_top (& EG (user_exception_handlers ));
1961+ EG (user_exception_handler ) = * tmp ;
1962+ zend_stack_del_top (& EG (user_exception_handlers ));
19641963 }
19651964} /* }}} */
19661965
@@ -1975,7 +1974,7 @@ ZEND_API zend_result zend_execute_script(int type, zval *retval, zend_file_handl
19751974 if (op_array ) {
19761975 zend_execute (op_array , retval );
19771976 if (UNEXPECTED (EG (exception ))) {
1978- if (Z_TYPE (EG (user_exception_handler )) != IS_UNDEF ) {
1977+ if (ZEND_FCC_INITIALIZED (EG (user_exception_handler ))) {
19791978 zend_user_exception_handler ();
19801979 }
19811980 if (EG (exception )) {
0 commit comments