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
beb42251
Commit
beb42251
authored
Apr 20, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always convert C integer values to 1/0 when testing them for their boolean value
parent
c6d6d842
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-5
tests/run/bint_binop_T145.pyx
tests/run/bint_binop_T145.pyx
+22
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
beb42251
...
...
@@ -744,13 +744,12 @@ class ExprNode(Node):
constant_result
=
bool_value
)
type
=
self
.
type
if
type
.
is_pyobject
or
type
.
is_ptr
or
type
.
is_float
:
if
type
.
is_enum
or
type
.
is_error
:
return
self
elif
type
.
is_pyobject
or
type
.
is_int
or
type
.
is_ptr
or
type
.
is_float
:
return
CoerceToBooleanNode
(
self
,
env
)
else
:
if
not
(
type
.
is_int
or
type
.
is_enum
or
type
.
is_error
):
error
(
self
.
pos
,
"Type '%s' not acceptable as a boolean"
%
type
)
return
self
error
(
self
.
pos
,
"Type '%s' not acceptable as a boolean"
%
type
)
def
coerce_to_integer
(
self
,
env
):
# If not already some C integer type, coerce to longint.
...
...
tests/run/bint_binop_T145.pyx
View file @
beb42251
...
...
@@ -111,3 +111,25 @@ def x_and_1_or_False(x):
False
"""
return
x
and
1
or
False
def
test_large_int
(
unsigned
long
x
):
"""
>>> try: test_large_int(1 << 127)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 63)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 48)
... except OverflowError: print True
True
>>> try: test_large_int(1 << 31)
... except OverflowError: print True
True
>>> test_large_int(0)
False
"""
if
True
and
x
:
return
True
else
:
return
False
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