mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	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).
This commit is contained in:
		
							parent
							
								
									b2b42ddcb1
								
							
						
					
					
						commit
						a400d8a96d
					
				
					 1 changed files with 13 additions and 20 deletions
				
			
		|  | @ -2740,7 +2740,6 @@ exec_statement(f, prog, globals, locals) | |||
| 	PyObject *globals; | ||||
| 	PyObject *locals; | ||||
| { | ||||
| 	char *s; | ||||
| 	int n; | ||||
| 	PyObject *v; | ||||
| 	int plain = 0; | ||||
|  | @ -2777,33 +2776,27 @@ exec_statement(f, prog, globals, locals) | |||
| 	if (PyDict_GetItemString(globals, "__builtins__") == NULL) | ||||
| 		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; | ||||
| 		v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals); | ||||
| 	} | ||||
| 	if (PyFile_Check(prog)) { | ||||
| 	else 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; | ||||
| 		v = PyRun_File(fp, name, Py_file_input, globals, locals); | ||||
| 	} | ||||
| 	s = PyString_AsString(prog); | ||||
| 	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); | ||||
| 	if (plain) | ||||
| 		PyFrame_LocalsToFast(f, 0); | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum