Mercurial > cpython-lru_cache-weakref
annotate Parser/intrcheck.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | fd25030223b0 |
| children |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
113
diff
changeset
|
1 |
| 6 | 2 /* Check for interrupts */ |
| 3 | |
|
14136
aae37dc99f57
Simplified inclusions and avoid prototypes copied in from elsewhere.
Fred Drake <fdrake@acm.org>
parents:
13761
diff
changeset
|
4 #include "Python.h" |
|
47664
db99f8752710
#1683 prevent forking from interfering in threading storage
Benjamin Peterson <benjamin@python.org>
parents:
33747
diff
changeset
|
5 #include "pythread.h" |
|
293
f900b692b37e
Generalize to macintosh.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
6 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
7 #ifdef QUICKWIN |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
8 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
9 #include <io.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
10 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
11 void |
| 13659 | 12 PyOS_InitInterrupts(void) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
13 { |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
14 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
15 |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
16 void |
| 13659 | 17 PyOS_FiniInterrupts(void) |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
18 { |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
19 } |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
20 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
21 int |
| 13659 | 22 PyOS_InterruptOccurred(void) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
23 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
24 _wyield(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
25 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
26 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
27 #define OK |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
28 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
29 #endif /* QUICKWIN */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
30 |
|
6716
d854a1c7e74d
Patch for QNX, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
6578
diff
changeset
|
31 #if defined(_M_IX86) && !defined(__QNX__) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
32 #include <io.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
33 #endif |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
34 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
35 #if defined(MSDOS) && !defined(QUICKWIN) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
36 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
37 #ifdef __GNUC__ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
38 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
39 /* This is for DJGPP's GO32 extender. I don't know how to trap |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
40 * control-C (There's no API for ctrl-C, and I don't want to mess with |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
41 * the interrupt vectors.) However, this DOES catch control-break. |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
42 * --Amrit |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
43 */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
44 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
45 #include <go32.h> |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
46 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
47 void |
| 13659 | 48 PyOS_InitInterrupts(void) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
49 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
50 _go32_want_ctrl_break(1 /* TRUE */); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
51 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
52 |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
53 void |
| 13659 | 54 PyOS_FiniInterrupts(void) |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
55 { |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
56 } |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
57 |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
58 int |
| 13659 | 59 PyOS_InterruptOccurred(void) |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
60 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
61 return _go32_was_ctrl_break_hit(); |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
62 } |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
63 |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
64 #else /* !__GNUC__ */ |
| 6 | 65 |
| 86 | 66 /* This might work for MS-DOS (untested though): */ |
| 6 | 67 |
| 68 void | |
| 13659 | 69 PyOS_InitInterrupts(void) |
| 6 | 70 { |
| 71 } | |
| 72 | |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
73 void |
| 13659 | 74 PyOS_FiniInterrupts(void) |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
75 { |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
76 } |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
77 |
| 6 | 78 int |
| 13659 | 79 PyOS_InterruptOccurred(void) |
| 6 | 80 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
81 int interrupted = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
82 while (kbhit()) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
83 if (getch() == '\003') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
84 interrupted = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
85 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
86 return interrupted; |
| 6 | 87 } |
| 88 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
89 #endif /* __GNUC__ */ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
90 |
| 6 | 91 #define OK |
| 92 | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
93 #endif /* MSDOS && !QUICKWIN */ |
| 6 | 94 |
| 95 | |
| 96 #ifndef OK | |
| 97 | |
| 86 | 98 /* Default version -- for real operating systems and for Standard C */ |
| 6 | 99 |
| 100 #include <stdio.h> | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
101 #include <string.h> |
| 6 | 102 #include <signal.h> |
| 103 | |
|
2148
f99a23998770
made interrupted static again
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
104 static int interrupted; |
| 6 | 105 |
|
2520
847d24841c85
added PyErr_SetInterrupt()
Guido van Rossum <guido@python.org>
parents:
2272
diff
changeset
|
106 void |
| 13659 | 107 PyErr_SetInterrupt(void) |
|
2520
847d24841c85
added PyErr_SetInterrupt()
Guido van Rossum <guido@python.org>
parents:
2272
diff
changeset
|
108 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
109 interrupted = 1; |
|
2520
847d24841c85
added PyErr_SetInterrupt()
Guido van Rossum <guido@python.org>
parents:
2272
diff
changeset
|
110 } |
|
847d24841c85
added PyErr_SetInterrupt()
Guido van Rossum <guido@python.org>
parents:
2272
diff
changeset
|
111 |
| 13659 | 112 extern int PyErr_CheckSignals(void); |
|
5019
28935609dfae
In the Unix version, arrange for sigcheck() to be called via
Guido van Rossum <guido@python.org>
parents:
4577
diff
changeset
|
113 |
| 13659 | 114 static int |
| 115 checksignals_witharg(void * arg) | |
| 116 { | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
117 return PyErr_CheckSignals(); |
| 13659 | 118 } |
| 119 | |
|
13676
5423b132bc97
Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents:
13671
diff
changeset
|
120 static void |
| 13659 | 121 intcatcher(int sig) |
| 6 | 122 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
123 extern void Py_Exit(int); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
124 static char message[] = |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
125 "python: to interrupt a truly hanging Python program, interrupt once more.\n"; |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
126 switch (interrupted++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
127 case 0: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
128 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
129 case 1: |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
130 #ifdef RISCOS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
131 fprintf(stderr, message); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
132 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
133 write(2, message, strlen(message)); |
|
16947
b25131bc6ec7
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
134 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
135 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
136 case 2: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
137 interrupted = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
138 Py_Exit(1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
139 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
140 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
141 PyOS_setsig(SIGINT, intcatcher); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
142 Py_AddPendingCall(checksignals_witharg, NULL); |
| 6 | 143 } |
| 144 | |
|
13676
5423b132bc97
Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents:
13671
diff
changeset
|
145 static void (*old_siginthandler)(int) = SIG_DFL; |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
146 |
| 6 | 147 void |
| 13659 | 148 PyOS_InitInterrupts(void) |
| 6 | 149 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
150 if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
151 PyOS_setsig(SIGINT, intcatcher); |
| 6 | 152 } |
| 153 | |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
154 void |
| 13659 | 155 PyOS_FiniInterrupts(void) |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
156 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
157 PyOS_setsig(SIGINT, old_siginthandler); |
|
5924
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
158 } |
|
08b1e9d847e6
Added finalization routines.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
159 |
| 6 | 160 int |
| 13659 | 161 PyOS_InterruptOccurred(void) |
| 6 | 162 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
163 if (!interrupted) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
164 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
165 interrupted = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
166 return 1; |
| 6 | 167 } |
| 168 | |
| 169 #endif /* !OK */ | |
|
6578
01ee5607bb35
This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents:
5924
diff
changeset
|
170 |
|
01ee5607bb35
This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents:
5924
diff
changeset
|
171 void |
| 13659 | 172 PyOS_AfterFork(void) |
|
6578
01ee5607bb35
This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents:
5924
diff
changeset
|
173 { |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14136
diff
changeset
|
174 #ifdef WITH_THREAD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
175 PyEval_ReInitThreads(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
47664
diff
changeset
|
176 PyThread_ReInitTLS(); |
|
14225
cbe9590d2344
Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents:
14136
diff
changeset
|
177 #endif |
|
6578
01ee5607bb35
This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents:
5924
diff
changeset
|
178 } |
