[Python-checkins] CVS: python/dist/src/Python pythonrun.c,2.105,2.106

Fred L. Drake python-dev@python.org
Tue, 15 Aug 2000 08:49:06 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv25706/Python

Modified Files:
	pythonrun.c 
Log Message:

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).


Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.105
retrieving revision 2.106
diff -C2 -r2.105 -r2.106
*** pythonrun.c	2000/07/22 18:47:25	2.105
--- pythonrun.c	2000/08/15 15:49:03	2.106
***************
*** 21,24 ****
--- 21,25 ----
  #include "eval.h"
  #include "marshal.h"
+ #include "osdefs.h"			/* SEP */
  
  #ifdef HAVE_UNISTD_H
***************
*** 1004,1010 ****
  	}
  	w = Py_BuildValue("(sO)", msg, v);
- 	Py_XDECREF(v);
  	PyErr_SetObject(errtype, w);
  	Py_XDECREF(w);
  }
  
--- 1005,1028 ----
  	}
  	w = Py_BuildValue("(sO)", msg, 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);
+ 	}
  }