Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Python/clinic/traceback.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_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
11
12
PyDoc_STRVAR(tb_new__doc__,
13
"traceback(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
14
"--\n"
15
"\n"
16
"Create a new traceback object.");
17
18
static PyObject *
19
tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame,
20
            int tb_lasti, int tb_lineno);
21
22
static PyObject *
23
tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
24
0
{
25
0
    PyObject *return_value = NULL;
26
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
27
28
0
    #define NUM_KEYWORDS 4
29
0
    static struct {
30
0
        PyGC_Head _this_is_not_used;
31
0
        PyObject_VAR_HEAD
32
0
        Py_hash_t ob_hash;
33
0
        PyObject *ob_item[NUM_KEYWORDS];
34
0
    } _kwtuple = {
35
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36
0
        .ob_hash = -1,
37
0
        .ob_item = { &_Py_ID(tb_next), &_Py_ID(tb_frame), &_Py_ID(tb_lasti), &_Py_ID(tb_lineno), },
38
0
    };
39
0
    #undef NUM_KEYWORDS
40
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
41
42
    #else  // !Py_BUILD_CORE
43
    #  define KWTUPLE NULL
44
    #endif  // !Py_BUILD_CORE
45
46
0
    static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL};
47
0
    static _PyArg_Parser _parser = {
48
0
        .keywords = _keywords,
49
0
        .fname = "traceback",
50
0
        .kwtuple = KWTUPLE,
51
0
    };
52
0
    #undef KWTUPLE
53
0
    PyObject *argsbuf[4];
54
0
    PyObject * const *fastargs;
55
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
56
0
    PyObject *tb_next;
57
0
    PyFrameObject *tb_frame;
58
0
    int tb_lasti;
59
0
    int tb_lineno;
60
61
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
62
0
            /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
63
0
    if (!fastargs) {
64
0
        goto exit;
65
0
    }
66
0
    tb_next = fastargs[0];
67
0
    if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) {
68
0
        _PyArg_BadArgument("traceback", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
69
0
        goto exit;
70
0
    }
71
0
    tb_frame = (PyFrameObject *)fastargs[1];
72
0
    tb_lasti = PyLong_AsInt(fastargs[2]);
73
0
    if (tb_lasti == -1 && PyErr_Occurred()) {
74
0
        goto exit;
75
0
    }
76
0
    tb_lineno = PyLong_AsInt(fastargs[3]);
77
0
    if (tb_lineno == -1 && PyErr_Occurred()) {
78
0
        goto exit;
79
0
    }
80
0
    return_value = tb_new_impl(type, tb_next, tb_frame, tb_lasti, tb_lineno);
81
82
0
exit:
83
0
    return return_value;
84
0
}
85
86
static PyObject *
87
traceback_tb_next_get_impl(PyTracebackObject *self);
88
89
static PyObject *
90
traceback_tb_next_get(PyObject *self, void *Py_UNUSED(context))
91
0
{
92
0
    PyObject *return_value = NULL;
93
94
0
    Py_BEGIN_CRITICAL_SECTION(self);
95
0
    return_value = traceback_tb_next_get_impl((PyTracebackObject *)self);
96
0
    Py_END_CRITICAL_SECTION();
97
98
0
    return return_value;
99
0
}
100
101
static int
102
traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value);
103
104
static int
105
traceback_tb_next_set(PyObject *self, PyObject *arg, void *Py_UNUSED(context))
106
0
{
107
0
    int return_value = -1;
108
0
    PyObject *value;
109
110
0
    if (arg == NULL) {
111
0
        PyErr_Format(PyExc_AttributeError,
112
0
                     "attribute 'tb_next' of '%.100s' objects cannot be deleted",
113
0
                     Py_TYPE(self)->tp_name);
114
0
        return -1;
115
0
    }
116
0
    value = arg;
117
0
    Py_BEGIN_CRITICAL_SECTION(self);
118
0
    return_value = traceback_tb_next_set_impl((PyTracebackObject *)self, value);
119
0
    Py_END_CRITICAL_SECTION();
120
121
0
    return return_value;
122
0
}
123
#define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, NULL},
124
125
/*[clinic end generated code: output=0f7bb7a58d9f8d65 input=a9049054013a1b77]*/