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 #ifdef __cplusplus |
|
62 class |
|
63 octave_interrupt_exception |
|
64 { |
|
65 }; |
|
66 #endif |
|
67 |
4180
|
68 extern sig_atomic_t octave_interrupt_immediately; |
4153
|
69 |
4180
|
70 extern sig_atomic_t octave_interrupt_state; |
|
71 |
|
72 extern sig_atomic_t octave_allocation_error; |
4153
|
73 |
|
74 extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN; |
|
75 |
4180
|
76 extern void octave_throw_bad_alloc (void) GCC_ATTR_NORETURN; |
|
77 |
4153
|
78 #define OCTAVE_QUIT \ |
|
79 do \ |
|
80 { \ |
|
81 if (octave_interrupt_state) \ |
|
82 { \ |
|
83 octave_interrupt_state = 0; \ |
|
84 octave_throw_interrupt_exception (); \ |
|
85 } \ |
|
86 } \ |
|
87 while (0) |
|
88 |
|
89 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
|
90 do \ |
|
91 { \ |
4182
|
92 octave_jmp_buf saved_context; \ |
4153
|
93 \ |
|
94 octave_save_current_context ((char *) saved_context); \ |
|
95 \ |
|
96 if (octave_set_current_context) \ |
|
97 { \ |
|
98 octave_restore_current_context ((char *) saved_context); \ |
4182
|
99 octave_throw_interrupt_exception (); \ |
4153
|
100 } \ |
|
101 else \ |
|
102 { \ |
4182
|
103 octave_interrupt_immediately++ |
4153
|
104 |
|
105 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
4182
|
106 octave_interrupt_immediately--; \ |
4153
|
107 octave_restore_current_context ((char *) saved_context); \ |
|
108 } \ |
|
109 } \ |
|
110 while (0) |
|
111 |
4180
|
112 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \ |
4182
|
113 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \ |
4180
|
114 \ |
4182
|
115 try \ |
4180
|
116 { \ |
4182
|
117 octave_interrupt_immediately = 0; |
4180
|
118 |
|
119 #define END_INTERRUPT_WITH_EXCEPTIONS \ |
|
120 } \ |
4182
|
121 catch (octave_interrupt_exception) \ |
4180
|
122 { \ |
4182
|
123 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
4180
|
124 octave_jump_to_enclosing_context (); \ |
|
125 } \ |
4181
|
126 catch (std::bad_alloc) \ |
4180
|
127 { \ |
4182
|
128 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
4180
|
129 octave_allocation_error = 1; \ |
|
130 octave_jump_to_enclosing_context (); \ |
|
131 } \ |
|
132 \ |
4182
|
133 octave_interrupt_immediately = saved_octave_interrupt_immediately |
4153
|
134 |
|
135 #ifdef __cplusplus |
|
136 } |
|
137 #endif |
|
138 |
|
139 #endif |
|
140 |
|
141 /* |
|
142 ;;; Local Variables: *** |
|
143 ;;; mode: C++ *** |
|
144 ;;; End: *** |
|
145 */ |