Coverage Report

Created: 2026-05-30 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/faulthandler.c.h
Line
Count
Source
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_abstract.h"      // _PyNumber_Index()
10
#include "pycore_long.h"          // _PyLong_UnsignedInt_Converter()
11
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
12
13
PyDoc_STRVAR(faulthandler_dump_traceback_py__doc__,
14
"dump_traceback($module, /, file=sys.stderr, all_threads=True, *,\n"
15
"               max_threads=100)\n"
16
"--\n"
17
"\n"
18
"Dump the traceback of the current thread into file.\n"
19
"\n"
20
"Dump the traceback of all threads if all_threads is true. max_threads\n"
21
"caps the number of threads dumped.");
22
23
#define FAULTHANDLER_DUMP_TRACEBACK_PY_METHODDEF    \
24
    {"dump_traceback", _PyCFunction_CAST(faulthandler_dump_traceback_py), METH_FASTCALL|METH_KEYWORDS, faulthandler_dump_traceback_py__doc__},
25
26
static PyObject *
27
faulthandler_dump_traceback_py_impl(PyObject *module, PyObject *file,
28
                                    int all_threads, Py_ssize_t max_threads);
29
30
static PyObject *
31
faulthandler_dump_traceback_py(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
32
0
{
33
0
    PyObject *return_value = NULL;
34
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
35
36
0
    #define NUM_KEYWORDS 3
37
0
    static struct {
38
0
        PyGC_Head _this_is_not_used;
39
0
        PyObject_VAR_HEAD
40
0
        Py_hash_t ob_hash;
41
0
        PyObject *ob_item[NUM_KEYWORDS];
42
0
    } _kwtuple = {
43
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
44
0
        .ob_hash = -1,
45
0
        .ob_item = { &_Py_ID(file), &_Py_ID(all_threads), &_Py_ID(max_threads), },
46
0
    };
47
0
    #undef NUM_KEYWORDS
48
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
49
50
    #else  // !Py_BUILD_CORE
51
    #  define KWTUPLE NULL
52
    #endif  // !Py_BUILD_CORE
53
54
0
    static const char * const _keywords[] = {"file", "all_threads", "max_threads", NULL};
55
0
    static _PyArg_Parser _parser = {
56
0
        .keywords = _keywords,
57
0
        .fname = "dump_traceback",
58
0
        .kwtuple = KWTUPLE,
59
0
    };
60
0
    #undef KWTUPLE
61
0
    PyObject *argsbuf[3];
62
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
63
0
    PyObject *file = NULL;
64
0
    int all_threads = 1;
65
0
    Py_ssize_t max_threads = 100;
66
67
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
68
0
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
69
0
    if (!args) {
70
0
        goto exit;
71
0
    }
72
0
    if (!noptargs) {
73
0
        goto skip_optional_pos;
74
0
    }
75
0
    if (args[0]) {
76
0
        file = args[0];
77
0
        if (!--noptargs) {
78
0
            goto skip_optional_pos;
79
0
        }
80
0
    }
81
0
    if (args[1]) {
82
0
        all_threads = PyObject_IsTrue(args[1]);
83
0
        if (all_threads < 0) {
84
0
            goto exit;
85
0
        }
86
0
        if (!--noptargs) {
87
0
            goto skip_optional_pos;
88
0
        }
89
0
    }
90
0
skip_optional_pos:
91
0
    if (!noptargs) {
92
0
        goto skip_optional_kwonly;
93
0
    }
94
0
    {
95
0
        Py_ssize_t ival = -1;
96
0
        PyObject *iobj = _PyNumber_Index(args[2]);
97
0
        if (iobj != NULL) {
98
0
            ival = PyLong_AsSsize_t(iobj);
99
0
            Py_DECREF(iobj);
100
0
        }
101
0
        if (ival == -1 && PyErr_Occurred()) {
102
0
            goto exit;
103
0
        }
104
0
        max_threads = ival;
105
0
    }
106
0
skip_optional_kwonly:
107
0
    return_value = faulthandler_dump_traceback_py_impl(module, file, all_threads, max_threads);
108
109
0
exit:
110
0
    return return_value;
111
0
}
112
113
PyDoc_STRVAR(faulthandler_dump_c_stack_py__doc__,
114
"dump_c_stack($module, /, file=sys.stderr)\n"
115
"--\n"
116
"\n"
117
"Dump the C stack of the current thread.");
118
119
#define FAULTHANDLER_DUMP_C_STACK_PY_METHODDEF    \
120
    {"dump_c_stack", _PyCFunction_CAST(faulthandler_dump_c_stack_py), METH_FASTCALL|METH_KEYWORDS, faulthandler_dump_c_stack_py__doc__},
121
122
static PyObject *
123
faulthandler_dump_c_stack_py_impl(PyObject *module, PyObject *file);
124
125
static PyObject *
126
faulthandler_dump_c_stack_py(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
127
0
{
128
0
    PyObject *return_value = NULL;
129
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
130
131
0
    #define NUM_KEYWORDS 1
132
0
    static struct {
133
0
        PyGC_Head _this_is_not_used;
134
0
        PyObject_VAR_HEAD
135
0
        Py_hash_t ob_hash;
136
0
        PyObject *ob_item[NUM_KEYWORDS];
137
0
    } _kwtuple = {
138
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
139
0
        .ob_hash = -1,
140
0
        .ob_item = { &_Py_ID(file), },
141
0
    };
142
0
    #undef NUM_KEYWORDS
143
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
144
145
    #else  // !Py_BUILD_CORE
146
    #  define KWTUPLE NULL
147
    #endif  // !Py_BUILD_CORE
148
149
0
    static const char * const _keywords[] = {"file", NULL};
150
0
    static _PyArg_Parser _parser = {
151
0
        .keywords = _keywords,
152
0
        .fname = "dump_c_stack",
153
0
        .kwtuple = KWTUPLE,
154
0
    };
155
0
    #undef KWTUPLE
156
0
    PyObject *argsbuf[1];
157
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
158
0
    PyObject *file = NULL;
159
160
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
161
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
162
0
    if (!args) {
163
0
        goto exit;
164
0
    }
165
0
    if (!noptargs) {
166
0
        goto skip_optional_pos;
167
0
    }
168
0
    file = args[0];
169
0
skip_optional_pos:
170
0
    return_value = faulthandler_dump_c_stack_py_impl(module, file);
171
172
0
exit:
173
0
    return return_value;
174
0
}
175
176
PyDoc_STRVAR(faulthandler_py_enable__doc__,
177
"enable($module, /, file=sys.stderr, all_threads=True, c_stack=True, *,\n"
178
"       max_threads=100)\n"
179
"--\n"
180
"\n"
181
"Enable the fault handler.");
182
183
#define FAULTHANDLER_PY_ENABLE_METHODDEF    \
184
    {"enable", _PyCFunction_CAST(faulthandler_py_enable), METH_FASTCALL|METH_KEYWORDS, faulthandler_py_enable__doc__},
185
186
static PyObject *
187
faulthandler_py_enable_impl(PyObject *module, PyObject *file,
188
                            int all_threads, int c_stack,
189
                            Py_ssize_t max_threads);
190
191
static PyObject *
192
faulthandler_py_enable(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
193
0
{
194
0
    PyObject *return_value = NULL;
195
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
196
197
0
    #define NUM_KEYWORDS 4
198
0
    static struct {
199
0
        PyGC_Head _this_is_not_used;
200
0
        PyObject_VAR_HEAD
201
0
        Py_hash_t ob_hash;
202
0
        PyObject *ob_item[NUM_KEYWORDS];
203
0
    } _kwtuple = {
204
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
205
0
        .ob_hash = -1,
206
0
        .ob_item = { &_Py_ID(file), &_Py_ID(all_threads), &_Py_ID(c_stack), &_Py_ID(max_threads), },
207
0
    };
208
0
    #undef NUM_KEYWORDS
209
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
210
211
    #else  // !Py_BUILD_CORE
212
    #  define KWTUPLE NULL
213
    #endif  // !Py_BUILD_CORE
214
215
0
    static const char * const _keywords[] = {"file", "all_threads", "c_stack", "max_threads", NULL};
216
0
    static _PyArg_Parser _parser = {
217
0
        .keywords = _keywords,
218
0
        .fname = "enable",
219
0
        .kwtuple = KWTUPLE,
220
0
    };
221
0
    #undef KWTUPLE
222
0
    PyObject *argsbuf[4];
223
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
224
0
    PyObject *file = NULL;
225
0
    int all_threads = 1;
226
0
    int c_stack = 1;
227
0
    Py_ssize_t max_threads = 100;
228
229
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
230
0
            /*minpos*/ 0, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
231
0
    if (!args) {
232
0
        goto exit;
233
0
    }
234
0
    if (!noptargs) {
235
0
        goto skip_optional_pos;
236
0
    }
237
0
    if (args[0]) {
238
0
        file = args[0];
239
0
        if (!--noptargs) {
240
0
            goto skip_optional_pos;
241
0
        }
242
0
    }
243
0
    if (args[1]) {
244
0
        all_threads = PyObject_IsTrue(args[1]);
245
0
        if (all_threads < 0) {
246
0
            goto exit;
247
0
        }
248
0
        if (!--noptargs) {
249
0
            goto skip_optional_pos;
250
0
        }
251
0
    }
252
0
    if (args[2]) {
253
0
        c_stack = PyObject_IsTrue(args[2]);
254
0
        if (c_stack < 0) {
255
0
            goto exit;
256
0
        }
257
0
        if (!--noptargs) {
258
0
            goto skip_optional_pos;
259
0
        }
260
0
    }
261
0
skip_optional_pos:
262
0
    if (!noptargs) {
263
0
        goto skip_optional_kwonly;
264
0
    }
265
0
    {
266
0
        Py_ssize_t ival = -1;
267
0
        PyObject *iobj = _PyNumber_Index(args[3]);
268
0
        if (iobj != NULL) {
269
0
            ival = PyLong_AsSsize_t(iobj);
270
0
            Py_DECREF(iobj);
271
0
        }
272
0
        if (ival == -1 && PyErr_Occurred()) {
273
0
            goto exit;
274
0
        }
275
0
        max_threads = ival;
276
0
    }
277
0
skip_optional_kwonly:
278
0
    return_value = faulthandler_py_enable_impl(module, file, all_threads, c_stack, max_threads);
279
280
0
exit:
281
0
    return return_value;
282
0
}
283
284
PyDoc_STRVAR(faulthandler_disable_py__doc__,
285
"disable($module, /)\n"
286
"--\n"
287
"\n"
288
"Disable the fault handler.");
289
290
#define FAULTHANDLER_DISABLE_PY_METHODDEF    \
291
    {"disable", (PyCFunction)faulthandler_disable_py, METH_NOARGS, faulthandler_disable_py__doc__},
292
293
static PyObject *
294
faulthandler_disable_py_impl(PyObject *module);
295
296
static PyObject *
297
faulthandler_disable_py(PyObject *module, PyObject *Py_UNUSED(ignored))
298
0
{
299
0
    return faulthandler_disable_py_impl(module);
300
0
}
301
302
PyDoc_STRVAR(faulthandler_is_enabled__doc__,
303
"is_enabled($module, /)\n"
304
"--\n"
305
"\n"
306
"Check if the handler is enabled.");
307
308
#define FAULTHANDLER_IS_ENABLED_METHODDEF    \
309
    {"is_enabled", (PyCFunction)faulthandler_is_enabled, METH_NOARGS, faulthandler_is_enabled__doc__},
310
311
static int
312
faulthandler_is_enabled_impl(PyObject *module);
313
314
static PyObject *
315
faulthandler_is_enabled(PyObject *module, PyObject *Py_UNUSED(ignored))
316
0
{
317
0
    PyObject *return_value = NULL;
318
0
    int _return_value;
319
320
0
    _return_value = faulthandler_is_enabled_impl(module);
321
0
    if ((_return_value == -1) && PyErr_Occurred()) {
322
0
        goto exit;
323
0
    }
324
0
    return_value = PyBool_FromLong((long)_return_value);
325
326
0
exit:
327
0
    return return_value;
328
0
}
329
330
PyDoc_STRVAR(faulthandler_dump_traceback_later__doc__,
331
"dump_traceback_later($module, /, timeout, repeat=False,\n"
332
"                     file=sys.stderr, exit=False, *, max_threads=100)\n"
333
"--\n"
334
"\n"
335
"Dump the traceback of all threads in timeout seconds.\n"
336
"\n"
337
"If repeat is true, the tracebacks of all threads are dumped every\n"
338
"timeout seconds.  If exit is true, call _exit(1) which is not safe.\n"
339
"max_threads caps the number of threads dumped.");
340
341
#define FAULTHANDLER_DUMP_TRACEBACK_LATER_METHODDEF    \
342
    {"dump_traceback_later", _PyCFunction_CAST(faulthandler_dump_traceback_later), METH_FASTCALL|METH_KEYWORDS, faulthandler_dump_traceback_later__doc__},
343
344
static PyObject *
345
faulthandler_dump_traceback_later_impl(PyObject *module,
346
                                       PyObject *timeout_obj, int repeat,
347
                                       PyObject *file, int exit,
348
                                       Py_ssize_t max_threads);
349
350
static PyObject *
351
faulthandler_dump_traceback_later(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
352
0
{
353
0
    PyObject *return_value = NULL;
354
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
355
356
0
    #define NUM_KEYWORDS 5
357
0
    static struct {
358
0
        PyGC_Head _this_is_not_used;
359
0
        PyObject_VAR_HEAD
360
0
        Py_hash_t ob_hash;
361
0
        PyObject *ob_item[NUM_KEYWORDS];
362
0
    } _kwtuple = {
363
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
364
0
        .ob_hash = -1,
365
0
        .ob_item = { &_Py_ID(timeout), &_Py_ID(repeat), &_Py_ID(file), &_Py_ID(exit), &_Py_ID(max_threads), },
366
0
    };
367
0
    #undef NUM_KEYWORDS
368
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
369
370
    #else  // !Py_BUILD_CORE
371
    #  define KWTUPLE NULL
372
    #endif  // !Py_BUILD_CORE
373
374
0
    static const char * const _keywords[] = {"timeout", "repeat", "file", "exit", "max_threads", NULL};
375
0
    static _PyArg_Parser _parser = {
376
0
        .keywords = _keywords,
377
0
        .fname = "dump_traceback_later",
378
0
        .kwtuple = KWTUPLE,
379
0
    };
380
0
    #undef KWTUPLE
381
0
    PyObject *argsbuf[5];
382
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
383
0
    PyObject *timeout_obj;
384
0
    int repeat = 0;
385
0
    PyObject *file = NULL;
386
0
    int exit = 0;
387
0
    Py_ssize_t max_threads = 100;
388
389
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
390
0
            /*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
391
0
    if (!args) {
392
0
        goto exit;
393
0
    }
394
0
    timeout_obj = args[0];
395
0
    if (!noptargs) {
396
0
        goto skip_optional_pos;
397
0
    }
398
0
    if (args[1]) {
399
0
        repeat = PyObject_IsTrue(args[1]);
400
0
        if (repeat < 0) {
401
0
            goto exit;
402
0
        }
403
0
        if (!--noptargs) {
404
0
            goto skip_optional_pos;
405
0
        }
406
0
    }
407
0
    if (args[2]) {
408
0
        file = args[2];
409
0
        if (!--noptargs) {
410
0
            goto skip_optional_pos;
411
0
        }
412
0
    }
413
0
    if (args[3]) {
414
0
        exit = PyObject_IsTrue(args[3]);
415
0
        if (exit < 0) {
416
0
            goto exit;
417
0
        }
418
0
        if (!--noptargs) {
419
0
            goto skip_optional_pos;
420
0
        }
421
0
    }
422
0
skip_optional_pos:
423
0
    if (!noptargs) {
424
0
        goto skip_optional_kwonly;
425
0
    }
426
0
    {
427
0
        Py_ssize_t ival = -1;
428
0
        PyObject *iobj = _PyNumber_Index(args[4]);
429
0
        if (iobj != NULL) {
430
0
            ival = PyLong_AsSsize_t(iobj);
431
0
            Py_DECREF(iobj);
432
0
        }
433
0
        if (ival == -1 && PyErr_Occurred()) {
434
0
            goto exit;
435
0
        }
436
0
        max_threads = ival;
437
0
    }
438
0
skip_optional_kwonly:
439
0
    return_value = faulthandler_dump_traceback_later_impl(module, timeout_obj, repeat, file, exit, max_threads);
440
441
0
exit:
442
0
    return return_value;
443
0
}
444
445
PyDoc_STRVAR(faulthandler_cancel_dump_traceback_later_py__doc__,
446
"cancel_dump_traceback_later($module, /)\n"
447
"--\n"
448
"\n"
449
"Cancel the previous call to dump_traceback_later().");
450
451
#define FAULTHANDLER_CANCEL_DUMP_TRACEBACK_LATER_PY_METHODDEF    \
452
    {"cancel_dump_traceback_later", (PyCFunction)faulthandler_cancel_dump_traceback_later_py, METH_NOARGS, faulthandler_cancel_dump_traceback_later_py__doc__},
453
454
static PyObject *
455
faulthandler_cancel_dump_traceback_later_py_impl(PyObject *module);
456
457
static PyObject *
458
faulthandler_cancel_dump_traceback_later_py(PyObject *module, PyObject *Py_UNUSED(ignored))
459
0
{
460
0
    return faulthandler_cancel_dump_traceback_later_py_impl(module);
461
0
}
462
463
#if defined(FAULTHANDLER_USER)
464
465
PyDoc_STRVAR(faulthandler_register_py__doc__,
466
"register($module, /, signum, file=sys.stderr, all_threads=True,\n"
467
"         chain=False, *, max_threads=100)\n"
468
"--\n"
469
"\n"
470
"Register a handler for the signal \'signum\'.\n"
471
"\n"
472
"Dump the traceback of the current thread, or of all threads if\n"
473
"all_threads is True, into file. max_threads caps the number of threads\n"
474
"dumped.");
475
476
#define FAULTHANDLER_REGISTER_PY_METHODDEF    \
477
    {"register", _PyCFunction_CAST(faulthandler_register_py), METH_FASTCALL|METH_KEYWORDS, faulthandler_register_py__doc__},
478
479
static PyObject *
480
faulthandler_register_py_impl(PyObject *module, int signum, PyObject *file,
481
                              int all_threads, int chain,
482
                              Py_ssize_t max_threads);
483
484
static PyObject *
485
faulthandler_register_py(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
486
0
{
487
0
    PyObject *return_value = NULL;
488
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
489
490
0
    #define NUM_KEYWORDS 5
491
0
    static struct {
492
0
        PyGC_Head _this_is_not_used;
493
0
        PyObject_VAR_HEAD
494
0
        Py_hash_t ob_hash;
495
0
        PyObject *ob_item[NUM_KEYWORDS];
496
0
    } _kwtuple = {
497
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
498
0
        .ob_hash = -1,
499
0
        .ob_item = { &_Py_ID(signum), &_Py_ID(file), &_Py_ID(all_threads), &_Py_ID(chain), &_Py_ID(max_threads), },
500
0
    };
501
0
    #undef NUM_KEYWORDS
502
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
503
504
    #else  // !Py_BUILD_CORE
505
    #  define KWTUPLE NULL
506
    #endif  // !Py_BUILD_CORE
507
508
0
    static const char * const _keywords[] = {"signum", "file", "all_threads", "chain", "max_threads", NULL};
509
0
    static _PyArg_Parser _parser = {
510
0
        .keywords = _keywords,
511
0
        .fname = "register",
512
0
        .kwtuple = KWTUPLE,
513
0
    };
514
0
    #undef KWTUPLE
515
0
    PyObject *argsbuf[5];
516
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
517
0
    int signum;
518
0
    PyObject *file = NULL;
519
0
    int all_threads = 1;
520
0
    int chain = 0;
521
0
    Py_ssize_t max_threads = 100;
522
523
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
524
0
            /*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
525
0
    if (!args) {
526
0
        goto exit;
527
0
    }
528
0
    signum = PyLong_AsInt(args[0]);
529
0
    if (signum == -1 && PyErr_Occurred()) {
530
0
        goto exit;
531
0
    }
532
0
    if (!noptargs) {
533
0
        goto skip_optional_pos;
534
0
    }
535
0
    if (args[1]) {
536
0
        file = args[1];
537
0
        if (!--noptargs) {
538
0
            goto skip_optional_pos;
539
0
        }
540
0
    }
541
0
    if (args[2]) {
542
0
        all_threads = PyObject_IsTrue(args[2]);
543
0
        if (all_threads < 0) {
544
0
            goto exit;
545
0
        }
546
0
        if (!--noptargs) {
547
0
            goto skip_optional_pos;
548
0
        }
549
0
    }
550
0
    if (args[3]) {
551
0
        chain = PyObject_IsTrue(args[3]);
552
0
        if (chain < 0) {
553
0
            goto exit;
554
0
        }
555
0
        if (!--noptargs) {
556
0
            goto skip_optional_pos;
557
0
        }
558
0
    }
559
0
skip_optional_pos:
560
0
    if (!noptargs) {
561
0
        goto skip_optional_kwonly;
562
0
    }
563
0
    {
564
0
        Py_ssize_t ival = -1;
565
0
        PyObject *iobj = _PyNumber_Index(args[4]);
566
0
        if (iobj != NULL) {
567
0
            ival = PyLong_AsSsize_t(iobj);
568
0
            Py_DECREF(iobj);
569
0
        }
570
0
        if (ival == -1 && PyErr_Occurred()) {
571
0
            goto exit;
572
0
        }
573
0
        max_threads = ival;
574
0
    }
575
0
skip_optional_kwonly:
576
0
    return_value = faulthandler_register_py_impl(module, signum, file, all_threads, chain, max_threads);
577
578
0
exit:
579
0
    return return_value;
580
0
}
581
582
#endif /* defined(FAULTHANDLER_USER) */
583
584
#if defined(FAULTHANDLER_USER)
585
586
PyDoc_STRVAR(faulthandler_unregister_py__doc__,
587
"unregister($module, signum, /)\n"
588
"--\n"
589
"\n"
590
"Unregister the handler of the signal \'signum\' registered by register().");
591
592
#define FAULTHANDLER_UNREGISTER_PY_METHODDEF    \
593
    {"unregister", (PyCFunction)faulthandler_unregister_py, METH_O, faulthandler_unregister_py__doc__},
594
595
static PyObject *
596
faulthandler_unregister_py_impl(PyObject *module, int signum);
597
598
static PyObject *
599
faulthandler_unregister_py(PyObject *module, PyObject *arg)
600
0
{
601
0
    PyObject *return_value = NULL;
602
0
    int signum;
603
604
0
    signum = PyLong_AsInt(arg);
605
0
    if (signum == -1 && PyErr_Occurred()) {
606
0
        goto exit;
607
0
    }
608
0
    return_value = faulthandler_unregister_py_impl(module, signum);
609
610
0
exit:
611
0
    return return_value;
612
0
}
613
614
#endif /* defined(FAULTHANDLER_USER) */
615
616
PyDoc_STRVAR(faulthandler__sigsegv__doc__,
617
"_sigsegv($module, release_gil=False, /)\n"
618
"--\n"
619
"\n"
620
"Raise a SIGSEGV signal.");
621
622
#define FAULTHANDLER__SIGSEGV_METHODDEF    \
623
    {"_sigsegv", _PyCFunction_CAST(faulthandler__sigsegv), METH_FASTCALL, faulthandler__sigsegv__doc__},
624
625
static PyObject *
626
faulthandler__sigsegv_impl(PyObject *module, int release_gil);
627
628
static PyObject *
629
faulthandler__sigsegv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
630
0
{
631
0
    PyObject *return_value = NULL;
632
0
    int release_gil = 0;
633
634
0
    if (!_PyArg_CheckPositional("_sigsegv", nargs, 0, 1)) {
635
0
        goto exit;
636
0
    }
637
0
    if (nargs < 1) {
638
0
        goto skip_optional;
639
0
    }
640
0
    release_gil = PyObject_IsTrue(args[0]);
641
0
    if (release_gil < 0) {
642
0
        goto exit;
643
0
    }
644
0
skip_optional:
645
0
    return_value = faulthandler__sigsegv_impl(module, release_gil);
646
647
0
exit:
648
0
    return return_value;
649
0
}
650
651
PyDoc_STRVAR(faulthandler__fatal_error_c_thread__doc__,
652
"_fatal_error_c_thread($module, /)\n"
653
"--\n"
654
"\n"
655
"Call Py_FatalError() in a new C thread.");
656
657
#define FAULTHANDLER__FATAL_ERROR_C_THREAD_METHODDEF    \
658
    {"_fatal_error_c_thread", (PyCFunction)faulthandler__fatal_error_c_thread, METH_NOARGS, faulthandler__fatal_error_c_thread__doc__},
659
660
static PyObject *
661
faulthandler__fatal_error_c_thread_impl(PyObject *module);
662
663
static PyObject *
664
faulthandler__fatal_error_c_thread(PyObject *module, PyObject *Py_UNUSED(ignored))
665
0
{
666
0
    return faulthandler__fatal_error_c_thread_impl(module);
667
0
}
668
669
PyDoc_STRVAR(faulthandler__sigfpe__doc__,
670
"_sigfpe($module, /)\n"
671
"--\n"
672
"\n"
673
"Raise a SIGFPE signal.");
674
675
#define FAULTHANDLER__SIGFPE_METHODDEF    \
676
    {"_sigfpe", (PyCFunction)faulthandler__sigfpe, METH_NOARGS, faulthandler__sigfpe__doc__},
677
678
static PyObject *
679
faulthandler__sigfpe_impl(PyObject *module);
680
681
static PyObject *
682
faulthandler__sigfpe(PyObject *module, PyObject *Py_UNUSED(ignored))
683
0
{
684
0
    return faulthandler__sigfpe_impl(module);
685
0
}
686
687
PyDoc_STRVAR(faulthandler__sigabrt__doc__,
688
"_sigabrt($module, /)\n"
689
"--\n"
690
"\n"
691
"Raise a SIGABRT signal.");
692
693
#define FAULTHANDLER__SIGABRT_METHODDEF    \
694
    {"_sigabrt", (PyCFunction)faulthandler__sigabrt, METH_NOARGS, faulthandler__sigabrt__doc__},
695
696
static PyObject *
697
faulthandler__sigabrt_impl(PyObject *module);
698
699
static PyObject *
700
faulthandler__sigabrt(PyObject *module, PyObject *Py_UNUSED(ignored))
701
0
{
702
0
    return faulthandler__sigabrt_impl(module);
703
0
}
704
705
#if defined(FAULTHANDLER_USE_ALT_STACK)
706
707
PyDoc_STRVAR(faulthandler__stack_overflow__doc__,
708
"_stack_overflow($module, /)\n"
709
"--\n"
710
"\n"
711
"Recursive call to raise a stack overflow.");
712
713
#define FAULTHANDLER__STACK_OVERFLOW_METHODDEF    \
714
    {"_stack_overflow", (PyCFunction)faulthandler__stack_overflow, METH_NOARGS, faulthandler__stack_overflow__doc__},
715
716
static PyObject *
717
faulthandler__stack_overflow_impl(PyObject *module);
718
719
static PyObject *
720
faulthandler__stack_overflow(PyObject *module, PyObject *Py_UNUSED(ignored))
721
0
{
722
0
    return faulthandler__stack_overflow_impl(module);
723
0
}
724
725
#endif /* defined(FAULTHANDLER_USE_ALT_STACK) */
726
727
#if defined(MS_WINDOWS)
728
729
PyDoc_STRVAR(faulthandler__raise_exception__doc__,
730
"_raise_exception($module, code, flags=0, /)\n"
731
"--\n"
732
"\n"
733
"Call RaiseException(code, flags).");
734
735
#define FAULTHANDLER__RAISE_EXCEPTION_METHODDEF    \
736
    {"_raise_exception", _PyCFunction_CAST(faulthandler__raise_exception), METH_FASTCALL, faulthandler__raise_exception__doc__},
737
738
static PyObject *
739
faulthandler__raise_exception_impl(PyObject *module, unsigned int code,
740
                                   unsigned int flags);
741
742
static PyObject *
743
faulthandler__raise_exception(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
744
{
745
    PyObject *return_value = NULL;
746
    unsigned int code;
747
    unsigned int flags = 0;
748
749
    if (!_PyArg_CheckPositional("_raise_exception", nargs, 1, 2)) {
750
        goto exit;
751
    }
752
    if (!_PyLong_UnsignedInt_Converter(args[0], &code)) {
753
        goto exit;
754
    }
755
    if (nargs < 2) {
756
        goto skip_optional;
757
    }
758
    if (!_PyLong_UnsignedInt_Converter(args[1], &flags)) {
759
        goto exit;
760
    }
761
skip_optional:
762
    return_value = faulthandler__raise_exception_impl(module, code, flags);
763
764
exit:
765
    return return_value;
766
}
767
768
#endif /* defined(MS_WINDOWS) */
769
770
#ifndef FAULTHANDLER_REGISTER_PY_METHODDEF
771
    #define FAULTHANDLER_REGISTER_PY_METHODDEF
772
#endif /* !defined(FAULTHANDLER_REGISTER_PY_METHODDEF) */
773
774
#ifndef FAULTHANDLER_UNREGISTER_PY_METHODDEF
775
    #define FAULTHANDLER_UNREGISTER_PY_METHODDEF
776
#endif /* !defined(FAULTHANDLER_UNREGISTER_PY_METHODDEF) */
777
778
#ifndef FAULTHANDLER__STACK_OVERFLOW_METHODDEF
779
    #define FAULTHANDLER__STACK_OVERFLOW_METHODDEF
780
#endif /* !defined(FAULTHANDLER__STACK_OVERFLOW_METHODDEF) */
781
782
#ifndef FAULTHANDLER__RAISE_EXCEPTION_METHODDEF
783
    #define FAULTHANDLER__RAISE_EXCEPTION_METHODDEF
784
#endif /* !defined(FAULTHANDLER__RAISE_EXCEPTION_METHODDEF) */
785
/*[clinic end generated code: output=14815a5f8afe813f input=a9049054013a1b77]*/