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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
846acc18
Commit
846acc18
authored
Apr 14, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
29655b04
95cd0a3d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
5 deletions
+48
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-4
tests/run/enumboolctx.pyx
tests/run/enumboolctx.pyx
+40
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
846acc18
...
@@ -593,7 +593,7 @@ class ExprNode(Node):
...
@@ -593,7 +593,7 @@ class ExprNode(Node):
if
type
.
is_pyobject
or
type
.
is_ptr
or
type
.
is_float
:
if
type
.
is_pyobject
or
type
.
is_ptr
or
type
.
is_float
:
return
CoerceToBooleanNode
(
self
,
env
)
return
CoerceToBooleanNode
(
self
,
env
)
else
:
else
:
if
not
type
.
is_int
and
not
type
.
is_error
:
if
not
(
type
.
is_int
or
type
.
is_enum
or
type
.
is_error
)
:
error
(
self
.
pos
,
error
(
self
.
pos
,
"Type '%s' not acceptable as a boolean"
%
type
)
"Type '%s' not acceptable as a boolean"
%
type
)
return
self
return
self
...
...
Cython/Compiler/Nodes.py
View file @
846acc18
...
@@ -2622,10 +2622,13 @@ class DefNode(FuncDefNode):
...
@@ -2622,10 +2622,13 @@ class DefNode(FuncDefNode):
func
=
new_type
.
from_py_function
func
=
new_type
.
from_py_function
# copied from CoerceFromPyTypeNode
# copied from CoerceFromPyTypeNode
if
func
:
if
func
:
code
.
putln
(
"%s = %s(%s); %s"
%
(
lhs
=
arg
.
entry
.
cname
arg
.
entry
.
cname
,
rhs
=
"%s(%s)"
%
(
func
,
arg
.
hdr_cname
)
func
,
if
new_type
.
is_enum
:
arg
.
hdr_cname
,
rhs
=
PyrexTypes
.
typecast
(
new_type
,
PyrexTypes
.
c_long_type
,
rhs
)
code
.
putln
(
"%s = %s; %s"
%
(
lhs
,
rhs
,
code
.
error_goto_if
(
new_type
.
error_condition
(
arg
.
entry
.
cname
),
arg
.
pos
)))
code
.
error_goto_if
(
new_type
.
error_condition
(
arg
.
entry
.
cname
),
arg
.
pos
)))
else
:
else
:
error
(
arg
.
pos
,
error
(
arg
.
pos
,
...
...
tests/run/enumboolctx.pyx
0 → 100644
View file @
846acc18
cdef
public
enum
Truth
:
FALSE
=
0
TRUE
=
1
def
enum_boolctx
(
Truth
arg
):
"""
>>> enum_boolctx(FALSE)
False
>>> enum_boolctx(TRUE)
True
"""
if
arg
:
return
True
else
:
return
False
cdef
extern
from
*
:
enum
:
FALSE_VALUE
"(0)"
enum
:
TRUE_VALUE
"(1)"
def
extern_enum_false
():
"""
>>> extern_enum_false()
"""
if
FALSE_VALUE
:
raise
ValueError
def
extern_enum_true
():
"""
>>> extern_enum_true()
"""
if
not
TRUE_VALUE
:
raise
ValueError
def
extern_enum_false_true
():
"""
>>> extern_enum_false_true()
"""
if
not
TRUE_VALUE
or
FALSE_VALUE
:
raise
ValueError
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