1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Check for interrupts */
36 /* config.h may or may not define DL_IMPORT */
37 #ifndef DL_IMPORT /* declarations for DLL import/export */
38 #define DL_IMPORT(RTYPE) RTYPE
42 #include "mymalloc.h" /* For ANY */
43 #include "intrcheck.h"
45 /* Copied here from ceval.h -- can't include that file. */
46 int Py_AddPendingCall
Py_PROTO((int (*func
) Py_PROTO((ANY
*)), ANY
*arg
));
64 PyOS_InterruptOccurred()
73 #if defined(_M_IX86) && !defined(__QNX__)
77 #if defined(MSDOS) && !defined(QUICKWIN)
81 /* This is for DJGPP's GO32 extender. I don't know how to trap
82 * control-C (There's no API for ctrl-C, and I don't want to mess with
83 * the interrupt vectors.) However, this DOES catch control-break.
92 _go32_want_ctrl_break(1 /* TRUE */);
101 PyOS_InterruptOccurred()
103 return _go32_was_ctrl_break_hit();
106 #else /* !__GNUC__ */
108 /* This might work for MS-DOS (untested though): */
111 PyOS_InitInterrupts()
116 PyOS_FiniInterrupts()
121 PyOS_InterruptOccurred()
125 if (getch() == '\003')
131 #endif /* __GNUC__ */
135 #endif /* MSDOS && !QUICKWIN */
140 /* The Mac interrupt code has moved to macglue.c */
143 #endif /* macintosh */
148 /* Default version -- for real operating systems and for Standard C */
157 static int interrupted
;
165 extern int PyErr_CheckSignals();
169 #if defined(_M_IX86) && !defined(__QNX__)
170 intcatcher(int sig
) /* So the C compiler shuts up */
173 int sig
; /* Not used by required by interface */
176 extern void Py_Exit
Py_PROTO((int));
177 static char message
[] =
178 "python: to interrupt a truly hanging Python program, interrupt once more.\n";
179 switch (interrupted
++) {
183 write(2, message
, strlen(message
));
190 signal(SIGINT
, intcatcher
);
191 Py_AddPendingCall(PyErr_CheckSignals
, NULL
);
194 static RETSIGTYPE (*old_siginthandler
)() = SIG_DFL
;
197 PyOS_InitInterrupts()
199 if ((old_siginthandler
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
200 signal(SIGINT
, intcatcher
);
201 #ifdef HAVE_SIGINTERRUPT
202 /* This is for SunOS and other modern BSD derivatives.
203 It means that system calls (like read()) are not restarted
204 after an interrupt. This is necessary so interrupting a
205 read() or readline() call works as expected.
206 XXX On old BSD (pure 4.2 or older) you may have to do this
208 siginterrupt(SIGINT
, 1);
209 #endif /* HAVE_SIGINTERRUPT */
213 PyOS_FiniInterrupts()
215 signal(SIGINT
, old_siginthandler
);
219 PyOS_InterruptOccurred()