annotate Modules/signalmodule.c @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 642f20b22577
children fb719049044f ca6e90470d96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
2 /* Signal module -- many thanks to Lance Ellinghaus */
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5101
diff changeset
4 /* XXX Signals should be recorded per thread, now we have thread state. */
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5101
diff changeset
5
1888
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
6 #include "Python.h"
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include "intrcheck.h"
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23843
diff changeset
9 #ifdef MS_WINDOWS
5287
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5101
diff changeset
10 #include <process.h>
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5101
diff changeset
11 #endif
5af766a1b531 Tweaks to keep the Microsoft compiler quier.
Guido van Rossum <guido@python.org>
parents: 5101
diff changeset
12
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 #include <signal.h>
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
15 #include <sys/stat.h>
46055
02ae311256a7 Conditionalize sys/time.h inclusion.
Martin v. Löwis <martin@v.loewis.de>
parents: 46053
diff changeset
16 #ifdef HAVE_SYS_TIME_H
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
17 #include <sys/time.h>
46055
02ae311256a7 Conditionalize sys/time.h inclusion.
Martin v. Löwis <martin@v.loewis.de>
parents: 46053
diff changeset
18 #endif
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
19
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
20 #ifndef SIG_ERR
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
21 #define SIG_ERR ((PyOS_sighandler_t)(-1))
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
22 #endif
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
23
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21715
diff changeset
24 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
25 #define NSIG 12
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
26 #include <process.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
27 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
28
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
29 #ifndef NSIG
13338
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
30 # if defined(_NSIG)
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
31 # define NSIG _NSIG /* For BSD/SysV */
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
32 # elif defined(_SIGMAX)
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
33 # define NSIG (_SIGMAX + 1) /* For QNX */
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
34 # elif defined(SIGMAX)
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
35 # define NSIG (SIGMAX + 1) /* For djgpp */
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
36 # else
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
37 # define NSIG 64 /* Use a reasonable default value */
a7f72022b93a Fixed symbol search for defining NSIG. It now also checks _NSIG
Marc-André Lemburg <mal@egenix.com>
parents: 13256
diff changeset
38 # endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
39 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
40
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
41
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
42 /*
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
43 NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
44
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
45 When threads are supported, we want the following semantics:
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
46
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
47 - only the main thread can set a signal handler
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
48 - any thread can get a signal handler
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
49 - signals are only delivered to the main thread
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
50
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
51 I.e. we don't support "synchronous signals" like SIGFPE (catching
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
52 this doesn't make much sense in Python anyway) nor do we support
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
53 signals as a means of inter-thread communication, since not all
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
54 thread implementations support that (at least our thread library
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
55 doesn't).
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
56
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
57 We still have the problem that in some implementations signals
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
58 generated by the keyboard (e.g. SIGINT) are delivered to all
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
59 threads (e.g. SGI), while in others (e.g. Solaris) such signals are
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
60 delivered to one random thread (an intermediate possibility would
2126
af36bae343fc cosmetics
Guido van Rossum <guido@python.org>
parents: 2123
diff changeset
61 be to deliver it to the main thread -- POSIX?). For now, we have
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
62 a working implementation that works in all three cases -- the
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
63 handler ignores signals if getpid() isn't the same as in the main
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
64 thread. XXX This is a hack.
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
65
14674
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
66 GNU pth is a user-space threading library, and as such, all threads
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
67 run within the same process. In this case, if the currently running
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
68 thread is not the main_thread, send the signal to the main_thread.
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
69 */
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
70
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
71 #ifdef WITH_THREAD
5730
996079744566 Add sys/types.h include for pid_t when threading.
Guido van Rossum <guido@python.org>
parents: 5287
diff changeset
72 #include <sys/types.h> /* For pid_t */
9203
07dae6fdae79 Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents: 9127
diff changeset
73 #include "pythread.h"
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
74 static long main_thread;
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
75 static pid_t main_pid;
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
76 #endif
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
77
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
78 static struct {
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
79 int tripped;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
80 PyObject *func;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
81 } Handlers[NSIG];
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
82
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
83 static sig_atomic_t wakeup_fd = -1;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
84
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
85 /* Speed up sigcheck() when none tripped */
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
86 static volatile sig_atomic_t is_tripped = 0;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
88 static PyObject *DefaultHandler;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
89 static PyObject *IgnoreHandler;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
90 static PyObject *IntHandler;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
16998
4f9db834825c Document SIG_* warning causes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents: 14674
diff changeset
92 /* On Solaris 8, gcc will produce a warning that the function
4f9db834825c Document SIG_* warning causes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents: 14674
diff changeset
93 declaration is not a prototype. This is caused by the definition of
4f9db834825c Document SIG_* warning causes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents: 14674
diff changeset
94 SIG_DFL as (void (*)())0; the correct declaration would have been
4f9db834825c Document SIG_* warning causes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents: 14674
diff changeset
95 (void (*)(int))0. */
4f9db834825c Document SIG_* warning causes on Solaris.
Martin v. Löwis <martin@v.loewis.de>
parents: 14674
diff changeset
96
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
97 static PyOS_sighandler_t old_siginthandler = SIG_DFL;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
98
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
99 #ifdef HAVE_GETITIMER
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
100 static PyObject *ItimerError;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
101
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
102 /* auxiliary functions for setitimer/getitimer */
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
103 static void
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
104 timeval_from_double(double d, struct timeval *tv)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
105 {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
106 tv->tv_sec = floor(d);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
107 tv->tv_usec = fmod(d, 1.0) * 1000000.0;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
108 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
109
49386
642f20b22577 Merged revisions 66748 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 48847
diff changeset
110 Py_LOCAL_INLINE(double)
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
111 double_from_timeval(struct timeval *tv)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
112 {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
113 return tv->tv_sec + (double)(tv->tv_usec / 1000000.0);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
114 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
115
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
116 static PyObject *
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
117 itimer_retval(struct itimerval *iv)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
118 {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
119 PyObject *r, *v;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
120
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
121 r = PyTuple_New(2);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
122 if (r == NULL)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
123 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
124
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
125 if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_value)))) {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
126 Py_DECREF(r);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
127 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
128 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
129
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
130 PyTuple_SET_ITEM(r, 0, v);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
131
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
132 if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_interval)))) {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
133 Py_DECREF(r);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
134 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
135 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
136
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
137 PyTuple_SET_ITEM(r, 1, v);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
138
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
139 return r;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
140 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
141 #endif
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
143 static PyObject *
13500
d9cc620ff186 ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13447
diff changeset
144 signal_default_int_handler(PyObject *self, PyObject *args)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 {
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
146 PyErr_SetNone(PyExc_KeyboardInterrupt);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
147 return NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
149
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
150 PyDoc_STRVAR(default_int_handler_doc,
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
151 "default_int_handler(...)\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
152 \n\
32361
55ba51bef0a8 silly typo
Michael W. Hudson <mwh@python.net>
parents: 30032
diff changeset
153 The default handler for SIGINT installed by Python.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
154 It raises KeyboardInterrupt.");
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
155
13664
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
156
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
157 static int
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
158 checksignals_witharg(void * unused)
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
159 {
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
160 return PyErr_CheckSignals();
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
161 }
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
162
13676
5423b132bc97 Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents: 13673
diff changeset
163 static void
13500
d9cc620ff186 ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13447
diff changeset
164 signal_handler(int sig_num)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 {
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
166 #ifdef WITH_THREAD
14674
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
167 #ifdef WITH_PTH
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
168 if (PyThread_get_thread_ident() != main_thread) {
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
169 pth_raise(*(pth_t *) main_thread, sig_num);
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
170 return;
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
171 }
756c8c6535fe Make better use of GNU Pth -- patch by Andy Dustman.
Guido van Rossum <guido@python.org>
parents: 14638
diff changeset
172 #endif
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
173 /* See NOTES section above */
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
174 if (getpid() == main_pid) {
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
175 #endif
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
176 Handlers[sig_num].tripped = 1;
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
177 /* Set is_tripped after setting .tripped, as it gets
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
178 cleared in PyErr_CheckSignals() before .tripped. */
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
179 is_tripped = 1;
13664
ee10834d67a3 Further ANSIfication of functionpointers and declarations. Also, make sure
Thomas Wouters <thomas@python.org>
parents: 13651
diff changeset
180 Py_AddPendingCall(checksignals_witharg, NULL);
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
181 if (wakeup_fd != -1)
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
182 write(wakeup_fd, "\0", 1);
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
183 #ifdef WITH_THREAD
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
184 }
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
185 #endif
1888
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
186 #ifdef SIGCHLD
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
187 if (sig_num == SIGCHLD) {
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
188 /* To avoid infinite recursion, this signal remains
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
189 reset until explicit re-instated.
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
190 Don't clear the 'func' field as it is our pointer
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
191 to the Python handler... */
13676
5423b132bc97 Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents: 13673
diff changeset
192 return;
1888
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
193 }
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1867
diff changeset
194 #endif
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
195 PyOS_setsig(sig_num, signal_handler);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
2521
e7d480cf16ba added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents: 2211
diff changeset
197
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
198
6142
144db635b49d Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents: 5923
diff changeset
199 #ifdef HAVE_ALARM
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
200 static PyObject *
13500
d9cc620ff186 ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13447
diff changeset
201 signal_alarm(PyObject *self, PyObject *args)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1678
diff changeset
202 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1678
diff changeset
203 int t;
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
204 if (!PyArg_ParseTuple(args, "i:alarm", &t))
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
205 return NULL;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
206 /* alarm() returns the number of seconds remaining */
18754
3cd03a64c338 Make more warnings go away on the SGI compiler.
Fred Drake <fdrake@acm.org>
parents: 16998
diff changeset
207 return PyInt_FromLong((long)alarm(t));
1817
20e1d296fdcc * Modules/signalmodule.c: added pause().
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
208 }
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
209
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
210 PyDoc_STRVAR(alarm_doc,
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
211 "alarm(seconds)\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
212 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
213 Arrange for SIGALRM to arrive after the given number of seconds.");
2521
e7d480cf16ba added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents: 2211
diff changeset
214 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1678
diff changeset
215
6142
144db635b49d Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents: 5923
diff changeset
216 #ifdef HAVE_PAUSE
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2076
diff changeset
217 static PyObject *
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22114
diff changeset
218 signal_pause(PyObject *self)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 {
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2076
diff changeset
220 Py_BEGIN_ALLOW_THREADS
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
221 (void)pause();
2123
fd5ab7e828fc cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents: 2076
diff changeset
222 Py_END_ALLOW_THREADS
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
223 /* make sure that any exceptions that got raised are propagated
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
224 * back into Python
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
225 */
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
226 if (PyErr_CheckSignals())
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
227 return NULL;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
228
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
229 Py_INCREF(Py_None);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
230 return Py_None;
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
231 }
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
232 PyDoc_STRVAR(pause_doc,
8696
f7b4db0c5b08 (pause_doc): Sun CC complains about newline in string literal
Barry Warsaw <barry@python.org>
parents: 8571
diff changeset
233 "pause()\n\
f7b4db0c5b08 (pause_doc): Sun CC complains about newline in string literal
Barry Warsaw <barry@python.org>
parents: 8571
diff changeset
234 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
235 Wait until a signal arrives.");
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
236
2521
e7d480cf16ba added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents: 2211
diff changeset
237 #endif
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
238
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
239
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
240 static PyObject *
13500
d9cc620ff186 ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13447
diff changeset
241 signal_signal(PyObject *self, PyObject *args)
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
242 {
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
243 PyObject *obj;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 int sig_num;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
245 PyObject *old_handler;
13676
5423b132bc97 Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents: 13673
diff changeset
246 void (*func)(int);
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
247 if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj))
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
248 return NULL;
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
249 #ifdef WITH_THREAD
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
250 if (PyThread_get_thread_ident() != main_thread) {
2564
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
251 PyErr_SetString(PyExc_ValueError,
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
252 "signal only works in main thread");
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
253 return NULL;
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
254 }
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
255 #endif
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 if (sig_num < 1 || sig_num >= NSIG) {
2564
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
257 PyErr_SetString(PyExc_ValueError,
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
258 "signal number out of range");
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
259 return NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 }
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
261 if (obj == IgnoreHandler)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 func = SIG_IGN;
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
263 else if (obj == DefaultHandler)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 func = SIG_DFL;
2564
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
265 else if (!PyCallable_Check(obj)) {
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
266 PyErr_SetString(PyExc_TypeError,
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 "signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object");
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
268 return NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 else
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
271 func = signal_handler;
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
272 if (PyOS_setsig(sig_num, func) == SIG_ERR) {
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
273 PyErr_SetFromErrno(PyExc_RuntimeError);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
274 return NULL;
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
275 }
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
276 old_handler = Handlers[sig_num].func;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
277 Handlers[sig_num].tripped = 0;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
278 Py_INCREF(obj);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
279 Handlers[sig_num].func = obj;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 return old_handler;
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
282
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
283 PyDoc_STRVAR(signal_doc,
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
284 "signal(sig, action) -> action\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
285 \n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
286 Set the action for the given signal. The action can be SIG_DFL,\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
287 SIG_IGN, or a callable Python object. The previous action is\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
288 returned. See getsignal() for possible return values.\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
289 \n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
290 *** IMPORTANT NOTICE ***\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
291 A signal handler function is called with two arguments:\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
292 the first is the signal number, the second is the interrupted stack frame.");
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
293
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
294
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
295 static PyObject *
13500
d9cc620ff186 ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents: 13447
diff changeset
296 signal_getsignal(PyObject *self, PyObject *args)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 {
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 int sig_num;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
299 PyObject *old_handler;
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
300 if (!PyArg_ParseTuple(args, "i:getsignal", &sig_num))
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
301 return NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 if (sig_num < 1 || sig_num >= NSIG) {
2564
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
303 PyErr_SetString(PyExc_ValueError,
7fbff52db087 use PyCallable_Check; split some lines
Guido van Rossum <guido@python.org>
parents: 2521
diff changeset
304 "signal number out of range");
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
305 return NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 }
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
307 old_handler = Handlers[sig_num].func;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
308 Py_INCREF(old_handler);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 return old_handler;
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
311
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
312 PyDoc_STRVAR(getsignal_doc,
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
313 "getsignal(sig) -> action\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
314 \n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
315 Return the current action for the given signal. The return value can be:\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
316 SIG_IGN -- if the signal is being ignored\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
317 SIG_DFL -- if the default action for the signal is in effect\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
318 None -- if an unknown handler is in effect\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
319 anything else -- the callable Python object used as a handler");
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
320
45452
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
321 #ifdef HAVE_SIGINTERRUPT
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
322 PyDoc_STRVAR(siginterrupt_doc,
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
323 "siginterrupt(sig, flag) -> None\n\
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
324 change system call restart behaviour: if flag is False, system calls\n\
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
325 will be restarted when interrupted by signal sig, else system calls\n\
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
326 will be interrupted.");
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
327
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
328 static PyObject *
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
329 signal_siginterrupt(PyObject *self, PyObject *args)
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
330 {
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
331 int sig_num;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
332 int flag;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
333
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
334 if (!PyArg_ParseTuple(args, "ii:siginterrupt", &sig_num, &flag))
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
335 return NULL;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
336 if (sig_num < 1 || sig_num >= NSIG) {
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
337 PyErr_SetString(PyExc_ValueError,
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
338 "signal number out of range");
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
339 return NULL;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
340 }
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
341 if (siginterrupt(sig_num, flag)<0) {
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
342 PyErr_SetFromErrno(PyExc_RuntimeError);
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
343 return NULL;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
344 }
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
345
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
346 Py_INCREF(Py_None);
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
347 return Py_None;
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
348 }
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
349
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
350 #endif
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
351
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
352 static PyObject *
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
353 signal_set_wakeup_fd(PyObject *self, PyObject *args)
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
354 {
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
355 struct stat buf;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
356 int fd, old_fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
357 if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd))
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
358 return NULL;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
359 #ifdef WITH_THREAD
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
360 if (PyThread_get_thread_ident() != main_thread) {
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
361 PyErr_SetString(PyExc_ValueError,
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
362 "set_wakeup_fd only works in main thread");
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
363 return NULL;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
364 }
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
365 #endif
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
366 if (fd != -1 && fstat(fd, &buf) != 0) {
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
367 PyErr_SetString(PyExc_ValueError, "invalid fd");
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
368 return NULL;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
369 }
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
370 old_fd = wakeup_fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
371 wakeup_fd = fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
372 return PyLong_FromLong(old_fd);
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
373 }
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
374
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
375 PyDoc_STRVAR(set_wakeup_fd_doc,
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
376 "set_wakeup_fd(fd) -> fd\n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
377 \n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
378 Sets the fd to be written to (with '\\0') when a signal\n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
379 comes in. A library can use this to wakeup select or poll.\n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
380 The previous fd is returned.\n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
381 \n\
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
382 The fd must be non-blocking.");
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
383
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
384 /* C API for the same, without all the error checking */
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
385 int
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
386 PySignal_SetWakeupFd(int fd)
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
387 {
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
388 int old_fd = wakeup_fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
389 if (fd < 0)
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
390 fd = -1;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
391 wakeup_fd = fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
392 return old_fd;
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
393 }
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
394
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
395
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
396 #ifdef HAVE_SETITIMER
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
397 static PyObject *
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
398 signal_setitimer(PyObject *self, PyObject *args)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
399 {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
400 double first;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
401 double interval = 0;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
402 int which;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
403 struct itimerval new, old;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
404
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
405 if(!PyArg_ParseTuple(args, "id|d:setitimer", &which, &first, &interval))
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
406 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
407
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
408 timeval_from_double(first, &new.it_value);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
409 timeval_from_double(interval, &new.it_interval);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
410 /* Let OS check "which" value */
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
411 if (setitimer(which, &new, &old) != 0) {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
412 PyErr_SetFromErrno(ItimerError);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
413 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
414 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
415
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
416 return itimer_retval(&old);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
417 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
418
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
419 PyDoc_STRVAR(setitimer_doc,
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
420 "setitimer(which, seconds[, interval])\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
421 \n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
422 Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
423 or ITIMER_PROF) to fire after value seconds and after\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
424 that every interval seconds.\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
425 The itimer can be cleared by setting seconds to zero.\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
426 \n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
427 Returns old values as a tuple: (delay, interval).");
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
428 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
429
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
430
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
431 #ifdef HAVE_GETITIMER
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
432 static PyObject *
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
433 signal_getitimer(PyObject *self, PyObject *args)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
434 {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
435 int which;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
436 struct itimerval old;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
437
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
438 if (!PyArg_ParseTuple(args, "i:getitimer", &which))
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
439 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
440
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
441 if (getitimer(which, &old) != 0) {
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
442 PyErr_SetFromErrno(ItimerError);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
443 return NULL;
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
444 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
445
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
446 return itimer_retval(&old);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
447 }
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
448
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
449 PyDoc_STRVAR(getitimer_doc,
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
450 "getitimer(which)\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
451 \n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
452 Returns current value of given itimer.");
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
453 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
454
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
455
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
456 /* List of functions defined in the module */
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
457 static PyMethodDef signal_methods[] = {
6142
144db635b49d Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents: 5923
diff changeset
458 #ifdef HAVE_ALARM
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
459 {"alarm", signal_alarm, METH_VARARGS, alarm_doc},
2521
e7d480cf16ba added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents: 2211
diff changeset
460 #endif
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
461 #ifdef HAVE_SETITIMER
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
462 {"setitimer", signal_setitimer, METH_VARARGS, setitimer_doc},
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
463 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
464 #ifdef HAVE_GETITIMER
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
465 {"getitimer", signal_getitimer, METH_VARARGS, getitimer_doc},
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
466 #endif
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
467 {"signal", signal_signal, METH_VARARGS, signal_doc},
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
468 {"getsignal", signal_getsignal, METH_VARARGS, getsignal_doc},
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
469 {"set_wakeup_fd", signal_set_wakeup_fd, METH_VARARGS, set_wakeup_fd_doc},
45452
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
470 #ifdef HAVE_SIGINTERRUPT
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
471 {"siginterrupt", signal_siginterrupt, METH_VARARGS, siginterrupt_doc},
3657c27ea2fd Issue 1089358. Adds the siginterrupt() function, that is just a
Facundo Batista <facundobatista@gmail.com>
parents: 44355
diff changeset
472 #endif
6142
144db635b49d Added configuration tests for presence of alarm(), pause(), and getpwent()
Guido van Rossum <guido@python.org>
parents: 5923
diff changeset
473 #ifdef HAVE_PAUSE
22630
e6fccde61086 Add type cast.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22561
diff changeset
474 {"pause", (PyCFunction)signal_pause,
e6fccde61086 Add type cast.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22561
diff changeset
475 METH_NOARGS,pause_doc},
2521
e7d480cf16ba added PyErr_SetInterrupt(); NT ifdefs
Guido van Rossum <guido@python.org>
parents: 2211
diff changeset
476 #endif
44355
b89b0334372b Patch #1583 by Adam Olsen.
Guido van Rossum <guido@python.org>
parents: 44264
diff changeset
477 {"default_int_handler", signal_default_int_handler,
22709
3aa4bf7ac31e Remove METH_OLDARGS:
Neal Norwitz <nnorwitz@gmail.com>
parents: 22630
diff changeset
478 METH_VARARGS, default_int_handler_doc},
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
479 {NULL, NULL} /* sentinel */
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 };
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
481
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
482
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
483 PyDoc_STRVAR(module_doc,
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
484 "This module provides mechanisms to use signal handlers in Python.\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
485 \n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
486 Functions:\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
487 \n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
488 alarm() -- cause SIGALRM after a specified time [Unix only]\n\
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
489 setitimer() -- cause a signal (described below) after a specified\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
490 float time and the timer may restart then [Unix only]\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
491 getitimer() -- get current value of timer [Unix only]\n\
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
492 signal() -- set the action for a given signal\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
493 getsignal() -- get the signal action for a given signal\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
494 pause() -- wait until a signal arrives [Unix only]\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
495 default_int_handler() -- default SIGINT handler\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
496 \n\
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
497 signal constants:\n\
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
498 SIG_DFL -- used to refer to the system default handler\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
499 SIG_IGN -- used to ignore the signal\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
500 NSIG -- number of defined signals\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
501 SIGINT, SIGTERM, etc. -- signal numbers\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
502 \n\
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
503 itimer constants:\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
504 ITIMER_REAL -- decrements in real time, and delivers SIGALRM upon\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
505 expiration\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
506 ITIMER_VIRTUAL -- decrements only when the process is executing,\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
507 and delivers SIGVTALRM upon expiration\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
508 ITIMER_PROF -- decrements both when the process is executing and\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
509 when the system is executing on behalf of the process.\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
510 Coupled with ITIMER_VIRTUAL, this timer is usually\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
511 used to profile the time spent by the application\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
512 in user and kernel space. SIGPROF is delivered upon\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
513 expiration.\n\
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
514 \n\n\
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
515 *** IMPORTANT NOTICE ***\n\
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
516 A signal handler function is called with two arguments:\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23550
diff changeset
517 the first is the signal number, the second is the interrupted stack frame.");
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
518
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24071
diff changeset
519 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
520 initsignal(void)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 {
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
522 PyObject *m, *d, *x;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 int i;
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
524
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
525 #ifdef WITH_THREAD
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
526 main_thread = PyThread_get_thread_ident();
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
527 main_pid = getpid();
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
528 #endif
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
529
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 /* Create the module and add the functions */
8570
bd695de18ecf Added doc strings.
Guido van Rossum <guido@python.org>
parents: 8210
diff changeset
531 m = Py_InitModule3("signal", signal_methods, module_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35551
diff changeset
532 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35551
diff changeset
533 return;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
534
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 /* Add some symbolic constants to the module */
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
536 d = PyModule_GetDict(m);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
537
13253
a6a64e9ab238 Fix another error on AIX by using a proper cast.
Guido van Rossum <guido@python.org>
parents: 13103
diff changeset
538 x = DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
539 if (!x || PyDict_SetItemString(d, "SIG_DFL", x) < 0)
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
540 goto finally;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
541
13253
a6a64e9ab238 Fix another error on AIX by using a proper cast.
Guido van Rossum <guido@python.org>
parents: 13103
diff changeset
542 x = IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
543 if (!x || PyDict_SetItemString(d, "SIG_IGN", x) < 0)
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
544 goto finally;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
545
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
546 x = PyInt_FromLong((long)NSIG);
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
547 if (!x || PyDict_SetItemString(d, "NSIG", x) < 0)
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
548 goto finally;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
549 Py_DECREF(x);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
550
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
551 x = IntHandler = PyDict_GetItemString(d, "default_int_handler");
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
552 if (!x)
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
553 goto finally;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
554 Py_INCREF(IntHandler);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
555
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
556 Handlers[0].tripped = 0;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
557 for (i = 1; i < NSIG; i++) {
13676
5423b132bc97 Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents: 13673
diff changeset
558 void (*t)(int);
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
559 t = PyOS_getsig(i);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
560 Handlers[i].tripped = 0;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
561 if (t == SIG_DFL)
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
562 Handlers[i].func = DefaultHandler;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
563 else if (t == SIG_IGN)
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
564 Handlers[i].func = IgnoreHandler;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
565 else
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
566 Handlers[i].func = Py_None; /* None of our business */
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
567 Py_INCREF(Handlers[i].func);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 }
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
569 if (Handlers[SIGINT].func == DefaultHandler) {
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 /* Install default int handler */
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
571 Py_INCREF(IntHandler);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
572 Py_DECREF(Handlers[SIGINT].func);
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
573 Handlers[SIGINT].func = IntHandler;
23843
85a4e727b16b SF # 533070 Silence AIX C Compiler Warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 23832
diff changeset
574 old_siginthandler = PyOS_setsig(SIGINT, signal_handler);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
576
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
577 #ifdef SIGHUP
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
578 x = PyInt_FromLong(SIGHUP);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
579 PyDict_SetItemString(d, "SIGHUP", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
580 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
581 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 #ifdef SIGINT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
583 x = PyInt_FromLong(SIGINT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
584 PyDict_SetItemString(d, "SIGINT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
585 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
586 #endif
20207
e2da9a929aca SF patch [#466877] SIGBREAK is missing from signal module.
Tim Peters <tim.peters@gmail.com>
parents: 18754
diff changeset
587 #ifdef SIGBREAK
e2da9a929aca SF patch [#466877] SIGBREAK is missing from signal module.
Tim Peters <tim.peters@gmail.com>
parents: 18754
diff changeset
588 x = PyInt_FromLong(SIGBREAK);
e2da9a929aca SF patch [#466877] SIGBREAK is missing from signal module.
Tim Peters <tim.peters@gmail.com>
parents: 18754
diff changeset
589 PyDict_SetItemString(d, "SIGBREAK", x);
e2da9a929aca SF patch [#466877] SIGBREAK is missing from signal module.
Tim Peters <tim.peters@gmail.com>
parents: 18754
diff changeset
590 Py_XDECREF(x);
e2da9a929aca SF patch [#466877] SIGBREAK is missing from signal module.
Tim Peters <tim.peters@gmail.com>
parents: 18754
diff changeset
591 #endif
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
592 #ifdef SIGQUIT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
593 x = PyInt_FromLong(SIGQUIT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
594 PyDict_SetItemString(d, "SIGQUIT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
595 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
597 #ifdef SIGILL
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
598 x = PyInt_FromLong(SIGILL);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
599 PyDict_SetItemString(d, "SIGILL", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
600 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
602 #ifdef SIGTRAP
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
603 x = PyInt_FromLong(SIGTRAP);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
604 PyDict_SetItemString(d, "SIGTRAP", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
605 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
606 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 #ifdef SIGIOT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
608 x = PyInt_FromLong(SIGIOT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
609 PyDict_SetItemString(d, "SIGIOT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
610 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
612 #ifdef SIGABRT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
613 x = PyInt_FromLong(SIGABRT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
614 PyDict_SetItemString(d, "SIGABRT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
615 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 #ifdef SIGEMT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
618 x = PyInt_FromLong(SIGEMT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
619 PyDict_SetItemString(d, "SIGEMT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
620 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
621 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
622 #ifdef SIGFPE
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
623 x = PyInt_FromLong(SIGFPE);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
624 PyDict_SetItemString(d, "SIGFPE", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
625 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 #ifdef SIGKILL
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
628 x = PyInt_FromLong(SIGKILL);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
629 PyDict_SetItemString(d, "SIGKILL", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
630 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 #ifdef SIGBUS
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
633 x = PyInt_FromLong(SIGBUS);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
634 PyDict_SetItemString(d, "SIGBUS", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
635 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 #ifdef SIGSEGV
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
638 x = PyInt_FromLong(SIGSEGV);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
639 PyDict_SetItemString(d, "SIGSEGV", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
640 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 #ifdef SIGSYS
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
643 x = PyInt_FromLong(SIGSYS);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
644 PyDict_SetItemString(d, "SIGSYS", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
645 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
646 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
647 #ifdef SIGPIPE
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
648 x = PyInt_FromLong(SIGPIPE);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
649 PyDict_SetItemString(d, "SIGPIPE", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
650 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
652 #ifdef SIGALRM
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
653 x = PyInt_FromLong(SIGALRM);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
654 PyDict_SetItemString(d, "SIGALRM", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
655 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
656 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
657 #ifdef SIGTERM
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
658 x = PyInt_FromLong(SIGTERM);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
659 PyDict_SetItemString(d, "SIGTERM", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
660 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
661 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
662 #ifdef SIGUSR1
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
663 x = PyInt_FromLong(SIGUSR1);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
664 PyDict_SetItemString(d, "SIGUSR1", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
665 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
666 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 #ifdef SIGUSR2
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
668 x = PyInt_FromLong(SIGUSR2);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
669 PyDict_SetItemString(d, "SIGUSR2", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
670 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
671 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
672 #ifdef SIGCLD
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
673 x = PyInt_FromLong(SIGCLD);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
674 PyDict_SetItemString(d, "SIGCLD", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
675 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
676 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 #ifdef SIGCHLD
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
678 x = PyInt_FromLong(SIGCHLD);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
679 PyDict_SetItemString(d, "SIGCHLD", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
680 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
682 #ifdef SIGPWR
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
683 x = PyInt_FromLong(SIGPWR);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
684 PyDict_SetItemString(d, "SIGPWR", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
685 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
686 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 #ifdef SIGIO
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
688 x = PyInt_FromLong(SIGIO);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
689 PyDict_SetItemString(d, "SIGIO", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
690 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
691 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
692 #ifdef SIGURG
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
693 x = PyInt_FromLong(SIGURG);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
694 PyDict_SetItemString(d, "SIGURG", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
695 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
696 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
697 #ifdef SIGWINCH
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
698 x = PyInt_FromLong(SIGWINCH);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
699 PyDict_SetItemString(d, "SIGWINCH", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
700 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
702 #ifdef SIGPOLL
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
703 x = PyInt_FromLong(SIGPOLL);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
704 PyDict_SetItemString(d, "SIGPOLL", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
705 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 #ifdef SIGSTOP
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
708 x = PyInt_FromLong(SIGSTOP);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
709 PyDict_SetItemString(d, "SIGSTOP", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
710 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
711 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
712 #ifdef SIGTSTP
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
713 x = PyInt_FromLong(SIGTSTP);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
714 PyDict_SetItemString(d, "SIGTSTP", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
715 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 #ifdef SIGCONT
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
718 x = PyInt_FromLong(SIGCONT);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
719 PyDict_SetItemString(d, "SIGCONT", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
720 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
721 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
722 #ifdef SIGTTIN
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
723 x = PyInt_FromLong(SIGTTIN);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
724 PyDict_SetItemString(d, "SIGTTIN", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
725 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
726 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 #ifdef SIGTTOU
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
728 x = PyInt_FromLong(SIGTTOU);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
729 PyDict_SetItemString(d, "SIGTTOU", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
730 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
731 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 #ifdef SIGVTALRM
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
733 x = PyInt_FromLong(SIGVTALRM);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
734 PyDict_SetItemString(d, "SIGVTALRM", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
735 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 #endif
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 #ifdef SIGPROF
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
738 x = PyInt_FromLong(SIGPROF);
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
739 PyDict_SetItemString(d, "SIGPROF", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
740 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 #endif
4736
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
742 #ifdef SIGXCPU
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
743 x = PyInt_FromLong(SIGXCPU);
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
744 PyDict_SetItemString(d, "SIGXCPU", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
745 Py_XDECREF(x);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
746 #endif
4736
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
747 #ifdef SIGXFSZ
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
748 x = PyInt_FromLong(SIGXFSZ);
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
749 PyDict_SetItemString(d, "SIGXFSZ", x);
4920
e77585af2a21 initsignal(): Py_DECREFs really should be Py_XDECREFs in case the
Barry Warsaw <barry@python.org>
parents: 4863
diff changeset
750 Py_XDECREF(x);
4736
94ad56ef5073 initsignal(): Added SIGXCPU and SIGXFSZ. Left in the definitions for
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
751 #endif
30032
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
752 #ifdef SIGRTMIN
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
753 x = PyInt_FromLong(SIGRTMIN);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
754 PyDict_SetItemString(d, "SIGRTMIN", x);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
755 Py_XDECREF(x);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
756 #endif
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
757 #ifdef SIGRTMAX
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
758 x = PyInt_FromLong(SIGRTMAX);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
759 PyDict_SetItemString(d, "SIGRTMAX", x);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
760 Py_XDECREF(x);
677038873a22 Patch [ 776725 ] add SIGRTMIN, SIGRTMAX to signalmodule.c
Anthony Baxter <anthonybaxter@gmail.com>
parents: 28295
diff changeset
761 #endif
21715
4c6c13aa8a99 Export SIGINFO. Fixes #502077.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
762 #ifdef SIGINFO
4c6c13aa8a99 Export SIGINFO. Fixes #502077.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
763 x = PyInt_FromLong(SIGINFO);
4c6c13aa8a99 Export SIGINFO. Fixes #502077.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
764 PyDict_SetItemString(d, "SIGINFO", x);
4c6c13aa8a99 Export SIGINFO. Fixes #502077.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
765 Py_XDECREF(x);
4c6c13aa8a99 Export SIGINFO. Fixes #502077.
Martin v. Löwis <martin@v.loewis.de>
parents: 21712
diff changeset
766 #endif
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
767
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
768 #ifdef ITIMER_REAL
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
769 x = PyLong_FromLong(ITIMER_REAL);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
770 PyDict_SetItemString(d, "ITIMER_REAL", x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
771 Py_DECREF(x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
772 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
773 #ifdef ITIMER_VIRTUAL
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
774 x = PyLong_FromLong(ITIMER_VIRTUAL);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
775 PyDict_SetItemString(d, "ITIMER_VIRTUAL", x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
776 Py_DECREF(x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
777 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
778 #ifdef ITIMER_PROF
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
779 x = PyLong_FromLong(ITIMER_PROF);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
780 PyDict_SetItemString(d, "ITIMER_PROF", x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
781 Py_DECREF(x);
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
782 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
783
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
784 #if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
785 ItimerError = PyErr_NewException("signal.ItimerError",
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
786 PyExc_IOError, NULL);
48847
Neal Norwitz <nnorwitz@gmail.com>
parents: 47664
diff changeset
787 if (ItimerError != NULL)
Neal Norwitz <nnorwitz@gmail.com>
parents: 47664
diff changeset
788 PyDict_SetItemString(d, "ItimerError", ItimerError);
46053
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
789 #endif
461ff43e74d0 Patch #2240: Implement signal.setitimer and signal.getitimer.
Martin v. Löwis <martin@v.loewis.de>
parents: 45452
diff changeset
790
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
791 if (!PyErr_Occurred())
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
792 return;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
793
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
794 /* Check for errors */
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
795 finally:
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
796 return;
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
797 }
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
798
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
799 static void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
800 finisignal(void)
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
801 {
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
802 int i;
6546
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
803 PyObject *func;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
804
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
805 PyOS_setsig(SIGINT, old_siginthandler);
6546
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
806 old_siginthandler = SIG_DFL;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
807
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
808 for (i = 1; i < NSIG; i++) {
6546
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
809 func = Handlers[i].func;
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
810 Handlers[i].tripped = 0;
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
811 Handlers[i].func = NULL;
6546
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
812 if (i != SIGINT && func != NULL && func != Py_None &&
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
813 func != DefaultHandler && func != IgnoreHandler)
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
814 PyOS_setsig(i, SIG_DFL);
6546
c915c94ebb6b Change the signal finialization so that it also resets the signal
Guido van Rossum <guido@python.org>
parents: 6142
diff changeset
815 Py_XDECREF(func);
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
816 }
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
817
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
818 Py_XDECREF(IntHandler);
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
819 IntHandler = NULL;
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
820 Py_XDECREF(DefaultHandler);
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
821 DefaultHandler = NULL;
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
822 Py_XDECREF(IgnoreHandler);
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
823 IgnoreHandler = NULL;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
824 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
825
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
826
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
827 /* Declared in pyerrors.h */
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
828 int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
829 PyErr_CheckSignals(void)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 {
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
831 int i;
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
832 PyObject *f;
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
833
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
834 if (!is_tripped)
1658
a862d8f4507b Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents: 1630
diff changeset
835 return 0;
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
836
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
837 #ifdef WITH_THREAD
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
838 if (PyThread_get_thread_ident() != main_thread)
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
839 return 0;
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
840 #endif
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
841
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
842 /*
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
843 * The is_stripped variable is meant to speed up the calls to
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
844 * PyErr_CheckSignals (both directly or via pending calls) when no
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
845 * signal has arrived. This variable is set to 1 when a signal arrives
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
846 * and it is set to 0 here, when we know some signals arrived. This way
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
847 * we can run the registered handlers with no signals blocked.
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
848 *
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
849 * NOTE: with this approach we can have a situation where is_tripped is
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
850 * 1 but we have no more signals to handle (Handlers[i].tripped
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
851 * is 0 for every signal i). This won't do us any harm (except
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
852 * we're gonna spent some cycles for nothing). This happens when
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
853 * we receive a signal i after we zero is_tripped and before we
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
854 * check Handlers[i].tripped.
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
855 */
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
856 is_tripped = 0;
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
857
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 24471
diff changeset
858 if (!(f = (PyObject *)PyEval_GetFrame()))
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
859 f = Py_None;
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
860
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
861 for (i = 1; i < NSIG; i++) {
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
862 if (Handlers[i].tripped) {
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
863 PyObject *result = NULL;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
864 PyObject *arglist = Py_BuildValue("(iO)", i, f);
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
865 Handlers[i].tripped = 0;
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
866
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
867 if (arglist) {
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
868 result = PyEval_CallObject(Handlers[i].func,
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
869 arglist);
1867
758c1374f303 Setup.in: added tkinter; rearranged the definition of PYTHONPATH so
Guido van Rossum <guido@python.org>
parents: 1817
diff changeset
870 Py_DECREF(arglist);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
871 }
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
872 if (!result)
5020
0eca9d5f7b2d Arrange for PyErr_CheckSignals() to be called via Py_AddPendingCall().
Guido van Rossum <guido@python.org>
parents: 4920
diff changeset
873 return -1;
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
874
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
875 Py_DECREF(result);
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
876 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
877 }
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
878
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
879 return 0;
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
880 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
881
14638
2e170c2f61e1 Use typedef PyOS_sighandler_t and APIs PyOS_getsig() and
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
882
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
883 /* Replacements for intrcheck.c functionality
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
884 * Declared in pyerrors.h
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
885 */
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
886 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
887 PyErr_SetInterrupt(void)
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
888 {
44264
a4aab72c2cc0 Backport patch #1643738.
Guido van Rossum <guido@python.org>
parents: 36324
diff changeset
889 is_tripped = 1;
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
890 Handlers[SIGINT].tripped = 1;
13709
4e2aaf1e722a Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Thomas Wouters <thomas@python.org>
parents: 13676
diff changeset
891 Py_AddPendingCall((int (*)(void *))PyErr_CheckSignals, NULL);
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
892 }
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
893
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
894 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
895 PyOS_InitInterrupts(void)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
896 {
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
897 initsignal();
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
898 _PyImport_FixupExtension("signal", "signal");
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
899 }
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
900
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
901 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
902 PyOS_FiniInterrupts(void)
5923
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
903 {
3e158e69ac5d Add finialization routines; fixed some memory leaks related to this.
Guido van Rossum <guido@python.org>
parents: 5730
diff changeset
904 finisignal();
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
905 }
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
906
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
907 int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
908 PyOS_InterruptOccurred(void)
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
909 {
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
910 if (Handlers[SIGINT].tripped) {
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
911 #ifdef WITH_THREAD
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
912 if (PyThread_get_thread_ident() != main_thread)
1678
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
913 return 0;
1f06f71904c2 * Modules/signalmodule.c: added thread compatibility (only main
Guido van Rossum <guido@python.org>
parents: 1658
diff changeset
914 #endif
4863
b1707bcdc265 Several changes:
Barry Warsaw <barry@python.org>
parents: 4736
diff changeset
915 Handlers[SIGINT].tripped = 0;
1658
a862d8f4507b Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents: 1630
diff changeset
916 return 1;
a862d8f4507b Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents: 1630
diff changeset
917 }
a862d8f4507b Speed up checking for signals and define intrcheck differently
Guido van Rossum <guido@python.org>
parents: 1630
diff changeset
918 return 0;
1630
0202a72d994e New experimental modules -- signal and sybase
Guido van Rossum <guido@python.org>
parents:
diff changeset
919 }
6578
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
920
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
921 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13500
diff changeset
922 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: 6546
diff changeset
923 {
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
924 #ifdef WITH_THREAD
14225
cbe9590d2344 Charles Waldman's patch to reinitialize the interpreter lock after a
Guido van Rossum <guido@python.org>
parents: 13820
diff changeset
925 PyEval_ReInitThreads();
9679
877d23bd5bdc Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
926 main_thread = PyThread_get_thread_ident();
6578
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
927 main_pid = getpid();
35551
57f630a9de26 - Changes donated by Elemental Security to make it work on AIX 5.3
Guido van Rossum <guido@python.org>
parents: 33747
diff changeset
928 _PyImport_ReInitLock();
47664
db99f8752710 #1683 prevent forking from interfering in threading storage
Benjamin Peterson <benjamin@python.org>
parents: 46055
diff changeset
929 PyThread_ReInitTLS();
6578
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
930 #endif
01ee5607bb35 This fix (across 4 files in 3 directories) solves a subtle problem with
Guido van Rossum <guido@python.org>
parents: 6546
diff changeset
931 }