Debian Codegraph @

Python/clinic/traceback.c.h

raw
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 {
25 PyObject *return_value = NULL;
26 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
27
28 #define NUM_KEYWORDS 4
29 static struct {
30 PyGC_Head _this_is_not_used;
31 PyObject_VAR_HEAD
32 Py_hash_t ob_hash;
33 PyObject *ob_item[NUM_KEYWORDS];
34 } _kwtuple = {
35 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
36 .ob_hash = -1,
37 .ob_item = { &_Py_ID(tb_next), &_Py_ID(tb_frame), &_Py_ID(tb_lasti), &_Py_ID(tb_lineno), },
38 };
39 #undef NUM_KEYWORDS
40 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
41
42 #else // !Py_BUILD_CORE
43 # define KWTUPLE NULL
44 #endif // !Py_BUILD_CORE
45
46 static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL};
47 static _PyArg_Parser _parser = {
48 .keywords = _keywords,
49 .fname = "traceback",
50 .kwtuple = KWTUPLE,
51 };
52 #undef KWTUPLE
53 PyObject *argsbuf[4];
54 PyObject * const *fastargs;
55 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
56 PyObject *tb_next;
57 PyFrameObject *tb_frame;
58 int tb_lasti;
59 int tb_lineno;
60
61 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
62 /*minpos*/ 4, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
63 if (!fastargs) {
64 goto exit;
65 }
66 tb_next = fastargs[0];
67 if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) {
68 _PyArg_BadArgument("traceback", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
69 goto exit;
70 }
71 tb_frame = (PyFrameObject *)fastargs[1];
72 tb_lasti = PyLong_AsInt(fastargs[2]);
73 if (tb_lasti == -1 && PyErr_Occurred()) {
74 goto exit;
75 }
76 tb_lineno = PyLong_AsInt(fastargs[3]);
77 if (tb_lineno == -1 && PyErr_Occurred()) {
78 goto exit;
79 }
80 return_value = tb_new_impl(type, tb_next, tb_frame, tb_lasti, tb_lineno);
81
82 exit:
83 return return_value;
84 }
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 {
102 PyObject *return_value = NULL;
103
104 Py_BEGIN_CRITICAL_SECTION(self);
105 return_value = traceback_tb_next_get_impl((PyTracebackObject *)self);
106 Py_END_CRITICAL_SECTION();
107
108 return return_value;
109 }
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 {
127 int return_value;
128
129 Py_BEGIN_CRITICAL_SECTION(self);
130 return_value = traceback_tb_next_set_impl((PyTracebackObject *)self, value);
131 Py_END_CRITICAL_SECTION();
132
133 return return_value;
134 }
135 /*[clinic end generated code: output=5361141395da963e input=a9049054013a1b77]*/