Skip to content

Commit 798b3bc

Browse files
committed
expose slot_new_wrapper as its base type
1 parent 18044ab commit 798b3bc

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

vm/src/class.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
builtins::{PyBaseObject, PyBoundMethod, PyType, PyTypeRef},
55
identifier,
6-
object::{Py, PyObjectRef},
6+
object::Py,
77
types::{hash_not_implemented, PyTypeFlags, PyTypeSlots},
88
vm::Context,
99
};
@@ -99,10 +99,12 @@ pub trait PyClassImpl: PyClassDef {
9999
);
100100
}
101101
if class.slots.new.load().is_some() {
102-
let bound: PyObjectRef =
103-
PyBoundMethod::new_ref(class.to_owned().into(), ctx.slot_new_wrapper.clone(), ctx)
104-
.into();
105-
class.set_attr(identifier!(ctx, __new__), bound);
102+
let bound = PyBoundMethod::new_ref(
103+
class.to_owned().into(),
104+
ctx.slot_new_wrapper.clone().into(),
105+
ctx,
106+
);
107+
class.set_attr(identifier!(ctx, __new__), bound.into());
106108
}
107109

108110
if class.slots.hash.load().map_or(0, |h| h as usize) == hash_not_implemented as usize {

vm/src/vm/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct Context {
4545
pub int_cache_pool: Vec<PyIntRef>,
4646
// there should only be exact objects of str in here, no non-str objects and no subclasses
4747
pub(crate) string_pool: StringPool,
48-
pub(crate) slot_new_wrapper: PyObjectRef,
48+
pub(crate) slot_new_wrapper: PyRef<PyBuiltinFunction>,
4949
pub names: ConstName,
5050
}
5151

@@ -290,8 +290,7 @@ impl Context {
290290
let slot_new_wrapper = create_object(
291291
PyNativeFuncDef::new(PyType::__new__.into_func(), names.__new__).into_function(),
292292
types.builtin_function_or_method_type,
293-
)
294-
.into();
293+
);
295294

296295
let empty_str = unsafe { string_pool.intern("", types.str_type.to_owned()) }.to_owned();
297296
let empty_bytes = create_object(PyBytes::from(Vec::new()), types.bytes_type);

wasm/lib/src/convert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
216216
let func = js_sys::Function::from(js_val);
217217
vm.ctx
218218
.new_function(
219-
String::from(func.name()),
219+
String::from(func.name()).as_str(),
220220
move |args: FuncArgs, vm: &VirtualMachine| -> PyResult {
221221
let this = Object::new();
222222
for (k, v) in args.kwargs {

0 commit comments

Comments
 (0)