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
a734b360
Commit
a734b360
authored
Oct 24, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Cheaper) overflow check for const rhs.
parent
2da25603
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+6
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
a734b360
...
...
@@ -8013,7 +8013,10 @@ class NumBinopNode(BinopNode):
self
.
infix
=
False
if
self
.
type
.
is_int
and
env
.
directives
[
'overflowcheck'
]
and
self
.
operator
in
(
'+'
,
'-'
,
'*'
):
self
.
overflow_check
=
True
self
.
func
=
self
.
type
.
overflow_check_binop
(
self
.
op_names
[
self
.
operator
],
env
)
self
.
func
=
self
.
type
.
overflow_check_binop
(
self
.
op_names
[
self
.
operator
],
env
,
const_rhs
=
self
.
operand2
.
has_constant_result
())
self
.
is_temp
=
True
if
not
self
.
infix
or
(
type1
.
is_numeric
and
type2
.
is_numeric
):
self
.
operand1
=
self
.
operand1
.
coerce_to
(
self
.
type
,
env
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
a734b360
...
...
@@ -402,7 +402,9 @@ class CTypedefType(BaseType):
# delegation
return
self
.
typedef_base_type
.
create_from_py_utility_code
(
env
)
def
overflow_check_binop
(
self
,
binop
,
env
):
def
overflow_check_binop
(
self
,
binop
,
env
,
const_rhs
=
False
):
if
const_rhs
:
binop
+=
"_const"
env
.
use_utility_code
(
UtilityCode
.
load
(
"Common"
,
"Overflow.c"
))
type
=
self
.
declaration_code
(
""
)
name
=
self
.
specialization_name
()
...
...
@@ -1557,10 +1559,12 @@ class CIntType(CNumericType):
# be negative for signed ints, which is good.
return
"0xbad0bad0"
def
overflow_check_binop
(
self
,
binop
,
env
):
def
overflow_check_binop
(
self
,
binop
,
env
,
const_rhs
=
False
):
env
.
use_utility_code
(
UtilityCode
.
load
(
"Common"
,
"Overflow.c"
))
type
=
self
.
declaration_code
(
""
)
name
=
self
.
specialization_name
()
if
const_rhs
:
binop
+=
"_const"
if
type
in
(
'int'
,
'long'
,
'long long'
):
env
.
use_utility_code
(
TempitaUtilityCode
.
load
(
"BaseCaseSigned"
,
"Overflow.c"
,
context
=
{
'INT'
:
type
,
'NAME'
:
name
}))
elif
type
in
(
'unsigned int'
,
'unsigned long'
,
'unsigned long long'
):
...
...
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