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 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
4154
|
27 #include <cstring> |
|
28 |
4180
|
29 #include <new> |
|
30 |
4153
|
31 // Include signal.h, not csignal since the latter might only define |
|
32 // the ANSI standard C signal interface. |
|
33 |
|
34 #include <signal.h> |
|
35 |
|
36 #include "quit.h" |
|
37 |
4180
|
38 octave_jmp_buf current_context; |
4153
|
39 |
4429
|
40 void (*octave_interrupt_hook) (void) = 0; |
|
41 void (*octave_bad_alloc_hook) (void) = 0; |
|
42 |
4153
|
43 void |
|
44 octave_save_current_context (void *save_buf) |
|
45 { |
4270
|
46 std::memcpy (save_buf, current_context, sizeof (octave_jmp_buf)); |
4153
|
47 } |
|
48 |
|
49 void |
|
50 octave_restore_current_context (void *save_buf) |
|
51 { |
4270
|
52 std::memcpy (current_context, save_buf, sizeof (octave_jmp_buf)); |
4153
|
53 } |
|
54 |
|
55 void |
|
56 octave_jump_to_enclosing_context (void) |
|
57 { |
4180
|
58 #if defined (OCTAVE_HAVE_SIG_JUMP) |
|
59 siglongjmp (current_context, 1); |
|
60 #else |
4153
|
61 longjmp (current_context, 1); |
4180
|
62 #endif |
4153
|
63 } |
|
64 |
|
65 // Allow us to save the signal mask and then restore it to the most |
|
66 // recently saved value. This is necessary when using the POSIX |
|
67 // signal handling interface on some systems calling longjmp out of |
|
68 // the signal handler to get to the top level on an interrupt doesn't |
|
69 // restore the original signal mask. Alternatively, we could use |
|
70 // sigsetjmp/siglongjmp, but saving and restoring the signal mask |
|
71 // ourselves works ok and seems simpler just now. |
|
72 |
|
73 #if defined (HAVE_POSIX_SIGNALS) |
|
74 static sigset_t octave_signal_mask; |
|
75 #endif |
|
76 |
|
77 void |
|
78 octave_save_signal_mask (void) |
|
79 { |
|
80 #if defined (HAVE_POSIX_SIGNALS) |
|
81 sigprocmask (0, 0, &octave_signal_mask); |
|
82 #endif |
|
83 } |
|
84 |
|
85 void |
|
86 octave_restore_signal_mask (void) |
|
87 { |
|
88 #if defined (HAVE_POSIX_SIGNALS) |
|
89 sigprocmask (SIG_SETMASK, &octave_signal_mask, 0); |
|
90 #endif |
|
91 } |
|
92 |
4180
|
93 sig_atomic_t octave_interrupt_immediately = 0; |
4153
|
94 |
4180
|
95 sig_atomic_t octave_interrupt_state = 0; |
|
96 |
|
97 sig_atomic_t octave_allocation_error = 0; |
4153
|
98 |
|
99 void |
|
100 octave_throw_interrupt_exception (void) |
|
101 { |
4429
|
102 if (octave_interrupt_hook) |
|
103 octave_interrupt_hook (); |
|
104 |
4153
|
105 throw octave_interrupt_exception (); |
|
106 } |
|
107 |
4180
|
108 void |
|
109 octave_throw_bad_alloc (void) |
|
110 { |
4429
|
111 if (octave_bad_alloc_hook) |
|
112 octave_bad_alloc_hook (); |
|
113 |
4181
|
114 throw std::bad_alloc (); |
4180
|
115 } |
|
116 |
4153
|
117 /* |
|
118 ;;; Local Variables: *** |
|
119 ;;; mode: C++ *** |
|
120 ;;; End: *** |
|
121 */ |