comparison 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
comparison
equal deleted inserted replaced
13991:7834a113ce24 13992:97f5388a6dce
18 #include "parsetok.h" 18 #include "parsetok.h"
19 #include "errcode.h" 19 #include "errcode.h"
20 #include "compile.h" 20 #include "compile.h"
21 #include "eval.h" 21 #include "eval.h"
22 #include "marshal.h" 22 #include "marshal.h"
23 #include "osdefs.h" /* SEP */
23 24
24 #ifdef HAVE_UNISTD_H 25 #ifdef HAVE_UNISTD_H
25 #include <unistd.h> 26 #include <unistd.h>
26 #endif 27 #endif
27 28
1001 fprintf(stderr, "error=%d\n", err->error); 1002 fprintf(stderr, "error=%d\n", err->error);
1002 msg = "unknown parsing error"; 1003 msg = "unknown parsing error";
1003 break; 1004 break;
1004 } 1005 }
1005 w = Py_BuildValue("(sO)", msg, v); 1006 w = Py_BuildValue("(sO)", msg, v);
1006 Py_XDECREF(v);
1007 PyErr_SetObject(errtype, w); 1007 PyErr_SetObject(errtype, w);
1008 Py_XDECREF(w); 1008 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 }
1009 } 1027 }
1010 1028
1011 /* Print fatal error message and abort */ 1029 /* Print fatal error message and abort */
1012 1030
1013 void 1031 void