Skip to content

Commit 545d18f

Browse files
youknowoneqingshi163
authored andcommitted
unbox tp_buffer
1 parent 88d4f05 commit 545d18f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

derive/src/pyclass.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,22 @@ where
344344
let slot_ident = item_meta.slot_name()?;
345345
let slot_name = slot_ident.to_string();
346346
let tokens = {
347-
if slot_name == "new" {
348-
let into_func = quote_spanned! {ident.span() =>
347+
let into_func = if slot_name == "new" {
348+
quote_spanned! {ident.span() =>
349349
::rustpython_vm::function::IntoPyNativeFunc::into_func(Self::#ident)
350-
};
351-
quote! {
352-
slots.#slot_ident = Some(#into_func);
353350
}
354-
} else if slot_name == "buffer" {
355-
let into_func = quote_spanned! {ident.span() =>
356-
::std::boxed::Box::new(Self::#ident)
357-
};
351+
} else {
352+
quote_spanned! {ident.span() =>
353+
Self::#ident as _
354+
}
355+
};
356+
if slot_name == "new" || slot_name == "buffer" {
358357
quote! {
359358
slots.#slot_ident = Some(#into_func);
360359
}
361360
} else {
362361
quote! {
363-
slots.#slot_ident.store(Some(Self::#ident as _))
362+
slots.#slot_ident.store(Some(#into_func))
364363
}
365364
}
366365
};

vm/src/slots.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct PyClassSlots {
6767
}
6868

6969
type BufferFunc =
70-
Box<py_dyn_fn!(dyn Fn(PyObjectRef, &VirtualMachine) -> PyResult<Box<dyn BufferProtocol>>)>;
70+
fn(PyObjectRef, &VirtualMachine) -> PyResult<Box<dyn BufferProtocol>>;
7171

7272
impl PyClassSlots {
7373
pub fn from_flags(flags: PyTpFlags) -> Self {

0 commit comments

Comments
 (0)