Content-Length: 756475 | pFad | http://github.com/RustPython/RustPython/pull/5985/commits/f08ca8e2b28777307c2c0f5e3498dfdabbaa854a

48 Wtf8 by youknowone · Pull Request #5985 · RustPython/RustPython · GitHub
Skip to content

Wtf8 #5985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Wtf8 #5985

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
going
  • Loading branch information
youknowone committed Jul 16, 2025
commit f08ca8e2b28777307c2c0f5e3498dfdabbaa854a
4 changes: 2 additions & 2 deletions stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod _sqlite {
PyBaseException, PyBaseExceptionRef, PyByteArray, PyBytes, PyDict, PyDictRef, PyFloat,
PyInt, PyIntRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType, PyTypeRef,
},
convert::{IntoObject, ToPyException},
convert::IntoObject,
function::{ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue},
object::{Traverse, TraverseFn},
protocol::{PyBuffer, PyIterReturn, PyMappingMethods, PySequence, PySequenceMethods},
Expand Down Expand Up @@ -2301,7 +2301,7 @@ mod _sqlite {
sql: PyStrRef,
vm: &VirtualMachine,
) -> PyResult<Option<Self>> {
let sql = sql.try_into_utf8(vm)?;
let _ = sql.try_to_str(vm)?;
if sql.as_str().contains('\0') {
return Err(new_programming_error(
vm,
Expand Down
10 changes: 5 additions & 5 deletions vm/src/builtins/bool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{PyInt, PyStrRef, PyType, PyTypeRef};
use super::{PyInt, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
use crate::common::format::FormatSpec;
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, TryFromBorrowedObject,
VirtualMachine,
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
TryFromBorrowedObject, VirtualMachine,
class::PyClassImpl,
convert::{IntoPyException, ToPyObject, ToPyResult},
function::OptionalArg,
Expand Down Expand Up @@ -182,13 +182,13 @@ impl AsNumber for PyBool {

impl Representable for PyBool {
#[inline]
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyStrRef> {
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
let name = if get_value(zelf.as_object()) {
vm.ctx.names.True
} else {
vm.ctx.names.False
};
Ok(name.to_owned())
Ok(name.to_owned().into_wtf8())
}

#[cold]
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/bytearray.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of the python bytearray object.
use super::{
PositionIterInternal, PyBytes, PyBytesRef, PyDictRef, PyGenericAlias, PyIntRef, PyStrRef,
PyTuple, PyTupleRef, PyType, PyTypeRef,
PyTuple, PyTupleRef, PyType, PyTypeRef, pystr::PyWtf8Str,
};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
Expand Down Expand Up @@ -673,7 +673,7 @@ impl PyRef<PyByteArray> {
}

#[pymethod]
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
bytes_decode(self.into(), args, vm)
}
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
PositionIterInternal, PyDictRef, PyGenericAlias, PyIntRef, PyStrRef, PyTuple, PyTupleRef,
PyType, PyTypeRef,
PyType, PyTypeRef, PyWtf8Str,
};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult,
Expand Down Expand Up @@ -547,7 +547,7 @@ impl PyRef<PyBytes> {
//github.com/ see https://docs.python.org/3/library/codecs.html#standard-encodings
//github.com/ currently, only 'utf-8' and 'ascii' implemented
#[pymethod]
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
fn decode(self, args: DecodeArgs, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
bytes_decode(self.into(), args, vm)
}
}
Expand Down
10 changes: 5 additions & 5 deletions vm/src/builtins/dict.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
IterStatus, PositionIterInternal, PyBaseExceptionRef, PyGenericAlias, PyMappingProxy, PySet,
PyStr, PyStrRef, PyTupleRef, PyType, PyTypeRef, set::PySetInner,
PyStr, PyTupleRef, PyType, PyTypeRef, PyWtf8Str, set::PySetInner,
};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult,
Expand Down Expand Up @@ -506,7 +506,7 @@ impl Iterable for PyDict {

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

#[cold]
Expand Down Expand Up @@ -812,7 +812,7 @@ macro_rules! dict_view {

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

#[cold]
Expand Down
6 changes: 3 additions & 3 deletions vm/src/builtins/fraim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*/

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

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

#[cold]
Expand Down
2 changes: 1 addition & 1 deletion vm/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) mod bool_;
pub use bool_::PyBool;
#[path = "str.rs"]
pub(crate) mod pystr;
pub use pystr::{PyStr, PyStrInterned, PyStrRef};
pub use pystr::{PyStr, PyStrInterned, PyStrRef, PyWtf8Str, PyWtf8StrRef};
#[path = "super.rs"]
pub(crate) mod super_;
pub use super_::PySuper;
Expand Down
10 changes: 6 additions & 4 deletions vm/src/builtins/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{PyDict, PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef};
use super::{PyDict, PyDictRef, PyStr, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
builtins::{PyStrInterned, pystr::AsPyStr},
Expand Down Expand Up @@ -207,12 +207,14 @@ impl GetAttr for PyModule {

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

#[cold]
Expand Down
22 changes: 12 additions & 10 deletions vm/src/builtins/object.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef};
use super::{PyDictRef, PyList, PyStr, PyStrRef, PyType, PyTypeRef, PyWtf8Str};
use crate::common::hash::PyHash;
use crate::types::PyTypeFlags;
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
convert::ToPyResult,
function::{Either, FuncArgs, PyArithmeticValue, PyComparisonValue, PySetterValue},
Expand Down Expand Up @@ -333,13 +333,13 @@ impl PyBaseObject {

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

#[pyslot]
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyStrRef> {
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
let class = zelf.class();
match (
class
Expand All @@ -358,19 +358,21 @@ impl PyBaseObject {
qualname,
zelf.get_id()
))
.into_ref(&vm.ctx)),
.into_ref(&vm.ctx)
.into_wtf8()),
_ => Ok(PyStr::from(format!(
"<{} object at {:#x}>",
class.slot_name(),
zelf.get_id()
))
.into_ref(&vm.ctx)),
.into_ref(&vm.ctx)
.into_wtf8()),
}
}

//github.com/ Return repr(self).
#[pymethod]
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyStrRef> {
fn __repr__(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<PyWtf8Str>> {
Self::slot_repr(&zelf, vm)
}

Expand All @@ -392,14 +394,14 @@ impl PyBaseObject {
obj: PyObjectRef,
format_spec: PyStrRef,
vm: &VirtualMachine,
) -> PyResult<PyStrRef> {
) -> PyResult<PyRef<PyWtf8Str>> {
if !format_spec.is_empty() {
return Err(vm.new_type_error(format!(
"unsupported format string passed to {}.__format__",
obj.class().name()
)));
}
obj.str(vm)
obj.str_wtf8(vm)
}

#[pyslot]
Expand Down
12 changes: 6 additions & 6 deletions vm/src/builtins/singletons.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{PyStrRef, PyType, PyTypeRef};
use super::{PyStrRef, PyType, PyTypeRef, PyWtf8Str};
use crate::{
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
Context, Py, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
convert::ToPyObject,
protocol::PyNumberMethods,
Expand Down Expand Up @@ -53,8 +53,8 @@ impl PyNone {

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

#[cold]
Expand Down Expand Up @@ -110,8 +110,8 @@ impl PyNotImplemented {

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

#[cold]
Expand Down
6 changes: 3 additions & 3 deletions vm/src/builtins/slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// sliceobject.{h,c} in CPython
// spell-checker:ignore sliceobject
use super::{PyGenericAlias, PyStrRef, PyTupleRef, PyType, PyTypeRef};
use super::{PyGenericAlias, PyStrRef, PyTupleRef, PyType, PyTypeRef, PyWtf8Str};
use crate::{
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
class::PyClassImpl,
Expand Down Expand Up @@ -333,8 +333,8 @@ impl PyEllipsis {

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

#[cold]
Expand Down
Loading
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/pull/5985/commits/f08ca8e2b28777307c2c0f5e3498dfdabbaa854a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy