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 #include "mymalloc.h" /* For ANY */
37 #include "intrcheck.h"
39 /* Copied here from ceval.h -- can't include that file. */
40 int Py_AddPendingCall
Py_PROTO((int (*func
) Py_PROTO((ANY
*)), ANY
*arg
));
58 PyOS_InterruptOccurred()
67 #if defined(_M_IX86) && !defined(__QNX__)
71 #if defined(MSDOS) && !defined(QUICKWIN)
75 /* This is for DJGPP's GO32 extender. I don't know how to trap
76 * control-C (There's no API for ctrl-C, and I don't want to mess with
77 * the interrupt vectors.) However, this DOES catch control-break.
86 _go32_want_ctrl_break(1 /* TRUE */);
95 PyOS_InterruptOccurred()
97 return _go32_was_ctrl_break_hit();
100 #else /* !__GNUC__ */
102 /* This might work for MS-DOS (untested though): */
105 PyOS_InitInterrupts()
110 PyOS_FiniInterrupts()
115 PyOS_InterruptOccurred()
119 if (getch() == '\003')
125 #endif /* __GNUC__ */
129 #endif /* MSDOS && !QUICKWIN */
134 /* The Mac interrupt code has moved to macglue.c */
137 #endif /* macintosh */
142 /* Default version -- for real operating systems and for Standard C */
151 static int interrupted
;
159 extern int PyErr_CheckSignals();
163 #if defined(_M_IX86) && !defined(__QNX__)
164 intcatcher(int sig
) /* So the C compiler shuts up */
167 int sig
; /* Not used by required by interface */
170 extern void Py_Exit
Py_PROTO((int));
171 static char message
[] =
172 "python: to interrupt a truly hanging Python program, interrupt once more.\n";
173 switch (interrupted
++) {
177 write(2, message
, strlen(message
));
184 signal(SIGINT
, intcatcher
);
185 Py_AddPendingCall(PyErr_CheckSignals
, NULL
);
188 static RETSIGTYPE (*old_siginthandler
)() = SIG_DFL
;
191 PyOS_InitInterrupts()
193 if ((old_siginthandler
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
194 signal(SIGINT
, intcatcher
);
195 #ifdef HAVE_SIGINTERRUPT
196 /* This is for SunOS and other modern BSD derivatives.
197 It means that system calls (like read()) are not restarted
198 after an interrupt. This is necessary so interrupting a
199 read() or readline() call works as expected.
200 XXX On old BSD (pure 4.2 or older) you may have to do this
202 siginterrupt(SIGINT
, 1);
203 #endif /* HAVE_SIGINTERRUPT */
207 PyOS_FiniInterrupts()
209 signal(SIGINT
, old_siginthandler
);
213 PyOS_InterruptOccurred()