-
-
Notifications
You must be signed in to change notification settings - Fork 122
fix ref bug with iter, views and istr #1311
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1db2d00
fix ref bug with iter, views and istr
Vizonex f1c199f
add bugfix to timeline
Vizonex 8756a8c
fix crash
Vizonex ac7e50e
fix crash
Vizonex b105a4a
Merge branch 'master' into iterator-ref-leak
bdraco 81aa7b7
add type leak test to testsuite
Vizonex 7e0f887
Merge branch 'iterator-ref-leak' of https://github.com/Vizonex/multid…
Vizonex ec06238
rather than stick to python's dictionary traditions try freeing the t…
Vizonex 5d7d955
cast str object
Vizonex 5faf6d6
fix tests must've been mistakeful programming
Vizonex 731c82d
turns out freethreaded mode cleans up more types so use a lt operator…
Vizonex acbe739
add a test back in seems it was missing on accident.
Vizonex 1d0b323
try to make code-coverage little bit more happy
Vizonex 2c11dd9
fix ranges in code coverage
Vizonex 064710a
Merge branch 'master' into iterator-ref-leak
Vizonex d8093f7
add #1314 to timeline
Vizonex c06e3a0
Delete CHANGES/1314.feature.rst WRONG BRANCH SORRY :(
Vizonex 3eb26a1
Merge branch 'master' into iterator-ref-leak
bdraco e777b36
fix missing self traverse
bdraco f0ede3d
cleanup
bdraco a9007d7
0 leaks allowed, skip on ft
bdraco 324d624
items values as well
bdraco f94782d
Merge branch 'master' into iterator-ref-leak
bdraco 9ff2c61
newline
bdraco f94b029
Merge branch 'master' into iterator-ref-leak
bdraco 959a16b
Merge branch 'master' into iterator-ref-leak
Vizonex c7d3d1d
Merge branch 'master' into iterator-ref-leak
bdraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fixed reference leak in iterators, views and ``istr`` | ||
| -- by :user:`Vizonex`. |
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import gc | ||
| import sys | ||
| import sysconfig | ||
|
|
||
| from multidict import MultiDict, istr | ||
|
|
||
| # sys.getrefcount is not meaningful under the free-threaded build: | ||
| # refcounts are biased per-thread and types may be immortalized, so | ||
| # the simple baseline/after comparison below does not apply. | ||
| FREETHREADED = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if FREETHREADED: | ||
| raise SystemExit(0) | ||
|
|
||
| md = MultiDict([("a", "1"), ("b", "2")]) | ||
|
|
||
| # Iterator type leak | ||
| iter_type = type(iter(md.keys())) | ||
| gc.collect() | ||
| baseline = sys.getrefcount(iter_type) | ||
| for _ in range(1000): | ||
| _it = iter(md.keys()) | ||
| list(_it) | ||
| del _it | ||
| gc.collect() | ||
| after = sys.getrefcount(iter_type) | ||
| assert after == baseline, f"iterator type leaked: {after - baseline}" | ||
|
|
||
| # View type leak | ||
| view_type = type(md.keys()) | ||
| gc.collect() | ||
| baseline = sys.getrefcount(view_type) | ||
| for _ in range(1000): | ||
| _v = md.keys() | ||
| del _v | ||
| gc.collect() | ||
| after = sys.getrefcount(view_type) | ||
| assert after == baseline, f"view type leaked: {after - baseline}" | ||
|
|
||
| # istr type leak | ||
| gc.collect() | ||
| baseline = sys.getrefcount(istr) | ||
| for _ in range(1000): | ||
| _s = istr("hello") | ||
|
|
||
| del _s | ||
| gc.collect() | ||
| after = sys.getrefcount(istr) | ||
| assert after == baseline, f"istr type leaked: {after - baseline}" | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.