Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
f966a77e
Commit
f966a77e
authored
Apr 03, 2015
by
Chris Toshok
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expose our f_locals/f_lineno as getLocals/getLineno
parent
9be533f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
src/runtime/frame.cpp
src/runtime/frame.cpp
+10
-1
test/tests/sys_getframe1.py
test/tests/sys_getframe1.py
+7
-1
No files found.
src/runtime/frame.cpp
View file @
f966a77e
...
...
@@ -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
();
}
...
...
test/tests/sys_getframe1.py
View file @
f966a77e
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment