-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactor PyBuffer #3029
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
Refactor PyBuffer #3029
Conversation
fd029dc
to
1b912aa
Compare
#[derive(Debug)] | ||
pub struct PyBuffer { | ||
pub options: BufferOptions, | ||
pub(crate) internal: PyRc<dyn PyBufferInternal>, |
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.
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 { |
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.
split the role of buffer internal and PyBuffer
@@ -18,49 +16,78 @@ pub trait PyBuffer: Debug + PyThreadingConstraint { | |||
/// might operate on, among other footguns. | |||
fn obj_bytes_mut(&self) -> BorrowedValueMut<[u8]>; | |||
fn release(&self); | |||
// not included in PyBuffer protocol itself | |||
fn retain(&self); |
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.
type based RC rather than manual counting
@@ -44,7 +44,6 @@ pub struct PyMemoryView { | |||
stop: usize, | |||
// step can be negative, means read the memory from stop-1 to start | |||
step: isize, | |||
exports: AtomicCell<usize>, |
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.
This variable does nothing for memoryview. RC for release will be tracked by obj: PyObjectRef
and Drop for PyBuffer
835ad82
to
437647e
Compare
@qingshi163 could you review this PR? |
5d8f1b1
to
a6fb210
Compare
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.
Great!
PyBuffer doesn't require vtable access for options maintaining internal using manual Rc model
a6fb210
to
f2ecab4
Compare
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.
as far as I can tell, lgtm
resembled CPython Py_buffer, less access to internal through vtable