mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
BufferProtocol -> AsBuffer
This commit is contained in:
@@ -20,9 +20,7 @@ use crate::common::lock::{
|
||||
};
|
||||
use crate::function::{FuncArgs, OptionalArg, OptionalOption};
|
||||
use crate::sliceable::{PySliceableSequence, PySliceableSequenceMut, SequenceIndex};
|
||||
use crate::slots::{
|
||||
BufferProtocol, Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable,
|
||||
};
|
||||
use crate::slots::{AsBuffer, Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable};
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
@@ -99,7 +97,7 @@ pub(crate) fn init(context: &PyContext) {
|
||||
PyByteArrayIterator::extend_class(context, &context.types.bytearray_iterator_type);
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, BufferProtocol, Iterable))]
|
||||
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, AsBuffer, Iterable))]
|
||||
impl PyByteArray {
|
||||
#[pyslot]
|
||||
fn tp_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
@@ -667,7 +665,7 @@ impl Comparable for PyByteArray {
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferProtocol for PyByteArray {
|
||||
impl AsBuffer for PyByteArray {
|
||||
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
|
||||
zelf.exports.fetch_add(1);
|
||||
let buf = ByteArrayBuffer {
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::bytesinner::{
|
||||
use crate::byteslike::PyBytesLike;
|
||||
use crate::common::hash::PyHash;
|
||||
use crate::function::{OptionalArg, OptionalOption};
|
||||
use crate::slots::{BufferProtocol, Comparable, Hashable, Iterable, PyComparisonOp, PyIter};
|
||||
use crate::slots::{AsBuffer, Comparable, Hashable, Iterable, PyComparisonOp, PyIter};
|
||||
use crate::utils::Either;
|
||||
use crate::vm::VirtualMachine;
|
||||
use crate::{
|
||||
@@ -96,7 +96,7 @@ pub(crate) fn init(context: &PyContext) {
|
||||
PyBytesIterator::extend_class(context, &context.types.bytes_iterator_type);
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, BufferProtocol, Iterable))]
|
||||
#[pyimpl(flags(BASETYPE), with(Hashable, Comparable, AsBuffer, Iterable))]
|
||||
impl PyBytes {
|
||||
#[pyslot]
|
||||
fn tp_new(
|
||||
@@ -500,7 +500,7 @@ impl PyBytes {
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferProtocol for PyBytes {
|
||||
impl AsBuffer for PyBytes {
|
||||
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
|
||||
let buf = BytesBuffer {
|
||||
bytes: zelf.clone(),
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::common::hash::PyHash;
|
||||
use crate::common::lock::OnceCell;
|
||||
use crate::function::{FuncArgs, OptionalArg};
|
||||
use crate::sliceable::{convert_slice, saturate_range, wrap_index, SequenceIndex};
|
||||
use crate::slots::{BufferProtocol, Comparable, Hashable, PyComparisonOp};
|
||||
use crate::slots::{AsBuffer, Comparable, Hashable, PyComparisonOp};
|
||||
use crate::stdlib::pystruct::_struct::FormatSpec;
|
||||
use crate::utils::Either;
|
||||
use crate::{
|
||||
@@ -51,7 +51,7 @@ pub struct PyMemoryView {
|
||||
|
||||
type PyMemoryViewRef = PyRef<PyMemoryView>;
|
||||
|
||||
#[pyimpl(with(Hashable, Comparable, BufferProtocol))]
|
||||
#[pyimpl(with(Hashable, Comparable, AsBuffer))]
|
||||
impl PyMemoryView {
|
||||
fn parse_format(format: &str, vm: &VirtualMachine) -> PyResult<FormatSpec> {
|
||||
FormatSpec::parse(format)
|
||||
@@ -695,7 +695,7 @@ impl Drop for PyMemoryView {
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferProtocol for PyMemoryView {
|
||||
impl AsBuffer for PyMemoryView {
|
||||
fn get_buffer(zelf: &PyRef<Self>, vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
|
||||
if zelf.released.load() {
|
||||
Err(vm.new_value_error("operation forbidden on released memoryview object".to_owned()))
|
||||
|
||||
@@ -493,7 +493,7 @@ pub trait SlotSetattro: PyValue {
|
||||
}
|
||||
|
||||
#[pyimpl]
|
||||
pub trait BufferProtocol: PyValue {
|
||||
pub trait AsBuffer: PyValue {
|
||||
#[pyslot]
|
||||
fn tp_as_buffer(zelf: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
|
||||
if let Some(zelf) = zelf.downcast_ref() {
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::common::lock::{
|
||||
};
|
||||
use crate::function::OptionalArg;
|
||||
use crate::sliceable::{saturate_index, PySliceableSequence, PySliceableSequenceMut};
|
||||
use crate::slots::{BufferProtocol, Comparable, Iterable, PyComparisonOp, PyIter};
|
||||
use crate::slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter};
|
||||
use crate::utils::Either;
|
||||
use crate::VirtualMachine;
|
||||
use crate::{
|
||||
@@ -488,7 +488,7 @@ impl From<ArrayContentType> for PyArray {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyimpl(flags(BASETYPE), with(Comparable, BufferProtocol, Iterable))]
|
||||
#[pyimpl(flags(BASETYPE), with(Comparable, AsBuffer, Iterable))]
|
||||
impl PyArray {
|
||||
fn read(&self) -> PyRwLockReadGuard<'_, ArrayContentType> {
|
||||
self.array.read()
|
||||
@@ -848,7 +848,7 @@ impl Comparable for PyArray {
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferProtocol for PyArray {
|
||||
impl AsBuffer for PyArray {
|
||||
fn get_buffer(zelf: &PyRef<Self>, _vm: &VirtualMachine) -> PyResult<Box<dyn PyBuffer>> {
|
||||
zelf.exports.fetch_add(1);
|
||||
let array = zelf.read();
|
||||
|
||||
Reference in New Issue
Block a user