Skip to content

Refactor PyBuffer#3029

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:pybuffer
Sep 15, 2021
Merged

Refactor PyBuffer#3029
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:pybuffer

Conversation

@youknowone

@youknowone youknowone commented Sep 9, 2021

Copy link
Copy Markdown
Member

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
Comment thread vm/src/buffer.rs
#[derive(Debug)]
pub struct PyBuffer {
pub options: BufferOptions,
pub(crate) internal: PyRc<dyn PyBufferInternal>,

Copy link
Copy Markdown
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.

Comment thread vm/src/buffer.rs

pub trait PyBuffer: Debug + PyThreadingConstraint {
fn get_options(&self) -> &BufferOptions;
pub trait PyBufferInternal: Debug + PyThreadingConstraint {

Copy link
Copy Markdown
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

Comment thread vm/src/buffer.rs
fn obj_bytes_mut(&self) -> BorrowedValueMut<[u8]>;
fn release(&self);
// not included in PyBuffer protocol itself
fn retain(&self);

Copy link
Copy Markdown
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

Comment thread vm/src/builtins/memory.rs
stop: usize,
// step can be negative, means read the memory from stop-1 to start
step: isize,
exports: AtomicCell<usize>,

Copy link
Copy Markdown
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
Copy Markdown
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

@qingshi163 qingshi163 left a comment

Copy link
Copy Markdown
Contributor

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

@DimitrisJim DimitrisJim left a comment

Copy link
Copy Markdown
Member

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