Skip to content

Commit 8e2a268

Browse files
committed
Use PyBytesLike rather than PyBytesInner
1 parent c07d3f0 commit 8e2a268

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

vm/src/builtins.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod decl {
1414
use rustpython_parser::parser;
1515

1616
use super::to_ascii;
17-
use crate::bytesinner::PyBytesInner;
17+
use crate::byteslike::PyBytesLike;
1818
use crate::exceptions::PyBaseExceptionRef;
1919
use crate::function::{single_or_tuple_any, Args, KwArgs, OptionalArg, PyFuncArgs};
2020
use crate::obj::objbool::{self, IntoPyBool};
@@ -554,18 +554,18 @@ mod decl {
554554
}
555555

556556
#[pyfunction]
557-
fn ord(string: Either<PyBytesInner, PyStringRef>, vm: &VirtualMachine) -> PyResult<u32> {
557+
fn ord(string: Either<PyBytesLike, PyStringRef>, vm: &VirtualMachine) -> PyResult<u32> {
558558
match string {
559-
Either::A(bytes) => {
560-
let bytes_len = bytes.elements.len();
559+
Either::A(bytes) => bytes.with_ref(|bytes| {
560+
let bytes_len = bytes.len();
561561
if bytes_len != 1 {
562562
return Err(vm.new_type_error(format!(
563563
"ord() expected a character, but string of length {} found",
564564
bytes_len
565565
)));
566566
}
567-
Ok(u32::from(bytes.elements[0]))
568-
}
567+
Ok(u32::from(bytes[0]))
568+
}),
569569
Either::B(string) => {
570570
let string = string.as_str();
571571
let string_len = string.chars().count();

vm/src/bytesinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl TryFromObject for PyBytesInner {
4444
k @ PyMemoryView => Ok(PyBytesInner {
4545
elements: k.try_value().unwrap()
4646
}),
47-
l @ PyList => l.get_byte_inner(vm),
47+
l @ PyList => l.to_byte_inner(vm),
4848
obj => {
4949
let iter = vm.get_method_or_type_error(obj.clone(), "__iter__", || {
5050
format!("a bytes-like object is required, not {}", obj.class())

vm/src/obj/objlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl PyList {
6262
self.elements.write()
6363
}
6464

65-
pub(crate) fn get_byte_inner(&self, vm: &VirtualMachine) -> PyResult<bytesinner::PyBytesInner> {
65+
pub(crate) fn to_byte_inner(&self, vm: &VirtualMachine) -> PyResult<bytesinner::PyBytesInner> {
6666
let mut elements = Vec::<u8>::with_capacity(self.borrow_elements().len());
6767
for elem in self.borrow_elements().iter() {
6868
match PyIntRef::try_from_object(vm, elem.clone()) {

0 commit comments

Comments
 (0)