[Python-checkins] CVS: python/dist/src/Python compile.c,2.234.4.2,2.234.4.3 errors.c,2.66,2.66.10.1 exceptions.c,1.28,1.28.6.1 pythonrun.c,2.153.6.1,2.153.6.2

Martin v. L?wis loewis@users.sourceforge.net
Sun, 03 Mar 2002 13:32:03 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv22284/Python

Modified Files:
      Tag: release22-maint
	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.234.4.2
retrieving revision 2.234.4.3
diff -C2 -d -r2.234.4.2 -r2.234.4.3
*** compile.c	6 Feb 2002 17:06:02 -0000	2.234.4.2
--- compile.c	3 Mar 2002 21:32:00 -0000	2.234.4.3
***************
*** 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.66.10.1
diff -C2 -d -r2.66 -r2.66.10.1
*** errors.c	2 Oct 2001 21:32:07 -0000	2.66
--- errors.c	3 Mar 2002 21:32:01 -0000	2.66.10.1
***************
*** 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.28.6.1
diff -C2 -d -r1.28 -r1.28.6.1
*** exceptions.c	28 Nov 2001 20:24:33 -0000	1.28
--- exceptions.c	3 Mar 2002 21:32:01 -0000	1.28.6.1
***************
*** 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.153.6.1
retrieving revision 2.153.6.2
diff -C2 -d -r2.153.6.1 -r2.153.6.2
*** pythonrun.c	12 Jan 2002 11:13:24 -0000	2.153.6.1
--- pythonrun.c	3 Mar 2002 21:32:01 -0000	2.153.6.2
***************
*** 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;