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
4a6234d2
Commit
4a6234d2
authored
Oct 22, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix casts and negations in except clauses.
parent
9cece7db
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
3 deletions
+34
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+10
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+9
-2
tests/run/exceptionpropagation.pyx
tests/run/exceptionpropagation.pyx
+14
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
4a6234d2
...
...
@@ -4106,6 +4106,11 @@ class UnaryMinusNode(UnopNode):
else
:
return
"%s(%s)"
%
(
self
.
operand
.
type
.
unary_op
(
'-'
),
self
.
operand
.
result
())
def
get_constant_c_result_code
(
self
):
value
=
self
.
operand
.
get_constant_c_result_code
()
if
value
:
return
"(-%s)"
%
(
value
)
class
TildeNode
(
UnopNode
):
# unary '~' operator
...
...
@@ -4251,6 +4256,11 @@ class TypecastNode(ExprNode):
opnd
=
self
.
operand
return
self
.
type
.
cast_code
(
opnd
.
result
())
def
get_constant_c_result_code
(
self
):
operand_result
=
self
.
operand
.
get_constant_c_result_code
()
if
operand_result
:
return
self
.
type
.
cast_code
(
operand_result
)
def
result_as
(
self
,
type
):
if
self
.
type
.
is_pyobject
and
not
self
.
is_temp
:
# Optimise away some unnecessary casting
...
...
Cython/Compiler/Nodes.py
View file @
4a6234d2
...
...
@@ -546,7 +546,6 @@ class CFuncDeclaratorNode(CDeclaratorNode):
else
:
if
self
.
exception_value
:
self
.
exception_value
.
analyse_const_expression
(
env
)
exc_val
=
self
.
exception_value
.
get_constant_c_result_code
()
if
self
.
exception_check
==
'+'
:
exc_val_type
=
self
.
exception_value
.
type
if
not
exc_val_type
.
is_error
and
\
...
...
@@ -555,6 +554,7 @@ class CFuncDeclaratorNode(CDeclaratorNode):
error
(
self
.
exception_value
.
pos
,
"Exception value must be a Python exception or cdef function with no arguments."
)
else
:
exc_val
=
self
.
exception_value
.
get_constant_c_result_code
()
if
not
return_type
.
assignable_from
(
self
.
exception_value
.
type
):
error
(
self
.
exception_value
.
pos
,
"Exception value incompatible with function return type"
)
...
...
Cython/Compiler/PyrexTypes.py
View file @
4a6234d2
...
...
@@ -1282,10 +1282,17 @@ class CFuncType(CType):
arg_reprs
=
map
(
repr
,
self
.
args
)
if
self
.
has_varargs
:
arg_reprs
.
append
(
"..."
)
return
"<CFuncType %s %s[%s]>"
%
(
if
self
.
exception_value
:
except_clause
=
" %r"
%
self
.
exception_value
else
:
except_clause
=
""
if
self
.
exception_check
:
except_clause
+=
"?"
return
"<CFuncType %s %s[%s]%s>"
%
(
repr
(
self
.
return_type
),
self
.
calling_convention_prefix
(),
","
.
join
(
arg_reprs
))
","
.
join
(
arg_reprs
),
except_clause
)
def
calling_convention_prefix
(
self
):
cc
=
self
.
calling_convention
...
...
tests/run/exceptionpropagation.pyx
View file @
4a6234d2
...
...
@@ -15,3 +15,17 @@ cdef int obj2int(object ob) except *:
def
foo
(
a
):
cdef
int
i
=
obj2int
(
a
)
CHKERR
(
i
)
cdef
int
*
except_expr
(
bint
fire
)
except
<
int
*>-
1
:
if
fire
:
raise
RuntimeError
def
test_except_expr
(
bint
fire
):
"""
>>> test_except_expr(False)
>>> test_except_expr(True)
Traceback (most recent call last):
...
RuntimeError
"""
except_expr
(
fire
)
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