Skip to content

Commit fc719cd

Browse files
nbdd0121BennoLossin
authored andcommitted
rust: macros: allow arbitrary types to be used in module! macro
Previously this only accepts an identifier, but now with `syn` it is easy to make it accepts any type. Reviewed-by: Benno Lossin <[email protected]> Signed-off-by: Gary Guo <[email protected]>
1 parent ff67ce8 commit fc719cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

rust/macros/module.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use syn::{
2626
LitStr,
2727
Path,
2828
Result,
29-
Token, //
29+
Token,
30+
Type, //
3031
};
3132

3233
use crate::helpers::*;
@@ -370,7 +371,7 @@ impl Parse for Parameter {
370371
}
371372

372373
pub(crate) struct ModuleInfo {
373-
type_: Ident,
374+
type_: Type,
374375
license: AsciiLitStr,
375376
name: AsciiLitStr,
376377
authors: Option<Punctuated<AsciiLitStr, Token![,]>>,
@@ -529,7 +530,6 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
529530
// Double nested modules, since then nobody can access the public items inside.
530531
mod __module_init {
531532
mod __module_init {
532-
use super::super::#type_;
533533
use pin_init::PinInit;
534534

535535
/// The "Rust loadable module" mark.
@@ -541,7 +541,7 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
541541
#[used(compiler)]
542542
static __IS_RUST_MODULE: () = ();
543543

544-
static mut __MOD: ::core::mem::MaybeUninit<#type_> =
544+
static mut __MOD: ::core::mem::MaybeUninit<super::super::LocalModule> =
545545
::core::mem::MaybeUninit::uninit();
546546

547547
// Loadable modules need to export the `{init,cleanup}_module` identifiers.
@@ -628,8 +628,9 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
628628
///
629629
/// This function must only be called once.
630630
unsafe fn __init() -> ::kernel::ffi::c_int {
631-
let initer =
632-
<#type_ as ::kernel::InPlaceModule>::init(&super::super::THIS_MODULE);
631+
let initer = <super::super::LocalModule as ::kernel::InPlaceModule>::init(
632+
&super::super::THIS_MODULE
633+
);
633634
// SAFETY: No data race, since `__MOD` can only be accessed by this module
634635
// and there only `__init` and `__exit` access it. These functions are only
635636
// called once and `__exit` cannot be called before or during `__init`.

0 commit comments

Comments
 (0)