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
68b2ed7a
Commit
68b2ed7a
authored
Feb 22, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1054 from Daetalus/sequence_fixing
Tuple and list calling order fixing.
parents
c1f25c37
005eac26
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
20 deletions
+69
-20
src/runtime/list.cpp
src/runtime/list.cpp
+16
-8
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+16
-12
test/tests/list.py
test/tests/list.py
+16
-0
test/tests/tuples.py
test/tests/tuples.py
+21
-0
No files found.
src/runtime/list.cpp
View file @
68b2ed7a
...
...
@@ -691,11 +691,15 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
}
Box
*
listMul
(
BoxedList
*
self
,
Box
*
rhs
)
{
static
BoxedString
*
index_str
=
internStringImmortal
(
"__index__"
)
;
Py_ssize_t
n
;
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
PyIndex_Check
(
rhs
))
{
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_OverflowError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
}
else
{
return
NotImplemented
;
}
int
s
=
self
->
size
;
...
...
@@ -715,11 +719,15 @@ Box* listMul(BoxedList* self, Box* rhs) {
}
Box
*
listImul
(
BoxedList
*
self
,
Box
*
rhs
)
{
static
BoxedString
*
index_str
=
internStringImmortal
(
"__index__"
)
;
Py_ssize_t
n
;
Py_ssize_t
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_IndexError
);
if
(
PyIndex_Check
(
rhs
))
{
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_OverflowError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
}
else
{
return
NotImplemented
;
}
int
s
=
self
->
size
;
...
...
src/runtime/tuple.cpp
View file @
68b2ed7a
...
...
@@ -169,16 +169,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
return
rtn
;
}
Box
*
tupleMul
(
BoxedTuple
*
self
,
Box
*
rhs
)
{
Py_ssize_t
n
;
if
(
PyIndex_Check
(
rhs
))
{
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_OverflowError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
}
else
{
raiseExcHelper
(
TypeError
,
"can't multiply sequence by non-int of type '%s'"
,
getTypeName
(
rhs
));
}
Box
*
tupleMulInt
(
BoxedTuple
*
self
,
int
n
)
{
int
s
=
self
->
size
();
if
(
n
<
0
)
...
...
@@ -197,6 +188,19 @@ Box* tupleMul(BoxedTuple* self, Box* rhs) {
}
}
Box
*
tupleMul
(
BoxedTuple
*
self
,
Box
*
rhs
)
{
Py_ssize_t
n
;
if
(
PyIndex_Check
(
rhs
))
{
n
=
PyNumber_AsSsize_t
(
rhs
,
PyExc_OverflowError
);
if
(
n
==
-
1
&&
PyErr_Occurred
())
throwCAPIException
();
return
tupleMulInt
(
self
,
n
);
}
else
{
return
NotImplemented
;
}
}
Box
*
tupleLen
(
BoxedTuple
*
t
)
{
assert
(
PyTuple_Check
(
t
));
return
boxInt
(
t
->
size
());
...
...
@@ -690,8 +694,8 @@ void setupTuple() {
// Return type is UNKNOWN as it could be NotImplemented.
tuple_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleAdd
,
UNKNOWN
,
2
)));
tuple_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleMul
,
BOXED_TUPLE
,
2
)));
tuple_cls
->
giveAttr
(
"__rmul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleMul
,
BOXED_TUPLE
,
2
)));
tuple_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleMul
,
UNKNOWN
,
2
)));
tuple_cls
->
giveAttr
(
"__rmul__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleMul
,
UNKNOWN
,
2
)));
tuple_cls
->
giveAttr
(
"__getnewargs__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tuple_getnewargs
,
UNKNOWN
,
1
,
ParamNames
::
empty
(),
CAPI
)));
...
...
test/tests/list.py
View file @
68b2ed7a
...
...
@@ -219,3 +219,19 @@ try:
RaisingCmp
()
in
[
1
,
2
,
3
]
except
ZeroDivisionError
as
e
:
print
e
class
D
(
object
):
def
__rmul__
(
self
,
other
):
return
other
*
2
d
=
D
()
try
:
print
([
1
,
2
]
*
3.5
)
except
TypeError
as
e
:
print
(
type
(
e
))
try
:
print
([
1
,
2
]
*
d
)
except
TypeError
as
e
:
print
(
type
(
e
))
test/tests/tuples.py
View file @
68b2ed7a
...
...
@@ -239,3 +239,24 @@ class C(object):
def
__repr__
(
self
):
return
repr
(
self
.
t
)
print
repr
(
C
())
try
:
(
1
,
2
)
+
"a"
except
TypeError
as
e
:
print
(
type
(
e
))
class
D
(
object
):
def
__rmul__
(
self
,
other
):
return
other
*
2
d
=
D
()
try
:
print
((
1
,
2
)
*
3.5
)
except
TypeError
as
e
:
print
(
type
(
e
))
try
:
print
((
1
,
2
)
*
d
)
except
TypeError
as
e
:
print
(
e
.
message
)
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