annotate liboctave/util/quit.h @ 24520:c5c11b07598a

refactor signal handling (bug #52757) Given that any library code may now be multi-threaded it is not likely to be save to jump out of a signal handler when executing a call to a library function. We are almost assured to fail if the call to siglongjmp occurs in a different thread from the corresponding call to sigsetjmp. Similarly, we should avoid calling the interrupt signal handler function in an arbitrary thread. This is already done by default on Windows systems. On Posix systems, we now set up a separate thread to handle asynchronous signals (not just SIGINT). We no longer attempt to jump out of the signal handler. Instead, we only set global status variables and respond to them in octave_quit. This means that some external library functions are no longer interruptible. If that becomes important, then we will need to look for other alternatives such as setting up worker threads that can be canceled when a SIGINT is detected. * sighandlers.cc (interrupt_manager, base_interrupt_manager, w32_interrupt_manager, posix_interrupt_manager): Delete classes and all uses. (respond_to_pending_signals): Rename from signal_handler. Change all uses. Take action on more signals. (generic_sig_handler): Simply record that a signal was caught and add it to the list of caught signals. (deadly_sig_handler): New function. (fpe_sig_handler): Rename from sigfpe_handler. Don't make specific to Alpha systems. Simply warn that an exception has occurred. (sigint_handler): Simply record that an interrupt signal was caught. (sigterm_handler, sigpipe_handler): Delete. (install_signal_handlers): Rework actions for various signals. (Vsigquit_dumps_octave_core): New static variable. (Fsigquit_dumps_octave_core): New function. * io.txi: Document sigquit_dumps_octave_core. * f77-fcn.h, f77-fcn.c (xSTRINGIZE, STRINGIZE, F77_XFCN_ERROR): Delete macros. (F77_XFCN): Don't do setjmp/longjmp exception handling. (f77_exception_encountered): Delete global variable. (XSTOPX): Don't set f77_exception_encountered. If message is empty, report "unknown error in fortran subroutine". * eigs-base.cc, gsvd.cc: Delete all direct uses of f77_exception_encountered. * liboctave/util/f77-extern.cc: Delete file. * liboctave/util/module.mk: Update. * cmd-edit.h, cmd-edit.cc (command_editor::interrupt_exception): New class. (command_editor::handle_interrupt_signal): New static function. (command_editor::do_handle_interrupt_signal): New virtual function. (command_editor::event_hanlder): Call handle_interrupt_signal if octave_interrupt_state is not zero. (command_editor::instance_ok): Set event hook here. (command_editor::add_event_hook): Not here. (command_editor::remove_event_hook): Never remove event hook. (gnu_readline::do_handle_interrupt_signal): New function. (gnu_readline::do_readline): Retry if an interrupt exception occurs inside readline. * oct-rl-edit.h, oct-rl-edit.c (octave_rl_recover_from_interrupt): New function. * quit.h, cquit.c (current_context, octave_save_current_context, octave_restore_current_context, octave_jump_to_enclosing_context, octave_interrupt_immediately, octave_jmp_buf): Delete. * quit.h: Don't include <setjmp.h> (octave_set_current_context): Delete macro. (octave_exit_exception_status, octave_exit_exception_safe_to_return): Mark as deprecated. (BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1): Delete. (BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2): Delete. (BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE, END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE): Define to only create a dummy do-while scope. (BEGIN_INTERRUPT_WITH_EXCEPTIONS, END_INTERRUPT_WITH_EXCEPTIONS): Define to only create a dummy scope. * interpreter.cc (interpreter::recover_from_exception): Don't reset octave_interrupt_immediately. * main-cli.cc (main): Call octave_block_async_signals. * main.in.cc (main): Call octave_block_async_signals initially. Only in install signal handlers and unblock signals if starting managed subprocess. * main-window.cc (octave_interpreter::executed): Don't unblock interrupt signals. * signal-wrappers.h, signal-wrappers.c (signal_watcher, octave_async_signals, block_or_unblock_signal_by_name): New static functions. (octave_set_default_signal_handler, octave_set_default_signal_handler_by_name, octave_block_signal_by_name, octave_unblock_signal_by_name, octave_create_interrupt_watcher_thread, octave_block_async_signals, octave_unblock_async_signals): New functions. (octave_block_interrupt_signal, octave_unblock_interrupt_signal): Treat SIGBREAK as an interrupt signal. (octave_block_child): Also handle SIGCLD the same as SIGCHLD. (print_sigset, print_sigmask): New static functions. (octave_show_sigmask): New function.
author John W. Eaton <jwe@octave.org>
date Wed, 03 Jan 2018 07:52:11 -0500
parents be7b884ac589
children 194eb4bd202b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
1 /*
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2002-2017 John W. Eaton
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
4
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
6
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
16
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
19 <http://www.gnu.org/licenses/>.
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
20
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
21 */
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
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
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
24 #define octave_quit_h 1
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
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
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21849
diff changeset
28 /* 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
29 #if defined (__cplusplus)
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21849
diff changeset
30 # include <csignal>
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21040
diff changeset
31 # include <string>
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
32 extern "C" {
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21849
diff changeset
33 #else
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21849
diff changeset
34 # include <signal.h>
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
35 #endif
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
36
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
37 #if defined (__cplusplus)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
38
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
39 namespace octave
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
40 {
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
41 class
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
42 execution_exception
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
43 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
44 public:
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
45
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
46 execution_exception (void) : m_stack_trace () { }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
47
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
48 execution_exception (const execution_exception& x)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
49 : m_stack_trace (x.m_stack_trace) { }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
50
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
51 execution_exception& operator = (const execution_exception& x)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
52 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
53 if (&x != this)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
54 m_stack_trace = x.m_stack_trace;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
55
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
56 return *this;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
57 }
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
58
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
59 ~execution_exception (void) = default;
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
60
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
61 virtual void set_stack_trace (const std::string& st)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
62 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
63 m_stack_trace = st;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
64 }
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
65
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
66 virtual void set_stack_trace (void)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
67 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
68 m_stack_trace = "";
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
69 }
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
70
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
71 virtual std::string info (void) const
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
72 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
73 return m_stack_trace;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
74 }
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
75
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
76 private:
20666
e0e2c2ce7e94 defer stack trace until back at top level
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
77
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
78 std::string m_stack_trace;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
79 };
20785
b6f2909e7f94 always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents: 20666
diff changeset
80
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
81 class
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
82 exit_exception
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
83 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
84 public:
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
85
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
86 exit_exception (int exit_status = 0, bool safe_to_return = false)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
87 : m_exit_status (exit_status), m_safe_to_return (safe_to_return)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
88 { }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
89
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
90 exit_exception (const exit_exception& ex)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
91 : m_exit_status (ex.m_exit_status), m_safe_to_return (ex.m_safe_to_return)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
92 { }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
93
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
94 exit_exception& operator = (exit_exception& ex)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
95 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
96 if (this != &ex)
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
97 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
98 m_exit_status = ex.m_exit_status;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
99 m_safe_to_return = ex.m_safe_to_return;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
100 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
101
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
102 return *this;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
103 }
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
104
22868
87e3163f6c87 use c++11 "= default" syntax for declaration of trivial destructors
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
105 ~exit_exception (void) = default;
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
106
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
107 int exit_status (void) const { return m_exit_status; }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
108
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
109 bool safe_to_return (void) const { return m_safe_to_return; }
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
110
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
111 private:
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
112
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
113 int m_exit_status;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
114
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
115 bool m_safe_to_return;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
116 };
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
117
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
118 class
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
119 interrupt_exception
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
120 {
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
121 };
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
122 }
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
123
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23426
diff changeset
124 OCTAVE_DEPRECATED (4.2, "use 'octave::execution_exception' instead")
23041
52d06f98c15e Fix typo in typedef for octave_execution_exception (bug #50027)
Rik <rik@octave.org>
parents: 22868
diff changeset
125 typedef octave::execution_exception octave_execution_exception;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
126
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23426
diff changeset
127 OCTAVE_DEPRECATED (4.2, "use 'octave::exit_exception' instead")
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
128 typedef octave::exit_exception octave_exit_exception;
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
129
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23426
diff changeset
130 OCTAVE_DEPRECATED (4.2, "use 'octave::interrupt_exception' instead")
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
131 typedef octave::interrupt_exception octave_interrupt_exception;
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
132
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
133 #endif
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
134
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
135 enum octave_exception
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
136 {
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
137 octave_no_exception = 0,
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
138 octave_exec_exception = 1,
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
139 octave_alloc_exception = 3,
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
140 octave_quit_exception = 4
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
141 };
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
142
5133
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 4793
diff changeset
143 /*
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 4793
diff changeset
144 > 0: interrupt pending
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 4793
diff changeset
145 0: no interrupt pending
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 4793
diff changeset
146 < 0: handling interrupt
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 4793
diff changeset
147 */
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
148 OCTAVE_API extern sig_atomic_t octave_interrupt_state;
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4155
diff changeset
149
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
150 OCTAVE_API extern sig_atomic_t octave_exception_state;
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
151
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
152 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
153 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
154
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
155 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
156 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
157
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
158 OCTAVE_API extern volatile sig_atomic_t octave_signal_caught;
5142
0f9108f298ab [project @ 2005-02-12 02:29:34 by jwe]
jwe
parents: 5133
diff changeset
159
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
160 OCTAVE_API extern void octave_handle_signal (void);
5142
0f9108f298ab [project @ 2005-02-12 02:29:34 by jwe]
jwe
parents: 5133
diff changeset
161
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
162 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_interrupt_exception (void);
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
163
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
164 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
165
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
166 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_bad_alloc (void);
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4155
diff changeset
167
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23426
diff changeset
168 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
23238
3de5efeffb86 Eliminate compilation warnings related to clean_up_and_exit fcn (bug #50265).
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
169 OCTAVE_NORETURN OCTAVE_API extern void
3de5efeffb86 Eliminate compilation warnings related to clean_up_and_exit fcn (bug #50265).
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
170 octave_throw_exit_exception (int exit_status, int safe_to_return);
3de5efeffb86 Eliminate compilation warnings related to clean_up_and_exit fcn (bug #50265).
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
171
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
172 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
173
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
174 #if defined (__cplusplus)
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
175
23615
be7b884ac589 use version number in OCTAVE_DEPRECATED macro
John W. Eaton <jwe@octave.org>
parents: 23426
diff changeset
176 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
177 extern OCTAVE_API void
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
178 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
179
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
180 inline void octave_quit (void)
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
181 {
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
182 if (octave_signal_caught)
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
183 {
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
184 octave_signal_caught = 0;
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
185 octave_handle_signal ();
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
186 }
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
187 };
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 #define OCTAVE_QUIT octave_quit ()
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 #else
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
192
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
193 #define OCTAVE_QUIT \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
194 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
195 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
196 if (octave_signal_caught) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
197 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
198 octave_signal_caught = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
199 octave_handle_signal (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
200 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
201 } \
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
202 while (0)
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9933
diff changeset
203 #endif
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
204
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
205 /* The following macros are obsolete. Interrupting immediately by
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
206 calling siglongjmp or similar from a signal handler is asking for
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
207 trouble. We need another way to handle that situation. Rather
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
208 than remove them, however, please leave them in place until we can
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
209 either find a replacement or determine that a given block of code
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
210 does not need special treatment. They are defined to create a
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
211 dummy do-while block to match the previous definitions. */
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4268
diff changeset
212
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
213 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
214 do \
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
215 {
4302
ebc2d8e4968b [project @ 2003-01-22 22:02:23 by jwe]
jwe
parents: 4268
diff changeset
216
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
217 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
218 } \
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
219 while (0)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
220
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
221 #if defined (__cplusplus)
4196
f874c6c68845 [project @ 2002-11-20 22:27:01 by jwe]
jwe
parents: 4182
diff changeset
222
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
223 /* Likewise, these are obsolete. They are defined to create a
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
224 dummy scope to match the previous versions that created a try-catch
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
225 block. */
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4155
diff changeset
226
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
227 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
228 {
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
229
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
230 #define END_INTERRUPT_WITH_EXCEPTIONS \
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
231 }
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 23615
diff changeset
232
4196
f874c6c68845 [project @ 2002-11-20 22:27:01 by jwe]
jwe
parents: 4182
diff changeset
233 #endif
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
234
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
235 #if defined (__cplusplus)
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
236 }
4560
661246155bbc [project @ 2003-10-28 21:02:43 by jwe]
jwe
parents: 4551
diff changeset
237
4572
4623ef02a605 [project @ 2003-10-31 03:07:05 by jwe]
jwe
parents: 4560
diff changeset
238 /* These should only be declared for C++ code, and should also be
4623ef02a605 [project @ 2003-10-31 03:07:05 by jwe]
jwe
parents: 4560
diff changeset
239 outside of any extern "C" block. */
4560
661246155bbc [project @ 2003-10-28 21:02:43 by jwe]
jwe
parents: 4551
diff changeset
240
21227
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
241 extern OCTAVE_API void (*octave_signal_hook) (void);
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
242 extern OCTAVE_API void (*octave_interrupt_hook) (void);
25150962bfd3 eliminate CRUFT_API macro
John W. Eaton <jwe@octave.org>
parents: 21213
diff changeset
243 extern OCTAVE_API void (*octave_bad_alloc_hook) (void);
4560
661246155bbc [project @ 2003-10-28 21:02:43 by jwe]
jwe
parents: 4551
diff changeset
244
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
245 #endif
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
246
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents:
diff changeset
247 #endif