Fix sf bug 666219: assertion error in httplib.
[python/dscho.git] / Parser / intrcheck.c
blobe2ca5b46a88973c32e5e064838ae0b16dec25db9
2 /* Check for interrupts */
4 #include "Python.h"
6 #ifdef QUICKWIN
8 #include <io.h>
10 void
11 PyOS_InitInterrupts(void)
15 void
16 PyOS_FiniInterrupts(void)
20 int
21 PyOS_InterruptOccurred(void)
23 _wyield();
26 #define OK
28 #endif /* QUICKWIN */
30 #if defined(_M_IX86) && !defined(__QNX__)
31 #include <io.h>
32 #endif
34 #if defined(MSDOS) && !defined(QUICKWIN)
36 #ifdef __GNUC__
38 /* This is for DJGPP's GO32 extender. I don't know how to trap
39 * control-C (There's no API for ctrl-C, and I don't want to mess with
40 * the interrupt vectors.) However, this DOES catch control-break.
41 * --Amrit
44 #include <go32.h>
46 void
47 PyOS_InitInterrupts(void)
49 _go32_want_ctrl_break(1 /* TRUE */);
52 void
53 PyOS_FiniInterrupts(void)
57 int
58 PyOS_InterruptOccurred(void)
60 return _go32_was_ctrl_break_hit();
63 #else /* !__GNUC__ */
65 /* This might work for MS-DOS (untested though): */
67 void
68 PyOS_InitInterrupts(void)
72 void
73 PyOS_FiniInterrupts(void)
77 int
78 PyOS_InterruptOccurred(void)
80 int interrupted = 0;
81 while (kbhit()) {
82 if (getch() == '\003')
83 interrupted = 1;
85 return interrupted;
88 #endif /* __GNUC__ */
90 #define OK
92 #endif /* MSDOS && !QUICKWIN */
95 #ifdef macintosh
97 /* The Mac interrupt code has moved to macglue.c */
98 #define OK
100 #endif /* macintosh */
103 #ifndef OK
105 /* Default version -- for real operating systems and for Standard C */
107 #include <stdio.h>
108 #include <string.h>
109 #include <signal.h>
111 static int interrupted;
113 void
114 PyErr_SetInterrupt(void)
116 interrupted = 1;
119 extern int PyErr_CheckSignals(void);
121 static int
122 checksignals_witharg(void * arg)
124 return PyErr_CheckSignals();
127 static void
128 intcatcher(int sig)
130 extern void Py_Exit(int);
131 static char message[] =
132 "python: to interrupt a truly hanging Python program, interrupt once more.\n";
133 switch (interrupted++) {
134 case 0:
135 break;
136 case 1:
137 #ifdef RISCOS
138 fprintf(stderr, message);
139 #else
140 write(2, message, strlen(message));
141 #endif
142 break;
143 case 2:
144 interrupted = 0;
145 Py_Exit(1);
146 break;
148 signal(SIGINT, intcatcher);
149 Py_AddPendingCall(checksignals_witharg, NULL);
152 static void (*old_siginthandler)(int) = SIG_DFL;
154 void
155 PyOS_InitInterrupts(void)
157 if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN)
158 signal(SIGINT, intcatcher);
159 #ifdef HAVE_SIGINTERRUPT
160 /* This is for SunOS and other modern BSD derivatives.
161 It means that system calls (like read()) are not restarted
162 after an interrupt. This is necessary so interrupting a
163 read() or readline() call works as expected.
164 XXX On old BSD (pure 4.2 or older) you may have to do this
165 differently! */
166 siginterrupt(SIGINT, 1);
167 #endif /* HAVE_SIGINTERRUPT */
170 void
171 PyOS_FiniInterrupts(void)
173 signal(SIGINT, old_siginthandler);
177 PyOS_InterruptOccurred(void)
179 if (!interrupted)
180 return 0;
181 interrupted = 0;
182 return 1;
185 #endif /* !OK */
187 void
188 PyOS_AfterFork(void)
190 #ifdef WITH_THREAD
191 PyEval_ReInitThreads();
192 #endif