diff mbox series

[06/13] rust: remove unused macro module_init!

Message ID 20241018144306.954716-7-pbonzini@redhat.com (mailing list archive)
State New
Headers show
Series rust: miscellaneous cleanups + QOM integration tests | expand

Commit Message

Paolo Bonzini Oct. 18, 2024, 2:42 p.m. UTC
Registering the object is now done by the #[derive(Object)] macro.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 rust/qemu-api/src/definitions.rs | 43 --------------------------------
 1 file changed, 43 deletions(-)

Comments

Junjie Mao Oct. 21, 2024, 10:16 a.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Registering the object is now done by the #[derive(Object)] macro.

The module_init! macro is still necessary when a device needs more logic
(in addition to a single type registration) in module init. That is not
rare among the devices in C we have today.

Manos and I had a conversation on this. He mentioned that he had a
second Rust device that needs this macro [1].

[1] https://lore.kernel.org/qemu-devel/itblf.by425lac4ow@linaro.org/

--
Best Regards
Junjie Mao

>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  rust/qemu-api/src/definitions.rs | 43 --------------------------------
>  1 file changed, 43 deletions(-)
Paolo Bonzini Oct. 21, 2024, 10:46 a.m. UTC | #2
Il lun 21 ott 2024, 12:19 Junjie Mao <junjie.mao@hotmail.com> ha scritto:

>
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
> > Registering the object is now done by the #[derive(Object)] macro.
>
> The module_init! macro is still necessary when a device needs more logic
> (in addition to a single type registration) in module init. That is not
> rare among the devices in C we have today.
>
> Manos and I had a conversation on this. He mentioned that he had a
> second Rust device that needs this macro [1].
>

Ok, I will change derive(Object) to use module_init! instead. What matters
is that module_init! is also fixed to not use the .ctors section.

Paolo


> [1] https://lore.kernel.org/qemu-devel/itblf.by425lac4ow@linaro.org/
>
> --
> Best Regards
> Junjie Mao
>
> >
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  rust/qemu-api/src/definitions.rs | 43 --------------------------------
> >  1 file changed, 43 deletions(-)
>
>
diff mbox series

Patch

diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs
index 49ac59af123..73ef9a52c1b 100644
--- a/rust/qemu-api/src/definitions.rs
+++ b/rust/qemu-api/src/definitions.rs
@@ -27,49 +27,6 @@  pub trait Class {
     >;
 }
 
-#[macro_export]
-macro_rules! module_init {
-    ($func:expr, $type:expr) => {
-        #[used]
-        #[cfg_attr(target_os = "linux", link_section = ".ctors")]
-        #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
-        #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
-        pub static LOAD_MODULE: extern "C" fn() = {
-            extern "C" fn __load() {
-                unsafe {
-                    $crate::bindings::register_module_init(Some($func), $type);
-                }
-            }
-
-            __load
-        };
-    };
-    (qom: $func:ident => $body:block) => {
-        // NOTE: To have custom identifiers for the ctor func we need to either supply
-        // them directly as a macro argument or create them with a proc macro.
-        #[used]
-        #[cfg_attr(target_os = "linux", link_section = ".ctors")]
-        #[cfg_attr(target_os = "macos", link_section = "__DATA,__mod_init_func")]
-        #[cfg_attr(target_os = "windows", link_section = ".CRT$XCU")]
-        pub static LOAD_MODULE: extern "C" fn() = {
-            extern "C" fn __load() {
-                unsafe extern "C" fn $func() {
-                    $body
-                }
-
-                unsafe {
-                    $crate::bindings::register_module_init(
-                        Some($func),
-                        $crate::bindings::module_init_type::MODULE_INIT_QOM,
-                    );
-                }
-            }
-
-            __load
-        };
-    };
-}
-
 #[macro_export]
 macro_rules! type_info {
     ($t:ty) => {