diff Python/pythonrun.c @ 13992:97f5388a6dce legacy-trunk

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).
author Fred Drake <fdrake@acm.org>
date Tue, 15 Aug 2000 15:49:03 +0000
parents f79434ee41fa
children 65c1abf451dc
line wrap: on
line diff
--- a/Python/pythonrun.c	Tue Aug 15 15:46:16 2000 +0000
+++ b/Python/pythonrun.c	Tue Aug 15 15:49:03 2000 +0000
@@ -20,6 +20,7 @@
 #include "compile.h"
 #include "eval.h"
 #include "marshal.h"
+#include "osdefs.h"			/* SEP */
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -1003,9 +1004,26 @@
 		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 */