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
37fa8a96
Commit
37fa8a96
authored
Jul 10, 2016
by
Kevin Modzelewski
Committed by
GitHub
Jul 10, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1289 from kmod/execfile_globals
Support attrwrapper as globals argument to execfile
parents
4d4d78ae
10f9ec7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
5 deletions
+17
-5
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+2
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+7
-1
test/tests/execfile_test.py
test/tests/execfile_test.py
+5
-0
test/tests/pyc_stress_test.py
test/tests/pyc_stress_test.py
+3
-3
No files found.
src/codegen/irgen/hooks.cpp
View file @
37fa8a96
...
@@ -502,7 +502,8 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
...
@@ -502,7 +502,8 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
if
(
globals
->
cls
==
attrwrapper_cls
)
if
(
globals
->
cls
==
attrwrapper_cls
)
globals
=
unwrapAttrWrapper
(
globals
);
globals
=
unwrapAttrWrapper
(
globals
);
assert
(
globals
&&
(
globals
->
cls
==
module_cls
||
globals
->
cls
==
dict_cls
));
RELEASE_ASSERT
(
globals
&&
(
globals
->
cls
==
module_cls
||
globals
->
cls
==
dict_cls
),
"Unspported globals type: %s"
,
globals
?
globals
->
cls
->
tp_name
:
"NULL"
);
if
(
globals
)
{
if
(
globals
)
{
// From CPython (they set it to be f->f_builtins):
// From CPython (they set it to be f->f_builtins):
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
37fa8a96
...
@@ -1932,7 +1932,8 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
...
@@ -1932,7 +1932,8 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
if
(
PyErr_WarnPy3k
(
"execfile() not supported in 3.x; use exec()"
,
1
)
<
0
)
if
(
PyErr_WarnPy3k
(
"execfile() not supported in 3.x; use exec()"
,
1
)
<
0
)
return
NULL
;
return
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s|O!O:execfile"
,
&
filename
,
&
PyDict_Type
,
&
globals
,
&
locals
))
// Pyston change: allow attrwrappers here
if
(
!
PyArg_ParseTuple
(
args
,
"s|OO:execfile"
,
&
filename
,
&
globals
,
&
locals
))
return
NULL
;
return
NULL
;
if
(
locals
!=
Py_None
&&
!
PyMapping_Check
(
locals
))
{
if
(
locals
!=
Py_None
&&
!
PyMapping_Check
(
locals
))
{
PyErr_SetString
(
PyExc_TypeError
,
"locals must be a mapping"
);
PyErr_SetString
(
PyExc_TypeError
,
"locals must be a mapping"
);
...
@@ -1945,6 +1946,11 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
...
@@ -1945,6 +1946,11 @@ static PyObject* builtin_execfile(PyObject* self, PyObject* args) noexcept {
}
else
if
(
locals
==
Py_None
)
}
else
if
(
locals
==
Py_None
)
locals
=
globals
;
locals
=
globals
;
if
(
!
PyDict_CheckExact
(
globals
)
&&
globals
->
cls
!=
attrwrapper_cls
)
{
PyErr_Format
(
TypeError
,
"execfile() globals must be dict, not %s"
,
globals
->
cls
->
tp_name
);
return
NULL
;
}
if
(
PyDict_GetItemString
(
globals
,
"__builtins__"
)
==
NULL
)
{
if
(
PyDict_GetItemString
(
globals
,
"__builtins__"
)
==
NULL
)
{
if
(
PyDict_SetItemString
(
globals
,
"__builtins__"
,
PyEval_GetBuiltins
())
!=
0
)
if
(
PyDict_SetItemString
(
globals
,
"__builtins__"
,
PyEval_GetBuiltins
())
!=
0
)
return
NULL
;
return
NULL
;
...
...
test/tests/execfile_test.py
View file @
37fa8a96
...
@@ -8,6 +8,11 @@ fn = os.path.join(os.path.dirname(__file__), 'execfile_target.py')
...
@@ -8,6 +8,11 @@ fn = os.path.join(os.path.dirname(__file__), 'execfile_target.py')
execfile
(
fn
)
execfile
(
fn
)
print
"done with first execfile"
print
"done with first execfile"
execfile
(
fn
)
execfile
(
fn
)
execfile
(
fn
,
globals
())
try
:
execfile
(
fn
,
[])
except
Exception
as
e
:
print
type
(
e
)
print
test_name
print
test_name
print
type
(
execfile_target
)
print
type
(
execfile_target
)
...
...
test/tests/pyc_stress_test.py
View file @
37fa8a96
...
@@ -8,7 +8,7 @@ import multiprocessing
...
@@ -8,7 +8,7 @@ import multiprocessing
def
worker
():
def
worker
():
global
done
global
done
for
i
in
xrange
(
100
0
):
for
i
in
xrange
(
100
):
del
sys
.
modules
[
"pyc_import_target"
]
del
sys
.
modules
[
"pyc_import_target"
]
import
pyc_import_target
import
pyc_import_target
...
@@ -30,10 +30,10 @@ idx = 0
...
@@ -30,10 +30,10 @@ idx = 0
while
l
:
while
l
:
p
=
l
.
pop
()
p
=
l
.
pop
()
while
p
.
is_alive
():
while
p
.
is_alive
():
for
i
in
xrange
(
10
0
):
for
i
in
xrange
(
10
):
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
os
.
remove
(
path
)
os
.
remove
(
path
)
for
i
in
xrange
(
10
0
):
for
i
in
xrange
(
10
):
if
os
.
path
.
exists
(
path
):
if
os
.
path
.
exists
(
path
):
with
open
(
path
,
"rw+"
)
as
f
:
with
open
(
path
,
"rw+"
)
as
f
:
f
.
write
(
chr
(
i
)
*
100
)
f
.
write
(
chr
(
i
)
*
100
)
...
...
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