39
39
return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
42
/* copied from pythonrun.c, 3.2.0 */
42
/* copied from pythonrun.c, 3.3.0 */
44
44
parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
45
45
int *lineno, int *offset, const char **text)
50
_Py_IDENTIFIER(filename);
51
_Py_IDENTIFIER(lineno);
52
_Py_IDENTIFIER(offset);
50
/* old style errors */
51
if (PyTuple_Check(err))
52
return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
53
lineno, offset, text);
55
57
/* new style errors. `err' is an instance */
57
if (!(v = PyObject_GetAttrString(err, "msg")))
61
if (!(v = PyObject_GetAttrString(err, "filename")))
58
*message = _PyObject_GetAttrId(err, &PyId_msg);
62
v = _PyObject_GetAttrId(err, &PyId_filename);
65
else if (!(*filename = _PyUnicode_AsString(v)))
70
*filename = _PyUnicode_AsString(v);
69
if (!(v = PyObject_GetAttrString(err, "lineno")))
76
v = _PyObject_GetAttrId(err, &PyId_lineno);
71
79
hold = PyLong_AsLong(v);
74
81
if (hold < 0 && PyErr_Occurred())
76
83
*lineno = (int)hold;
78
if (!(v = PyObject_GetAttrString(err, "offset")))
85
v = _PyObject_GetAttrId(err, &PyId_offset);
80
88
if (v == Py_None) {
86
92
hold = PyLong_AsLong(v);
89
94
if (hold < 0 && PyErr_Occurred())
91
96
*offset = (int)hold;
94
if (!(v = PyObject_GetAttrString(err, "text")))
99
v = _PyObject_GetAttrId(err, &PyId_text);
98
else if (!PyUnicode_Check(v) ||
99
!(*text = _PyUnicode_AsString(v)))
107
*text = _PyUnicode_AsString(v);
115
Py_XDECREF(*message);
108
118
/* end copied function! */