blob: bc46515cb436bd4dcc242d8a851e830dc32fe511 [file] [log] [blame]
Tal Einatc7027b72015-05-16 14:14:49 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5#if defined(HAVE_ALARM)
6
7PyDoc_STRVAR(signal_alarm__doc__,
8"alarm($module, seconds, /)\n"
9"--\n"
10"\n"
11"Arrange for SIGALRM to arrive after the given number of seconds.");
12
13#define SIGNAL_ALARM_METHODDEF \
14 {"alarm", (PyCFunction)signal_alarm, METH_O, signal_alarm__doc__},
15
16static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030017signal_alarm_impl(PyObject *module, int seconds);
Tal Einatc7027b72015-05-16 14:14:49 +030018
19static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030020signal_alarm(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +030021{
22 PyObject *return_value = NULL;
23 int seconds;
24 long _return_value;
25
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020026 if (PyFloat_Check(arg)) {
27 PyErr_SetString(PyExc_TypeError,
28 "integer argument expected, got float" );
29 goto exit;
30 }
31 seconds = _PyLong_AsInt(arg);
32 if (seconds == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030034 }
Tal Einatc7027b72015-05-16 14:14:49 +030035 _return_value = signal_alarm_impl(module, seconds);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030036 if ((_return_value == -1) && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +030037 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030038 }
Tal Einatc7027b72015-05-16 14:14:49 +030039 return_value = PyLong_FromLong(_return_value);
40
41exit:
42 return return_value;
43}
44
45#endif /* defined(HAVE_ALARM) */
46
47#if defined(HAVE_PAUSE)
48
49PyDoc_STRVAR(signal_pause__doc__,
50"pause($module, /)\n"
51"--\n"
52"\n"
53"Wait until a signal arrives.");
54
55#define SIGNAL_PAUSE_METHODDEF \
56 {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
57
58static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030059signal_pause_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +030060
61static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030062signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +030063{
64 return signal_pause_impl(module);
65}
66
67#endif /* defined(HAVE_PAUSE) */
68
Vladimir Matveevc24c6c22019-01-08 01:58:25 -080069PyDoc_STRVAR(signal_raise_signal__doc__,
70"raise_signal($module, signalnum, /)\n"
71"--\n"
72"\n"
73"Send a signal to the executing process.");
74
75#define SIGNAL_RAISE_SIGNAL_METHODDEF \
76 {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__},
77
78static PyObject *
79signal_raise_signal_impl(PyObject *module, int signalnum);
80
81static PyObject *
82signal_raise_signal(PyObject *module, PyObject *arg)
83{
84 PyObject *return_value = NULL;
85 int signalnum;
86
87 if (PyFloat_Check(arg)) {
88 PyErr_SetString(PyExc_TypeError,
89 "integer argument expected, got float" );
90 goto exit;
91 }
92 signalnum = _PyLong_AsInt(arg);
93 if (signalnum == -1 && PyErr_Occurred()) {
94 goto exit;
95 }
96 return_value = signal_raise_signal_impl(module, signalnum);
97
98exit:
99 return return_value;
100}
101
Tal Einatc7027b72015-05-16 14:14:49 +0300102PyDoc_STRVAR(signal_signal__doc__,
103"signal($module, signalnum, handler, /)\n"
104"--\n"
105"\n"
106"Set the action for the given signal.\n"
107"\n"
108"The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
109"The previous action is returned. See getsignal() for possible return values.\n"
110"\n"
111"*** IMPORTANT NOTICE ***\n"
112"A signal handler function is called with two arguments:\n"
113"the first is the signal number, the second is the interrupted stack frame.");
114
115#define SIGNAL_SIGNAL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200116 {"signal", (PyCFunction)(void(*)(void))signal_signal, METH_FASTCALL, signal_signal__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300117
118static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300119signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
Tal Einatc7027b72015-05-16 14:14:49 +0300120
121static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200122signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300123{
124 PyObject *return_value = NULL;
125 int signalnum;
126 PyObject *handler;
127
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200128 if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100129 goto exit;
130 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200131 if (PyFloat_Check(args[0])) {
132 PyErr_SetString(PyExc_TypeError,
133 "integer argument expected, got float" );
134 goto exit;
135 }
136 signalnum = _PyLong_AsInt(args[0]);
137 if (signalnum == -1 && PyErr_Occurred()) {
138 goto exit;
139 }
140 handler = args[1];
Tal Einatc7027b72015-05-16 14:14:49 +0300141 return_value = signal_signal_impl(module, signalnum, handler);
142
143exit:
144 return return_value;
145}
146
147PyDoc_STRVAR(signal_getsignal__doc__,
148"getsignal($module, signalnum, /)\n"
149"--\n"
150"\n"
151"Return the current action for the given signal.\n"
152"\n"
153"The return value can be:\n"
154" SIG_IGN -- if the signal is being ignored\n"
155" SIG_DFL -- if the default action for the signal is in effect\n"
156" None -- if an unknown handler is in effect\n"
157" anything else -- the callable Python object used as a handler");
158
159#define SIGNAL_GETSIGNAL_METHODDEF \
160 {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
161
162static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300163signal_getsignal_impl(PyObject *module, int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300164
165static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300166signal_getsignal(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300167{
168 PyObject *return_value = NULL;
169 int signalnum;
170
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200171 if (PyFloat_Check(arg)) {
172 PyErr_SetString(PyExc_TypeError,
173 "integer argument expected, got float" );
174 goto exit;
175 }
176 signalnum = _PyLong_AsInt(arg);
177 if (signalnum == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300178 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300179 }
Tal Einatc7027b72015-05-16 14:14:49 +0300180 return_value = signal_getsignal_impl(module, signalnum);
181
182exit:
183 return return_value;
184}
185
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100186PyDoc_STRVAR(signal_strsignal__doc__,
187"strsignal($module, signalnum, /)\n"
188"--\n"
189"\n"
190"Return the system description of the given signal.\n"
191"\n"
192"The return values can be such as \"Interrupt\", \"Segmentation fault\", etc.\n"
193"Returns None if the signal is not recognized.");
194
195#define SIGNAL_STRSIGNAL_METHODDEF \
196 {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
197
198static PyObject *
199signal_strsignal_impl(PyObject *module, int signalnum);
200
201static PyObject *
202signal_strsignal(PyObject *module, PyObject *arg)
203{
204 PyObject *return_value = NULL;
205 int signalnum;
206
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200207 if (PyFloat_Check(arg)) {
208 PyErr_SetString(PyExc_TypeError,
209 "integer argument expected, got float" );
210 goto exit;
211 }
212 signalnum = _PyLong_AsInt(arg);
213 if (signalnum == -1 && PyErr_Occurred()) {
Antoine Pietri5d2a27d2018-03-12 14:42:34 +0100214 goto exit;
215 }
216 return_value = signal_strsignal_impl(module, signalnum);
217
218exit:
219 return return_value;
220}
221
Tal Einatc7027b72015-05-16 14:14:49 +0300222#if defined(HAVE_SIGINTERRUPT)
223
224PyDoc_STRVAR(signal_siginterrupt__doc__,
225"siginterrupt($module, signalnum, flag, /)\n"
226"--\n"
227"\n"
228"Change system call restart behaviour.\n"
229"\n"
230"If flag is False, system calls will be restarted when interrupted by\n"
231"signal sig, else system calls will be interrupted.");
232
233#define SIGNAL_SIGINTERRUPT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200234 {"siginterrupt", (PyCFunction)(void(*)(void))signal_siginterrupt, METH_FASTCALL, signal_siginterrupt__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300235
236static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300237signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
Tal Einatc7027b72015-05-16 14:14:49 +0300238
239static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200240signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300241{
242 PyObject *return_value = NULL;
243 int signalnum;
244 int flag;
245
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200246 if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) {
247 goto exit;
248 }
249 if (PyFloat_Check(args[0])) {
250 PyErr_SetString(PyExc_TypeError,
251 "integer argument expected, got float" );
252 goto exit;
253 }
254 signalnum = _PyLong_AsInt(args[0]);
255 if (signalnum == -1 && PyErr_Occurred()) {
256 goto exit;
257 }
258 if (PyFloat_Check(args[1])) {
259 PyErr_SetString(PyExc_TypeError,
260 "integer argument expected, got float" );
261 goto exit;
262 }
263 flag = _PyLong_AsInt(args[1]);
264 if (flag == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100265 goto exit;
266 }
Tal Einatc7027b72015-05-16 14:14:49 +0300267 return_value = signal_siginterrupt_impl(module, signalnum, flag);
268
269exit:
270 return return_value;
271}
272
273#endif /* defined(HAVE_SIGINTERRUPT) */
274
275#if defined(HAVE_SETITIMER)
276
277PyDoc_STRVAR(signal_setitimer__doc__,
278"setitimer($module, which, seconds, interval=0.0, /)\n"
279"--\n"
280"\n"
281"Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
282"\n"
283"The timer will fire after value seconds and after that every interval seconds.\n"
284"The itimer can be cleared by setting seconds to zero.\n"
285"\n"
286"Returns old values as a tuple: (delay, interval).");
287
288#define SIGNAL_SETITIMER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200289 {"setitimer", (PyCFunction)(void(*)(void))signal_setitimer, METH_FASTCALL, signal_setitimer__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300290
291static PyObject *
Victor Stinneref611c92017-10-13 13:49:43 -0700292signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,
293 PyObject *interval);
Tal Einatc7027b72015-05-16 14:14:49 +0300294
295static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200296signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300297{
298 PyObject *return_value = NULL;
299 int which;
Victor Stinneref611c92017-10-13 13:49:43 -0700300 PyObject *seconds;
301 PyObject *interval = NULL;
Tal Einatc7027b72015-05-16 14:14:49 +0300302
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200303 if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100304 goto exit;
305 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200306 if (PyFloat_Check(args[0])) {
307 PyErr_SetString(PyExc_TypeError,
308 "integer argument expected, got float" );
309 goto exit;
310 }
311 which = _PyLong_AsInt(args[0]);
312 if (which == -1 && PyErr_Occurred()) {
313 goto exit;
314 }
315 seconds = args[1];
316 if (nargs < 3) {
317 goto skip_optional;
318 }
319 interval = args[2];
320skip_optional:
Tal Einatc7027b72015-05-16 14:14:49 +0300321 return_value = signal_setitimer_impl(module, which, seconds, interval);
322
323exit:
324 return return_value;
325}
326
327#endif /* defined(HAVE_SETITIMER) */
328
329#if defined(HAVE_GETITIMER)
330
331PyDoc_STRVAR(signal_getitimer__doc__,
332"getitimer($module, which, /)\n"
333"--\n"
334"\n"
335"Returns current value of given itimer.");
336
337#define SIGNAL_GETITIMER_METHODDEF \
338 {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
339
340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300341signal_getitimer_impl(PyObject *module, int which);
Tal Einatc7027b72015-05-16 14:14:49 +0300342
343static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300344signal_getitimer(PyObject *module, PyObject *arg)
Tal Einatc7027b72015-05-16 14:14:49 +0300345{
346 PyObject *return_value = NULL;
347 int which;
348
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200349 if (PyFloat_Check(arg)) {
350 PyErr_SetString(PyExc_TypeError,
351 "integer argument expected, got float" );
352 goto exit;
353 }
354 which = _PyLong_AsInt(arg);
355 if (which == -1 && PyErr_Occurred()) {
Tal Einatc7027b72015-05-16 14:14:49 +0300356 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300357 }
Tal Einatc7027b72015-05-16 14:14:49 +0300358 return_value = signal_getitimer_impl(module, which);
359
360exit:
361 return return_value;
362}
363
364#endif /* defined(HAVE_GETITIMER) */
365
366#if defined(PYPTHREAD_SIGMASK)
367
368PyDoc_STRVAR(signal_pthread_sigmask__doc__,
369"pthread_sigmask($module, how, mask, /)\n"
370"--\n"
371"\n"
372"Fetch and/or change the signal mask of the calling thread.");
373
374#define SIGNAL_PTHREAD_SIGMASK_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200375 {"pthread_sigmask", (PyCFunction)(void(*)(void))signal_pthread_sigmask, METH_FASTCALL, signal_pthread_sigmask__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300376
377static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300378signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask);
Tal Einatc7027b72015-05-16 14:14:49 +0300379
380static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200381signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300382{
383 PyObject *return_value = NULL;
384 int how;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300385 sigset_t mask;
Tal Einatc7027b72015-05-16 14:14:49 +0300386
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200387 if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) {
388 goto exit;
389 }
390 if (PyFloat_Check(args[0])) {
391 PyErr_SetString(PyExc_TypeError,
392 "integer argument expected, got float" );
393 goto exit;
394 }
395 how = _PyLong_AsInt(args[0]);
396 if (how == -1 && PyErr_Occurred()) {
397 goto exit;
398 }
399 if (!_Py_Sigset_Converter(args[1], &mask)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100400 goto exit;
401 }
Tal Einatc7027b72015-05-16 14:14:49 +0300402 return_value = signal_pthread_sigmask_impl(module, how, mask);
403
404exit:
405 return return_value;
406}
407
408#endif /* defined(PYPTHREAD_SIGMASK) */
409
410#if defined(HAVE_SIGPENDING)
411
412PyDoc_STRVAR(signal_sigpending__doc__,
413"sigpending($module, /)\n"
414"--\n"
415"\n"
416"Examine pending signals.\n"
417"\n"
418"Returns a set of signal numbers that are pending for delivery to\n"
419"the calling thread.");
420
421#define SIGNAL_SIGPENDING_METHODDEF \
422 {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
423
424static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300425signal_sigpending_impl(PyObject *module);
Tal Einatc7027b72015-05-16 14:14:49 +0300426
427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300428signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored))
Tal Einatc7027b72015-05-16 14:14:49 +0300429{
430 return signal_sigpending_impl(module);
431}
432
433#endif /* defined(HAVE_SIGPENDING) */
434
435#if defined(HAVE_SIGWAIT)
436
437PyDoc_STRVAR(signal_sigwait__doc__,
438"sigwait($module, sigset, /)\n"
439"--\n"
440"\n"
441"Wait for a signal.\n"
442"\n"
443"Suspend execution of the calling thread until the delivery of one of the\n"
444"signals specified in the signal set sigset. The function accepts the signal\n"
445"and returns the signal number.");
446
447#define SIGNAL_SIGWAIT_METHODDEF \
448 {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
449
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300450static PyObject *
451signal_sigwait_impl(PyObject *module, sigset_t sigset);
452
453static PyObject *
454signal_sigwait(PyObject *module, PyObject *arg)
455{
456 PyObject *return_value = NULL;
457 sigset_t sigset;
458
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200459 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300460 goto exit;
461 }
462 return_value = signal_sigwait_impl(module, sigset);
463
464exit:
465 return return_value;
466}
467
Tal Einatc7027b72015-05-16 14:14:49 +0300468#endif /* defined(HAVE_SIGWAIT) */
469
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200470#if (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS))
471
472PyDoc_STRVAR(signal_valid_signals__doc__,
473"valid_signals($module, /)\n"
474"--\n"
475"\n"
476"Return a set of valid signal numbers on this platform.\n"
477"\n"
478"The signal numbers returned by this function can be safely passed to\n"
479"functions like `pthread_sigmask`.");
480
481#define SIGNAL_VALID_SIGNALS_METHODDEF \
482 {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__},
483
484static PyObject *
485signal_valid_signals_impl(PyObject *module);
486
487static PyObject *
488signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored))
489{
490 return signal_valid_signals_impl(module);
491}
492
493#endif /* (defined(HAVE_SIGFILLSET) || defined(MS_WINDOWS)) */
494
Tal Einatc7027b72015-05-16 14:14:49 +0300495#if defined(HAVE_SIGWAITINFO)
496
497PyDoc_STRVAR(signal_sigwaitinfo__doc__,
498"sigwaitinfo($module, sigset, /)\n"
499"--\n"
500"\n"
501"Wait synchronously until one of the signals in *sigset* is delivered.\n"
502"\n"
503"Returns a struct_siginfo containing information about the signal.");
504
505#define SIGNAL_SIGWAITINFO_METHODDEF \
506 {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
507
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300508static PyObject *
509signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset);
510
511static PyObject *
512signal_sigwaitinfo(PyObject *module, PyObject *arg)
513{
514 PyObject *return_value = NULL;
515 sigset_t sigset;
516
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200517 if (!_Py_Sigset_Converter(arg, &sigset)) {
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300518 goto exit;
519 }
520 return_value = signal_sigwaitinfo_impl(module, sigset);
521
522exit:
523 return return_value;
524}
525
Tal Einatc7027b72015-05-16 14:14:49 +0300526#endif /* defined(HAVE_SIGWAITINFO) */
527
528#if defined(HAVE_SIGTIMEDWAIT)
529
530PyDoc_STRVAR(signal_sigtimedwait__doc__,
531"sigtimedwait($module, sigset, timeout, /)\n"
532"--\n"
533"\n"
534"Like sigwaitinfo(), but with a timeout.\n"
535"\n"
536"The timeout is specified in seconds, with floating point numbers allowed.");
537
538#define SIGNAL_SIGTIMEDWAIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200539 {"sigtimedwait", (PyCFunction)(void(*)(void))signal_sigtimedwait, METH_FASTCALL, signal_sigtimedwait__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300540
541static PyObject *
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300542signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300543 PyObject *timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300544
545static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200546signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300547{
548 PyObject *return_value = NULL;
Serhiy Storchakad54cfb12018-05-08 07:48:50 +0300549 sigset_t sigset;
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300550 PyObject *timeout_obj;
Tal Einatc7027b72015-05-16 14:14:49 +0300551
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200552 if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100553 goto exit;
554 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200555 if (!_Py_Sigset_Converter(args[0], &sigset)) {
556 goto exit;
557 }
558 timeout_obj = args[1];
Serhiy Storchaka6b680cd2015-05-16 15:57:56 +0300559 return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
Tal Einatc7027b72015-05-16 14:14:49 +0300560
561exit:
562 return return_value;
563}
564
565#endif /* defined(HAVE_SIGTIMEDWAIT) */
566
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200567#if defined(HAVE_PTHREAD_KILL)
Tal Einatc7027b72015-05-16 14:14:49 +0300568
569PyDoc_STRVAR(signal_pthread_kill__doc__,
570"pthread_kill($module, thread_id, signalnum, /)\n"
571"--\n"
572"\n"
573"Send a signal to a thread.");
574
575#define SIGNAL_PTHREAD_KILL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200576 {"pthread_kill", (PyCFunction)(void(*)(void))signal_pthread_kill, METH_FASTCALL, signal_pthread_kill__doc__},
Tal Einatc7027b72015-05-16 14:14:49 +0300577
578static PyObject *
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200579signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,
580 int signalnum);
Tal Einatc7027b72015-05-16 14:14:49 +0300581
582static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200583signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Tal Einatc7027b72015-05-16 14:14:49 +0300584{
585 PyObject *return_value = NULL;
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200586 unsigned long thread_id;
Tal Einatc7027b72015-05-16 14:14:49 +0300587 int signalnum;
588
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200589 if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) {
590 goto exit;
591 }
592 if (!PyLong_Check(args[0])) {
593 _PyArg_BadArgument("pthread_kill", 1, "int", args[0]);
594 goto exit;
595 }
596 thread_id = PyLong_AsUnsignedLongMask(args[0]);
597 if (PyFloat_Check(args[1])) {
598 PyErr_SetString(PyExc_TypeError,
599 "integer argument expected, got float" );
600 goto exit;
601 }
602 signalnum = _PyLong_AsInt(args[1]);
603 if (signalnum == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100604 goto exit;
605 }
Tal Einatc7027b72015-05-16 14:14:49 +0300606 return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
607
608exit:
609 return return_value;
610}
611
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200612#endif /* defined(HAVE_PTHREAD_KILL) */
Tal Einatc7027b72015-05-16 14:14:49 +0300613
614#ifndef SIGNAL_ALARM_METHODDEF
615 #define SIGNAL_ALARM_METHODDEF
616#endif /* !defined(SIGNAL_ALARM_METHODDEF) */
617
618#ifndef SIGNAL_PAUSE_METHODDEF
619 #define SIGNAL_PAUSE_METHODDEF
620#endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
621
622#ifndef SIGNAL_SIGINTERRUPT_METHODDEF
623 #define SIGNAL_SIGINTERRUPT_METHODDEF
624#endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
625
626#ifndef SIGNAL_SETITIMER_METHODDEF
627 #define SIGNAL_SETITIMER_METHODDEF
628#endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
629
630#ifndef SIGNAL_GETITIMER_METHODDEF
631 #define SIGNAL_GETITIMER_METHODDEF
632#endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
633
634#ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
635 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
636#endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
637
638#ifndef SIGNAL_SIGPENDING_METHODDEF
639 #define SIGNAL_SIGPENDING_METHODDEF
640#endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
641
642#ifndef SIGNAL_SIGWAIT_METHODDEF
643 #define SIGNAL_SIGWAIT_METHODDEF
644#endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
645
Antoine Pitrou9d3627e2018-05-04 13:00:50 +0200646#ifndef SIGNAL_VALID_SIGNALS_METHODDEF
647 #define SIGNAL_VALID_SIGNALS_METHODDEF
648#endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */
649
Tal Einatc7027b72015-05-16 14:14:49 +0300650#ifndef SIGNAL_SIGWAITINFO_METHODDEF
651 #define SIGNAL_SIGWAITINFO_METHODDEF
652#endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
653
654#ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
655 #define SIGNAL_SIGTIMEDWAIT_METHODDEF
656#endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
657
658#ifndef SIGNAL_PTHREAD_KILL_METHODDEF
659 #define SIGNAL_PTHREAD_KILL_METHODDEF
660#endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200661/*[clinic end generated code: output=f0d3a5703581da76 input=a9049054013a1b77]*/