Commit 9ac97a1e authored by Kevin Modzelewski's avatar Kevin Modzelewski

Support attrwrapper as globals argument to execfile

Or rather, have execfile() be more permissive in what it accepts.
It may still abort when we get to pickGlobalsAndLocals() and we
discover that we can't actually execute in that particular attrwrapper.
parent 4d4d78ae
......@@ -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)
......
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