Mercurial > octave
annotate liboctave/util/quit.cc @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | aef11bb4e6d1 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 2002-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4153 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
4153 | 28 #endif |
29 | |
4154 | 30 #include <cstring> |
31 | |
27471 | 32 #include <ostream> |
33 #include <sstream> | |
4180 | 34 #include <new> |
35 | |
4153 | 36 #include "quit.h" |
37 | |
27480
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
38 sig_atomic_t octave_interrupt_state = 0; |
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
39 |
27520
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
40 // DEPRECATED in Octave 6. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
41 // This variable should never have been public. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
42 sig_atomic_t octave_exception_state = 0; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
43 // Use this variable internally until the functions that use it can be |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
44 // removed. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
45 static sig_atomic_t internal_exception_state; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
46 |
27480
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
47 volatile sig_atomic_t octave_signal_caught = 0; |
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
48 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23426
diff
changeset
|
49 void (*octave_signal_hook) (void) = nullptr; |
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23426
diff
changeset
|
50 void (*octave_interrupt_hook) (void) = nullptr; |
4429 | 51 |
27520
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
52 // DEPRECATED in Octave 6. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
53 void (*octave_bad_alloc_hook) (void) = nullptr; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
54 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
55 // The octave_exception enum values were DEPRECATED in Octave 6. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
56 // Use these values internally until the functions that use them can be |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
57 // removed. |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
58 enum octave_internal_exception |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
59 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
60 octave_internal_no_exception = 0, |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
61 octave_internal_exec_exception = 1, |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
62 octave_internal_alloc_exception = 3, |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
63 octave_internal_quit_exception = 4 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
64 }; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
65 |
27471 | 66 namespace octave |
67 { | |
68 std::string execution_exception::stack_trace (void) const | |
69 { | |
70 size_t nframes = m_stack_info.size (); | |
71 | |
72 if (nframes == 0) | |
73 return std::string (); | |
74 | |
75 std::ostringstream buf; | |
76 | |
77 buf << "error: called from\n"; | |
78 | |
79 for (const auto& frm : m_stack_info) | |
80 { | |
81 buf << " " << frm.fcn_name (); | |
82 | |
83 int line = frm.line (); | |
84 | |
85 if (line > 0) | |
86 { | |
87 buf << " at line " << line; | |
88 | |
89 int column = frm.column (); | |
90 | |
91 if (column > 0) | |
92 buf << " column " << column; | |
93 } | |
94 | |
95 buf << "\n"; | |
96 } | |
97 | |
98 return buf.str (); | |
99 } | |
100 | |
101 void execution_exception::display (std::ostream& os) const | |
102 { | |
103 if (! m_message.empty ()) | |
104 { | |
105 os << m_err_type << ": " << m_message; | |
106 | |
107 if (m_message.back () != '\n') | |
108 { | |
109 os << "\n"; | |
110 | |
111 std::string st = stack_trace (); | |
112 | |
113 if (! st.empty ()) | |
114 os << st; | |
115 } | |
116 } | |
117 } | |
118 } | |
119 | |
4153 | 120 void |
5142 | 121 octave_handle_signal (void) |
122 { | |
123 if (octave_signal_hook) | |
124 octave_signal_hook (); | |
125 | |
126 if (octave_interrupt_state > 0) | |
127 { | |
128 octave_interrupt_state = -1; | |
27480
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
129 |
27520
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
130 throw octave::interrupt_exception (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
131 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
132 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
133 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
134 // DEPRECATED in Octave 6 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
135 void |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
136 octave_throw_interrupt_exception (void) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
137 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
138 if (octave_interrupt_hook) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
139 octave_interrupt_hook (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
140 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
141 throw octave::interrupt_exception (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
142 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
143 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
144 // DEPRECATED in Octave 6 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
145 void |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
146 octave_throw_execution_exception (void) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
147 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
148 // FIXME: would a hook function be useful here? |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
149 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
150 internal_exception_state = octave_internal_exec_exception; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
151 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
152 throw octave::execution_exception (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
153 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
154 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
155 // DEPRECATED in Octave 6 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
156 void |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
157 octave_throw_bad_alloc (void) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
158 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
159 internal_exception_state = octave_internal_alloc_exception; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
160 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
161 throw std::bad_alloc (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
162 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
163 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
164 // DEPRECATED in Octave 6 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
165 void |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
166 octave_rethrow_exception (void) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
167 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
168 if (octave_interrupt_state) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
169 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
170 octave_interrupt_state = -1; |
27480
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
171 |
63b417917f5e
remove some obsolete signal handling functions
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
172 throw octave::interrupt_exception (); |
5142 | 173 } |
27520
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
174 else |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
175 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
176 switch (internal_exception_state) |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
177 { |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
178 case octave_internal_exec_exception: |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
179 throw octave::execution_exception (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
180 break; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
181 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
182 case octave_internal_alloc_exception: |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
183 throw std::bad_alloc (); |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
184 break; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
185 |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
186 default: |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
187 break; |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
188 } |
7a871724d4b0
restore some exception handling functions and variables and deprecate them
John W. Eaton <jwe@octave.org>
parents:
27480
diff
changeset
|
189 } |
5142 | 190 } |