Skip to content

Commit e594090

Browse files
committed
BufferProtocol -> AsBuffer
1 parent 888b382 commit e594090

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

vm/src/builtins/bytearray.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use crate::common::lock::{
2020
};
2121
use crate::function::{FuncArgs, OptionalArg, OptionalOption};
2222
use crate::sliceable::{PySliceableSequence, PySliceableSequenceMut, SequenceIndex};
23-
use crate::slots::{
24-
BufferProtocol, Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable,
25-
};
23+
use crate::slots::{AsBuffer, Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable};
2624
use crate::utils::Either;
2725
use crate::vm::VirtualMachine;
2826
use crate::{
@@ -99,7 +97,7 @@ pub(crate) fn init(context: &PyContext) {
9997
PyByteArrayIterator::extend_class(context, &context.types.bytearray_iterator_type);
10098
}
10199

102-
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, BufferProtocol, Iterable))]
100+
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, AsBuffer, Iterable))]
103101
impl PyByteArray {
104102
#[pyslot]
105103
fn tp_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
@@ -667,7 +665,7 @@ impl Comparable for PyByteArray {
667665
}
668666
}
669667

670-
impl BufferProtocol for PyByteArray {
668+
impl AsBuffer for PyByteArray {
671669
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
672670
zelf.exports.fetch_add(1);
673671
let buf = ByteArrayBuffer {

vm/src/builtins/bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::bytesinner::{
1212
use crate::byteslike::PyBytesLike;
1313
use crate::common::hash::PyHash;
1414
use crate::function::{OptionalArg, OptionalOption};
15-
use crate::slots::{BufferProtocol, Comparable, Hashable, Iterable, PyComparisonOp, PyIter};
15+
use crate::slots::{AsBuffer, Comparable, Hashable, Iterable, PyComparisonOp, PyIter};
1616
use crate::utils::Either;
1717
use crate::vm::VirtualMachine;
1818
use crate::{
@@ -96,7 +96,7 @@ pub(crate) fn init(context: &PyContext) {
9696
PyBytesIterator::extend_class(context, &context.types.bytes_iterator_type);
9797
}
9898

99-
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, BufferProtocol, Iterable))]
99+
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, AsBuffer, Iterable))]
100100
impl PyBytes {
101101
#[pyslot]
102102
fn tp_new(
@@ -500,7 +500,7 @@ impl PyBytes {
500500
}
501501
}
502502

503-
impl BufferProtocol for PyBytes {
503+
impl AsBuffer for PyBytes {
504504
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
505505
let buf = BytesBuffer {
506506
bytes: zelf.clone(),

vm/src/builtins/memory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::common::hash::PyHash;
1010
use crate::common::lock::OnceCell;
1111
use crate::function::{FuncArgs, OptionalArg};
1212
use crate::sliceable::{convert_slice, saturate_range, wrap_index, SequenceIndex};
13-
use crate::slots::{BufferProtocol, Comparable, Hashable, PyComparisonOp};
13+
use crate::slots::{AsBuffer, Comparable, Hashable, PyComparisonOp};
1414
use crate::stdlib::pystruct::_struct::FormatSpec;
1515
use crate::utils::Either;
1616
use crate::{
@@ -51,7 +51,7 @@ pub struct PyMemoryView {
5151

5252
type PyMemoryViewRef = PyRef<PyMemoryView>;
5353

54-
#[pyimpl(with(Hashable, Comparable, BufferProtocol))]
54+
#[pyimpl(with(Hashable, Comparable, AsBuffer))]
5555
impl PyMemoryView {
5656
fn parse_format(format: &str, vm: &VirtualMachine) -> PyResult<FormatSpec> {
5757
FormatSpec::parse(format)
@@ -695,7 +695,7 @@ impl Drop for PyMemoryView {
695695
}
696696
}
697697

698-
impl BufferProtocol for PyMemoryView {
698+
impl AsBuffer for PyMemoryView {
699699
fn get_buffer(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
700700
if zelf.released.load() {
701701
Err(vm.new_value_error("operation forbidden on released memoryview object".to_owned()))

vm/src/slots.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub trait SlotSetattro: PyValue {
493493
}
494494

495495
#[pyimpl]
496-
pub trait BufferProtocol: PyValue {
496+
pub trait AsBuffer: PyValue {
497497
#[pyslot]
498498
fn tp_as_buffer(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
499499
if let Some(zelf) = zelf.downcast_ref() {

vm/src/stdlib/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::common::lock::{
1313
};
1414
use crate::function::OptionalArg;
1515
use crate::sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut};
16-
use crate::slots::{BufferProtocol, Comparable, Iterable, PyComparisonOp, PyIter};
16+
use crate::slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter};
1717
use crate::utils::Either;
1818
use crate::VirtualMachine;
1919
use crate::{
@@ -488,7 +488,7 @@ impl From<ArrayContentType> for PyArray {
488488
}
489489
}
490490

491-
#[pyimpl(flags(BASETYPE), with(Comparable, BufferProtocol, Iterable))]
491+
#[pyimpl(flags(BASETYPE), with(Comparable, AsBuffer, Iterable))]
492492
impl PyArray {
493493
fn read(&self) -> PyRwLockReadGuard<'_, ArrayContentType> {
494494
self.array.read()
@@ -848,7 +848,7 @@ impl Comparable for PyArray {
848848
}
849849
}
850850

851-
impl BufferProtocol for PyArray {
851+
impl AsBuffer for PyArray {
852852
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
853853
zelf.exports.fetch_add(1);
854854
let array = zelf.read();

0 commit comments

Comments
 (0)