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
0e2a4c25
Commit
0e2a4c25
authored
May 08, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for import * if globals is not a module
parent
12abc42b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
12 deletions
+10
-12
src/codegen/ast_interpreter.cpp
src/codegen/ast_interpreter.cpp
+1
-3
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+3
-8
src/runtime/objmodel.h
src/runtime/objmodel.h
+1
-1
test/tests/exec_in_test.py
test/tests/exec_in_test.py
+5
-0
No files found.
src/codegen/ast_interpreter.cpp
View file @
0e2a4c25
...
...
@@ -618,9 +618,7 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) {
Value
module
=
visit_expr
(
node
->
args
[
0
]);
RELEASE_ASSERT
(
globals
==
source_info
->
parent_module
,
"'import *' currently not supported with overridden globals"
);
v
=
importStar
(
module
.
o
,
source_info
->
parent_module
);
v
=
importStar
(
module
.
o
,
globals
);
}
else
if
(
node
->
opcode
==
AST_LangPrimitive
::
NONE
)
{
v
=
None
;
}
else
if
(
node
->
opcode
==
AST_LangPrimitive
::
LANDINGPAD
)
{
...
...
src/runtime/objmodel.cpp
View file @
0e2a4c25
...
...
@@ -4863,13 +4863,9 @@ extern "C" Box* importFrom(Box* _m, const std::string* name) {
raiseExcHelper
(
ImportError
,
"cannot import name %s"
,
name
->
c_str
());
}
extern
"C"
Box
*
importStar
(
Box
*
_from_module
,
Box
edModule
*
to_module
)
{
extern
"C"
Box
*
importStar
(
Box
*
_from_module
,
Box
*
to_globals
)
{
STAT_TIMER
(
t0
,
"us_timer_importStar"
);
// TODO(kmod): it doesn't seem too bad to update this to take custom globals;
// it looks like mostly a matter of changing the getattr calls to getitem.
RELEASE_ASSERT
(
getGlobals
()
==
to_module
,
"importStar doesn't support custom globals yet"
);
ASSERT
(
isSubclass
(
_from_module
->
cls
,
module_cls
),
"%s"
,
_from_module
->
cls
->
tp_name
);
BoxedModule
*
from_module
=
static_cast
<
BoxedModule
*>
(
_from_module
);
...
...
@@ -4902,8 +4898,7 @@ extern "C" Box* importStar(Box* _from_module, BoxedModule* to_module) {
if
(
!
attr_value
)
raiseExcHelper
(
AttributeError
,
"'module' object has no attribute '%s'"
,
casted_attr_name
->
data
());
to_module
->
setattr
(
casted_attr_name
->
s
,
attr_value
,
NULL
);
setGlobal
(
to_globals
,
casted_attr_name
->
s
,
attr_value
);
}
return
None
;
}
...
...
@@ -4913,7 +4908,7 @@ extern "C" Box* importStar(Box* _from_module, BoxedModule* to_module) {
if
(
p
.
first
()[
0
]
==
'_'
)
continue
;
to_module
->
setattr
(
p
.
first
(),
module_attrs
->
attr_list
->
attrs
[
p
.
second
],
NULL
);
setGlobal
(
to_globals
,
p
.
first
(),
module_attrs
->
attr_list
->
attrs
[
p
.
second
]
);
}
return
None
;
...
...
src/runtime/objmodel.h
View file @
0e2a4c25
...
...
@@ -79,7 +79,7 @@ extern "C" void delitem(Box* target, Box* slice);
extern
"C"
Box
*
getclsattr
(
Box
*
obj
,
const
char
*
attr
);
extern
"C"
Box
*
unaryop
(
Box
*
operand
,
int
op_type
);
extern
"C"
Box
*
importFrom
(
Box
*
obj
,
const
std
::
string
*
attr
);
extern
"C"
Box
*
importStar
(
Box
*
from_module
,
Box
edModule
*
to_module
);
extern
"C"
Box
*
importStar
(
Box
*
from_module
,
Box
*
to_globals
);
extern
"C"
Box
**
unpackIntoArray
(
Box
*
obj
,
int64_t
expected_size
);
extern
"C"
void
assertNameDefined
(
bool
b
,
const
char
*
name
,
BoxedClass
*
exc_cls
,
bool
local_var_msg
);
extern
"C"
void
assertFailDerefNameDefined
(
const
char
*
name
);
...
...
test/tests/exec_in_test.py
View file @
0e2a4c25
...
...
@@ -156,3 +156,8 @@ l = types.ModuleType("TestMod2")
exec
(
"global a; a=1; print a; b=2"
,
g
.
__dict__
,
l
.
__dict__
)
print
g
.
a
print
l
.
b
s
=
"from sys import *"
g
=
dict
()
exec
s
in
g
print
"version"
in
g
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