Skip to content

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

Merged
merged 2 commits into from
Sep 15, 2021
Merged

Refactor PyBuffer #3029

merged 2 commits into from
Sep 15, 2021

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Sep 9, 2021

resembled CPython Py_buffer, less access to internal through vtable

@youknowone youknowone force-pushed the pybuffer branch 14 times, most recently from fd029dc to 1b912aa Compare September 12, 2021 14:21
#[derive(Debug)]
pub struct PyBuffer {
pub options: BufferOptions,
pub(crate) internal: PyRc<dyn PyBufferInternal>,
Copy link
Member Author

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 {
Copy link
Member Author

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);
Copy link
Member Author

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>,
Copy link
Member Author

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

@youknowone youknowone force-pushed the pybuffer branch 3 times, most recently from 835ad82 to 437647e Compare September 12, 2021 15:33
@youknowone
Copy link
Member Author

@qingshi163 could you review this PR?

@youknowone youknowone force-pushed the pybuffer branch 2 times, most recently from 5d8f1b1 to a6fb210 Compare September 13, 2021 03:43
Copy link
Contributor

@qingshi163 qingshi163 left a 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
Copy link
Member

@DimitrisJim DimitrisJim left a 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

@youknowone youknowone merged commit 00a86ba into RustPython:main Sep 15, 2021
@youknowone youknowone deleted the pybuffer branch September 15, 2021 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants