Refactor PyBuffer#3029
Merged
Merged
Conversation
fd029dc to
1b912aa
Compare
youknowone
commented
Sep 12, 2021
| #[derive(Debug)] | ||
| pub struct PyBuffer { | ||
| pub options: BufferOptions, | ||
| pub(crate) internal: PyRc<dyn PyBufferInternal>, |
Member
Author
There was a problem hiding this comment.
Use Rc rather than Box for now. A lot simpler, only with tiny overhead comparing to creating a PyBuffer object itself.
|
|
||
| pub trait PyBuffer: Debug + PyThreadingConstraint { | ||
| fn get_options(&self) -> &BufferOptions; | ||
| pub trait PyBufferInternal: Debug + PyThreadingConstraint { |
Member
Author
There was a problem hiding this comment.
split the role of buffer internal and PyBuffer
| fn obj_bytes_mut(&self) -> BorrowedValueMut<[u8]>; | ||
| fn release(&self); | ||
| // not included in PyBuffer protocol itself | ||
| fn retain(&self); |
Member
Author
There was a problem hiding this comment.
type based RC rather than manual counting
| stop: usize, | ||
| // step can be negative, means read the memory from stop-1 to start | ||
| step: isize, | ||
| exports: AtomicCell<usize>, |
Member
Author
There was a problem hiding this comment.
This variable does nothing for memoryview. RC for release will be tracked by obj: PyObjectRef and Drop for PyBuffer
835ad82 to
437647e
Compare
Member
Author
|
@qingshi163 could you review this PR? |
5d8f1b1 to
a6fb210
Compare
PyBuffer doesn't require vtable access for options maintaining internal using manual Rc model
a6fb210 to
f2ecab4
Compare
DimitrisJim
approved these changes
Sep 15, 2021
DimitrisJim
left a comment
Member
There was a problem hiding this comment.
as far as I can tell, lgtm
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
resembled CPython Py_buffer, less access to internal through vtable