Coverage Report

Created: 2025-08-26 06:26

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