Commit f966a77e authored by Chris Toshok's avatar Chris Toshok

expose our f_locals/f_lineno as getLocals/getLineno

parent 9be533f9
......@@ -111,10 +111,19 @@ void setupFrame() {
"frame");
frame_cls->giveAttr("f_code", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedFrame::code, NULL, NULL));
// until we can determine if there's code in the wild that depends
// on f_locals boxing up fast locals when it's called, add methods
// getLocals() and getLineno() that we can modify code to use.
#ifdef expose_f_locals
frame_cls->giveAttr("f_locals", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedFrame::locals, NULL, NULL));
frame_cls->giveAttr("f_lineno", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedFrame::lineno, NULL, NULL));
#else
frame_cls->giveAttr("getLocals", new BoxedFunction(boxRTFunction((void*)BoxedFrame::locals, UNKNOWN, 1)));
frame_cls->giveAttr("getLineno", new BoxedFunction(boxRTFunction((void*)BoxedFrame::lineno, BOXED_INT, 1)));
#endif
frame_cls->giveAttr("f_globals", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedFrame::globals, NULL, NULL));
frame_cls->giveAttr("f_lineno", new (pyston_getset_cls) BoxedGetsetDescriptor(BoxedFrame::lineno, NULL, NULL));
frame_cls->freeze();
}
......
......@@ -5,9 +5,15 @@ Frame Hack Recipe #1: Ruby-style string interpolation (version 1)
import sys
from string import Template
def getLocals(frame):
try:
return frame.f_locals
except AttributeError:
return frame.getLocals()
def interpolate(templateStr):
frame = sys._getframe(1)
framedict = frame.f_locals
framedict = getLocals(frame)
t = Template(templateStr)
return t.substitute(**framedict)
......
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