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