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
Gwenaël Samain
cython
Commits
bc07e339
Commit
bc07e339
authored
Nov 17, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed ref-count bug in try-except handling
parent
bc80f4d2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-0
tests/run/exceptionrefcount.pyx
tests/run/exceptionrefcount.pyx
+55
-0
No files found.
Cython/Compiler/Nodes.py
View file @
bc07e339
...
@@ -3882,6 +3882,8 @@ class TryExceptStatNode(StatNode):
...
@@ -3882,6 +3882,8 @@ class TryExceptStatNode(StatNode):
self
.
else_clause
.
generate_execution_code
(
code
)
self
.
else_clause
.
generate_execution_code
(
code
)
code
.
putln
(
code
.
putln
(
"}"
)
"}"
)
for
var
in
Naming
.
exc_save_vars
:
code
.
put_xdecref_clear
(
var
,
py_object_type
)
code
.
put_goto
(
try_end_label
)
code
.
put_goto
(
try_end_label
)
code
.
put_label
(
our_error_label
)
code
.
put_label
(
our_error_label
)
code
.
put_var_xdecrefs_clear
(
self
.
cleanup_list
)
code
.
put_var_xdecrefs_clear
(
self
.
cleanup_list
)
...
...
tests/run/exceptionrefcount.pyx
0 → 100644
View file @
bc07e339
__doc__
=
u"""
>>> class SampleException(Exception): pass
>>> import sys
>>> def assert_refcount(rc1, rc2, func):
... # test ref-counts, but allow a bit of freedom
... assert rc2 <= rc1 + 4, "%s, before: %d, after %d" % (
... func.__name__, rc1, rc2)
>>> def run_test(repeat, test_func):
... initial_refcount = sys.getrefcount(SampleException)
... for i in range(repeat):
... try: raise SampleException
... except:
... refcount1 = sys.getrefcount(SampleException)
... test_func()
... refcount2 = sys.getrefcount(SampleException)
...
... assert_refcount(refcount1, refcount2, test_func)
... assert_refcount(initial_refcount, refcount2, test_func)
... refcount3 = sys.getrefcount(SampleException)
... assert_refcount(refcount1, refcount3, test_func)
... assert_refcount(initial_refcount, refcount3, test_func)
>>> run_test(50, test_no_exception_else)
>>> run_test(50, test_no_exception)
>>> run_test(50, test_exception)
>>> run_test(50, test_finally)
"""
def
test_no_exception
():
try
:
a
=
1
+
1
except
:
pass
def
test_no_exception_else
():
try
:
a
=
1
+
1
except
:
pass
else
:
b
=
1
+
1
def
test_exception
():
try
:
raise
TypeError
except
:
pass
def
test_finally
():
try
:
a
=
1
+
1
finally
:
b
=
1
+
1
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