-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: Narrow conditions for load_value to give invalid address
#6157
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
Open
amjames
wants to merge
21
commits into
pybind:master
Choose a base branch
from
amjames:bugfix-6153
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b863457
fix: Guard against using a uninitialized value after `__new__` alloca…
amjames 66f8f37
fix: free lazily allocated storage on failed init and only permit laz…
henryiii 4991f00
Merge branch 'master' into amjames→bugfix-6153
rwgk b80c224
fix: isolate old-style constructor storage
rwgk 4455e3f
test: skip constructor thread test on Emscripten
rwgk 14e32ae
fix: bump internals version to 13
rwgk 9468fce
Revert "fix: bump internals version to 13"
rwgk 91122b1
Merge branch 'master' into amjames→bugfix-6153
rwgk bda1151
fix: recover from legacy constructor storage collisions
rwgk 23f2d0a
test: fix collision subprocess imports
rwgk 89a5f72
refactor: simplify old-style constructor storage tracking
henryiii 7a7e9f3
test: reject later self alias during old-style init
rwgk 955cb19
fix: restrict old-style constructor self permission to self's own loa…
607d3c6
style: pre-commit fixes
pre-commit-ci[bot] ad4544b
style: clang-tidy fixes
amjames f061048
fix: GraalPY exceptions
amjames bf7f96f
test: pin the two gaps identified in the load-phase review
amjames d1fbf07
perf: only test the old-style frame pointer where the phase can change
amjames ab56b0f
docs: describe status_value_constructing with the other status bits
amjames c10fcc5
style: pre-commit fixes
pre-commit-ci[bot] 182a9d0
style: clang-tidy/format
amjames 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
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 |
|---|---|---|
|
|
@@ -664,8 +664,10 @@ struct instance { | |
| * the [bb...] block (but not independently allocated). | ||
| * | ||
| * Status bits indicate whether the associated holder is constructed (& | ||
| * status_holder_constructed) and whether the value pointer is registered (& | ||
| * status_instance_registered) in `registered_instances`. | ||
| * status_holder_constructed), whether the value pointer is registered (& | ||
| * status_instance_registered) in `registered_instances`, and whether a constructor is | ||
| * currently constructing the C++ value in that slot (& status_value_constructing), during | ||
| * which the value pointer must not be treated as denoting a live C++ object. | ||
| */ | ||
| bool simple_layout : 1; | ||
| /// For simple layout, tracks whether the holder has been constructed | ||
|
|
@@ -676,6 +678,8 @@ struct instance { | |
| bool has_patients : 1; | ||
| /// If true, this Python object needs to be kept alive for the lifetime of the C++ value. | ||
| bool is_alias : 1; | ||
| /// For simple layout, tracks whether a constructor is currently constructing the C++ value. | ||
| bool simple_value_constructing : 1; | ||
|
|
||
| /// Initializes all of the above type/values/holders data (but not the instance values | ||
| /// themselves) | ||
|
|
@@ -693,6 +697,7 @@ struct instance { | |
| /// Bit values for the non-simple status flags | ||
| static constexpr uint8_t status_holder_constructed = 1; | ||
| static constexpr uint8_t status_instance_registered = 2; | ||
| static constexpr uint8_t status_value_constructing = 4; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A reference to this should be added in the comment above that describes the other two flags. |
||
| }; | ||
|
|
||
| static_assert(std::is_standard_layout<instance>::value, | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is begin_argument_load() defined? I don't see it in this PR or on master.
I wonder if we could add a
I == 0 &&or similar to the check here, so that we only pay for the null check once per call instead of once per argument.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
begin_argument_load is defined here.
We can pay for 2x per call. The phase only changes on the slot-0 to slot-1 transition; from argument 2 on it is already
later_argument, and the state carries across every remaining load.The phase is still checked on every argument load, but we skip the bookkeeping.
From claude
Getting it to exactly one check per call would mean initializing the frame to
self_argumentand transitioning only atI == 1, dropping thebefore_argumentsstate. I would rather not: that trades a local invariant for a non-local assumption that nothing loads a bound typebetween frame construction and argument 0.