Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Python/clinic/traceback.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_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
#if !defined(traceback_tb_next_DOCSTR)
87
#  define traceback_tb_next_DOCSTR NULL
88
#endif
89
#if defined(TRACEBACK_TB_NEXT_GETSETDEF)
90
#  undef TRACEBACK_TB_NEXT_GETSETDEF
91
#  define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR},
92
#else
93
#  define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, NULL, traceback_tb_next_DOCSTR},
94
#endif
95
96
static PyObject *
97
traceback_tb_next_get_impl(PyTracebackObject *self);
98
99
static PyObject *
100
traceback_tb_next_get(PyObject *self, void *Py_UNUSED(context))
101
0
{
102
0
    PyObject *return_value = NULL;
103
104
0
    Py_BEGIN_CRITICAL_SECTION(self);
105
0
    return_value = traceback_tb_next_get_impl((PyTracebackObject *)self);
106
0
    Py_END_CRITICAL_SECTION();
107
108
0
    return return_value;
109
0
}
110
111
#if !defined(traceback_tb_next_DOCSTR)
112
#  define traceback_tb_next_DOCSTR NULL
113
#endif
114
#if defined(TRACEBACK_TB_NEXT_GETSETDEF)
115
#  undef TRACEBACK_TB_NEXT_GETSETDEF
116
#  define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR},
117
#else
118
#  define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", NULL, (setter)traceback_tb_next_set, NULL},
119
#endif
120
121
static int
122
traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value);
123
124
static int
125
traceback_tb_next_set(PyObject *self, PyObject *value, void *Py_UNUSED(context))
126
0
{
127
0
    int return_value;
128
129
0
    Py_BEGIN_CRITICAL_SECTION(self);
130
0
    return_value = traceback_tb_next_set_impl((PyTracebackObject *)self, value);
131
0
    Py_END_CRITICAL_SECTION();
132
133
0
    return return_value;
134
0
}
135
/*[clinic end generated code: output=5361141395da963e input=a9049054013a1b77]*/