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
5b8971df
Commit
5b8971df
authored
Aug 24, 2013
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Conversion for very long ints.
parent
8243e467
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
17 deletions
+38
-17
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-3
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+35
-14
No files found.
Cython/Compiler/PyrexTypes.py
View file @
5b8971df
...
...
@@ -1566,17 +1566,17 @@ class CIntType(CNumericType):
self
.
get_from_py_type_conversion
()
def
create_from_py_utility_code
(
self
,
env
):
self
.
from_py_function
=
"__Pyx_PyInt_
to
_py_"
+
self
.
specialization_name
()
self
.
from_py_function
=
"__Pyx_PyInt_
from
_py_"
+
self
.
specialization_name
()
env
.
use_utility_code
(
TempitaUtilityCode
.
load
(
"CIntFromPy"
,
"TypeConversion.c"
,
context
=
{
"TYPE"
:
self
.
declaration_code
(
''
),
"FROM_PY_FUNCTION"
:
self
.
from_py_function
}))
return
True
def
create_to_py_utility_code
(
self
,
env
):
self
.
from_to_function
=
"__Pyx_PyInt_As
"
+
self
.
specialization_name
()
self
.
to_py_function
=
"__Pyx_PyInt_to_py_
"
+
self
.
specialization_name
()
env
.
use_utility_code
(
TempitaUtilityCode
.
load
(
"CIntToPy"
,
"TypeConversion.c"
,
context
=
{
"TYPE"
:
self
.
declaration_code
(
''
),
"TO_PY_FUNCTION"
:
self
.
from_to
_function
}))
context
=
{
"TYPE"
:
self
.
declaration_code
(
''
),
"TO_PY_FUNCTION"
:
self
.
to_py
_function
}))
return
True
def
get_to_py_type_conversion
(
self
):
...
...
Cython/Utility/TypeConversion.c
View file @
5b8971df
...
...
@@ -471,7 +471,7 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
))
{
return
PyInt_FromLong
(
value
);
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
long
))
{
return
PyLong_FromLong
(
value
);
return
PyLong_FromLong
Long
(
value
);
}
}
{
...
...
@@ -509,9 +509,9 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *);
//@requires: CIntFromPyVerify
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#endif
#endif
static
CYTHON_INLINE
{{
TYPE
}}
{{
FROM_PY_FUNCTION
}}(
PyObject
*
x
)
{
const
{{
TYPE
}}
neg_one
=
({{
TYPE
}})
-
1
,
const_zero
=
0
;
...
...
@@ -534,14 +534,14 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
if
(
likely
(
PyLong_Check
(
x
)))
{
if
(
is_unsigned
)
{
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#if CYTHON_USE_PYLONG_INTERNALS
if
(
sizeof
(
digit
)
<=
sizeof
({{
TYPE
}}))
{
switch
(
Py_SIZE
(
x
))
{
case
0
:
return
0
;
case
1
:
return
({{
TYPE
}})
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
];
}
}
#endif
#endif
#endif
if
(
unlikely
(
Py_SIZE
(
x
)
<
0
))
{
PyErr_SetString
(
PyExc_OverflowError
,
...
...
@@ -552,13 +552,10 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
,
PyLong_AsUnsignedLong
)
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
unsigned
long
long
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
unsigned
long
long
,
PyLong_AsUnsignedLongLong
)
}
else
{
// That's a big type...
return
({{
TYPE
}})
PyLong_AsUnsignedLongLong
(
x
);
}
}
else
{
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
#if CYTHON_USE_PYLONG_INTERNALS
#if CYTHON_USE_PYLONG_INTERNALS
if
(
sizeof
(
digit
)
<=
sizeof
({{
TYPE
}})
{
switch
(
Py_SIZE
(
x
))
{
case
0
:
return
0
;
...
...
@@ -566,17 +563,41 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
case
-
1
:
return
-
({{
TYPE
}})
((
PyLongObject
*
)
x
)
->
ob_digit
[
0
];
}
}
#endif
#endif
#endif
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
long
,
PyLong_AsLong
)
}
else
if
(
sizeof
({{
TYPE
}})
<=
sizeof
(
long
long
))
{
__PYX_VERIFY_RETURN_INT
({{
TYPE
}},
long
long
,
PyLong_AsLongLong
)
}
else
{
// That's a big type...
return
({{
TYPE
}})
PyLong_AsLongLong
(
x
);
}
}
{
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
PyErr_SetString
(
PyExc_RuntimeError
,
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"
);
#else
{{
TYPE
}}
val
;
PyObject
*
v
=
__Pyx_PyNumber_Int
(
x
);
#if PY_MAJOR_VERSION < 3
if
(
likely
(
v
)
&&
!
PyLong_Check
(
v
))
{
PyObject
*
tmp
=
v
;
v
=
PyNumber_Long
(
tmp
);
Py_DECREF
(
tmp
);
}
#endif
if
(
likely
(
v
))
{
int
one
=
1
;
int
is_little
=
(
int
)
*
(
unsigned
char
*
)
&
one
;
unsigned
char
*
bytes
=
(
unsigned
char
*
)
&
val
;
int
ret
=
_PyLong_AsByteArray
((
PyLongObject
*
)
v
,
bytes
,
sizeof
(
val
),
is_little
,
!
is_unsigned
);
Py_DECREF
(
v
);
if
(
likely
(
!
ret
))
return
val
;
}
#endif
return
({{
TYPE
}})
-
1
;
}
}
else
{
{{
TYPE
}}
val
;
PyObject
*
tmp
=
__Pyx_PyNumber_Int
(
x
);
...
...
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