Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 1 addition & 7 deletions crates/vm/src/builtins/builtin_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Representable for PyNativeFunction {
impl Unconstructible for PyNativeFunction {}

// `PyCMethodObject` in CPython
#[pyclass(name = "builtin_method", module = false, base = PyNativeFunction)]
#[pyclass(name = "builtin_method", module = false, base = PyNativeFunction, ctx = "builtin_method_type")]
pub struct PyNativeMethod {
pub(crate) func: PyNativeFunction,
pub(crate) class: &'static Py<PyType>, // TODO: the actual life is &'self
Expand Down Expand Up @@ -189,12 +189,6 @@ impl PyNativeMethod {
}
}

impl PyPayload for PyNativeMethod {
fn class(ctx: &Context) -> &'static Py<PyType> {
ctx.types.builtin_method_type
}
}

impl fmt::Debug for PyNativeMethod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand Down
10 changes: 4 additions & 6 deletions crates/vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,12 +1932,10 @@ impl PyPayload for PyUtf8Str {
std::any::TypeId::of::<PyStr>()
}

fn downcastable_from(obj: &PyObject) -> bool {
obj.typeid() == Self::payload_type_id() && {
// SAFETY: we know the object is a PyStr in this context
let wtf8 = unsafe { obj.downcast_unchecked_ref::<PyStr>() };
wtf8.is_utf8()
}
fn validate_downcastable_from(obj: &PyObject) -> bool {
// SAFETY: we know the object is a PyStr in this context
let wtf8 = unsafe { obj.downcast_unchecked_ref::<PyStr>() };
wtf8.is_utf8()
}

fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
Expand Down
7 changes: 6 additions & 1 deletion crates/vm/src/object/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ pub trait PyPayload: MaybeTraverse + PyThreadingConstraint + Sized + 'static {
/// # Safety: this function should only be called if `payload_type_id` matches the type of `obj`.
#[inline]
fn downcastable_from(obj: &PyObject) -> bool {
obj.typeid() == Self::payload_type_id()
obj.typeid() == Self::payload_type_id() && Self::validate_downcastable_from(obj)
}

#[inline]
fn validate_downcastable_from(_obj: &PyObject) -> bool {
true
}

fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
Expand Down
Loading