Commit 37fa8a96 authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by GitHub

Merge pull request #1289 from kmod/execfile_globals

Support attrwrapper as globals argument to execfile
parents 4d4d78ae 10f9ec7b
......@@ -502,7 +502,8 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
if (globals->cls == attrwrapper_cls)
globals = unwrapAttrWrapper(globals);
assert(globals && (globals->cls == module_cls || globals->cls == dict_cls));
RELEASE_ASSERT(globals && (globals->cls == module_cls || globals->cls == dict_cls), "Unspported globals type: %s",
globals ? globals->cls->tp_name : "NULL");
if (globals) {
// From CPython (they set it to be f->f_builtins):
......
......@@ -1932,7 +1932,8 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
if (PyErr_WarnPy3k("execfile() not supported in 3.x; use exec()", 1) < 0)
return NULL;
if (!PyArg_ParseTuple(args, "s|O!O:execfile", &filename, &PyDict_Type, &globals, &locals))
// Pyston change: allow attrwrappers here
if (!PyArg_ParseTuple(args, "s|OO:execfile", &filename, &globals, &locals))
return NULL;
if (locals != Py_None && !PyMapping_Check(locals)) {
PyErr_SetString(PyExc_TypeError, "locals must be a mapping");
......@@ -1945,6 +1946,11 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
} else if (locals == Py_None)
locals = globals;
if (!PyDict_CheckExact(globals) && globals->cls != attrwrapper_cls) {
PyErr_Format(TypeError, "execfile() globals must be dict, not %s", globals->cls->tp_name);
return NULL;
}
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
if (PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()) != 0)
return NULL;
......
......@@ -8,6 +8,11 @@ fn = os.path.join(os.path.dirname(__file__), 'execfile_target.py')
execfile(fn)
print "done with first execfile"
execfile(fn)
execfile(fn, globals())
try:
execfile(fn, [])
except Exception as e:
print type(e)
print test_name
print type(execfile_target)
......
......@@ -8,7 +8,7 @@ import multiprocessing
def worker():
global done
for i in xrange(1000):
for i in xrange(100):
del sys.modules["pyc_import_target"]
import pyc_import_target
......@@ -30,10 +30,10 @@ idx = 0
while l:
p = l.pop()
while p.is_alive():
for i in xrange(100):
for i in xrange(10):
if os.path.exists(path):
os.remove(path)
for i in xrange(100):
for i in xrange(10):
if os.path.exists(path):
with open(path, "rw+") as f:
f.write(chr(i) * 100)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment