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
6fbceed2
Commit
6fbceed2
authored
Dec 12, 2007
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overflow code (Ondrej suggested a much better way)
parent
ec84cb7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+7
-8
No files found.
Cython/Compiler/PyrexTypes.py
View file @
6fbceed2
...
...
@@ -384,32 +384,31 @@ class CIntType(CNumericType):
c_type
=
self
.
sign_and_name
()
c_name
=
c_type
.
replace
(
' '
,
'_'
);
func_name
=
"__pyx_PyInt_%s"
%
c_name
;
c_mask
=
"__pyx_%s_MASK"
%
c_name
if
not
int_conversion_list
.
has_key
(
func_name
):
# no env to add utility code to
global
type_conversion_predeclarations
,
type_conversion_functions
if
self
.
signed
:
neg_test
=
" && ((-val) & %s)"
%
c_mask
else
:
neg_test
=
""
else
:
neg_test
=
" || (long_val < 0)"
type_conversion_predeclarations
+=
"""
static INLINE %(c_type)s %(func_name)s(PyObject* x);"""
%
{
'c_type'
:
c_type
,
'c_name'
:
c_name
,
'func_name'
:
func_name
}
type_conversion_functions
+=
"""
#define %(c_mask)s ((long)(~((1LL << (8*sizeof(%(c_type)s))) - 1LL)))
static INLINE %(c_type)s %(func_name)s(PyObject* x) {
if (sizeof(%(c_type)s) < sizeof(long)) {
long val = __pyx_PyInt_AsLong(x);
if (unlikely((val & %(c_mask)s) %(neg_test)s)) {
long long_val = __pyx_PyInt_AsLong(x);
%(c_type)s val = (%(c_type)s)long_val;
if (unlikely((val != long_val) %(neg_test)s)) {
PyErr_SetString(PyExc_OverflowError, "value too large to convert to %(c_type)s");
return (%(c_type)s)-1;
}
return
(%(c_type)s)
val;
return val;
}
else {
return __pyx_PyInt_AsLong(x);
}
}
"""
%
{
'c_type'
:
c_type
,
'c_name'
:
c_name
,
'func_name'
:
func_name
,
'
c_mask'
:
c_mask
,
'
neg_test'
:
neg_test
}
"""
%
{
'c_type'
:
c_type
,
'c_name'
:
c_name
,
'func_name'
:
func_name
,
'neg_test'
:
neg_test
}
int_conversion_list
[
func_name
]
=
True
return
func_name
...
...
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