Skip to content

Commit 346ce1c

Browse files
committed
going
1 parent 5b10638 commit 346ce1c

File tree

21 files changed

+161
-113
lines changed

21 files changed

+161
-113
lines changed

vm/src/builtins/bool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::{PyInt, PyStrRef, PyType, PyTypeRef};
1+
use super::{PyInt, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
22
use crate::common::format::FormatSpec;
33
use crate::{
4-
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject,
5-
VirtualMachine,
4+
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
5+
TryFromBorrowedObject, VirtualMachine,
66
class::PyClassImpl,
77
convert::{IntoPyException, ToPyObject, ToPyResult},
88
function::OptionalArg,
@@ -182,13 +182,13 @@ impl AsNumber for PyBool {
182182

183183
impl Representable for PyBool {
184184
#[inline]
185-
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyStrRef> {
185+
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
186186
let name = if get_value(zelf.as_object()) {
187187
vm.ctx.names.True
188188
} else {
189189
vm.ctx.names.False
190190
};
191-
Ok(name.to_owned())
191+
Ok(name.to_owned().into_wtf8())
192192
}
193193

194194
#[cold]

vm/src/builtins/bytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of the python bytearray object.
22
use super::{
33
PositionIterInternal, PyBytes, PyBytesRef, PyDictRef, PyGenericAlias, PyIntRef, PyStrRef,
4-
PyTuple, PyTupleRef, PyType, PyTypeRef,
4+
PyTuple, PyTupleRef, PyType, PyTypeRef, pystr::PyWtf8Str,
55
};
66
use crate::{
77
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
@@ -673,7 +673,7 @@ impl PyRef<PyByteArray> {
673673
}
674674

675675
#[pymethod]
676-
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
676+
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
677677
bytes_decode(self.into(), args, vm)
678678
}
679679
}

vm/src/builtins/bytes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
22
PositionIterInternal, PyDictRef, PyGenericAlias, PyIntRef, PyStrRef, PyTuple, PyTupleRef,
3-
PyType, PyTypeRef,
3+
PyType, PyTypeRef, PyWtf8Str,
44
};
55
use crate::{
66
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
@@ -547,7 +547,7 @@ impl PyRef<PyBytes> {
547547
/// see https://docs.python.org/3/library/codecs.html#standard-encodings
548548
/// currently, only 'utf-8' and 'ascii' implemented
549549
#[pymethod]
550-
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
550+
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
551551
bytes_decode(self.into(), args, vm)
552552
}
553553
}

vm/src/builtins/dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
22
IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, PyMappingProxy, PySet,
3-
PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef, set::PySetInner,
3+
PyStr, PyTupleRef, PyType, PyTypeRef, PyWtf8Str, set::PySetInner,
44
};
55
use crate::{
66
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
@@ -506,7 +506,7 @@ impl Iterable for PyDict {
506506

507507
impl Representable for PyDict {
508508
#[inline]
509-
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
509+
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
510510
let s = if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {
511511
let mut str_parts = Vec::with_capacity(zelf.__len__());
512512
for (key, value) in zelf {
@@ -519,7 +519,7 @@ impl Representable for PyDict {
519519
} else {
520520
vm.ctx.intern_str("{...}").to_owned()
521521
};
522-
Ok(s)
522+
Ok(s.into_wtf8())
523523
}
524524

525525
#[cold]
@@ -812,7 +812,7 @@ macro_rules! dict_view {
812812

813813
impl Representable for $name {
814814
#[inline]
815-
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
815+
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
816816
let s = if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {
817817
let mut str_parts = Vec::with_capacity(zelf.__len__());
818818
for (key, value) in zelf.dict().clone() {
@@ -824,7 +824,7 @@ macro_rules! dict_view {
824824
} else {
825825
vm.ctx.intern_str("{...}").to_owned()
826826
};
827-
Ok(s)
827+
Ok(s.into_wtf8())
828828
}
829829

830830
#[cold]

vm/src/builtins/frame.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
*/
44

5-
use super::{PyCode, PyDictRef, PyIntRef, PyStrRef};
5+
use super::{PyCode, PyDictRef, PyIntRef, PyWtf8Str};
66
use crate::{
77
AsObject, Context, Py, PyObjectRef, PyRef, PyResult, VirtualMachine,
88
class::PyClassImpl,
@@ -20,9 +20,9 @@ impl Unconstructible for Frame {}
2020

2121
impl Representable for Frame {
2222
#[inline]
23-
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
23+
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
2424
const REPR: &str = "<frame object at .. >";
25-
Ok(vm.ctx.intern_str(REPR).to_owned())
25+
Ok(vm.ctx.intern_str(REPR).to_owned().into_wtf8())
2626
}
2727

2828
#[cold]

vm/src/builtins/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) mod bool_;
5959
pub use bool_::PyBool;
6060
#[path = "str.rs"]
6161
pub(crate) mod pystr;
62-
pub use pystr::{PyStr, PyStrInterned, PyStrRef};
62+
pub use pystr::{PyStr, PyStrInterned, PyStrRef, PyWtf8Str};
6363
#[path = "super.rs"]
6464
pub(crate) mod super_;
6565
pub use super_::PySuper;

vm/src/builtins/module.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{PyDict, PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef};
1+
use super::{PyDict, PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
22
use crate::{
33
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
44
builtins::{PyStrInterned, pystr::AsPyStr},
@@ -207,12 +207,14 @@ impl GetAttr for PyModule {
207207

208208
impl Representable for PyModule {
209209
#[inline]
210-
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
210+
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
211211
let importlib = vm.import("_frozen_importlib", 0)?;
212212
let module_repr = importlib.get_attr("_module_repr", vm)?;
213213
let repr = module_repr.call((zelf.to_owned(),), vm)?;
214-
repr.downcast()
215-
.map_err(|_| vm.new_type_error("_module_repr did not return a string"))
214+
Ok(repr
215+
.downcast::<PyStr>()
216+
.map_err(|_| vm.new_type_error("_module_repr did not return a string"))?
217+
.into_wtf8())
216218
}
217219

218220
#[cold]

vm/src/builtins/object.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef};
1+
use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
22
use crate::common::hash::PyHash;
33
use crate::types::PyTypeFlags;
44
use crate::{
5-
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
5+
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
66
class::PyClassImpl,
77
convert::ToPyResult,
88
function::{Either, FuncArgs, PyArithmeticValue, PyComparisonValue, PySetterValue},
@@ -333,13 +333,13 @@ impl PyBaseObject {
333333

334334
/// Return str(self).
335335
#[pymethod]
336-
fn __str__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
336+
fn __str__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
337337
// FIXME: try tp_repr first and fallback to object.__repr__
338-
zelf.repr(vm)
338+
zelf.repr_wtf8(vm)
339339
}
340340

341341
#[pyslot]
342-
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyStrRef> {
342+
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
343343
let class = zelf.class();
344344
match (
345345
class
@@ -358,19 +358,21 @@ impl PyBaseObject {
358358
qualname,
359359
zelf.get_id()
360360
))
361-
.into_ref(&vm.ctx)),
361+
.into_ref(&vm.ctx)
362+
.into_wtf8()),
362363
_ => Ok(PyStr::from(format!(
363364
"<{} object at {:#x}>",
364365
class.slot_name(),
365366
zelf.get_id()
366367
))
367-
.into_ref(&vm.ctx)),
368+
.into_ref(&vm.ctx)
369+
.into_wtf8()),
368370
}
369371
}
370372

371373
/// Return repr(self).
372374
#[pymethod]
373-
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
375+
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
374376
Self::slot_repr(&zelf, vm)
375377
}
376378

@@ -392,14 +394,14 @@ impl PyBaseObject {
392394
obj: PyObjectRef,
393395
format_spec: PyStrRef,
394396
vm: &VirtualMachine,
395-
) -> PyResult<PyStrRef> {
397+
) -> PyResult<PyRef<PyWtf8Str>> {
396398
if !format_spec.is_empty() {
397399
return Err(vm.new_type_error(format!(
398400
"unsupported format string passed to {}.__format__",
399401
obj.class().name()
400402
)));
401403
}
402-
obj.str(vm)
404+
obj.str_wtf8(vm)
403405
}
404406

405407
#[pyslot]

vm/src/builtins/singletons.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::{PyStrRef, PyType, PyTypeRef};
1+
use super::{PyStrRef, PyType, PyTypeRef, PyWtf8Str};
22
use crate::{
3-
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
3+
Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
44
class::PyClassImpl,
55
convert::ToPyObject,
66
protocol::PyNumberMethods,
@@ -53,8 +53,8 @@ impl PyNone {
5353

5454
impl Representable for PyNone {
5555
#[inline]
56-
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
57-
Ok(vm.ctx.names.None.to_owned())
56+
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
57+
Ok(vm.ctx.names.None.to_owned().into_wtf8())
5858
}
5959

6060
#[cold]
@@ -110,8 +110,8 @@ impl PyNotImplemented {
110110

111111
impl Representable for PyNotImplemented {
112112
#[inline]
113-
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
114-
Ok(vm.ctx.names.NotImplemented.to_owned())
113+
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
114+
Ok(vm.ctx.names.NotImplemented.to_owned().into_wtf8())
115115
}
116116

117117
#[cold]

vm/src/builtins/slice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// sliceobject.{h,c} in CPython
22
// spell-checker:ignore sliceobject
3-
use super::{PyGenericAlias, PyStrRef, PyTupleRef, PyType, PyTypeRef};
3+
use super::{PyGenericAlias, PyStrRef, PyTupleRef, PyType, PyTypeRef, PyWtf8Str};
44
use crate::{
55
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
66
class::PyClassImpl,
@@ -333,8 +333,8 @@ impl PyEllipsis {
333333

334334
impl Representable for PyEllipsis {
335335
#[inline]
336-
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
337-
Ok(vm.ctx.names.Ellipsis.to_owned())
336+
fn repr(_zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
337+
Ok(vm.ctx.names.Ellipsis.to_owned().into_wtf8())
338338
}
339339

340340
#[cold]

0 commit comments

Comments
 (0)