87 *message = _PyObject_GetAttrId(err, &PyId_msg);
92 v = _PyObject_GetAttrId(err, &PyId_filename);
98 *filename = _PyUnicode_FromId(&PyId_string);
99 if (*filename ==
nullptr) {
102 Py_INCREF(*filename);
108 v = _PyObject_GetAttrId(err, &PyId_lineno);
112 hold = PyLong_AsSsize_t(
v);
114 if (hold < 0 && PyErr_Occurred()) {
119 v = _PyObject_GetAttrId(err, &PyId_offset);
128 hold = PyLong_AsSsize_t(
v);
130 if (hold < 0 && PyErr_Occurred()) {
136 if (Py_TYPE(err) == (PyTypeObject *)PyExc_SyntaxError) {
137 v = _PyObject_GetAttrId(err, &PyId_end_lineno);
140 *end_lineno = *lineno;
142 else if (
v == Py_None) {
143 *end_lineno = *lineno;
147 hold = PyLong_AsSsize_t(
v);
149 if (hold < 0 && PyErr_Occurred()) {
155 v = _PyObject_GetAttrId(err, &PyId_end_offset);
160 else if (
v == Py_None) {
165 hold = PyLong_AsSsize_t(
v);
167 if (hold < 0 && PyErr_Occurred()) {
175 *end_lineno = *lineno;
179 v = _PyObject_GetAttrId(err, &PyId_text);
193 Py_XDECREF(*message);
194 Py_XDECREF(*filename);
200 const char *filepath,
int *r_lineno,
int *r_offset,
int *r_lineno_end,
int *r_offset_end)
202 bool success =
false;
203 PyObject *exception, *value, *tb;
211 PyErr_Fetch(&exception, &value, &tb);
212 if (exception ==
nullptr) {
215 PyObject *base_exception_type =
nullptr;
216 if (PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
217 base_exception_type = PyExc_SyntaxError;
220 PyErr_NormalizeException(&exception, &value, &tb);
222 if (base_exception_type == PyExc_SyntaxError) {
228 PyObject *filepath_exc_py, *text_py;
239 const char *filepath_exc = PyUnicode_AsUTF8(filepath_exc_py);
242 (
ELEM(filepath_exc[0],
'\\',
'/') &&
BLI_path_cmp(filepath_exc + 1, filepath) == 0))
250 for (PyTracebackObject *tb_iter = (PyTracebackObject *)tb;
251 tb_iter && (PyObject *)tb_iter != Py_None;
252 tb_iter = tb_iter->tb_next)
256 const int match = ((
BLI_path_cmp(tb_filepath, filepath) == 0) ||
257 (
ELEM(tb_filepath[0],
'\\',
'/') &&
269 PyErr_Restore(exception, value, tb);
static int parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, int *lineno, int *offset, int *end_lineno, int *end_offset, PyObject **text)