Mercurial > octave
annotate liboctave/cruft/misc/quit.h @ 22094:9203833cab7d
move new interpreter class to separate file
* libinterp/corefcn/interpreter.cc, libinterp/corefcn/interpreter.h:
New files. Move interpreter class and some supporting functions here
from octave.h, octave.cc, toplev.h, and toplev.cc. Move main_loop
into the interpreter class. Handle exiting with a separate exception
object from interrupts, passing the exit status with the object.
Update other files as needed to remove toplev.h or include
interpreter.h instead of toplev.h.
* libinterp/corefcn/module.mk: Update.
* toplev.h: Deprecate.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Jul 2016 18:05:53 -0400 |
parents | baeffde5c87d |
children | e43d83253e28 |
rev | line source |
---|---|
4153 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19082
diff
changeset
|
3 Copyright (C) 2002-2015 John W. Eaton |
4153 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4153 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4153 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20785
diff
changeset
|
23 #if ! defined (octave_quit_h) |
4153 | 24 #define octave_quit_h 1 |
25 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21227
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21227
diff
changeset
|
27 |
19082
96df707c7dad
Do not include system header files in extern "C" block (bug #43171)
Johannes Zarl <johannes.zarl@jku.at>
parents:
17744
diff
changeset
|
28 #include <setjmp.h> |
96df707c7dad
Do not include system header files in extern "C" block (bug #43171)
Johannes Zarl <johannes.zarl@jku.at>
parents:
17744
diff
changeset
|
29 |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21849
diff
changeset
|
30 /* The signal header is just needed for the sig_atomic_t type. */ |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
31 #if defined (__cplusplus) |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21849
diff
changeset
|
32 # include <csignal> |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
33 # include <string> |
4153 | 34 extern "C" { |
21941
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21849
diff
changeset
|
35 #else |
1d23b75cbcd1
hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents:
21849
diff
changeset
|
36 # include <signal.h> |
4153 | 37 #endif |
38 | |
4180 | 39 #if defined (OCTAVE_HAVE_SIG_JUMP) |
40 | |
41 typedef sigjmp_buf octave_jmp_buf; | |
42 | |
43 #define octave_set_current_context sigsetjmp (current_context, 1) | |
44 | |
45 #else | |
46 | |
47 typedef jmp_buf octave_jmp_buf; | |
48 | |
49 #define octave_set_current_context setjmp (current_context) | |
50 | |
51 #endif | |
52 | |
21227 | 53 OCTAVE_API extern octave_jmp_buf current_context; |
4153 | 54 |
21227 | 55 OCTAVE_API extern void octave_save_current_context (void *); |
4153 | 56 |
21227 | 57 OCTAVE_API extern void octave_restore_current_context (void *); |
4153 | 58 |
21227 | 59 OCTAVE_NORETURN OCTAVE_API extern void octave_jump_to_enclosing_context (void); |
4153 | 60 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
61 #if defined (__cplusplus) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
62 |
4153 | 63 class |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
64 octave_execution_exception |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
65 { |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
66 public: |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
67 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
68 octave_execution_exception (void) : m_stack_trace () { } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
69 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
70 octave_execution_exception (const octave_execution_exception& x) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
71 : m_stack_trace (x.m_stack_trace) { } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
72 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
73 octave_execution_exception& operator = (const octave_execution_exception& x) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
74 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
75 if (&x != this) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
76 m_stack_trace = x.m_stack_trace; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
77 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
78 return *this; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
79 } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
80 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
81 ~octave_execution_exception (void) { } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
82 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
83 virtual void set_stack_trace (const std::string& st) |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
84 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
85 m_stack_trace = st; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
86 } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
87 |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
88 virtual void set_stack_trace (void) |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
89 { |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
90 m_stack_trace = ""; |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
91 } |
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
92 |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
93 virtual std::string info (void) const |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
94 { |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
95 return m_stack_trace; |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
96 } |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
97 |
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
98 private: |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20666
diff
changeset
|
99 |
20666
e0e2c2ce7e94
defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
100 std::string m_stack_trace; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 }; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 class |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
104 octave_exit_exception |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
105 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
106 public: |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
107 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
108 octave_exit_exception (int exit_status = 0, bool safe_to_return = false) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
109 : m_exit_status (exit_status), m_safe_to_return (safe_to_return) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
110 { } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
111 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
112 octave_exit_exception (const octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
113 : m_exit_status (ex.m_exit_status), m_safe_to_return (ex.m_safe_to_return) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
114 { } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
115 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
116 octave_exit_exception& operator = (octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
117 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
118 if (this != &ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
119 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
120 m_exit_status = ex.m_exit_status; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
121 m_safe_to_return = ex.m_safe_to_return; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
122 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
123 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
124 return *this; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
125 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
126 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
127 ~octave_exit_exception (void) { } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
128 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
129 int exit_status (void) const { return m_exit_status; } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
130 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
131 bool safe_to_return (void) const { return m_safe_to_return; } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
132 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
133 private: |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
134 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
135 int m_exit_status; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
136 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
137 bool m_safe_to_return; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
138 }; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
139 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
140 class |
4153 | 141 octave_interrupt_exception |
142 { | |
143 }; | |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
144 |
4153 | 145 #endif |
146 | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
147 enum octave_exception |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
148 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
149 octave_no_exception = 0, |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
150 octave_exec_exception = 1, |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
151 octave_alloc_exception = 3, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
152 octave_quit_exception = 4 |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
153 }; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
154 |
21227 | 155 OCTAVE_API extern sig_atomic_t octave_interrupt_immediately; |
4153 | 156 |
5133 | 157 /* |
158 > 0: interrupt pending | |
159 0: no interrupt pending | |
160 < 0: handling interrupt | |
161 */ | |
21227 | 162 OCTAVE_API extern sig_atomic_t octave_interrupt_state; |
4180 | 163 |
21227 | 164 OCTAVE_API extern sig_atomic_t octave_exception_state; |
4153 | 165 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
166 OCTAVE_API extern sig_atomic_t octave_exit_exception_status; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
167 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
168 OCTAVE_API extern sig_atomic_t octave_exit_exception_safe_to_return; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
169 |
21227 | 170 OCTAVE_API extern volatile sig_atomic_t octave_signal_caught; |
5142 | 171 |
21227 | 172 OCTAVE_API extern void octave_handle_signal (void); |
5142 | 173 |
21227 | 174 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_interrupt_exception (void); |
4153 | 175 |
21227 | 176 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_execution_exception (void); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
177 |
21227 | 178 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_bad_alloc (void); |
4180 | 179 |
21227 | 180 OCTAVE_API extern void octave_rethrow_exception (void); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
181 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
182 #if defined (__cplusplus) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
183 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
184 extern OCTAVE_API void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
185 clean_up_and_exit (int exit_status, bool safe_to_return = false); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
186 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
187 inline void octave_quit (void) |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
188 { |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
189 if (octave_signal_caught) |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
190 { |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
191 octave_signal_caught = 0; |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
192 octave_handle_signal (); |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
193 } |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
194 }; |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
195 |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
196 #define OCTAVE_QUIT octave_quit () |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
197 |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
198 #else |
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
199 |
4153 | 200 #define OCTAVE_QUIT \ |
201 do \ | |
202 { \ | |
5142 | 203 if (octave_signal_caught) \ |
4153 | 204 { \ |
5142 | 205 octave_signal_caught = 0; \ |
206 octave_handle_signal (); \ | |
4153 | 207 } \ |
208 } \ | |
209 while (0) | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
210 #endif |
4153 | 211 |
4302 | 212 /* Normally, you just want to use |
213 | |
214 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
215 ... some code that calls a "foreign" function ... | |
216 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
217 | |
218 but sometimes it is useful to do something like | |
219 | |
220 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; | |
221 ... custom code here, normally ending in a call to | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
222 octave_rethrow_exception ... |
4302 | 223 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2; |
224 | |
225 so that you can perform extra clean up operations before throwing | |
226 the interrupt exception. */ | |
227 | |
4153 | 228 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
4302 | 229 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \ |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
230 octave_rethrow_exception (); \ |
4302 | 231 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 |
232 | |
233 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1 \ | |
4153 | 234 do \ |
235 { \ | |
4182 | 236 octave_jmp_buf saved_context; \ |
4153 | 237 \ |
5760 | 238 octave_save_current_context (saved_context); \ |
4153 | 239 \ |
240 if (octave_set_current_context) \ | |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
241 { \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
242 octave_restore_current_context (saved_context) |
4302 | 243 |
244 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 \ | |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
245 } \ |
4153 | 246 else \ |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
247 { \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
248 octave_interrupt_immediately++ |
4153 | 249 |
250 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ | |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8928
diff
changeset
|
251 octave_interrupt_immediately--; \ |
5760 | 252 octave_restore_current_context (saved_context); \ |
4153 | 253 } \ |
254 } \ | |
255 while (0) | |
256 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
257 #if defined (__cplusplus) |
4196 | 258 |
4180 | 259 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \ |
4182 | 260 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \ |
4180 | 261 \ |
4182 | 262 try \ |
4180 | 263 { \ |
4182 | 264 octave_interrupt_immediately = 0; |
4180 | 265 |
266 #define END_INTERRUPT_WITH_EXCEPTIONS \ | |
267 } \ | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
268 catch (const octave_interrupt_exception&) \ |
4180 | 269 { \ |
4182 | 270 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
4180 | 271 octave_jump_to_enclosing_context (); \ |
272 } \ | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
273 catch (const octave_execution_exception&) \ |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
274 { \ |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
275 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
276 octave_exception_state = octave_exec_exception; \ |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
277 octave_jump_to_enclosing_context (); \ |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
278 } \ |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
279 catch (const std::bad_alloc&) \ |
4180 | 280 { \ |
4182 | 281 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
282 octave_exception_state = octave_alloc_exception; \ |
4180 | 283 octave_jump_to_enclosing_context (); \ |
284 } \ | |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
285 catch (const octave_exit_exception& ex) \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
286 { \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
287 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
288 octave_exception_state = octave_quit_exception; \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
289 octave_exit_exception_status = ex.exit_status (); \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
290 octave_exit_exception_safe_to_return = ex.safe_to_return (); \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
291 octave_jump_to_enclosing_context (); \ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
292 } \ |
4180 | 293 \ |
4182 | 294 octave_interrupt_immediately = saved_octave_interrupt_immediately |
4196 | 295 #endif |
4153 | 296 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
297 #if defined (__cplusplus) |
4153 | 298 } |
4560 | 299 |
4572 | 300 /* These should only be declared for C++ code, and should also be |
301 outside of any extern "C" block. */ | |
4560 | 302 |
21227 | 303 extern OCTAVE_API void (*octave_signal_hook) (void); |
304 extern OCTAVE_API void (*octave_interrupt_hook) (void); | |
305 extern OCTAVE_API void (*octave_bad_alloc_hook) (void); | |
4560 | 306 |
4153 | 307 #endif |
308 | |
309 #endif |