90 *message = _PyObject_GetAttrId(err, &PyId_msg);
95 v = _PyObject_GetAttrId(err, &PyId_filename);
101 *
filename = _PyUnicode_FromId(&PyId_string);
111 v = _PyObject_GetAttrId(err, &PyId_lineno);
115 hold = PyLong_AsSsize_t(
v);
117 if (hold < 0 && PyErr_Occurred()) {
122 v = _PyObject_GetAttrId(err, &PyId_offset);
131 hold = PyLong_AsSsize_t(
v);
133 if (hold < 0 && PyErr_Occurred()) {
139 if (Py_TYPE(err) ==
reinterpret_cast<PyTypeObject *
>(PyExc_SyntaxError)) {
140 v = _PyObject_GetAttrId(err, &PyId_end_lineno);
143 *end_lineno = *lineno;
145 else if (
v == Py_None) {
146 *end_lineno = *lineno;
150 hold = PyLong_AsSsize_t(
v);
152 if (hold < 0 && PyErr_Occurred()) {
158 v = _PyObject_GetAttrId(err, &PyId_end_offset);
163 else if (
v == Py_None) {
168 hold = PyLong_AsSsize_t(
v);
170 if (hold < 0 && PyErr_Occurred()) {
178 *end_lineno = *lineno;
182 v = _PyObject_GetAttrId(err, &PyId_text);
196 Py_XDECREF(*message);
203 const char *filepath,
int *r_lineno,
int *r_offset,
int *r_lineno_end,
int *r_offset_end)
205 bool success =
false;
206 PyObject *exception, *value, *tb;
214 PyErr_Fetch(&exception, &value, &tb);
215 if (exception ==
nullptr) {
218 PyObject *base_exception_type =
nullptr;
219 if (PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
220 base_exception_type = PyExc_SyntaxError;
223 PyErr_NormalizeException(&exception, &value, &tb);
225 if (base_exception_type == PyExc_SyntaxError) {
231 PyObject *filepath_exc_py, *text_py;
242 const char *filepath_exc = PyUnicode_AsUTF8(filepath_exc_py);
245 (
ELEM(filepath_exc[0],
'\\',
'/') &&
BLI_path_cmp(filepath_exc + 1, filepath) == 0))
250 Py_DECREF(filepath_exc_py);
256 for (PyTracebackObject *tb_iter =
reinterpret_cast<PyTracebackObject *
>(tb);
257 tb_iter &&
reinterpret_cast<PyObject *
>(tb_iter) != Py_None;
258 tb_iter = tb_iter->tb_next)
262 const int match = ((
BLI_path_cmp(tb_filepath, filepath) == 0) ||
263 (
ELEM(tb_filepath[0],
'\\',
'/') &&
275 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)