Commit 050fe962 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Special-case "exec in globals()"

We don't support arbitrary dict-like objects as the globals, but
in the special case that that dict-like object is just an attrwrapper
around the current module, we can fall back on our module-as-globals
support.
parent 3136dd71
...@@ -368,6 +368,9 @@ Box* eval(Box* boxedCode) { ...@@ -368,6 +368,9 @@ Box* eval(Box* boxedCode) {
if (globals == module) if (globals == module)
globals = NULL; globals = NULL;
if (globals && globals->cls == attrwrapper_cls && unwrapAttrWrapper(globals) == module)
globals = NULL;
// TODO error message if parse fails or if it isn't an expr // TODO error message if parse fails or if it isn't an expr
// TODO should have a cleaner interface that can parse the Expression directly // TODO should have a cleaner interface that can parse the Expression directly
// TODO this memory leaks // TODO this memory leaks
...@@ -414,7 +417,10 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) { ...@@ -414,7 +417,10 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
if (globals == module) if (globals == module)
globals = NULL; globals = NULL;
assert(!globals || globals->cls == dict_cls); if (globals && globals->cls == attrwrapper_cls && unwrapAttrWrapper(globals) == module)
globals = NULL;
ASSERT(!globals || globals->cls == dict_cls, "%s", globals->cls->tp_name);
if (globals) { if (globals) {
// From CPython (they set it to be f->f_builtins): // From CPython (they set it to be f->f_builtins):
......
...@@ -1153,6 +1153,10 @@ public: ...@@ -1153,6 +1153,10 @@ public:
DEFAULT_CLASS(attrwrapper_cls); DEFAULT_CLASS(attrwrapper_cls);
Box* getUnderlying() {
return b;
}
static void gcHandler(GCVisitor* v, Box* b) { static void gcHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b); boxGCHandler(v, b);
...@@ -1401,6 +1405,11 @@ Box* makeAttrWrapper(Box* b) { ...@@ -1401,6 +1405,11 @@ Box* makeAttrWrapper(Box* b) {
return new AttrWrapper(b); return new AttrWrapper(b);
} }
Box* unwrapAttrWrapper(Box* b) {
assert(b->cls == attrwrapper_cls);
return static_cast<AttrWrapper*>(b)->getUnderlying();
}
Box* attrwrapperKeys(Box* b) { Box* attrwrapperKeys(Box* b) {
return AttrWrapper::keys(b); return AttrWrapper::keys(b);
} }
......
...@@ -784,6 +784,7 @@ Box* objectNewNoArgs(BoxedClass* cls); ...@@ -784,6 +784,7 @@ Box* objectNewNoArgs(BoxedClass* cls);
Box* objectSetattr(Box* obj, Box* attr, Box* value); Box* objectSetattr(Box* obj, Box* attr, Box* value);
Box* makeAttrWrapper(Box* b); Box* makeAttrWrapper(Box* b);
Box* unwrapAttrWrapper(Box* b);
Box* attrwrapperKeys(Box* b); Box* attrwrapperKeys(Box* b);
#define SystemError ((BoxedClass*)PyExc_SystemError) #define SystemError ((BoxedClass*)PyExc_SystemError)
......
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