Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83cb797

Browse files
committed
When raising a SyntaxError, make a best-effort attempt to set the
filename and lineno attributes, but do not mask the SyntaxError if we fail. This is part of what is needed to close SoruceForge bug #110628 (Jitterbug PR#278).
1 parent 1aba577 commit 83cb797

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

Python/pythonrun.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
2020
#include "compile.h"
2121
#include "eval.h"
2222
#include "marshal.h"
23+
#include "osdefs.h" /* SEP */
2324

2425
#ifdef HAVE_UNISTD_H
2526
#include <unistd.h>
@@ -1003,9 +1004,26 @@ err_input(perrdetail *err)
10031004
break;
10041005
}
10051006
w = Py_BuildValue("(sO)", msg, v);
1006-
Py_XDECREF(v);
10071007
PyErr_SetObject(errtype, w);
10081008
Py_XDECREF(w);
1009+
1010+
if (v != NULL) {
1011+
PyObject *exc, *tb;
1012+
1013+
PyErr_Fetch(&errtype, &exc, &tb);
1014+
PyErr_NormalizeException(&errtype, &exc, &tb);
1015+
if (PyObject_SetAttrString(exc, "filename",
1016+
PyTuple_GET_ITEM(v, 0)))
1017+
PyErr_Clear();
1018+
if (PyObject_SetAttrString(exc, "lineno",
1019+
PyTuple_GET_ITEM(v, 1)))
1020+
PyErr_Clear();
1021+
if (PyObject_SetAttrString(exc, "offset",
1022+
PyTuple_GET_ITEM(v, 2)))
1023+
PyErr_Clear();
1024+
Py_DECREF(v);
1025+
PyErr_Restore(errtype, exc, tb);
1026+
}
10091027
}
10101028

10111029
/* Print fatal error message and abort */

0 commit comments

Comments
 (0)