Commit 7c93e74e authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add a check to make sure users don't request custom __builtins__

We don't support that, and hopefully we don't have to.  CPython seems
pretty inconsistent about it and PyPy doesn't support it.
parent 4dad1667
......@@ -561,8 +561,14 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
Box* globals_dict = globals;
if (globals->cls == module_cls)
globals_dict = globals->getAttrWrapper();
if (PyDict_GetItemString(globals_dict, "__builtins__") == NULL)
auto requested_builtins = PyDict_GetItemString(globals_dict, "__builtins__");
if (requested_builtins == NULL)
PyDict_SetItemString(globals_dict, "__builtins__", builtins_module);
else
RELEASE_ASSERT(requested_builtins == builtins_module
|| requested_builtins == builtins_module->getAttrWrapper(),
"we don't support overriding __builtins__");
}
}
......
......@@ -129,3 +129,11 @@ print format(5.011111111111, '+.6')
print format("abc", '')
print '{n}'.format(n=None)
# Thankfully, setting __builtins__ has no effect:
__builtins__ = {'zzz': 2}
try:
print zzz
assert 0
except NameError as e:
print "caught NameError"
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