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
0db6c63b
Commit
0db6c63b
authored
May 01, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support frame.f_globals in frames with custom globals
parent
524b9284
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
9 deletions
+48
-9
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+15
-7
src/codegen/unwinding.h
src/codegen/unwinding.h
+1
-0
src/runtime/frame.cpp
src/runtime/frame.cpp
+2
-2
test/tests/exec_in_test.py
test/tests/exec_in_test.py
+18
-0
test/tests/sys_getframe.py
test/tests/sys_getframe.py
+12
-0
No files found.
src/codegen/unwinding.cpp
View file @
0db6c63b
...
...
@@ -346,6 +346,16 @@ public:
abort
();
}
Box
*
getGlobalsDict
()
{
Box
*
globals
=
getGlobals
();
if
(
!
globals
)
return
NULL
;
if
(
isSubclass
(
globals
->
cls
,
module_cls
))
return
globals
->
getAttrWrapper
();
return
globals
;
}
FrameInfo
*
getFrameInfo
()
{
if
(
id
.
type
==
PythonFrameId
::
COMPILED
)
{
CompiledFunction
*
cf
=
getCF
();
...
...
@@ -591,13 +601,7 @@ Box* getGlobals() {
}
Box
*
getGlobalsDict
()
{
Box
*
globals
=
getGlobals
();
if
(
!
globals
)
return
NULL
;
if
(
isSubclass
(
globals
->
cls
,
module_cls
))
return
globals
->
getAttrWrapper
();
return
globals
;
return
getTopPythonFrame
()
->
getGlobalsDict
();
}
BoxedModule
*
getCurrentModule
()
{
...
...
@@ -890,6 +894,10 @@ CompiledFunction* PythonFrameIterator::getCF() {
return
impl
->
getCF
();
}
Box
*
PythonFrameIterator
::
getGlobalsDict
()
{
return
impl
->
getGlobalsDict
();
}
FrameInfo
*
PythonFrameIterator
::
getFrameInfo
()
{
return
impl
->
getFrameInfo
();
}
...
...
src/codegen/unwinding.h
View file @
0db6c63b
...
...
@@ -53,6 +53,7 @@ public:
bool
exists
()
{
return
impl
.
get
()
!=
NULL
;
}
std
::
unique_ptr
<
ExecutionPoint
>
getExecutionPoint
();
Box
*
fastLocalsToBoxedLocals
();
Box
*
getGlobalsDict
();
// Gets the "current version" of this frame: if the frame has executed since
// the iterator was obtained, the methods may return old values. This returns
...
...
src/runtime/frame.cpp
View file @
0db6c63b
...
...
@@ -130,9 +130,9 @@ public:
FrameInfo
*
fi
=
it
.
getFrameInfo
();
if
(
fi
->
frame_obj
==
NULL
)
{
auto
cf
=
it
.
getCF
();
Box
*
globals
=
it
.
getGlobalsDict
();
BoxedFrame
*
f
=
fi
->
frame_obj
=
new
BoxedFrame
(
std
::
move
(
it
));
assert
(
cf
->
clfunc
->
source
->
scoping
->
areGlobalsFromModule
());
f
->
_globals
=
cf
->
clfunc
->
source
->
parent_module
->
getAttrWrapper
();
f
->
_globals
=
globals
;
f
->
_code
=
codeForCLFunction
(
cf
->
clfunc
);
}
...
...
test/tests/exec_in_test.py
View file @
0db6c63b
...
...
@@ -131,3 +131,21 @@ g = {}
l
=
{}
exec
(
"a=1; print a"
,
g
,
l
)
print
g
.
keys
(),
l
.
keys
()
s
=
"""
global a
a = 1
b = 2
def inner():
print sorted(globals().keys()), sorted(locals().keys())
print a
print b
print sorted(globals().keys()), sorted(locals().keys())
inner()
"""
exec
s
in
{}
try
:
exec
s
in
{},
{}
raise
Exception
()
except
NameError
as
e
:
print
e
test/tests/sys_getframe.py
View file @
0db6c63b
...
...
@@ -87,3 +87,15 @@ def f6(n):
else
:
get_main_module
()
f6
(
10
)
def
custom_globals
():
s
=
"""
def inner():
import sys
return sys._getframe(1).f_globals
print sorted(inner().keys())
"""
.
strip
()
exec
s
exec
s
in
{
'a'
:
1
}
exec
s
in
{
'b'
:
2
},
{
'c'
:
3
}
custom_globals
()
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