[Python-checkins] CVS: python/dist/src/Python ceval.c,2.165,2.166

Guido van Rossum guido@cnri.reston.va.us
Wed, 12 Jan 2000 17:45:57 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Python
In directory eric:/projects/python/develop/guido/src/Python

Modified Files:
	ceval.c 
Log Message:
Fix a bug in exec_statement() noted incidentally by Tim Peters in
PR#175 -- when exec is passed a code object, it didn't sync the locals
from the dictionary back into their fast representation.

Also took the time to remove some repetitive code there and to do the
syncing even when an exception is raised (since a partial effect
should still be synced).


Index: ceval.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/ceval.c,v
retrieving revision 2.165
retrieving revision 2.166
diff -C2 -r2.165 -r2.166
*** ceval.c	1999/11/15 19:29:33	2.165
--- ceval.c	2000/01/12 22:45:54	2.166
***************
*** 2741,2745 ****
  	PyObject *locals;
  {
- 	char *s;
  	int n;
  	PyObject *v;
--- 2741,2744 ----
***************
*** 2778,2808 ****
  		PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
  	if (PyCode_Check(prog)) {
! 		v = PyEval_EvalCode((PyCodeObject *) prog,
! 				    globals, locals);
! 		if (v == NULL)
! 			return -1;
! 		Py_DECREF(v);
! 		return 0;
  	}
! 	if (PyFile_Check(prog)) {
  		FILE *fp = PyFile_AsFile(prog);
  		char *name = PyString_AsString(PyFile_Name(prog));
! 		if (PyRun_File(fp, name, Py_file_input,
! 			       globals, locals) == NULL)
! 			return -1;
! 		return 0;
  	}
! 	s = PyString_AsString(prog);
! 	if ((int)strlen(s) != PyString_Size(prog)) {
! 		PyErr_SetString(PyExc_ValueError,
! 				"embedded '\\0' in exec string");
! 		return -1;
  	}
! 	v = PyRun_String(s, Py_file_input, globals, locals);
  	if (v == NULL)
  		return -1;
  	Py_DECREF(v);
- 	if (plain)
- 		PyFrame_LocalsToFast(f, 0);
  	return 0;
  }
--- 2777,2801 ----
  		PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
  	if (PyCode_Check(prog)) {
! 		v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
  	}
! 	else if (PyFile_Check(prog)) {
  		FILE *fp = PyFile_AsFile(prog);
  		char *name = PyString_AsString(PyFile_Name(prog));
! 		v = PyRun_File(fp, name, Py_file_input, globals, locals);
  	}
! 	else {
! 		char *s = PyString_AsString(prog);
! 		if ((int)strlen(s) != PyString_Size(prog)) {
! 			PyErr_SetString(PyExc_ValueError,
! 					"embedded '\\0' in exec string");
! 			return -1;
! 		}
! 		v = PyRun_String(s, Py_file_input, globals, locals);
  	}
! 	if (plain)
! 		PyFrame_LocalsToFast(f, 0);
  	if (v == NULL)
  		return -1;
  	Py_DECREF(v);
  	return 0;
  }