- Notifications
You must be signed in to change notification settings - Fork750
Fix exception refcnt#1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
BadSingleton wants to merge6 commits intopythonnet:masterfromUnity-Technologies:fix-exception-refcnt
Uh oh!
There was an error while loading.Please reload this page.
Closed
Fix exception refcnt#1402
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
ee30c94
Fix a ref count issue in PythonException
BadSingleton480a549
Fixes a leak in ExceptionClassObject
BadSingleton5ea9c3c
Code review fixes
BadSingleton891ad8c
code review fixes
BadSingletond180f2a
kick the build
BadSingleton47290ee
kick the build, again
BadSingletonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 0 additions & 1 deletionsrc/domain_tests/test_domain_reload.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionssrc/runtime/classbase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletionssrc/runtime/clrobject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
31 changes: 26 additions & 5 deletionssrc/runtime/exceptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssrc/runtime/importhook.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletionssrc/testing/exceptiontest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletionstests/test_exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,6 +9,53 @@ | ||
import pickle | ||
# begin code from https://utcc.utoronto.ca/~cks/space/blog/python/GetAllObjects | ||
filmor marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
import gc | ||
# Recursively expand slist's objects | ||
# into olist, using seen to track | ||
# already processed objects. | ||
def _getr(slist, olist, seen): | ||
for e in slist: | ||
if id(e) in seen: | ||
continue | ||
seen[id(e)] = None | ||
olist.append(e) | ||
tl = gc.get_referents(e) | ||
if tl: | ||
_getr(tl, olist, seen) | ||
# The public function. | ||
def get_all_objects(): | ||
gcl = gc.get_objects() | ||
olist = [] | ||
seen = {} | ||
# Just in case: | ||
seen[id(gcl)] = None | ||
seen[id(olist)] = None | ||
seen[id(seen)] = None | ||
# _getr does the real work. | ||
_getr(gcl, olist, seen) | ||
return olist | ||
# end code from https://utcc.utoronto.ca/~cks/space/blog/python/GetAllObjects | ||
def leak_check(func): | ||
def do_leak_check(): | ||
func() | ||
gc.collect() | ||
exc = {x for x in get_all_objects() if isinstance(x, Exception) and not isinstance(x, pytest.PytestDeprecationWarning)} | ||
print(len(exc)) | ||
if len(exc): | ||
for x in exc: | ||
print('-------') | ||
print(repr(x)) | ||
print(gc.get_referrers(x)) | ||
print(len(gc.get_referrers(x))) | ||
assert False | ||
gc.collect() | ||
return do_leak_check | ||
def test_unified_exception_semantics(): | ||
"""Test unified exception semantics.""" | ||
e = System.Exception('Something bad happened') | ||
@@ -375,3 +422,31 @@ def test_iteration_innerexception(): | ||
# after exception is thrown iterator is no longer valid | ||
with pytest.raises(StopIteration): | ||
next(val) | ||
def leak_test(func): | ||
def do_test_leak(): | ||
# PyTest leaks things, gather the current state | ||
orig_exc = {x for x in get_all_objects() if isinstance(x, Exception)} | ||
func() | ||
exc = {x for x in get_all_objects() if isinstance(x, Exception)} | ||
possibly_leaked = exc - orig_exc | ||
assert not possibly_leaked | ||
return do_test_leak | ||
@leak_test | ||
def test_dont_leak_exceptions_simple(): | ||
from Python.Test import ExceptionTest | ||
try: | ||
ExceptionTest.DoThrowSimple() | ||
except System.ArgumentException: | ||
print('type error, as expected') | ||
@leak_test | ||
def test_dont_leak_exceptions_inner(): | ||
from Python.Test import ExceptionTest | ||
try: | ||
ExceptionTest.DoThrowWithInner() | ||
except TypeError: | ||
print('type error, as expected') |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.