11 #include <frameobject.h>
23 PyCodeObject *code = PyFrame_GetCode(tb->tb_frame);
24 *coerce = PyUnicode_EncodeFSDefault(code->co_filename);
25 return PyBytes_AS_STRING(*coerce);
43 _Py_IDENTIFIER(filename);
44 _Py_IDENTIFIER(lineno);
46 _Py_IDENTIFIER(end_lineno);
47 _Py_IDENTIFIER(end_offset);
54 *message = _PyObject_GetAttrId(
err, &PyId_msg);
59 v = _PyObject_GetAttrId(
err, &PyId_filename);
65 *filename = _PyUnicode_FromId(&PyId_string);
66 if (*filename ==
NULL) {
75 v = _PyObject_GetAttrId(
err, &PyId_lineno);
79 hold = PyLong_AsSsize_t(
v);
81 if (hold < 0 && PyErr_Occurred()) {
86 v = _PyObject_GetAttrId(
err, &PyId_offset);
95 hold = PyLong_AsSsize_t(
v);
97 if (hold < 0 && PyErr_Occurred()) {
103 if (Py_TYPE(
err) == (PyTypeObject *)PyExc_SyntaxError) {
104 v = _PyObject_GetAttrId(
err, &PyId_end_lineno);
107 *end_lineno = *lineno;
109 else if (
v == Py_None) {
110 *end_lineno = *lineno;
114 hold = PyLong_AsSsize_t(
v);
116 if (hold < 0 && PyErr_Occurred()) {
122 v = _PyObject_GetAttrId(
err, &PyId_end_offset);
127 else if (
v == Py_None) {
132 hold = PyLong_AsSsize_t(
v);
134 if (hold < 0 && PyErr_Occurred()) {
142 *end_lineno = *lineno;
146 v = _PyObject_GetAttrId(
err, &PyId_text);
160 Py_XDECREF(*message);
161 Py_XDECREF(*filename);
167 const char *filepath,
int *r_lineno,
int *r_offset,
int *r_lineno_end,
int *r_offset_end)
173 bool success =
false;
174 PyObject *exception, *value;
175 PyTracebackObject *tb;
183 PyErr_Fetch(&exception, &value, (PyObject **)&tb);
184 if (exception ==
NULL) {
188 if (PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
191 PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
195 PyObject *filepath_exc_py, *text_py;
205 const char *filepath_exc = PyUnicode_AsUTF8(filepath_exc_py);
208 (
ELEM(filepath_exc[0],
'\\',
'/') &&
BLI_path_cmp(filepath_exc + 1, filepath) == 0)) {
215 PyErr_NormalizeException(&exception, &value, (PyObject **)&tb);
217 for (tb = (PyTracebackObject *)PySys_GetObject(
"last_traceback");
218 tb && (PyObject *)tb != Py_None;
222 const int match = ((
BLI_path_cmp(tb_filepath, filepath) == 0) ||
223 (
ELEM(tb_filepath[0],
'\\',
'/') &&
229 *r_lineno = *r_lineno_end = tb->tb_lineno;
235 PyErr_Restore(exception, value, (PyObject *)tb);
ATTR_WARN_UNUSED_RESULT const BMVert * v
static int parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, int *lineno, int *offset, int *end_lineno, int *end_offset, PyObject **text)
_Py_static_string(PyId_string, "<string>")
bool python_script_error_jump(const char *filepath, int *r_lineno, int *r_offset, int *r_lineno_end, int *r_offset_end)
static const char * traceback_filepath(PyTracebackObject *tb, PyObject **coerce)
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset