Skip to content

Commit e18dda3

Browse files
committed
Buffer arguments as PyObject
1 parent 1fa69eb commit e18dda3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

vm/src/function/buffer.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::{
22
builtins::{PyStr, PyStrRef},
33
common::borrow::{BorrowedValue, BorrowedValueMut},
44
protocol::PyBuffer,
5-
PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, VirtualMachine,
5+
AsObject, PyObject, PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject,
6+
VirtualMachine,
67
};
78

89
// Python/getargs.c
@@ -57,6 +58,10 @@ impl ArgBytesLike {
5758
pub fn is_empty(&self) -> bool {
5859
self.len() == 0
5960
}
61+
62+
pub fn as_object(&self) -> &PyObject {
63+
&self.0.obj
64+
}
6065
}
6166

6267
impl From<ArgBytesLike> for PyBuffer {
@@ -126,6 +131,15 @@ pub enum ArgStrOrBytesLike {
126131
Str(PyStrRef),
127132
}
128133

134+
impl ArgStrOrBytesLike {
135+
pub fn as_object(&self) -> &PyObject {
136+
match self {
137+
Self::Buf(b) => b.as_object(),
138+
Self::Str(s) => s.as_object(),
139+
}
140+
}
141+
}
142+
129143
impl TryFromObject for ArgStrOrBytesLike {
130144
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
131145
obj.downcast()

0 commit comments

Comments
 (0)