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
8da7f0ff
Commit
8da7f0ff
authored
Sep 03, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid compile time dependency on PY_LONG_LONG if user code doesn't explicitly make use of that type
parent
5f8d97cf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+14
-2
Cython/Utility/Overflow.c
Cython/Utility/Overflow.c
+14
-2
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+8
-0
No files found.
Cython/Utility/Optimize.c
View file @
8da7f0ff
...
...
@@ -499,9 +499,11 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject
if
((
size_t
)
shiftby
<=
sizeof
(
long
)
*
8
-
2
)
{
long
value
=
1L
<<
shiftby
;
return
PyInt_FromLong
(
value
);
#ifdef HAVE_LONG_LONG
}
else
if
((
size_t
)
shiftby
<=
sizeof
(
unsigned
PY_LONG_LONG
)
*
8
-
1
)
{
unsigned
PY_LONG_LONG
value
=
((
unsigned
PY_LONG_LONG
)
1
)
<<
shiftby
;
return
PyLong_FromUnsignedLongLong
(
value
);
#endif
}
else
{
PyObject
*
one
=
PyInt_FromLong
(
1L
);
if
(
unlikely
(
!
one
))
return
NULL
;
...
...
@@ -609,8 +611,10 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
const
long
{{
'a'
if
order
==
'
CObj
'
else
'b'
}}
=
intval
;
long
{{
ival
}}{{
if
op
not
in
(
'
Eq
'
,
'
Ne
'
)}},
x
{{
endif
}};
{{
if
op
not
in
(
'
Eq
'
,
'
Ne
'
,
'
TrueDivide
'
)}}
#ifdef HAVE_LONG_LONG
const
PY_LONG_LONG
ll
{{
'a'
if
order
==
'
CObj
'
else
'b'
}}
=
intval
;
PY_LONG_LONG
ll
{{
ival
}},
llx
;
#endif
{{
endif
}}
const
digit
*
digits
=
((
PyLongObject
*
){{
pyval
}})
->
ob_digit
;
const
Py_ssize_t
size
=
Py_SIZE
({{
pyval
}});
...
...
@@ -627,9 +631,11 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{
ival
}}
=
{{
'-'
if
_case
<
0
else
''
}}(
long
)
{{
pylong_join
(
_size
,
'
digits
'
)}};
break
;
{{
if
op
not
in
(
'
Eq
'
,
'
Ne
'
,
'
TrueDivide
'
)}}
#ifdef HAVE_LONG_LONG
}
else
if
(
8
*
sizeof
(
PY_LONG_LONG
)
-
1
>
{{
_size
}}
*
PyLong_SHIFT
)
{
ll
{{
ival
}}
=
{{
'-'
if
_case
<
0
else
''
}}(
PY_LONG_LONG
)
{{
pylong_join
(
_size
,
'
digits
'
,
'
unsigned
PY_LONG_LONG
'
)}};
goto
long_long
;
#endif
{{
endif
}}
}
// if size doesn't fit into a long or PY_LONG_LONG anymore, fall through to default
...
...
@@ -678,15 +684,20 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{
else
}}
x
=
a
{{
c_op
}}
b
;
{{
if
op
==
'
Lshift
'
}}
#ifdef HAVE_LONG_LONG
if
(
unlikely
(
a
!=
x
>>
b
))
{
ll
{{
ival
}}
=
{{
ival
}};
goto
long_long
;
}
#else
if
(
likely
(
a
==
x
>>
b
))
/* execute return statement below */
#endif
{{
endif
}}
{{
endif
}}
return
PyLong_FromLong
(
x
);
{{
if
op
!=
'
TrueDivide
'
}}
#ifdef HAVE_LONG_LONG
long_long:
{{
if
c_op
==
'%'
}}
// see ExprNodes.py :: mod_int_utility_code
...
...
@@ -708,8 +719,9 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
{{
endif
}}
{{
endif
}}
return
PyLong_FromLongLong
(
llx
);
{{
endif
}}
{{
endif
}}
#endif
{{
endif
}}{
#
if
op
!=
'
TrueDivide
'
#
}
{{
endif
}}{
#
if
op
in
(
'
Eq
'
,
'
Ne
'
)
#
}
}
#endif
...
...
Cython/Utility/Overflow.c
View file @
8da7f0ff
...
...
@@ -83,11 +83,13 @@ static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {
{{
UINT
}}
r
=
({{
UINT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
r
;
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
UINT
}})
<
sizeof
(
unsigned
PY_LONG_LONG
))
{
unsigned
PY_LONG_LONG
big_r
=
((
unsigned
PY_LONG_LONG
)
a
)
*
((
unsigned
PY_LONG_LONG
)
b
);
{{
UINT
}}
r
=
({{
UINT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
r
;
#endif
}
else
{
{{
UINT
}}
prod
=
a
*
b
;
double
dprod
=
((
double
)
a
)
*
((
double
)
b
);
...
...
@@ -137,11 +139,13 @@ static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{I
{{
INT
}}
r
=
({{
INT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
r
;
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
INT
}})
<
sizeof
(
PY_LONG_LONG
))
{
PY_LONG_LONG
big_r
=
((
PY_LONG_LONG
)
a
)
+
((
PY_LONG_LONG
)
b
);
{{
INT
}}
r
=
({{
INT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
r
;
#endif
}
else
{
// Signed overflow undefined, but unsigned overflow is well defined.
{{
INT
}}
r
=
({{
INT
}})
((
unsigned
{{
INT
}})
a
+
(
unsigned
{{
INT
}})
b
);
...
...
@@ -181,11 +185,13 @@ static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{I
{{
INT
}}
r
=
({{
INT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
({{
INT
}})
r
;
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
INT
}})
<
sizeof
(
PY_LONG_LONG
))
{
PY_LONG_LONG
big_r
=
((
PY_LONG_LONG
)
a
)
*
((
PY_LONG_LONG
)
b
);
{{
INT
}}
r
=
({{
INT
}})
big_r
;
*
overflow
|=
big_r
!=
r
;
return
({{
INT
}})
r
;
#endif
}
else
{
{{
INT
}}
prod
=
a
*
b
;
double
dprod
=
((
double
)
a
)
*
((
double
)
b
);
...
...
@@ -227,8 +233,10 @@ __Pyx_check_sane_{{NAME}}();
static
int
__Pyx_check_sane_
{{
NAME
}}(
void
)
{
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
int
)
||
sizeof
({{
TYPE
}})
==
sizeof
(
long
)
||
sizeof
({{
TYPE
}})
==
sizeof
(
PY_LONG_LONG
))
{
#ifdef HAVE_LONG_LONG
sizeof
({{
TYPE
}})
==
sizeof
(
PY_LONG_LONG
)
||
#endif
sizeof
({{
TYPE
}})
==
sizeof
(
long
))
{
return
0
;
}
else
{
PyErr_Format
(
PyExc_RuntimeError
,
\
...
...
@@ -252,8 +260,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}
return
__Pyx_
{{
BINOP
}}
_unsigned_int_checking_overflow
(
a
,
b
,
overflow
);
}
else
if
(
sizeof
({{
TYPE
}})
==
sizeof
(
unsigned
long
))
{
return
__Pyx_
{{
BINOP
}}
_unsigned_long_checking_overflow
(
a
,
b
,
overflow
);
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
==
sizeof
(
unsigned
PY_LONG_LONG
))
{
return
__Pyx_
{{
BINOP
}}
_unsigned_long_long_checking_overflow
(
a
,
b
,
overflow
);
#endif
}
else
{
abort
();
return
0
;
// handled elsewhere
}
...
...
@@ -262,8 +272,10 @@ static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}
return
__Pyx_
{{
BINOP
}}
_int_checking_overflow
(
a
,
b
,
overflow
);
}
else
if
(
sizeof
({{
TYPE
}})
==
sizeof
(
long
))
{
return
__Pyx_
{{
BINOP
}}
_long_checking_overflow
(
a
,
b
,
overflow
);
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
==
sizeof
(
PY_LONG_LONG
))
{
return
__Pyx_
{{
BINOP
}}
_long_long_checking_overflow
(
a
,
b
,
overflow
);
#endif
}
else
{
abort
();
return
0
;
// handled elsewhere
}
...
...
Cython/Utility/TypeConversion.c
View file @
8da7f0ff
...
...
@@ -555,14 +555,18 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
return
PyInt_FromLong
((
long
)
value
);
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
long
))
{
return
PyLong_FromUnsignedLong
((
unsigned
long
)
value
);
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
PY_LONG_LONG
))
{
return
PyLong_FromUnsignedLongLong
((
unsigned
PY_LONG_LONG
)
value
);
#endif
}
}
else
{
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
))
{
return
PyInt_FromLong
((
long
)
value
);
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
PY_LONG_LONG
))
{
return
PyLong_FromLongLong
((
PY_LONG_LONG
)
value
);
#endif
}
}
{
...
...
@@ -807,8 +811,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#endif
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
long
))
{
__PYX_VERIFY_RETURN_INT_EXC
({{
TYPE
}},
unsigned
long
,
PyLong_AsUnsignedLong
(
x
))
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
PY_LONG_LONG
))
{
__PYX_VERIFY_RETURN_INT_EXC
({{
TYPE
}},
unsigned
PY_LONG_LONG
,
PyLong_AsUnsignedLongLong
(
x
))
#endif
}
}
else
{
// signed
...
...
@@ -835,8 +841,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
#endif
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
))
{
__PYX_VERIFY_RETURN_INT_EXC
({{
TYPE
}},
long
,
PyLong_AsLong
(
x
))
#ifdef HAVE_LONG_LONG
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
PY_LONG_LONG
))
{
__PYX_VERIFY_RETURN_INT_EXC
({{
TYPE
}},
PY_LONG_LONG
,
PyLong_AsLongLong
(
x
))
#endif
}
}
{
...
...
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