4153
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_quit_h) |
|
24 #define octave_quit_h 1 |
|
25 |
|
26 #ifdef __cplusplus |
|
27 extern "C" { |
|
28 #endif |
|
29 |
4180
|
30 #include <stdio.h> |
4153
|
31 |
4180
|
32 #include <signal.h> |
4153
|
33 #include <setjmp.h> |
|
34 |
4180
|
35 #if defined (OCTAVE_HAVE_SIG_JUMP) |
|
36 |
|
37 typedef sigjmp_buf octave_jmp_buf; |
|
38 |
|
39 #define octave_set_current_context sigsetjmp (current_context, 1) |
|
40 |
|
41 #else |
|
42 |
|
43 typedef jmp_buf octave_jmp_buf; |
|
44 |
|
45 #define octave_set_current_context setjmp (current_context) |
|
46 |
|
47 #endif |
|
48 |
|
49 extern octave_jmp_buf current_context; |
4153
|
50 |
|
51 extern void octave_save_current_context (void *); |
|
52 |
|
53 extern void octave_restore_current_context (void *); |
|
54 |
|
55 extern void octave_jump_to_enclosing_context (void) GCC_ATTR_NORETURN; |
|
56 |
|
57 extern void octave_save_signal_mask (void); |
|
58 |
|
59 extern void octave_restore_signal_mask (void); |
|
60 |
|
61 #if defined (USE_EXCEPTIONS_FOR_INTERRUPTS) |
|
62 |
|
63 #ifdef __cplusplus |
|
64 class |
|
65 octave_interrupt_exception |
|
66 { |
|
67 }; |
|
68 #endif |
|
69 |
4180
|
70 extern sig_atomic_t octave_interrupt_immediately; |
4153
|
71 |
4180
|
72 extern sig_atomic_t octave_interrupt_state; |
|
73 |
|
74 extern sig_atomic_t octave_allocation_error; |
4153
|
75 |
|
76 extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN; |
|
77 |
4180
|
78 extern void octave_throw_bad_alloc (void) GCC_ATTR_NORETURN; |
|
79 |
4153
|
80 #define OCTAVE_QUIT \ |
|
81 do \ |
|
82 { \ |
|
83 if (octave_interrupt_state) \ |
|
84 { \ |
|
85 octave_interrupt_state = 0; \ |
|
86 octave_throw_interrupt_exception (); \ |
|
87 } \ |
|
88 } \ |
|
89 while (0) |
|
90 |
|
91 #define OCTAVE_JUMP_TO_TOP_LEVEL \ |
|
92 do { octave_interrupt_state = 1; } while (0) |
|
93 |
|
94 #define OCTAVE_THROW_TO_TOP_LEVEL octave_throw_interrupt_exception () |
|
95 |
4180
|
96 #define OCTAVE_THROW_BAD_ALLOC octave_throw_bad_alloc () |
|
97 |
4153
|
98 #define OCTAVE_TRY_WITH_INTERRUPTS try |
|
99 |
|
100 #define OCTAVE_CATCH_INTERRUPTS catch (octave_interrupt_exception) |
|
101 |
4180
|
102 #define SAVE_OCTAVE_INTERRUPT_IMMEDIATELY(var) \ |
|
103 sig_atomic_t var = octave_interrupt_immediately |
|
104 |
4155
|
105 #define INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY \ |
|
106 do { octave_interrupt_immediately++; } while (0) |
|
107 |
|
108 #define DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY \ |
|
109 do { octave_interrupt_immediately--; } while (0) |
|
110 |
|
111 #define SET_OCTAVE_INTERRUPT_IMMEDIATELY(x) \ |
|
112 do { octave_interrupt_immediately = x; } while (0) |
|
113 |
4153
|
114 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
|
115 do \ |
|
116 { \ |
|
117 jmp_buf saved_context; \ |
|
118 \ |
|
119 octave_save_current_context ((char *) saved_context); \ |
|
120 \ |
|
121 if (octave_set_current_context) \ |
|
122 { \ |
|
123 octave_restore_current_context ((char *) saved_context); \ |
|
124 OCTAVE_THROW_TO_TOP_LEVEL; \ |
|
125 } \ |
|
126 else \ |
|
127 { \ |
4155
|
128 INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY |
4153
|
129 |
|
130 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
4155
|
131 DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY; \ |
4153
|
132 octave_restore_current_context ((char *) saved_context); \ |
|
133 } \ |
|
134 } \ |
|
135 while (0) |
|
136 |
4180
|
137 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \ |
|
138 SAVE_OCTAVE_INTERRUPT_IMMEDIATELY (saved_octave_interrupt_immediately); \ |
|
139 \ |
|
140 OCTAVE_TRY_WITH_INTERRUPTS \ |
|
141 { \ |
|
142 SET_OCTAVE_INTERRUPT_IMMEDIATELY (0) |
|
143 |
|
144 #define END_INTERRUPT_WITH_EXCEPTIONS \ |
|
145 } \ |
|
146 OCTAVE_CATCH_INTERRUPTS \ |
|
147 { \ |
|
148 SET_OCTAVE_INTERRUPT_IMMEDIATELY (saved_octave_interrupt_immediately); \ |
|
149 octave_jump_to_enclosing_context (); \ |
|
150 } \ |
4181
|
151 catch (std::bad_alloc) \ |
4180
|
152 { \ |
|
153 SET_OCTAVE_INTERRUPT_IMMEDIATELY (saved_octave_interrupt_immediately); \ |
|
154 octave_allocation_error = 1; \ |
|
155 octave_jump_to_enclosing_context (); \ |
|
156 } \ |
|
157 \ |
|
158 SET_OCTAVE_INTERRUPT_IMMEDIATELY (saved_octave_interrupt_immediately) |
|
159 |
4153
|
160 #else |
|
161 |
|
162 #define OCTAVE_QUIT do { } while (0) |
|
163 |
|
164 #define OCTAVE_JUMP_TO_TOP_LEVEL octave_jump_to_enclosing_context () |
|
165 |
|
166 #define OCTAVE_THROW_TO_TOP_LEVEL OCTAVE_JUMP_TO_TOP_LEVEL |
|
167 |
4180
|
168 #define OCTAVE_THROW_BAD_ALLOC OCTAVE_JUMP_TO_TOP_LEVEL |
|
169 |
4153
|
170 #define OCTAVE_TRY_WITH_INTERRUPTS |
|
171 |
|
172 #define OCTAVE_CATCH_INTERRUPTS if (0) |
|
173 |
4180
|
174 #define SAVE_OCTAVE_INTERRUPT_IMMEDIATELY(var) do { } while (0) |
|
175 |
|
176 #define SET_OCTAVE_INTERRUPT_IMMEDIATELY(x) do { } while (0) |
|
177 |
4155
|
178 #define INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY do { } while (0) |
|
179 |
|
180 #define DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY do { } while (0) |
|
181 |
4153
|
182 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0) |
|
183 |
|
184 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0) |
|
185 |
4180
|
186 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS do { } while (0) |
|
187 |
|
188 #define END_INTERRUPT_WITH_EXCEPTIONS do { } while (0) |
|
189 |
4153
|
190 #endif |
|
191 |
|
192 #ifdef __cplusplus |
|
193 } |
|
194 #endif |
|
195 |
|
196 #endif |
|
197 |
|
198 /* |
|
199 ;;; Local Variables: *** |
|
200 ;;; mode: C++ *** |
|
201 ;;; End: *** |
|
202 */ |