Skip to content

Commit 81e8638

Browse files
committed
temp
1 parent 86a9639 commit 81e8638

29 files changed

+224
-113
lines changed

stdlib/src/sqlite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mod _sqlite {
6060
PyBaseException, PyBaseExceptionRef, PyByteArray, PyBytes, PyDict, PyDictRef, PyFloat,
6161
PyInt, PyIntRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
6262
},
63-
convert::{IntoObject, ToPyException},
63+
convert::IntoObject,
6464
function::{ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue},
6565
object::{Traverse, TraverseFn},
6666
protocol::{PyBuffer, PyIterReturn, PyMappingMethods, PySequence, PySequenceMethods},
@@ -2301,7 +2301,7 @@ mod _sqlite {
23012301
sql: PyStrRef,
23022302
vm: &VirtualMachine,
23032303
) -> PyResult<Option<Self>> {
2304-
let sql = sql.try_into_utf8(vm)?;
2304+
let _ = sql.try_to_str(vm)?;
23052305
if sql.as_str().contains('\0') {
23062306
return Err(new_programming_error(
23072307
vm,

vm/src/builtins/bool.rs

Lines changed: 4 additions & 4 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,7 +182,7 @@ 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 {

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: 3 additions & 3 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 {
@@ -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() {

vm/src/builtins/frame.rs

Lines changed: 2 additions & 2 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,7 +20,7 @@ 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 .. >";
2525
Ok(vm.ctx.intern_str(REPR).to_owned())
2626
}

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, PyWtf8StrRef};
6363
#[path = "super.rs"]
6464
pub(crate) mod super_;
6565
pub use super_::PySuper;

vm/src/builtins/module.rs

Lines changed: 5 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,13 @@ 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"))?)
216217
}
217218

218219
#[cold]

vm/src/builtins/object.rs

Lines changed: 8 additions & 8 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
@@ -370,7 +370,7 @@ impl PyBaseObject {
370370

371371
/// Return repr(self).
372372
#[pymethod]
373-
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
373+
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
374374
Self::slot_repr(&zelf, vm)
375375
}
376376

@@ -392,14 +392,14 @@ impl PyBaseObject {
392392
obj: PyObjectRef,
393393
format_spec: PyStrRef,
394394
vm: &VirtualMachine,
395-
) -> PyResult<PyStrRef> {
395+
) -> PyResult<PyRef<PyWtf8Str>> {
396396
if !format_spec.is_empty() {
397397
return Err(vm.new_type_error(format!(
398398
"unsupported format string passed to {}.__format__",
399399
obj.class().name()
400400
)));
401401
}
402-
obj.str(vm)
402+
obj.str_wtf8(vm)
403403
}
404404

405405
#[pyslot]

vm/src/builtins/singletons.rs

Lines changed: 4 additions & 4 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,7 +53,7 @@ impl PyNone {
5353

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

@@ -110,7 +110,7 @@ impl PyNotImplemented {
110110

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

0 commit comments

Comments
 (0)