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
9a40c840
Commit
9a40c840
authored
May 08, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle map(None,...), exec with module.__dict__ as globals
parent
0defcec2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
13 deletions
+88
-13
src/capi/abstract.cpp
src/capi/abstract.cpp
+44
-9
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+6
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+29
-4
test/tests/exec_in_test.py
test/tests/exec_in_test.py
+7
-0
test/tests/map.py
test/tests/map.py
+2
-0
No files found.
src/capi/abstract.cpp
View file @
9a40c840
...
...
@@ -1437,23 +1437,58 @@ extern "C" Py_ssize_t PyMapping_Size(PyObject* o) noexcept {
}
extern
"C"
int
PyMapping_HasKeyString
(
PyObject
*
o
,
char
*
key
)
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
-
1
;
PyObject
*
v
;
v
=
PyMapping_GetItemString
(
o
,
key
);
if
(
v
)
{
Py_DECREF
(
v
);
return
1
;
}
PyErr_Clear
();
return
0
;
}
extern
"C"
int
PyMapping_HasKey
(
PyObject
*
o
,
PyObject
*
key
)
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
-
1
;
PyObject
*
v
;
v
=
PyObject_GetItem
(
o
,
key
);
if
(
v
)
{
Py_DECREF
(
v
);
return
1
;
}
PyErr_Clear
();
return
0
;
}
extern
"C"
PyObject
*
PyMapping_GetItemString
(
PyObject
*
o
,
char
*
key
)
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
nullptr
;
PyObject
*
okey
,
*
r
;
if
(
key
==
NULL
)
return
null_error
();
okey
=
PyString_FromString
(
key
);
if
(
okey
==
NULL
)
return
NULL
;
r
=
PyObject_GetItem
(
o
,
okey
);
Py_DECREF
(
okey
);
return
r
;
}
extern
"C"
int
PyMapping_SetItemString
(
PyObject
*
o
,
char
*
key
,
PyObject
*
v
)
noexcept
{
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented"
);
return
-
1
;
extern
"C"
int
PyMapping_SetItemString
(
PyObject
*
o
,
char
*
key
,
PyObject
*
value
)
noexcept
{
PyObject
*
okey
;
int
r
;
if
(
key
==
NULL
)
{
null_error
();
return
-
1
;
}
okey
=
PyString_FromString
(
key
);
if
(
okey
==
NULL
)
return
-
1
;
r
=
PyObject_SetItem
(
o
,
okey
,
value
);
Py_DECREF
(
okey
);
return
r
;
}
extern
"C"
int
PyNumber_Check
(
PyObject
*
obj
)
noexcept
{
...
...
src/codegen/irgen/hooks.cpp
View file @
9a40c840
...
...
@@ -514,6 +514,9 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
if
(
globals
&&
globals
->
cls
==
attrwrapper_cls
&&
unwrapAttrWrapper
(
globals
)
==
module
)
globals
=
module
;
if
(
globals
->
cls
==
attrwrapper_cls
)
globals
=
unwrapAttrWrapper
(
globals
);
assert
(
globals
&&
(
globals
->
cls
==
module_cls
||
globals
->
cls
==
dict_cls
));
if
(
boxedCode
->
cls
==
unicode_cls
)
{
...
...
@@ -569,6 +572,9 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
if
(
globals
&&
globals
->
cls
==
attrwrapper_cls
&&
unwrapAttrWrapper
(
globals
)
==
module
)
globals
=
module
;
if
(
globals
->
cls
==
attrwrapper_cls
)
globals
=
unwrapAttrWrapper
(
globals
);
assert
(
globals
&&
(
globals
->
cls
==
module_cls
||
globals
->
cls
==
dict_cls
));
if
(
globals
)
{
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
9a40c840
...
...
@@ -465,8 +465,14 @@ Box* hasattr(Box* obj, Box* _str) {
Box
*
map2
(
Box
*
f
,
Box
*
container
)
{
Box
*
rtn
=
new
BoxedList
();
bool
use_identity_func
=
f
==
None
;
for
(
Box
*
e
:
container
->
pyElements
())
{
listAppendInternal
(
rtn
,
runtimeCall
(
f
,
ArgPassSpec
(
1
),
e
,
NULL
,
NULL
,
NULL
,
NULL
));
Box
*
val
;
if
(
use_identity_func
)
val
=
e
;
else
val
=
runtimeCall
(
f
,
ArgPassSpec
(
1
),
e
,
NULL
,
NULL
,
NULL
,
NULL
);
listAppendInternal
(
rtn
,
val
);
}
return
rtn
;
}
...
...
@@ -492,6 +498,7 @@ Box* map(Box* f, BoxedTuple* args) {
assert
(
args_it
.
size
()
==
num_iterable
);
assert
(
args_end
.
size
()
==
num_iterable
);
bool
use_identity_func
=
f
==
None
;
Box
*
rtn
=
new
BoxedList
();
std
::
vector
<
Box
*
,
StlCompatAllocator
<
Box
*>>
current_val
(
num_iterable
);
while
(
true
)
{
...
...
@@ -508,9 +515,14 @@ Box* map(Box* f, BoxedTuple* args) {
if
(
num_done
==
num_iterable
)
break
;
auto
v
=
getTupleFromArgsArray
(
&
current_val
[
0
],
num_iterable
);
listAppendInternal
(
rtn
,
runtimeCall
(
f
,
ArgPassSpec
(
num_iterable
),
std
::
get
<
0
>
(
v
),
std
::
get
<
1
>
(
v
),
std
::
get
<
2
>
(
v
),
std
::
get
<
3
>
(
v
),
NULL
));
Box
*
entry
;
if
(
!
use_identity_func
)
{
auto
v
=
getTupleFromArgsArray
(
&
current_val
[
0
],
num_iterable
);
entry
=
runtimeCall
(
f
,
ArgPassSpec
(
num_iterable
),
std
::
get
<
0
>
(
v
),
std
::
get
<
1
>
(
v
),
std
::
get
<
2
>
(
v
),
std
::
get
<
3
>
(
v
),
NULL
);
}
else
entry
=
BoxedTuple
::
create
(
num_iterable
,
&
current_val
[
0
]);
listAppendInternal
(
rtn
,
entry
);
for
(
int
i
=
0
;
i
<
num_iterable
;
++
i
)
{
if
(
args_it
[
i
]
!=
args_end
[
i
])
...
...
@@ -750,6 +762,19 @@ extern "C" PyObject* PyEval_GetLocals(void) noexcept {
}
}
extern
"C"
PyObject
*
PyEval_GetGlobals
(
void
)
noexcept
{
try
{
return
globals
();
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
extern
"C"
PyObject
*
PyEval_GetBuiltins
(
void
)
noexcept
{
return
builtins_module
;
}
Box
*
divmod
(
Box
*
lhs
,
Box
*
rhs
)
{
return
binopInternal
(
lhs
,
rhs
,
AST_TYPE
::
DivMod
,
false
,
NULL
);
}
...
...
test/tests/exec_in_test.py
View file @
9a40c840
...
...
@@ -149,3 +149,10 @@ try:
raise
Exception
()
except
NameError
as
e
:
print
e
import
types
g
=
types
.
ModuleType
(
"TestMod1"
)
l
=
types
.
ModuleType
(
"TestMod2"
)
exec
(
"global a; a=1; print a; b=2"
,
g
.
__dict__
,
l
.
__dict__
)
print
g
.
a
print
l
.
b
test/tests/map.py
View file @
9a40c840
...
...
@@ -13,3 +13,5 @@ def f(*args):
print
map
(
f
,
range
(
10
))
print
map
(
f
,
range
(
9
),
range
(
20
,
31
),
range
(
30
,
40
),
range
(
40
,
50
),
range
(
60
,
70
))
print
map
(
None
,
range
(
10
))
print
map
(
None
,
range
(
9
),
range
(
20
,
31
),
range
(
30
,
40
),
range
(
40
,
50
),
range
(
60
,
70
))
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