Update parse_syntax_error() to Python 3.4x version
This commit is contained in:
@@ -42,10 +42,12 @@ static const char *traceback_filepath(PyTracebackObject *tb, PyObject **coerce)
|
|||||||
return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
|
return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copied from pythonrun.c, 3.3.0 */
|
/* copied from pythonrun.c, 3.4.0 */
|
||||||
|
_Py_static_string(PyId_string, "<string>");
|
||||||
|
|
||||||
static int
|
static int
|
||||||
parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
|
parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
|
||||||
int *lineno, int *offset, const char **text)
|
int *lineno, int *offset, PyObject **text)
|
||||||
{
|
{
|
||||||
long hold;
|
long hold;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
@@ -56,6 +58,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
|
|||||||
_Py_IDENTIFIER(text);
|
_Py_IDENTIFIER(text);
|
||||||
|
|
||||||
*message = NULL;
|
*message = NULL;
|
||||||
|
*filename = NULL;
|
||||||
|
|
||||||
/* new style errors. `err' is an instance */
|
/* new style errors. `err' is an instance */
|
||||||
*message = _PyObject_GetAttrId(err, &PyId_msg);
|
*message = _PyObject_GetAttrId(err, &PyId_msg);
|
||||||
@@ -67,13 +70,13 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
|
|||||||
goto finally;
|
goto finally;
|
||||||
if (v == Py_None) {
|
if (v == Py_None) {
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
*filename = NULL;
|
*filename = _PyUnicode_FromId(&PyId_string);
|
||||||
|
if (*filename == NULL)
|
||||||
|
goto finally;
|
||||||
|
Py_INCREF(*filename);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*filename = _PyUnicode_AsString(v);
|
*filename = v;
|
||||||
Py_DECREF(v);
|
|
||||||
if (!*filename)
|
|
||||||
goto finally;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v = _PyObject_GetAttrId(err, &PyId_lineno);
|
v = _PyObject_GetAttrId(err, &PyId_lineno);
|
||||||
@@ -107,15 +110,13 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
|
|||||||
*text = NULL;
|
*text = NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*text = _PyUnicode_AsString(v);
|
*text = v;
|
||||||
Py_DECREF(v);
|
|
||||||
if (!*text)
|
|
||||||
goto finally;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
Py_XDECREF(*message);
|
Py_XDECREF(*message);
|
||||||
|
Py_XDECREF(*filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* end copied function! */
|
/* end copied function! */
|
||||||
@@ -139,9 +140,10 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset)
|
|||||||
|
|
||||||
if (value) { /* should always be true */
|
if (value) { /* should always be true */
|
||||||
PyObject *message;
|
PyObject *message;
|
||||||
const char *filename, *text;
|
PyObject *filename_py, *text_py;
|
||||||
|
|
||||||
if (parse_syntax_error(value, &message, &filename, lineno, offset, &text)) {
|
if (parse_syntax_error(value, &message, &filename_py, lineno, offset, &text_py)) {
|
||||||
|
const char *filename = _PyUnicode_AsString(filename_py);
|
||||||
/* python adds a '/', prefix, so check for both */
|
/* python adds a '/', prefix, so check for both */
|
||||||
if ((BLI_path_cmp(filename, filepath) == 0) ||
|
if ((BLI_path_cmp(filename, filepath) == 0) ||
|
||||||
((filename[0] == '\\' || filename[0] == '/') && BLI_path_cmp(filename + 1, filepath) == 0))
|
((filename[0] == '\\' || filename[0] == '/') && BLI_path_cmp(filename + 1, filepath) == 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user