summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-08-15 15:49:03 (GMT)
committerFred Drake <fdrake@acm.org>2000-08-15 15:49:03 (GMT)
commit83cb7973802441f1f6c7115bc8eb83d64534b853 (patch)
tree2480cf6ef04a93abc00517e34963e295fd82db9f /Python
parent1aba5770939c497c707eecd167856f98c9bb74c0 (diff)
downloadcpython-83cb7973802441f1f6c7115bc8eb83d64534b853.zip
cpython-83cb7973802441f1f6c7115bc8eb83d64534b853.tar.gz
cpython-83cb7973802441f1f6c7115bc8eb83d64534b853.tar.bz2
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).
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 7812de4..44b55d2 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -20,6 +20,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#include "compile.h"
#include "eval.h"
#include "marshal.h"
+#include "osdefs.h" /* SEP */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -1003,9 +1004,26 @@ err_input(perrdetail *err)
break;
}
w = Py_BuildValue("(sO)", msg, v);
- Py_XDECREF(v);
PyErr_SetObject(errtype, w);
Py_XDECREF(w);
+
+ if (v != NULL) {
+ PyObject *exc, *tb;
+
+ PyErr_Fetch(&errtype, &exc, &tb);
+ PyErr_NormalizeException(&errtype, &exc, &tb);
+ if (PyObject_SetAttrString(exc, "filename",
+ PyTuple_GET_ITEM(v, 0)))
+ PyErr_Clear();
+ if (PyObject_SetAttrString(exc, "lineno",
+ PyTuple_GET_ITEM(v, 1)))
+ PyErr_Clear();
+ if (PyObject_SetAttrString(exc, "offset",
+ PyTuple_GET_ITEM(v, 2)))
+ PyErr_Clear();
+ Py_DECREF(v);
+ PyErr_Restore(errtype, exc, tb);
+ }
}
/* Print fatal error message and abort */