Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a400d8a

Browse files
committed
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).
1 parent b2b42dd commit a400d8a

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

Python/ceval.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,6 @@ exec_statement(f, prog, globals, locals)
27402740
PyObject *globals;
27412741
PyObject *locals;
27422742
{
2743-
char *s;
27442743
int n;
27452744
PyObject *v;
27462745
int plain = 0;
@@ -2777,33 +2776,27 @@ exec_statement(f, prog, globals, locals)
27772776
if (PyDict_GetItemString(globals, "__builtins__") == NULL)
27782777
PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
27792778
if (PyCode_Check(prog)) {
2780-
v = PyEval_EvalCode((PyCodeObject *) prog,
2781-
globals, locals);
2782-
if (v == NULL)
2783-
return -1;
2784-
Py_DECREF(v);
2785-
return 0;
2779+
v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
27862780
}
2787-
if (PyFile_Check(prog)) {
2781+
else if (PyFile_Check(prog)) {
27882782
FILE *fp = PyFile_AsFile(prog);
27892783
char *name = PyString_AsString(PyFile_Name(prog));
2790-
if (PyRun_File(fp, name, Py_file_input,
2791-
globals, locals) == NULL)
2792-
return -1;
2793-
return 0;
2784+
v = PyRun_File(fp, name, Py_file_input, globals, locals);
27942785
}
2795-
s = PyString_AsString(prog);
2796-
if ((int)strlen(s) != PyString_Size(prog)) {
2797-
PyErr_SetString(PyExc_ValueError,
2798-
"embedded '\\0' in exec string");
2799-
return -1;
2786+
else {
2787+
char *s = PyString_AsString(prog);
2788+
if ((int)strlen(s) != PyString_Size(prog)) {
2789+
PyErr_SetString(PyExc_ValueError,
2790+
"embedded '\\0' in exec string");
2791+
return -1;
2792+
}
2793+
v = PyRun_String(s, Py_file_input, globals, locals);
28002794
}
2801-
v = PyRun_String(s, Py_file_input, globals, locals);
2795+
if (plain)
2796+
PyFrame_LocalsToFast(f, 0);
28022797
if (v == NULL)
28032798
return -1;
28042799
Py_DECREF(v);
2805-
if (plain)
2806-
PyFrame_LocalsToFast(f, 0);
28072800
return 0;
28082801
}
28092802

0 commit comments

Comments
 (0)