[Python-checkins] python/dist/src/Python pythonrun.c,2.161.2.4,2.161.2.5

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
2002年8月30日 13:20:44 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv11309/Python
Modified Files:
 Tag: ast-branch
	pythonrun.c 
Log Message:
Interim repair to parser error handling.
I haven't fully debugged the problem, but it appears that the
perrdetail structure isn't always setup properly. Perhaps an error is
raised inside PyAST_FromNode() and err_input() gets called anyway. At
any rate, recode this routine so it is a bit more defensive. Delay
calling Py_BuildValue() until err->error has been inspected. If
err->error is garbage, exit right away. The previous code passed
err->garbage to Py_BuildValue() causing a segfault.
XXX Need to figure out what is actually going wrong.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.161.2.4
retrieving revision 2.161.2.5
diff -C2 -d -r2.161.2.4 -r2.161.2.5
*** pythonrun.c	23 Aug 2002 18:13:27 -0000	2.161.2.4
--- pythonrun.c	30 Aug 2002 20:20:33 -0000	2.161.2.5
***************
*** 832,835 ****
--- 832,837 ----
 	}
 	PyErr_Fetch(&exception, &v, &tb);
+ 	if (exception == NULL)
+ 		return;
 	PyErr_NormalizeException(&exception, &v, &tb);
 	if (exception == NULL)
***************
*** 1096,1099 ****
--- 1098,1102 ----
 	node *n;
 	perrdetail err;
+ 	fprintf(stderr, "filename=%s\n", filename);
 	n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, start, 
 				 ps1, ps2, &err, flags);
***************
*** 1155,1164 ****
 	char *msg = NULL;
 	errtype = PyExc_SyntaxError;
- 	v = Py_BuildValue("(ziiz)", err->filename,
- 			 err->lineno, err->offset, err->text);
- 	if (err->text != NULL) {
- 		PyMem_DEL(err->text);
- 		err->text = NULL;
- 	}
 	switch (err->error) {
 	case E_SYNTAX:
--- 1158,1161 ----
***************
*** 1204,1211 ****
 		msg = "too many levels of indentation";
 		break;
! 	default:
! 		fprintf(stderr, "error=%d\n", err->error);
! 		msg = "unknown parsing error";
 		break;
 	}
 	w = Py_BuildValue("(sO)", msg, v);
--- 1201,1219 ----
 		msg = "too many levels of indentation";
 		break;
! 	default: {
! 		char buf[256];
! 		sprintf(buf, "unknown parsing error=%d\n", err->error);
! 		Py_FatalError(buf);
! 		/* If the error code is bogus, who knows what the state
! 		 of the rest of err is.
! 		*/
 		break;
+ 		}
+ 	}
+ 	v = Py_BuildValue("(ziiz)", err->filename,
+ 			 err->lineno, err->offset, err->text);
+ 	if (err->text != NULL) {
+ 		PyMem_DEL(err->text);
+ 		err->text = NULL;
 	}
 	w = Py_BuildValue("(sO)", msg, v);

AltStyle によって変換されたページ (->オリジナル) /