• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
10 
11 PyDoc_STRVAR(signal_default_int_handler__doc__,
12 "default_int_handler($module, signalnum, frame, /)\n"
13 "--\n"
14 "\n"
15 "The default handler for SIGINT installed by Python.\n"
16 "\n"
17 "It raises KeyboardInterrupt.");
18 
19 #define SIGNAL_DEFAULT_INT_HANDLER_METHODDEF    \
20     {"default_int_handler", _PyCFunction_CAST(signal_default_int_handler), METH_FASTCALL, signal_default_int_handler__doc__},
21 
22 static PyObject *
23 signal_default_int_handler_impl(PyObject *module, int signalnum,
24                                 PyObject *frame);
25 
26 static PyObject *
signal_default_int_handler(PyObject * module,PyObject * const * args,Py_ssize_t nargs)27 signal_default_int_handler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
28 {
29     PyObject *return_value = NULL;
30     int signalnum;
31     PyObject *frame;
32 
33     if (!_PyArg_CheckPositional("default_int_handler", nargs, 2, 2)) {
34         goto exit;
35     }
36     signalnum = PyLong_AsInt(args[0]);
37     if (signalnum == -1 && PyErr_Occurred()) {
38         goto exit;
39     }
40     frame = args[1];
41     return_value = signal_default_int_handler_impl(module, signalnum, frame);
42 
43 exit:
44     return return_value;
45 }
46 
47 #if defined(HAVE_ALARM)
48 
49 PyDoc_STRVAR(signal_alarm__doc__,
50 "alarm($module, seconds, /)\n"
51 "--\n"
52 "\n"
53 "Arrange for SIGALRM to arrive after the given number of seconds.");
54 
55 #define SIGNAL_ALARM_METHODDEF    \
56     {"alarm", (PyCFunction)signal_alarm, METH_O, signal_alarm__doc__},
57 
58 static long
59 signal_alarm_impl(PyObject *module, int seconds);
60 
61 static PyObject *
signal_alarm(PyObject * module,PyObject * arg)62 signal_alarm(PyObject *module, PyObject *arg)
63 {
64     PyObject *return_value = NULL;
65     int seconds;
66     long _return_value;
67 
68     seconds = PyLong_AsInt(arg);
69     if (seconds == -1 && PyErr_Occurred()) {
70         goto exit;
71     }
72     _return_value = signal_alarm_impl(module, seconds);
73     if ((_return_value == -1) && PyErr_Occurred()) {
74         goto exit;
75     }
76     return_value = PyLong_FromLong(_return_value);
77 
78 exit:
79     return return_value;
80 }
81 
82 #endif /* defined(HAVE_ALARM) */
83 
84 #if defined(HAVE_PAUSE)
85 
86 PyDoc_STRVAR(signal_pause__doc__,
87 "pause($module, /)\n"
88 "--\n"
89 "\n"
90 "Wait until a signal arrives.");
91 
92 #define SIGNAL_PAUSE_METHODDEF    \
93     {"pause", (PyCFunction)signal_pause, METH_NOARGS, signal_pause__doc__},
94 
95 static PyObject *
96 signal_pause_impl(PyObject *module);
97 
98 static PyObject *
signal_pause(PyObject * module,PyObject * Py_UNUSED (ignored))99 signal_pause(PyObject *module, PyObject *Py_UNUSED(ignored))
100 {
101     return signal_pause_impl(module);
102 }
103 
104 #endif /* defined(HAVE_PAUSE) */
105 
106 PyDoc_STRVAR(signal_raise_signal__doc__,
107 "raise_signal($module, signalnum, /)\n"
108 "--\n"
109 "\n"
110 "Send a signal to the executing process.");
111 
112 #define SIGNAL_RAISE_SIGNAL_METHODDEF    \
113     {"raise_signal", (PyCFunction)signal_raise_signal, METH_O, signal_raise_signal__doc__},
114 
115 static PyObject *
116 signal_raise_signal_impl(PyObject *module, int signalnum);
117 
118 static PyObject *
signal_raise_signal(PyObject * module,PyObject * arg)119 signal_raise_signal(PyObject *module, PyObject *arg)
120 {
121     PyObject *return_value = NULL;
122     int signalnum;
123 
124     signalnum = PyLong_AsInt(arg);
125     if (signalnum == -1 && PyErr_Occurred()) {
126         goto exit;
127     }
128     return_value = signal_raise_signal_impl(module, signalnum);
129 
130 exit:
131     return return_value;
132 }
133 
134 PyDoc_STRVAR(signal_signal__doc__,
135 "signal($module, signalnum, handler, /)\n"
136 "--\n"
137 "\n"
138 "Set the action for the given signal.\n"
139 "\n"
140 "The action can be SIG_DFL, SIG_IGN, or a callable Python object.\n"
141 "The previous action is returned.  See getsignal() for possible return values.\n"
142 "\n"
143 "*** IMPORTANT NOTICE ***\n"
144 "A signal handler function is called with two arguments:\n"
145 "the first is the signal number, the second is the interrupted stack frame.");
146 
147 #define SIGNAL_SIGNAL_METHODDEF    \
148     {"signal", _PyCFunction_CAST(signal_signal), METH_FASTCALL, signal_signal__doc__},
149 
150 static PyObject *
151 signal_signal_impl(PyObject *module, int signalnum, PyObject *handler);
152 
153 static PyObject *
signal_signal(PyObject * module,PyObject * const * args,Py_ssize_t nargs)154 signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
155 {
156     PyObject *return_value = NULL;
157     int signalnum;
158     PyObject *handler;
159 
160     if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) {
161         goto exit;
162     }
163     signalnum = PyLong_AsInt(args[0]);
164     if (signalnum == -1 && PyErr_Occurred()) {
165         goto exit;
166     }
167     handler = args[1];
168     return_value = signal_signal_impl(module, signalnum, handler);
169 
170 exit:
171     return return_value;
172 }
173 
174 PyDoc_STRVAR(signal_getsignal__doc__,
175 "getsignal($module, signalnum, /)\n"
176 "--\n"
177 "\n"
178 "Return the current action for the given signal.\n"
179 "\n"
180 "The return value can be:\n"
181 "  SIG_IGN -- if the signal is being ignored\n"
182 "  SIG_DFL -- if the default action for the signal is in effect\n"
183 "  None    -- if an unknown handler is in effect\n"
184 "  anything else -- the callable Python object used as a handler");
185 
186 #define SIGNAL_GETSIGNAL_METHODDEF    \
187     {"getsignal", (PyCFunction)signal_getsignal, METH_O, signal_getsignal__doc__},
188 
189 static PyObject *
190 signal_getsignal_impl(PyObject *module, int signalnum);
191 
192 static PyObject *
signal_getsignal(PyObject * module,PyObject * arg)193 signal_getsignal(PyObject *module, PyObject *arg)
194 {
195     PyObject *return_value = NULL;
196     int signalnum;
197 
198     signalnum = PyLong_AsInt(arg);
199     if (signalnum == -1 && PyErr_Occurred()) {
200         goto exit;
201     }
202     return_value = signal_getsignal_impl(module, signalnum);
203 
204 exit:
205     return return_value;
206 }
207 
208 PyDoc_STRVAR(signal_strsignal__doc__,
209 "strsignal($module, signalnum, /)\n"
210 "--\n"
211 "\n"
212 "Return the system description of the given signal.\n"
213 "\n"
214 "Returns the description of signal *signalnum*, such as \"Interrupt\"\n"
215 "for :const:`SIGINT`. Returns :const:`None` if *signalnum* has no\n"
216 "description. Raises :exc:`ValueError` if *signalnum* is invalid.");
217 
218 #define SIGNAL_STRSIGNAL_METHODDEF    \
219     {"strsignal", (PyCFunction)signal_strsignal, METH_O, signal_strsignal__doc__},
220 
221 static PyObject *
222 signal_strsignal_impl(PyObject *module, int signalnum);
223 
224 static PyObject *
signal_strsignal(PyObject * module,PyObject * arg)225 signal_strsignal(PyObject *module, PyObject *arg)
226 {
227     PyObject *return_value = NULL;
228     int signalnum;
229 
230     signalnum = PyLong_AsInt(arg);
231     if (signalnum == -1 && PyErr_Occurred()) {
232         goto exit;
233     }
234     return_value = signal_strsignal_impl(module, signalnum);
235 
236 exit:
237     return return_value;
238 }
239 
240 #if defined(HAVE_SIGINTERRUPT)
241 
242 PyDoc_STRVAR(signal_siginterrupt__doc__,
243 "siginterrupt($module, signalnum, flag, /)\n"
244 "--\n"
245 "\n"
246 "Change system call restart behaviour.\n"
247 "\n"
248 "If flag is False, system calls will be restarted when interrupted by\n"
249 "signal sig, else system calls will be interrupted.");
250 
251 #define SIGNAL_SIGINTERRUPT_METHODDEF    \
252     {"siginterrupt", _PyCFunction_CAST(signal_siginterrupt), METH_FASTCALL, signal_siginterrupt__doc__},
253 
254 static PyObject *
255 signal_siginterrupt_impl(PyObject *module, int signalnum, int flag);
256 
257 static PyObject *
signal_siginterrupt(PyObject * module,PyObject * const * args,Py_ssize_t nargs)258 signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
259 {
260     PyObject *return_value = NULL;
261     int signalnum;
262     int flag;
263 
264     if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) {
265         goto exit;
266     }
267     signalnum = PyLong_AsInt(args[0]);
268     if (signalnum == -1 && PyErr_Occurred()) {
269         goto exit;
270     }
271     flag = PyLong_AsInt(args[1]);
272     if (flag == -1 && PyErr_Occurred()) {
273         goto exit;
274     }
275     return_value = signal_siginterrupt_impl(module, signalnum, flag);
276 
277 exit:
278     return return_value;
279 }
280 
281 #endif /* defined(HAVE_SIGINTERRUPT) */
282 
283 PyDoc_STRVAR(signal_set_wakeup_fd__doc__,
284 "set_wakeup_fd($module, fd, /, *, warn_on_full_buffer=True)\n"
285 "--\n"
286 "\n"
287 "Sets the fd to be written to (with the signal number) when a signal comes in.\n"
288 "\n"
289 "A library can use this to wakeup select or poll.\n"
290 "The previous fd or -1 is returned.\n"
291 "\n"
292 "The fd must be non-blocking.");
293 
294 #define SIGNAL_SET_WAKEUP_FD_METHODDEF    \
295     {"set_wakeup_fd", _PyCFunction_CAST(signal_set_wakeup_fd), METH_FASTCALL|METH_KEYWORDS, signal_set_wakeup_fd__doc__},
296 
297 static PyObject *
298 signal_set_wakeup_fd_impl(PyObject *module, PyObject *fdobj,
299                           int warn_on_full_buffer);
300 
301 static PyObject *
signal_set_wakeup_fd(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)302 signal_set_wakeup_fd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
303 {
304     PyObject *return_value = NULL;
305     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
306 
307     #define NUM_KEYWORDS 1
308     static struct {
309         PyGC_Head _this_is_not_used;
310         PyObject_VAR_HEAD
311         PyObject *ob_item[NUM_KEYWORDS];
312     } _kwtuple = {
313         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
314         .ob_item = { &_Py_ID(warn_on_full_buffer), },
315     };
316     #undef NUM_KEYWORDS
317     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
318 
319     #else  // !Py_BUILD_CORE
320     #  define KWTUPLE NULL
321     #endif  // !Py_BUILD_CORE
322 
323     static const char * const _keywords[] = {"", "warn_on_full_buffer", NULL};
324     static _PyArg_Parser _parser = {
325         .keywords = _keywords,
326         .fname = "set_wakeup_fd",
327         .kwtuple = KWTUPLE,
328     };
329     #undef KWTUPLE
330     PyObject *argsbuf[2];
331     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
332     PyObject *fdobj;
333     int warn_on_full_buffer = 1;
334 
335     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
336     if (!args) {
337         goto exit;
338     }
339     fdobj = args[0];
340     if (!noptargs) {
341         goto skip_optional_kwonly;
342     }
343     warn_on_full_buffer = PyObject_IsTrue(args[1]);
344     if (warn_on_full_buffer < 0) {
345         goto exit;
346     }
347 skip_optional_kwonly:
348     return_value = signal_set_wakeup_fd_impl(module, fdobj, warn_on_full_buffer);
349 
350 exit:
351     return return_value;
352 }
353 
354 #if defined(HAVE_SETITIMER)
355 
356 PyDoc_STRVAR(signal_setitimer__doc__,
357 "setitimer($module, which, seconds, interval=0.0, /)\n"
358 "--\n"
359 "\n"
360 "Sets given itimer (one of ITIMER_REAL, ITIMER_VIRTUAL or ITIMER_PROF).\n"
361 "\n"
362 "The timer will fire after value seconds and after that every interval seconds.\n"
363 "The itimer can be cleared by setting seconds to zero.\n"
364 "\n"
365 "Returns old values as a tuple: (delay, interval).");
366 
367 #define SIGNAL_SETITIMER_METHODDEF    \
368     {"setitimer", _PyCFunction_CAST(signal_setitimer), METH_FASTCALL, signal_setitimer__doc__},
369 
370 static PyObject *
371 signal_setitimer_impl(PyObject *module, int which, PyObject *seconds,
372                       PyObject *interval);
373 
374 static PyObject *
signal_setitimer(PyObject * module,PyObject * const * args,Py_ssize_t nargs)375 signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
376 {
377     PyObject *return_value = NULL;
378     int which;
379     PyObject *seconds;
380     PyObject *interval = NULL;
381 
382     if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) {
383         goto exit;
384     }
385     which = PyLong_AsInt(args[0]);
386     if (which == -1 && PyErr_Occurred()) {
387         goto exit;
388     }
389     seconds = args[1];
390     if (nargs < 3) {
391         goto skip_optional;
392     }
393     interval = args[2];
394 skip_optional:
395     return_value = signal_setitimer_impl(module, which, seconds, interval);
396 
397 exit:
398     return return_value;
399 }
400 
401 #endif /* defined(HAVE_SETITIMER) */
402 
403 #if defined(HAVE_GETITIMER)
404 
405 PyDoc_STRVAR(signal_getitimer__doc__,
406 "getitimer($module, which, /)\n"
407 "--\n"
408 "\n"
409 "Returns current value of given itimer.");
410 
411 #define SIGNAL_GETITIMER_METHODDEF    \
412     {"getitimer", (PyCFunction)signal_getitimer, METH_O, signal_getitimer__doc__},
413 
414 static PyObject *
415 signal_getitimer_impl(PyObject *module, int which);
416 
417 static PyObject *
signal_getitimer(PyObject * module,PyObject * arg)418 signal_getitimer(PyObject *module, PyObject *arg)
419 {
420     PyObject *return_value = NULL;
421     int which;
422 
423     which = PyLong_AsInt(arg);
424     if (which == -1 && PyErr_Occurred()) {
425         goto exit;
426     }
427     return_value = signal_getitimer_impl(module, which);
428 
429 exit:
430     return return_value;
431 }
432 
433 #endif /* defined(HAVE_GETITIMER) */
434 
435 #if defined(HAVE_SIGSET_T) && defined(PYPTHREAD_SIGMASK)
436 
437 PyDoc_STRVAR(signal_pthread_sigmask__doc__,
438 "pthread_sigmask($module, how, mask, /)\n"
439 "--\n"
440 "\n"
441 "Fetch and/or change the signal mask of the calling thread.");
442 
443 #define SIGNAL_PTHREAD_SIGMASK_METHODDEF    \
444     {"pthread_sigmask", _PyCFunction_CAST(signal_pthread_sigmask), METH_FASTCALL, signal_pthread_sigmask__doc__},
445 
446 static PyObject *
447 signal_pthread_sigmask_impl(PyObject *module, int how, sigset_t mask);
448 
449 static PyObject *
signal_pthread_sigmask(PyObject * module,PyObject * const * args,Py_ssize_t nargs)450 signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
451 {
452     PyObject *return_value = NULL;
453     int how;
454     sigset_t mask;
455 
456     if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) {
457         goto exit;
458     }
459     how = PyLong_AsInt(args[0]);
460     if (how == -1 && PyErr_Occurred()) {
461         goto exit;
462     }
463     if (!_Py_Sigset_Converter(args[1], &mask)) {
464         goto exit;
465     }
466     return_value = signal_pthread_sigmask_impl(module, how, mask);
467 
468 exit:
469     return return_value;
470 }
471 
472 #endif /* defined(HAVE_SIGSET_T) && defined(PYPTHREAD_SIGMASK) */
473 
474 #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGPENDING)
475 
476 PyDoc_STRVAR(signal_sigpending__doc__,
477 "sigpending($module, /)\n"
478 "--\n"
479 "\n"
480 "Examine pending signals.\n"
481 "\n"
482 "Returns a set of signal numbers that are pending for delivery to\n"
483 "the calling thread.");
484 
485 #define SIGNAL_SIGPENDING_METHODDEF    \
486     {"sigpending", (PyCFunction)signal_sigpending, METH_NOARGS, signal_sigpending__doc__},
487 
488 static PyObject *
489 signal_sigpending_impl(PyObject *module);
490 
491 static PyObject *
signal_sigpending(PyObject * module,PyObject * Py_UNUSED (ignored))492 signal_sigpending(PyObject *module, PyObject *Py_UNUSED(ignored))
493 {
494     return signal_sigpending_impl(module);
495 }
496 
497 #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGPENDING) */
498 
499 #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAIT)
500 
501 PyDoc_STRVAR(signal_sigwait__doc__,
502 "sigwait($module, sigset, /)\n"
503 "--\n"
504 "\n"
505 "Wait for a signal.\n"
506 "\n"
507 "Suspend execution of the calling thread until the delivery of one of the\n"
508 "signals specified in the signal set sigset.  The function accepts the signal\n"
509 "and returns the signal number.");
510 
511 #define SIGNAL_SIGWAIT_METHODDEF    \
512     {"sigwait", (PyCFunction)signal_sigwait, METH_O, signal_sigwait__doc__},
513 
514 static PyObject *
515 signal_sigwait_impl(PyObject *module, sigset_t sigset);
516 
517 static PyObject *
signal_sigwait(PyObject * module,PyObject * arg)518 signal_sigwait(PyObject *module, PyObject *arg)
519 {
520     PyObject *return_value = NULL;
521     sigset_t sigset;
522 
523     if (!_Py_Sigset_Converter(arg, &sigset)) {
524         goto exit;
525     }
526     return_value = signal_sigwait_impl(module, sigset);
527 
528 exit:
529     return return_value;
530 }
531 
532 #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAIT) */
533 
534 #if ((defined(HAVE_SIGFILLSET) && defined(HAVE_SIGSET_T)) || defined(MS_WINDOWS))
535 
536 PyDoc_STRVAR(signal_valid_signals__doc__,
537 "valid_signals($module, /)\n"
538 "--\n"
539 "\n"
540 "Return a set of valid signal numbers on this platform.\n"
541 "\n"
542 "The signal numbers returned by this function can be safely passed to\n"
543 "functions like `pthread_sigmask`.");
544 
545 #define SIGNAL_VALID_SIGNALS_METHODDEF    \
546     {"valid_signals", (PyCFunction)signal_valid_signals, METH_NOARGS, signal_valid_signals__doc__},
547 
548 static PyObject *
549 signal_valid_signals_impl(PyObject *module);
550 
551 static PyObject *
signal_valid_signals(PyObject * module,PyObject * Py_UNUSED (ignored))552 signal_valid_signals(PyObject *module, PyObject *Py_UNUSED(ignored))
553 {
554     return signal_valid_signals_impl(module);
555 }
556 
557 #endif /* ((defined(HAVE_SIGFILLSET) && defined(HAVE_SIGSET_T)) || defined(MS_WINDOWS)) */
558 
559 #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAITINFO)
560 
561 PyDoc_STRVAR(signal_sigwaitinfo__doc__,
562 "sigwaitinfo($module, sigset, /)\n"
563 "--\n"
564 "\n"
565 "Wait synchronously until one of the signals in *sigset* is delivered.\n"
566 "\n"
567 "Returns a struct_siginfo containing information about the signal.");
568 
569 #define SIGNAL_SIGWAITINFO_METHODDEF    \
570     {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, METH_O, signal_sigwaitinfo__doc__},
571 
572 static PyObject *
573 signal_sigwaitinfo_impl(PyObject *module, sigset_t sigset);
574 
575 static PyObject *
signal_sigwaitinfo(PyObject * module,PyObject * arg)576 signal_sigwaitinfo(PyObject *module, PyObject *arg)
577 {
578     PyObject *return_value = NULL;
579     sigset_t sigset;
580 
581     if (!_Py_Sigset_Converter(arg, &sigset)) {
582         goto exit;
583     }
584     return_value = signal_sigwaitinfo_impl(module, sigset);
585 
586 exit:
587     return return_value;
588 }
589 
590 #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGWAITINFO) */
591 
592 #if defined(HAVE_SIGSET_T) && defined(HAVE_SIGTIMEDWAIT)
593 
594 PyDoc_STRVAR(signal_sigtimedwait__doc__,
595 "sigtimedwait($module, sigset, timeout, /)\n"
596 "--\n"
597 "\n"
598 "Like sigwaitinfo(), but with a timeout.\n"
599 "\n"
600 "The timeout is specified in seconds, with floating-point numbers allowed.");
601 
602 #define SIGNAL_SIGTIMEDWAIT_METHODDEF    \
603     {"sigtimedwait", _PyCFunction_CAST(signal_sigtimedwait), METH_FASTCALL, signal_sigtimedwait__doc__},
604 
605 static PyObject *
606 signal_sigtimedwait_impl(PyObject *module, sigset_t sigset,
607                          PyObject *timeout_obj);
608 
609 static PyObject *
signal_sigtimedwait(PyObject * module,PyObject * const * args,Py_ssize_t nargs)610 signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
611 {
612     PyObject *return_value = NULL;
613     sigset_t sigset;
614     PyObject *timeout_obj;
615 
616     if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) {
617         goto exit;
618     }
619     if (!_Py_Sigset_Converter(args[0], &sigset)) {
620         goto exit;
621     }
622     timeout_obj = args[1];
623     return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj);
624 
625 exit:
626     return return_value;
627 }
628 
629 #endif /* defined(HAVE_SIGSET_T) && defined(HAVE_SIGTIMEDWAIT) */
630 
631 #if defined(HAVE_PTHREAD_KILL)
632 
633 PyDoc_STRVAR(signal_pthread_kill__doc__,
634 "pthread_kill($module, thread_id, signalnum, /)\n"
635 "--\n"
636 "\n"
637 "Send a signal to a thread.");
638 
639 #define SIGNAL_PTHREAD_KILL_METHODDEF    \
640     {"pthread_kill", _PyCFunction_CAST(signal_pthread_kill), METH_FASTCALL, signal_pthread_kill__doc__},
641 
642 static PyObject *
643 signal_pthread_kill_impl(PyObject *module, unsigned long thread_id,
644                          int signalnum);
645 
646 static PyObject *
signal_pthread_kill(PyObject * module,PyObject * const * args,Py_ssize_t nargs)647 signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
648 {
649     PyObject *return_value = NULL;
650     unsigned long thread_id;
651     int signalnum;
652 
653     if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) {
654         goto exit;
655     }
656     if (!PyLong_Check(args[0])) {
657         _PyArg_BadArgument("pthread_kill", "argument 1", "int", args[0]);
658         goto exit;
659     }
660     thread_id = PyLong_AsUnsignedLongMask(args[0]);
661     signalnum = PyLong_AsInt(args[1]);
662     if (signalnum == -1 && PyErr_Occurred()) {
663         goto exit;
664     }
665     return_value = signal_pthread_kill_impl(module, thread_id, signalnum);
666 
667 exit:
668     return return_value;
669 }
670 
671 #endif /* defined(HAVE_PTHREAD_KILL) */
672 
673 #if (defined(__linux__) && defined(__NR_pidfd_send_signal) && !(defined(__ANDROID__) && __ANDROID_API__ < 31))
674 
675 PyDoc_STRVAR(signal_pidfd_send_signal__doc__,
676 "pidfd_send_signal($module, pidfd, signalnum, siginfo=None, flags=0, /)\n"
677 "--\n"
678 "\n"
679 "Send a signal to a process referred to by a pid file descriptor.");
680 
681 #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF    \
682     {"pidfd_send_signal", _PyCFunction_CAST(signal_pidfd_send_signal), METH_FASTCALL, signal_pidfd_send_signal__doc__},
683 
684 static PyObject *
685 signal_pidfd_send_signal_impl(PyObject *module, int pidfd, int signalnum,
686                               PyObject *siginfo, int flags);
687 
688 static PyObject *
signal_pidfd_send_signal(PyObject * module,PyObject * const * args,Py_ssize_t nargs)689 signal_pidfd_send_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
690 {
691     PyObject *return_value = NULL;
692     int pidfd;
693     int signalnum;
694     PyObject *siginfo = Py_None;
695     int flags = 0;
696 
697     if (!_PyArg_CheckPositional("pidfd_send_signal", nargs, 2, 4)) {
698         goto exit;
699     }
700     pidfd = PyLong_AsInt(args[0]);
701     if (pidfd == -1 && PyErr_Occurred()) {
702         goto exit;
703     }
704     signalnum = PyLong_AsInt(args[1]);
705     if (signalnum == -1 && PyErr_Occurred()) {
706         goto exit;
707     }
708     if (nargs < 3) {
709         goto skip_optional;
710     }
711     siginfo = args[2];
712     if (nargs < 4) {
713         goto skip_optional;
714     }
715     flags = PyLong_AsInt(args[3]);
716     if (flags == -1 && PyErr_Occurred()) {
717         goto exit;
718     }
719 skip_optional:
720     return_value = signal_pidfd_send_signal_impl(module, pidfd, signalnum, siginfo, flags);
721 
722 exit:
723     return return_value;
724 }
725 
726 #endif /* (defined(__linux__) && defined(__NR_pidfd_send_signal) && !(defined(__ANDROID__) && __ANDROID_API__ < 31)) */
727 
728 #ifndef SIGNAL_ALARM_METHODDEF
729     #define SIGNAL_ALARM_METHODDEF
730 #endif /* !defined(SIGNAL_ALARM_METHODDEF) */
731 
732 #ifndef SIGNAL_PAUSE_METHODDEF
733     #define SIGNAL_PAUSE_METHODDEF
734 #endif /* !defined(SIGNAL_PAUSE_METHODDEF) */
735 
736 #ifndef SIGNAL_SIGINTERRUPT_METHODDEF
737     #define SIGNAL_SIGINTERRUPT_METHODDEF
738 #endif /* !defined(SIGNAL_SIGINTERRUPT_METHODDEF) */
739 
740 #ifndef SIGNAL_SETITIMER_METHODDEF
741     #define SIGNAL_SETITIMER_METHODDEF
742 #endif /* !defined(SIGNAL_SETITIMER_METHODDEF) */
743 
744 #ifndef SIGNAL_GETITIMER_METHODDEF
745     #define SIGNAL_GETITIMER_METHODDEF
746 #endif /* !defined(SIGNAL_GETITIMER_METHODDEF) */
747 
748 #ifndef SIGNAL_PTHREAD_SIGMASK_METHODDEF
749     #define SIGNAL_PTHREAD_SIGMASK_METHODDEF
750 #endif /* !defined(SIGNAL_PTHREAD_SIGMASK_METHODDEF) */
751 
752 #ifndef SIGNAL_SIGPENDING_METHODDEF
753     #define SIGNAL_SIGPENDING_METHODDEF
754 #endif /* !defined(SIGNAL_SIGPENDING_METHODDEF) */
755 
756 #ifndef SIGNAL_SIGWAIT_METHODDEF
757     #define SIGNAL_SIGWAIT_METHODDEF
758 #endif /* !defined(SIGNAL_SIGWAIT_METHODDEF) */
759 
760 #ifndef SIGNAL_VALID_SIGNALS_METHODDEF
761     #define SIGNAL_VALID_SIGNALS_METHODDEF
762 #endif /* !defined(SIGNAL_VALID_SIGNALS_METHODDEF) */
763 
764 #ifndef SIGNAL_SIGWAITINFO_METHODDEF
765     #define SIGNAL_SIGWAITINFO_METHODDEF
766 #endif /* !defined(SIGNAL_SIGWAITINFO_METHODDEF) */
767 
768 #ifndef SIGNAL_SIGTIMEDWAIT_METHODDEF
769     #define SIGNAL_SIGTIMEDWAIT_METHODDEF
770 #endif /* !defined(SIGNAL_SIGTIMEDWAIT_METHODDEF) */
771 
772 #ifndef SIGNAL_PTHREAD_KILL_METHODDEF
773     #define SIGNAL_PTHREAD_KILL_METHODDEF
774 #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */
775 
776 #ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
777     #define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
778 #endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
779 /*[clinic end generated code: output=c57b4b98fad6f4b8 input=a9049054013a1b77]*/
780