Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
non-destructive text micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
badge fixer
non-destructive text micropython
Commits
8047340d
Commit
8047340d
authored
9 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Handle case of return within the finally block of try-finally.
Addresses issue #1636.
parent
117158fc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/vm.c
+8
-0
8 additions, 0 deletions
py/vm.c
tests/basics/try_finally_return2.py
+104
-0
104 additions, 0 deletions
tests/basics/try_finally_return2.py
with
112 additions
and
0 deletions
py/vm.c
+
8
−
0
View file @
8047340d
...
...
@@ -1032,6 +1032,14 @@ unwind_jump:;
ENTRY
(
MP_BC_RETURN_VALUE
)
:
MARK_EXC_IP_SELECTIVE
();
// These next 3 lines pop a try-finally exception handler, if one
// is there on the exception stack. Without this the finally block
// is executed a second time when the return is executed, because
// the try-finally exception handler is still on the stack.
// TODO Possibly find a better way to handle this case.
if
(
currently_in_except_block
)
{
POP_EXC_BLOCK
();
}
unwind_return:
while
(
exc_sp
>=
exc_stack
)
{
if
(
MP_TAGPTR_TAG1
(
exc_sp
->
val_sp
))
{
...
...
This diff is collapsed.
Click to expand it.
tests/basics/try_finally_return2.py
0 → 100644
+
104
−
0
View file @
8047340d
# test 'return' within the finally block
# it should swallow the exception
# simple case
def
f
():
try
:
raise
ValueError
()
finally
:
print
(
'
finally
'
)
return
0
print
(
'
got here
'
)
print
(
f
())
# nested, return in outer
def
f
():
try
:
try
:
raise
ValueError
finally
:
print
(
'
finally 1
'
)
print
(
'
got here
'
)
finally
:
print
(
'
finally 2
'
)
return
2
print
(
'
got here
'
)
print
(
f
())
# nested, return in inner
def
f
():
try
:
try
:
raise
ValueError
finally
:
print
(
'
finally 1
'
)
return
1
print
(
'
got here
'
)
finally
:
print
(
'
finally 2
'
)
print
(
'
got here
'
)
print
(
f
())
# nested, return in inner and outer
def
f
():
try
:
try
:
raise
ValueError
finally
:
print
(
'
finally 1
'
)
return
1
print
(
'
got here
'
)
finally
:
print
(
'
finally 2
'
)
return
2
print
(
'
got here
'
)
print
(
f
())
# nested with reraise
def
f
():
try
:
try
:
raise
ValueError
except
:
raise
print
(
'
got here
'
)
finally
:
print
(
'
finally
'
)
return
0
print
(
'
got here
'
)
print
(
f
())
# triple nesting with reraise
def
f
():
try
:
try
:
try
:
raise
ValueError
except
:
raise
except
:
raise
finally
:
print
(
'
finally
'
)
return
0
print
(
f
())
# exception when matching exception
def
f
():
try
:
raise
ValueError
except
NonExistingError
:
pass
finally
:
print
(
'
finally
'
)
return
0
print
(
f
())
# raising exception class, not instance
def
f
():
try
:
raise
ValueError
finally
:
print
(
'
finally
'
)
return
0
print
(
f
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment