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
ea6414cd
Commit
ea6414cd
authored
Sep 01, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct processing of large integers (PyLong values) in compile time env under Py2.x
parent
f4ae2572
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
+27
-3
CHANGES.rst
CHANGES.rst
+3
-0
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+6
-3
tests/run/ct_DEF.pyx
tests/run/ct_DEF.pyx
+18
-0
No files found.
CHANGES.rst
View file @
ea6414cd
...
@@ -8,6 +8,9 @@ Cython Changelog
...
@@ -8,6 +8,9 @@ Cython Changelog
Bugs fixed
Bugs fixed
----------
----------
* Incorrect handling of large integers in compile-time evaluated DEF
expressions under Python 2.x.
* Invalid C code when caching known builtin methods.
* Invalid C code when caching known builtin methods.
This fixes ticket 860.
This fixes ticket 860.
...
...
Cython/Compiler/Parsing.py
View file @
ea6414cd
...
@@ -761,9 +761,10 @@ def wrap_compile_time_constant(pos, value):
...
@@ -761,9 +761,10 @@ def wrap_compile_time_constant(pos, value):
elif
isinstance
(
value
,
bool
):
elif
isinstance
(
value
,
bool
):
return
ExprNodes
.
BoolNode
(
pos
,
value
=
value
)
return
ExprNodes
.
BoolNode
(
pos
,
value
=
value
)
elif
isinstance
(
value
,
int
):
elif
isinstance
(
value
,
int
):
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
)
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
,
constant_result
=
value
,
unsigned
=
'U'
if
value
>
0
else
''
)
elif
isinstance
(
value
,
float
):
elif
isinstance
(
value
,
float
):
return
ExprNodes
.
FloatNode
(
pos
,
value
=
rep
)
return
ExprNodes
.
FloatNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
elif
isinstance
(
value
,
_unicode
):
elif
isinstance
(
value
,
_unicode
):
return
ExprNodes
.
UnicodeNode
(
pos
,
value
=
EncodedString
(
value
))
return
ExprNodes
.
UnicodeNode
(
pos
,
value
=
EncodedString
(
value
))
elif
isinstance
(
value
,
_bytes
):
elif
isinstance
(
value
,
_bytes
):
...
@@ -777,7 +778,9 @@ def wrap_compile_time_constant(pos, value):
...
@@ -777,7 +778,9 @@ def wrap_compile_time_constant(pos, value):
# error already reported
# error already reported
return
None
return
None
elif
not
_IS_PY3
and
isinstance
(
value
,
long
):
elif
not
_IS_PY3
and
isinstance
(
value
,
long
):
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
,
longness
=
"L"
)
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
.
rstrip
(
'L'
),
longness
=
"L"
,
constant_result
=
value
,
unsigned
=
'U'
if
value
>
0
else
''
)
error
(
pos
,
"Invalid type for compile-time constant: %r (type %s)"
error
(
pos
,
"Invalid type for compile-time constant: %r (type %s)"
%
(
value
,
value
.
__class__
.
__name__
))
%
(
value
,
value
.
__class__
.
__name__
))
return
None
return
None
...
...
tests/run/ct_DEF.pyx
View file @
ea6414cd
...
@@ -11,6 +11,10 @@ if sys.version_info[0] < 3:
...
@@ -11,6 +11,10 @@ if sys.version_info[0] < 3:
__doc__
=
__doc__
.
replace
(
u" b'"
,
u" '"
)
__doc__
=
__doc__
.
replace
(
u" b'"
,
u" '"
)
def
print_large_number
(
n
):
print
(
str
(
n
).
rstrip
(
'L'
))
DEF
TUPLE
=
(
1
,
2
,
u"buckle my shoe"
)
DEF
TUPLE
=
(
1
,
2
,
u"buckle my shoe"
)
DEF
TRUE_FALSE
=
(
True
,
False
)
DEF
TRUE_FALSE
=
(
True
,
False
)
DEF
NONE
=
None
DEF
NONE
=
None
...
@@ -21,6 +25,8 @@ DEF INT1 = 42
...
@@ -21,6 +25,8 @@ DEF INT1 = 42
DEF
INT2
=
0x42
DEF
INT2
=
0x42
DEF
INT3
=
-
0x42
DEF
INT3
=
-
0x42
DEF
LONG
=
666L
DEF
LONG
=
666L
DEF
LARGE_NUM32
=
(
1
<<
32
)
-
1
DEF
LARGE_NUM64
=
(
1
<<
64
)
-
1
DEF
FLOAT
=
12.5
DEF
FLOAT
=
12.5
DEF
STR
=
b"spam"
DEF
STR
=
b"spam"
DEF
TWO
=
TUPLE
[
1
]
DEF
TWO
=
TUPLE
[
1
]
...
@@ -81,6 +87,18 @@ def l():
...
@@ -81,6 +87,18 @@ def l():
cdef
long
l
=
LONG
cdef
long
l
=
LONG
return
l
return
l
def
large_nums
():
"""
>>> l32, l64 = large_nums()
>>> print_large_number(l32)
4294967295
>>> print_large_number(l64)
18446744073709551615
"""
cdef
unsigned
long
l32
=
LARGE_NUM32
cdef
unsigned
long
long
l64
=
LARGE_NUM64
return
l32
,
l64
def
f
():
def
f
():
"""
"""
>>> f()
>>> f()
...
...
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