Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
41ee7f37
Commit
41ee7f37
authored
Nov 09, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix type coercion in cascaded comparisons
parent
ae0b93d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
9 deletions
+48
-9
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+22
-9
tests/run/inop.pyx
tests/run/inop.pyx
+26
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
41ee7f37
...
...
@@ -8919,9 +8919,10 @@ class PrimaryCmpNode(ExprNode, CmpNode):
# Instead, we override all the framework methods
# which use it.
child_attrs
=
[
'operand1'
,
'operand2'
,
'cascade'
]
child_attrs
=
[
'operand1'
,
'operand2'
,
'c
oerced_operand2'
,
'c
ascade'
]
cascade
=
None
coerced_operand2
=
None
is_memslice_nonecheck
=
False
def
infer_type
(
self
,
env
):
...
...
@@ -8999,9 +9000,11 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self
.
coerce_operands_to
(
common_type
,
env
)
if
self
.
cascade
:
self
.
operand2
=
self
.
cascade
.
optimise_comparison
(
self
.
operand2
.
coerce_to_simple
(
env
),
env
)
self
.
operand2
=
self
.
operand2
.
coerce_to_simple
(
env
)
self
.
cascade
.
coerce_cascaded_operands_to_temp
(
env
)
operand2
=
self
.
cascade
.
optimise_comparison
(
self
.
operand2
,
env
)
if
operand2
is
not
self
.
operand2
:
self
.
coerced_operand2
=
operand2
if
self
.
is_python_result
():
self
.
type
=
PyrexTypes
.
py_object_type
else
:
...
...
@@ -9105,8 +9108,9 @@ class PrimaryCmpNode(ExprNode, CmpNode):
self
.
generate_operation_code
(
code
,
self
.
result
(),
self
.
operand1
,
self
.
operator
,
self
.
operand2
)
if
self
.
cascade
:
self
.
cascade
.
generate_evaluation_code
(
code
,
self
.
result
(),
self
.
operand2
)
self
.
cascade
.
generate_evaluation_code
(
code
,
self
.
result
(),
self
.
coerced_operand2
or
self
.
operand2
,
needs_evaluation
=
self
.
coerced_operand2
is
not
None
)
self
.
operand1
.
generate_disposal_code
(
code
)
self
.
operand1
.
free_temps
(
code
)
self
.
operand2
.
generate_disposal_code
(
code
)
...
...
@@ -9141,9 +9145,10 @@ class CascadedCmpNode(Node, CmpNode):
# operand2 ExprNode
# cascade CascadedCmpNode
child_attrs
=
[
'operand2'
,
'cascade'
]
child_attrs
=
[
'operand2'
,
'c
oerced_operand2'
,
'c
ascade'
]
cascade
=
None
coerced_operand2
=
None
constant_result
=
constant_value_not_set
# FIXME: where to calculate this?
def
infer_type
(
self
,
env
):
...
...
@@ -9170,7 +9175,9 @@ class CascadedCmpNode(Node, CmpNode):
if
not
operand1
.
type
.
is_pyobject
:
operand1
=
operand1
.
coerce_to_pyobject
(
env
)
if
self
.
cascade
:
self
.
operand2
=
self
.
cascade
.
optimise_comparison
(
self
.
operand2
,
env
)
operand2
=
self
.
cascade
.
optimise_comparison
(
self
.
operand2
,
env
)
if
operand2
is
not
self
.
operand2
:
self
.
coerced_operand2
=
operand2
return
operand1
def
coerce_operands_to_pyobjects
(
self
,
env
):
...
...
@@ -9186,18 +9193,24 @@ class CascadedCmpNode(Node, CmpNode):
self
.
operand2
=
self
.
operand2
.
coerce_to_simple
(
env
)
self
.
cascade
.
coerce_cascaded_operands_to_temp
(
env
)
def
generate_evaluation_code
(
self
,
code
,
result
,
operand1
):
def
generate_evaluation_code
(
self
,
code
,
result
,
operand1
,
needs_evaluation
=
False
):
if
self
.
type
.
is_pyobject
:
code
.
putln
(
"if (__Pyx_PyObject_IsTrue(%s)) {"
%
result
)
code
.
put_decref
(
result
,
self
.
type
)
else
:
code
.
putln
(
"if (%s) {"
%
result
)
if
needs_evaluation
:
operand1
.
generate_evaluation_code
(
code
)
self
.
operand2
.
generate_evaluation_code
(
code
)
self
.
generate_operation_code
(
code
,
result
,
operand1
,
self
.
operator
,
self
.
operand2
)
if
self
.
cascade
:
self
.
cascade
.
generate_evaluation_code
(
code
,
result
,
self
.
operand2
)
code
,
result
,
self
.
coerced_operand2
or
self
.
operand2
,
needs_evaluation
=
self
.
coerced_operand2
is
not
None
)
if
needs_evaluation
:
operand1
.
generate_disposal_code
(
code
)
operand1
.
free_temps
(
code
)
# Cascaded cmp result is always temp
self
.
operand2
.
generate_disposal_code
(
code
)
self
.
operand2
.
free_temps
(
code
)
...
...
tests/run/inop.pyx
View file @
41ee7f37
...
...
@@ -376,3 +376,29 @@ def test_inop_cascaded(x):
False
"""
return
1
!=
x
in
[
2
]
def
test_inop_cascaded_one
():
"""
>>> test_inop_cascaded_one()
False
"""
# copied from CPython's test_grammar.py
return
1
<
1
>
1
==
1
>=
1
<=
1
!=
1
in
1
not
in
1
is
1
is
not
1
def
test_inop_cascaded_int_orig
(
int
x
):
"""
>>> test_inop_cascaded_int_orig(1)
False
"""
return
1
<
1
>
1
==
1
>=
1
<=
1
!=
x
in
1
not
in
1
is
1
is
not
1
def
test_inop_cascaded_int
(
int
x
):
"""
>>> test_inop_cascaded_int(1)
False
>>> test_inop_cascaded_int(2)
True
>>> test_inop_cascaded_int(3)
False
"""
return
1
!=
x
in
[
1
,
2
]
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