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
Kirill Smelkov
cython
Commits
d77f79c2
Commit
d77f79c2
authored
May 26, 2020
by
serge-sans-paille
Committed by
Stefan Behnel
May 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix overflow handling for abs() calls on signed integer types (GH-3634)
Fixes #1911
parent
134b5e8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+12
-7
tests/run/builtin_abs.pyx
tests/run/builtin_abs.pyx
+1
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
d77f79c2
...
@@ -5839,6 +5839,17 @@ class SimpleCallNode(CallNode):
...
@@ -5839,6 +5839,17 @@ class SimpleCallNode(CallNode):
if
function
.
is_name
or
function
.
is_attribute
:
if
function
.
is_name
or
function
.
is_attribute
:
code
.
globalstate
.
use_entry_utility_code
(
function
.
entry
)
code
.
globalstate
.
use_entry_utility_code
(
function
.
entry
)
abs_function_cnames
=
(
'abs'
,
'labs'
,
'__Pyx_abs_longlong'
)
is_signed_int
=
self
.
type
.
is_int
and
self
.
type
.
signed
if
self
.
overflowcheck
and
is_signed_int
and
function
.
result
()
in
abs_function_cnames
:
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"Common"
,
"Overflow.c"
))
code
.
putln
(
'if (unlikely(%s == __PYX_MIN(%s))) {
\
PyErr_SetString(PyExc_OverflowError,
\
"Trying to take the absolute value of the most negative integer is not defined."); %s; }'
%
(
self
.
args
[
0
].
result
(),
self
.
args
[
0
].
type
.
empty_declaration_code
(),
code
.
error_goto
(
self
.
pos
)))
if
not
function
.
type
.
is_pyobject
or
len
(
self
.
arg_tuple
.
args
)
>
1
or
(
if
not
function
.
type
.
is_pyobject
or
len
(
self
.
arg_tuple
.
args
)
>
1
or
(
self
.
arg_tuple
.
args
and
self
.
arg_tuple
.
is_literal
):
self
.
arg_tuple
.
args
and
self
.
arg_tuple
.
is_literal
):
super
(
SimpleCallNode
,
self
).
generate_evaluation_code
(
code
)
super
(
SimpleCallNode
,
self
).
generate_evaluation_code
(
code
)
...
@@ -5941,13 +5952,7 @@ class SimpleCallNode(CallNode):
...
@@ -5941,13 +5952,7 @@ class SimpleCallNode(CallNode):
self
.
result
()
if
self
.
type
.
is_pyobject
else
None
,
self
.
result
()
if
self
.
type
.
is_pyobject
else
None
,
func_type
.
exception_value
,
self
.
nogil
)
func_type
.
exception_value
,
self
.
nogil
)
else
:
else
:
if
(
self
.
overflowcheck
if
exc_checks
:
and
self
.
type
.
is_int
and
self
.
type
.
signed
and
self
.
function
.
result
()
in
(
'abs'
,
'labs'
,
'__Pyx_abs_longlong'
)):
goto_error
=
'if (unlikely(%s < 0)) { PyErr_SetString(PyExc_OverflowError, "value too large"); %s; }'
%
(
self
.
result
(),
code
.
error_goto
(
self
.
pos
))
elif
exc_checks
:
goto_error
=
code
.
error_goto_if
(
" && "
.
join
(
exc_checks
),
self
.
pos
)
goto_error
=
code
.
error_goto_if
(
" && "
.
join
(
exc_checks
),
self
.
pos
)
else
:
else
:
goto_error
=
""
goto_error
=
""
...
...
tests/run/builtin_abs.pyx
View file @
d77f79c2
# mode: run
# mode: run
# ticket: 698
# ticket: 698
# distutils: extra_compile_args=-fwrapv
cdef
extern
from
*
:
cdef
extern
from
*
:
int
INT_MAX
int
INT_MAX
...
...
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