25 #include <frameobject.h>
37 *coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename);
38 return PyBytes_AS_STRING(*coerce);
54 _Py_IDENTIFIER(filename);
55 _Py_IDENTIFIER(lineno);
56 _Py_IDENTIFIER(offset);
63 *message = _PyObject_GetAttrId(
err, &PyId_msg);
68 v = _PyObject_GetAttrId(
err, &PyId_filename);
74 *filename = _PyUnicode_FromId(&PyId_string);
75 if (*filename ==
NULL) {
84 v = _PyObject_GetAttrId(
err, &PyId_lineno);
88 hold = PyLong_AsLong(
v);
90 if (hold < 0 && PyErr_Occurred()) {
95 v = _PyObject_GetAttrId(
err, &PyId_offset);
104 hold = PyLong_AsLong(
v);
106 if (hold < 0 && PyErr_Occurred()) {
112 v = _PyObject_GetAttrId(
err, &PyId_text);
126 Py_XDECREF(*message);
127 Py_XDECREF(*filename);
134 PyObject *exception, *value;
135 PyTracebackObject *tb;
140 PyErr_Fetch(&exception, &value, (PyObject **)&tb);
142 if (exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
145 PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
149 PyObject *filename_py, *text_py;
152 const char *filename = PyUnicode_AsUTF8(filename_py);
155 (
ELEM(filename[0],
'\\',
'/') &&
BLI_path_cmp(filename + 1, filepath) == 0)) {
166 PyErr_Restore(exception, value, (PyObject *)tb);
169 PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
170 PyErr_Restore(exception, value, (PyObject *)tb);
173 for (tb = (PyTracebackObject *)PySys_GetObject(
"last_traceback");
174 tb && (PyObject *)tb != Py_None;
178 const int match = ((
BLI_path_cmp(tb_filepath, filepath) == 0) ||
179 (
ELEM(tb_filepath[0],
'\\',
'/') &&
184 *lineno = tb->tb_lineno;
ATTR_WARN_UNUSED_RESULT const BMVert * v
_Py_static_string(PyId_string, "<string>")
void python_script_error_jump(const char *filepath, int *lineno, int *offset)
static int parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, int *lineno, int *offset, PyObject **text)
static const char * traceback_filepath(PyTracebackObject *tb, PyObject **coerce)