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
51efd523
Commit
51efd523
authored
Mar 22, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate shorter code for empty except blocks (ticket #251)
parent
120364fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+21
-3
No files found.
Cython/Compiler/Nodes.py
View file @
51efd523
...
@@ -4218,6 +4218,7 @@ class ExceptClauseNode(Node):
...
@@ -4218,6 +4218,7 @@ class ExceptClauseNode(Node):
exc_value
=
None
exc_value
=
None
excinfo_target
=
None
excinfo_target
=
None
empty_body
=
False
def
analyse_declarations
(
self
,
env
):
def
analyse_declarations
(
self
,
env
):
if
self
.
target
:
if
self
.
target
:
...
@@ -4236,7 +4237,18 @@ class ExceptClauseNode(Node):
...
@@ -4236,7 +4237,18 @@ class ExceptClauseNode(Node):
self
.
match_flag
=
env
.
allocate_temp
(
PyrexTypes
.
c_int_type
)
self
.
match_flag
=
env
.
allocate_temp
(
PyrexTypes
.
c_int_type
)
self
.
pattern
.
release_temp
(
env
)
self
.
pattern
.
release_temp
(
env
)
env
.
release_temp
(
self
.
match_flag
)
env
.
release_temp
(
self
.
match_flag
)
self
.
exc_vars
=
[
env
.
allocate_temp
(
py_object_type
)
for
i
in
xrange
(
3
)]
# most simple case: empty body (pass)
self
.
empty_body
=
not
self
.
target
and
not
self
.
excinfo_target
and
\
not
getattr
(
self
.
body
,
'stats'
,
True
)
if
not
self
.
empty_body
:
self
.
exc_vars
=
[
env
.
allocate_temp
(
py_object_type
)
for
i
in
xrange
(
3
)]
env
.
use_utility_code
(
get_exception_utility_code
)
env
.
use_utility_code
(
restore_exception_utility_code
)
else
:
self
.
exc_vars
=
[]
if
self
.
target
:
if
self
.
target
:
self
.
exc_value
=
ExprNodes
.
ExcValueNode
(
self
.
pos
,
env
,
self
.
exc_vars
[
1
])
self
.
exc_value
=
ExprNodes
.
ExcValueNode
(
self
.
pos
,
env
,
self
.
exc_vars
[
1
])
self
.
exc_value
.
allocate_temps
(
env
)
self
.
exc_value
.
allocate_temps
(
env
)
...
@@ -4255,8 +4267,6 @@ class ExceptClauseNode(Node):
...
@@ -4255,8 +4267,6 @@ class ExceptClauseNode(Node):
self
.
body
.
analyse_expressions
(
env
)
self
.
body
.
analyse_expressions
(
env
)
for
var
in
self
.
exc_vars
:
for
var
in
self
.
exc_vars
:
env
.
release_temp
(
var
)
env
.
release_temp
(
var
)
env
.
use_utility_code
(
get_exception_utility_code
)
env
.
use_utility_code
(
restore_exception_utility_code
)
def
generate_handling_code
(
self
,
code
,
end_label
):
def
generate_handling_code
(
self
,
code
,
end_label
):
code
.
mark_pos
(
self
.
pos
)
code
.
mark_pos
(
self
.
pos
)
...
@@ -4273,6 +4283,14 @@ class ExceptClauseNode(Node):
...
@@ -4273,6 +4283,14 @@ class ExceptClauseNode(Node):
self
.
match_flag
)
self
.
match_flag
)
else
:
else
:
code
.
putln
(
"/*except:*/ {"
)
code
.
putln
(
"/*except:*/ {"
)
if
self
.
empty_body
:
# most simple case: reset the exception state, done
code
.
putln
(
"PyErr_Restore(0,0,0);"
)
code
.
put_goto
(
end_label
)
code
.
putln
(
"}"
)
return
code
.
putln
(
'__Pyx_AddTraceback("%s");'
%
self
.
function_name
)
code
.
putln
(
'__Pyx_AddTraceback("%s");'
%
self
.
function_name
)
# We always have to fetch the exception value even if
# We always have to fetch the exception value even if
# there is no target, because this also normalises the
# there is no target, because this also normalises the
...
...
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