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