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
Boxiang Sun
cython
Commits
5bdfbcb5
Commit
5bdfbcb5
authored
Sep 09, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cast integers to their expected type in Pythran expressions to enforce template type matches.
parent
49851cae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
24 deletions
+29
-24
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+22
-18
Cython/Compiler/Pythran.py
Cython/Compiler/Pythran.py
+7
-6
No files found.
Cython/Compiler/ExprNodes.py
View file @
5bdfbcb5
...
...
@@ -11042,10 +11042,11 @@ class NumBinopNode(BinopNode):
self
.
operand2
.
result
(),
self
.
overflow_bit_node
.
overflow_bit
)
elif
self
.
type
.
is_cpp_class
or
self
.
infix
:
return
"(%s %s %s)"
%
(
self
.
operand1
.
result
(),
self
.
operator
,
self
.
operand2
.
result
())
if
is_pythran_expr
(
self
.
type
):
result1
,
result2
=
self
.
operand1
.
pythran_result
(),
self
.
operand2
.
pythran_result
()
else
:
result1
,
result2
=
self
.
operand1
.
result
(),
self
.
operand2
.
result
()
return
"(%s %s %s)"
%
(
result1
,
self
.
operator
,
result2
)
else
:
func
=
self
.
type
.
binary_op
(
self
.
operator
)
if
func
is
None
:
...
...
@@ -12385,18 +12386,19 @@ class PrimaryCmpNode(ExprNode, CmpNode):
return
self
.
operand1
.
check_const
()
and
self
.
operand2
.
check_const
()
def
calculate_result_code
(
self
):
if
self
.
operand1
.
type
.
is_complex
:
operand1
,
operand2
=
self
.
operand1
,
self
.
operand2
if
operand1
.
type
.
is_complex
:
if
self
.
operator
==
"!="
:
negation
=
"!"
else
:
negation
=
""
return
"(%s%s(%s, %s))"
%
(
negation
,
self
.
operand1
.
type
.
binary_op
(
'=='
),
self
.
operand1
.
result
(),
self
.
operand2
.
result
())
operand1
.
type
.
binary_op
(
'=='
),
operand1
.
result
(),
operand2
.
result
())
elif
self
.
is_c_string_contains
():
if
self
.
operand2
.
type
is
unicode_type
:
if
operand2
.
type
is
unicode_type
:
method
=
"__Pyx_UnicodeContainsUCS4"
else
:
method
=
"__Pyx_BytesContains"
...
...
@@ -12407,16 +12409,18 @@ class PrimaryCmpNode(ExprNode, CmpNode):
return
"(%s%s(%s, %s))"
%
(
negation
,
method
,
self
.
operand2
.
result
(),
self
.
operand1
.
result
())
operand2
.
result
(),
operand1
.
result
())
else
:
result1
=
self
.
operand1
.
result
()
result2
=
self
.
operand2
.
result
()
if
self
.
is_memslice_nonecheck
:
if
self
.
operand1
.
type
.
is_memoryviewslice
:
result1
=
"((PyObject *) %s.memview)"
%
result1
else
:
result2
=
"((PyObject *) %s.memview)"
%
result2
if
is_pythran_expr
(
self
.
type
):
result1
,
result2
=
operand1
.
pythran_result
(),
operand2
.
pythran_result
()
else
:
result1
,
result2
=
operand1
.
result
(),
operand2
.
result
()
if
self
.
is_memslice_nonecheck
:
if
operand1
.
type
.
is_memoryviewslice
:
result1
=
"((PyObject *) %s.memview)"
%
result1
else
:
result2
=
"((PyObject *) %s.memview)"
%
result2
return
"(%s %s %s)"
%
(
result1
,
...
...
Cython/Compiler/Pythran.py
View file @
5bdfbcb5
...
...
@@ -75,7 +75,7 @@ def pythran_indexing_code(indices):
func
=
"slice"
return
"pythonic::types::%s(%s)"
%
(
func
,
","
.
join
((
v
.
pythran_result
()
for
v
in
values
)))
elif
idx
.
type
.
is_int
:
return
idx
.
result
(
)
return
to_pythran
(
idx
)
elif
idx
.
type
.
is_pythran_expr
:
return
idx
.
pythran_result
()
raise
ValueError
(
"unsupported indice type %s!"
%
str
(
idx
.
type
))
...
...
@@ -85,10 +85,12 @@ def pythran_func_type(func, args):
args
=
","
.
join
((
"std::declval<%s>()"
%
pythran_type
(
a
.
type
)
for
a
in
args
))
return
"decltype(pythonic::numpy::functor::%s{}(%s))"
%
(
func
,
args
)
def
to_pythran
(
op
,
ptype
=
None
):
def
to_pythran
(
op
,
ptype
=
None
):
op_type
=
op
.
type
if
is_type
(
op_type
,[
"is_pythran_expr"
,
"is_int"
,
"is_numeric"
,
"is_float"
,
"is_complex"
]):
if
op_type
.
is_int
:
# Make sure that integer literals always have exactly the type that the templates expect.
return
op_type
.
cast_code
(
op
.
result
())
if
is_type
(
op_type
,
[
"is_pythran_expr"
,
"is_numeric"
,
"is_float"
,
"is_complex"
]):
return
op
.
result
()
if
op
.
is_none
:
return
"pythonic::__builtin__::None"
...
...
@@ -111,8 +113,7 @@ def is_pythran_supported_node_or_none(node):
def
is_pythran_supported_type
(
type_
):
pythran_supported
=
(
"is_pythran_expr"
,
"is_int"
,
"is_numeric"
,
"is_float"
,
"is_none"
,
"is_complex"
)
"is_pythran_expr"
,
"is_int"
,
"is_numeric"
,
"is_float"
,
"is_none"
,
"is_complex"
)
return
is_type
(
type_
,
pythran_supported
)
or
is_pythran_expr
(
type_
)
def
is_pythran_supported_operation_type
(
type_
):
...
...
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