00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_quit_h)
00024 #define octave_quit_h 1
00025
00026 #ifdef __cplusplus
00027 #include <new>
00028 extern "C" {
00029 #endif
00030
00031 #include <stdio.h>
00032
00033 #include <signal.h>
00034 #include <setjmp.h>
00035
00036 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
00037
00038 #include <windows.h>
00039 #undef min
00040 #undef max
00041
00042 CRUFT_API extern void w32_sigint_init (void);
00043 CRUFT_API extern void w32_raise_final (void);
00044 CRUFT_API extern void w32_raise (int sig);
00045 CRUFT_API extern int w32_in_main_thread (void);
00046
00047 #endif
00048
00049 #if defined (OCTAVE_HAVE_SIG_JUMP)
00050
00051 typedef sigjmp_buf octave_jmp_buf;
00052
00053 #define octave_set_current_context sigsetjmp (current_context, 1)
00054
00055 #else
00056
00057 typedef jmp_buf octave_jmp_buf;
00058
00059 #define octave_set_current_context setjmp (current_context)
00060
00061 #endif
00062
00063 CRUFT_API extern octave_jmp_buf current_context;
00064
00065 CRUFT_API extern void octave_save_current_context (void *);
00066
00067 CRUFT_API extern void octave_restore_current_context (void *);
00068
00069 CRUFT_API extern void octave_jump_to_enclosing_context (void) GCC_ATTR_NORETURN;
00070
00071 CRUFT_API extern void octave_save_signal_mask (void);
00072
00073 CRUFT_API extern void octave_restore_signal_mask (void);
00074
00075 #ifdef __cplusplus
00076 class
00077 octave_execution_exception
00078 {
00079 };
00080
00081 class
00082 octave_interrupt_exception
00083 {
00084 };
00085 #endif
00086
00087 enum octave_exception
00088 {
00089 octave_no_exception = 0,
00090 octave_exec_exception = 1,
00091 octave_alloc_exception = 2
00092 };
00093
00094 CRUFT_API extern sig_atomic_t octave_interrupt_immediately;
00095
00096
00097
00098
00099
00100
00101 CRUFT_API extern sig_atomic_t octave_interrupt_state;
00102
00103 CRUFT_API extern sig_atomic_t octave_exception_state;
00104
00105 CRUFT_API extern volatile sig_atomic_t octave_signal_caught;
00106
00107 CRUFT_API extern void octave_handle_signal (void);
00108
00109 CRUFT_API extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN;
00110
00111 CRUFT_API extern void octave_throw_execution_exception (void) GCC_ATTR_NORETURN;
00112
00113 CRUFT_API extern void octave_throw_bad_alloc (void) GCC_ATTR_NORETURN;
00114
00115 CRUFT_API extern void octave_rethrow_exception (void);
00116
00117 #define OCTAVE_QUIT \
00118 do \
00119 { \
00120 if (octave_signal_caught) \
00121 { \
00122 octave_signal_caught = 0; \
00123 octave_handle_signal (); \
00124 } \
00125 } \
00126 while (0)
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
00145 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \
00146 octave_rethrow_exception (); \
00147 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2
00148
00149 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1 \
00150 do \
00151 { \
00152 octave_jmp_buf saved_context; \
00153 \
00154 octave_save_current_context (saved_context); \
00155 \
00156 if (octave_set_current_context) \
00157 { \
00158 octave_restore_current_context (saved_context)
00159
00160 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 \
00161 } \
00162 else \
00163 { \
00164 octave_interrupt_immediately++
00165
00166 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
00167 octave_interrupt_immediately--; \
00168 octave_restore_current_context (saved_context); \
00169 } \
00170 } \
00171 while (0)
00172
00173 #ifdef __cplusplus
00174
00175 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \
00176 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \
00177 \
00178 try \
00179 { \
00180 octave_interrupt_immediately = 0;
00181
00182 #define END_INTERRUPT_WITH_EXCEPTIONS \
00183 } \
00184 catch (octave_interrupt_exception) \
00185 { \
00186 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00187 octave_jump_to_enclosing_context (); \
00188 } \
00189 catch (octave_execution_exception) \
00190 { \
00191 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00192 octave_exception_state = octave_exec_exception; \
00193 octave_jump_to_enclosing_context (); \
00194 } \
00195 catch (std::bad_alloc) \
00196 { \
00197 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00198 octave_exception_state = octave_alloc_exception; \
00199 octave_jump_to_enclosing_context (); \
00200 } \
00201 \
00202 octave_interrupt_immediately = saved_octave_interrupt_immediately
00203 #endif
00204
00205 #ifdef __cplusplus
00206 }
00207
00208
00209
00210
00211 extern CRUFT_API void (*octave_signal_hook) (void);
00212 extern CRUFT_API void (*octave_interrupt_hook) (void);
00213 extern CRUFT_API void (*octave_bad_alloc_hook) (void);
00214
00215 #endif
00216
00217 #endif
00218
00219
00220
00221
00222
00223