source: vendor/python/2.5/Parser/intrcheck.c

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.4 KB
Line 
1
2/* Check for interrupts */
3
4#include "Python.h"
5
6#ifdef QUICKWIN
7
8#include <io.h>
9
10void
11PyOS_InitInterrupts(void)
12{
13}
14
15void
16PyOS_FiniInterrupts(void)
17{
18}
19
20int
21PyOS_InterruptOccurred(void)
22{
23 _wyield();
24}
25
26#define OK
27
28#endif /* QUICKWIN */
29
30#if defined(_M_IX86) && !defined(__QNX__)
31#include <io.h>
32#endif
33
34#if defined(MSDOS) && !defined(QUICKWIN)
35
36#ifdef __GNUC__
37
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
42 */
43
44#include <go32.h>
45
46void
47PyOS_InitInterrupts(void)
48{
49 _go32_want_ctrl_break(1 /* TRUE */);
50}
51
52void
53PyOS_FiniInterrupts(void)
54{
55}
56
57int
58PyOS_InterruptOccurred(void)
59{
60 return _go32_was_ctrl_break_hit();
61}
62
63#else /* !__GNUC__ */
64
65/* This might work for MS-DOS (untested though): */
66
67void
68PyOS_InitInterrupts(void)
69{
70}
71
72void
73PyOS_FiniInterrupts(void)
74{
75}
76
77int
78PyOS_InterruptOccurred(void)
79{
80 int interrupted = 0;
81 while (kbhit()) {
82 if (getch() == '\003')
83 interrupted = 1;
84 }
85 return interrupted;
86}
87
88#endif /* __GNUC__ */
89
90#define OK
91
92#endif /* MSDOS && !QUICKWIN */
93
94
95#ifndef OK
96
97/* Default version -- for real operating systems and for Standard C */
98
99#include <stdio.h>
100#include <string.h>
101#include <signal.h>
102
103static int interrupted;
104
105void
106PyErr_SetInterrupt(void)
107{
108 interrupted = 1;
109}
110
111extern int PyErr_CheckSignals(void);
112
113static int
114checksignals_witharg(void * arg)
115{
116 return PyErr_CheckSignals();
117}
118
119static void
120intcatcher(int sig)
121{
122 extern void Py_Exit(int);
123 static char message[] =
124"python: to interrupt a truly hanging Python program, interrupt once more.\n";
125 switch (interrupted++) {
126 case 0:
127 break;
128 case 1:
129#ifdef RISCOS
130 fprintf(stderr, message);
131#else
132 write(2, message, strlen(message));
133#endif
134 break;
135 case 2:
136 interrupted = 0;
137 Py_Exit(1);
138 break;
139 }
140 PyOS_setsig(SIGINT, intcatcher);
141 Py_AddPendingCall(checksignals_witharg, NULL);
142}
143
144static void (*old_siginthandler)(int) = SIG_DFL;
145
146void
147PyOS_InitInterrupts(void)
148{
149 if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
150 PyOS_setsig(SIGINT, intcatcher);
151}
152
153void
154PyOS_FiniInterrupts(void)
155{
156 PyOS_setsig(SIGINT, old_siginthandler);
157}
158
159int
160PyOS_InterruptOccurred(void)
161{
162 if (!interrupted)
163 return 0;
164 interrupted = 0;
165 return 1;
166}
167
168#endif /* !OK */
169
170void
171PyOS_AfterFork(void)
172{
173#ifdef WITH_THREAD
174 PyEval_ReInitThreads();
175#endif
176}
Note: See TracBrowser for help on using the repository browser.