-
Notifications
You must be signed in to change notification settings - Fork 773
Proposal: Safe pointers #1043
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
Proposal: Safe pointers #1043
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a84a1e
NewReference type and an example usage
lostmsu 88944a2
BorrowedReference + example, that exposes dangerous pattern
lostmsu e1ba92c
actually, borrowed refrences can be copied
lostmsu 2d11f82
make BorrowedReference readonly ref struct
lostmsu dbb3dc5
updated old project file
lostmsu 7304b25
BorrowedReference.Pointer is a private readonly field
lostmsu 2bc218c
drop C# 8.0 requirement
lostmsu 2cf9fc3
renamed NewReference.ToPyObject to MoveToPyObject
lostmsu 6ae63cd
added xmldoc comments to *Reference members
lostmsu 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
renamed NewReference.ToPyObject to MoveToPyObject
removed public property Pointer from NewReference and replaced with DangerousGetAddress
- Loading branch information
commit 2cf9fc36872789bbbb863a173addb4b35b7c5e95
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
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.
Is it necessary to limit it as a stack-allocated value? If make it to a normal struct and rename it to
PyReference, it can be assigned to a collection and implement the IDisposable forusing ()usage.For better usage, a
BorrowedReferencemay be able to promote to aPyReferencefor using the implict operate overloading.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.
With
[NoCopyable]you won't be able to put it into a collection anyway. And without[NoCopyable]it does not provide any safety guarantees.Having it as
ref structsaves you from addingrefeverywhere you take it.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.
But....sometimes I just want to put them into collections...😂
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.
Then you can still do
DangerousGetHandleor create aPyObjectfrom them.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.
But this type also has a purpose for reminding others that it's a reference don't forget to decref it, isn't it?
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.
Because it must be clear from code, that care is necessary around this scenario.
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.
Also, as mentioned above,
[NoCopyable]would already prevent you from putting an instance into a collection, even ifrefwere removed. And[NoCopyable]is basically the sole purpose of this change, as if you doThen you already miappropriated refcounts.
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.
Maybe more introduce a type named
PyHandlefor that?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.
emmm, but that make
BorrowedReferenceembarrassed.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.
@amos402 The idea with
PyHandlecan be reviewed separately. This PR is only for tracking new vs borrowed references as used in Python documentation for C API.