[Python-checkins] CVS: python/dist/src/Python compile.c,2.238,2.239 errors.c,2.66,2.67 exceptions.c,1.28,1.29 pythonrun.c,2.154,2.155
Martin v. L?wis
loewis@users.sourceforge.net
Sun, 03 Mar 2002 13:30:29 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv20927/Python
Modified Files:
compile.c errors.c exceptions.c pythonrun.c
Log Message:
Patch #50002: Display line information for bad \x escapes:
- recognize "SyntaxError"s by the print_file_and_line attribute.
- add the syntaxerror attributes to all exceptions in compile.c.
Fixes #221791
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.238
retrieving revision 2.239
diff -C2 -d -r2.238 -r2.239
*** compile.c 29 Jan 2002 00:56:37 -0000 2.238
--- compile.c 3 Mar 2002 21:30:27 -0000 2.239
***************
*** 466,477 ****
line = Py_None;
}
! t = Py_BuildValue("(ziOO)", c->c_filename, c->c_lineno,
! Py_None, line);
! if (t == NULL)
! goto exit;
! w = Py_BuildValue("(OO)", v, t);
! if (w == NULL)
! goto exit;
! PyErr_SetObject(exc, w);
exit:
Py_XDECREF(t);
--- 466,484 ----
line = Py_None;
}
! if (exc == PyExc_SyntaxError) {
! t = Py_BuildValue("(ziOO)", c->c_filename, c->c_lineno,
! Py_None, line);
! if (t == NULL)
! goto exit;
! w = Py_BuildValue("(OO)", v, t);
! if (w == NULL)
! goto exit;
! PyErr_SetObject(exc, w);
! } else {
! /* Make sure additional exceptions are printed with
! file and line, also. */
! PyErr_SetObject(exc, v);
! PyErr_SyntaxLocation(c->c_filename, c->c_lineno);
! }
exit:
Py_XDECREF(t);
***************
*** 1154,1158 ****
len = strlen(s);
if (len > INT_MAX) {
! PyErr_SetString(PyExc_OverflowError, "string to parse is too long");
return NULL;
}
--- 1161,1166 ----
len = strlen(s);
if (len > INT_MAX) {
! com_error(com, PyExc_OverflowError,
! "string to parse is too long");
return NULL;
}
***************
*** 1172,1180 ****
if (unicode || Py_UnicodeFlag) {
if (rawmode)
! return PyUnicode_DecodeRawUnicodeEscape(
! s, len, NULL);
else
! return PyUnicode_DecodeUnicodeEscape(
s, len, NULL);
}
#endif
--- 1180,1192 ----
if (unicode || Py_UnicodeFlag) {
if (rawmode)
! v = PyUnicode_DecodeRawUnicodeEscape(
! s, len, NULL);
else
! v = PyUnicode_DecodeUnicodeEscape(
s, len, NULL);
+ if (v == NULL)
+ PyErr_SyntaxLocation(com->c_filename, com->c_lineno);
+ return v;
+
}
#endif
***************
*** 1239,1245 ****
break;
}
- PyErr_SetString(PyExc_ValueError,
- "invalid \\x escape");
Py_DECREF(v);
return NULL;
default:
--- 1251,1257 ----
break;
}
Py_DECREF(v);
+ com_error(com, PyExc_ValueError,
+ "invalid \\x escape");
return NULL;
default:
Index: errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.66
retrieving revision 2.67
diff -C2 -d -r2.66 -r2.67
*** errors.c 2 Oct 2001 21:32:07 -0000 2.66
--- errors.c 3 Mar 2002 21:30:27 -0000 2.67
***************
*** 562,566 ****
! /* XXX There's a comment missing here */
void
--- 562,568 ----
! /* Set file and line information for the current exception.
! If the exception is not a SyntaxError, also sets additional attributes
! to make printing of exceptions believe it is a syntax error. */
void
***************
*** 595,598 ****
--- 597,620 ----
PyObject_SetAttrString(v, "text", tmp);
Py_DECREF(tmp);
+ }
+ }
+ if (PyObject_SetAttrString(v, "offset", Py_None)) {
+ PyErr_Clear();
+ }
+ if (exc != PyExc_SyntaxError) {
+ if (!PyObject_HasAttrString(v, "msg")) {
+ tmp = PyObject_Str(v);
+ if (tmp) {
+ if (PyObject_SetAttrString(v, "msg", tmp))
+ PyErr_Clear();
+ Py_DECREF(tmp);
+ } else {
+ PyErr_Clear();
+ }
+ }
+ if (!PyObject_HasAttrString(v, "print_file_and_line")) {
+ if (PyObject_SetAttrString(v, "print_file_and_line",
+ Py_None))
+ PyErr_Clear();
}
}
Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** exceptions.c 28 Nov 2001 20:24:33 -0000 1.28
--- exceptions.c 3 Mar 2002 21:30:27 -0000 1.29
***************
*** 671,675 ****
PyObject_SetAttrString(klass, "lineno", Py_None) ||
PyObject_SetAttrString(klass, "offset", Py_None) ||
! PyObject_SetAttrString(klass, "text", Py_None))
{
retval = -1;
--- 671,676 ----
PyObject_SetAttrString(klass, "lineno", Py_None) ||
PyObject_SetAttrString(klass, "offset", Py_None) ||
! PyObject_SetAttrString(klass, "text", Py_None) ||
! PyObject_SetAttrString(klass, "print_file_and_line", Py_None))
{
retval = -1;
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.154
retrieving revision 2.155
diff -C2 -d -r2.154 -r2.155
*** pythonrun.c 12 Jan 2002 11:05:11 -0000 2.154
--- pythonrun.c 3 Mar 2002 21:30:27 -0000 2.155
***************
*** 921,925 ****
err = PyTraceBack_Print(tb, f);
if (err == 0 &&
! PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError))
{
PyObject *message;
--- 921,925 ----
err = PyTraceBack_Print(tb, f);
if (err == 0 &&
! PyObject_HasAttrString(v, "print_file_and_line"))
{
PyObject *message;