-
Notifications
You must be signed in to change notification settings - Fork 6
Upgrade to C++20 modules #43
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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
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
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,59 @@ | ||
| # An unset __slots__ entry must read as unset, however the slot storage was recycled. | ||
| # | ||
| # The storage lives in extra bytes past the object, and both the GC and the member | ||
| # accessor test each entry against null. Slab memory is poisoned rather than zeroed, | ||
| # so if the allocator does not clear those bytes an unset slot reads back as a | ||
| # non-null garbage pointer: the accessor returns it instead of raising AttributeError, | ||
| # and the GC dereferences it. | ||
|
|
||
|
|
||
| class C: | ||
| __slots__ = ("a", "b", "c") | ||
|
|
||
|
|
||
| def unset_raises(obj, name): | ||
| try: | ||
| getattr(obj, name) | ||
| except AttributeError: | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
|
|
||
| c = C() | ||
| c.a = 1 | ||
| assert c.a == 1 | ||
| assert unset_raises(c, "b"), "unset slot 'b' should raise AttributeError" | ||
| assert unset_raises(c, "c"), "unset slot 'c' should raise AttributeError" | ||
|
|
||
| # Churn so that later instances land on slots that were freed and poisoned. | ||
| for i in range(2000): | ||
| x = C() | ||
| x.a = i | ||
| x.b = i | ||
| x.c = i | ||
|
|
||
| for i in range(2000): | ||
| y = C() | ||
| y.a = i | ||
| assert y.a == i | ||
| assert unset_raises(y, "b"), "recycled slot 'b' should still read as unset" | ||
| assert unset_raises(y, "c"), "recycled slot 'c' should still read as unset" | ||
|
|
||
| # Slots that are set must survive a collection with their values intact. The list is a | ||
| # heap object reachable only through the slot, so the GC has to trace the slot correctly. | ||
| kept = [] | ||
| for i in range(500): | ||
| z = C() | ||
| z.a = i | ||
| z.b = [i, i + 1] | ||
| kept.append(z) | ||
|
|
||
| i = 0 | ||
| for z in kept: | ||
| assert z.a == i | ||
| assert z.b == [i, i + 1] | ||
| assert unset_raises(z, "c") | ||
| i += 1 | ||
|
|
||
| print("slots_uninitialised: ok") |
Oops, something went wrong.
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.