Skip to contentSkip to conversation

rust: macros: document emit_base in ModInfoBuilder

PATCH New Ivan Tverdokhleb 1 participant 1 message Nov 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rust: macros: document emit_base in ModInfoBuilder

Add documentation for the emit_base method within the ModInfoBuilder struct. Explain its role in formatting metadata strings, handling the differentiation between built-in and loadable modules, and managing linker sections and conditional compilation.

---
Changes in v2:
- Fixed the typo in my last name in the From and Signed-off-by lines.
- Reworded the documentation: dropped an unverified claim about the reason for the module name prefix, and documented the param argument.

v1: https://lore.kernel.org/rust-for-linux/[email protected]/

 rust/macros/module.rs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
rust/macros/module.rs +14 -0
index 0a7b9e24c..6f4aacfe7 100644
@@ -49,6 +49,20 @@ fn new(module: &'a str) -> Self {
         }
     }
 
+    /// Emits a single metadata entry into the module information table.
+    ///
+    /// This method formats a `field=content\0` byte string and places it into the
+    /// `.modinfo` linker section, except on macOS where `link_section` is omitted.
+    /// For built-in modules (`builtin == true`), the string is prefixed with
+    /// `<module>.`; for loadable modules, it is emitted without a prefix.
+    ///
+    /// The `param` flag selects which token stream receives the generated item: when
+    /// `true`, the entry is appended to `param_ts` (used for module parameters via
+    /// [`Self::emit_param`] and placed inside `mod module_parameters`); when
+    /// `false`, it is appended to `ts` in the main generated module code.
+    ///
+    /// The method also generates a unique static identifier using an internal counter
+    /// and applies `#[cfg(not(MODULE))]` or `#[cfg(MODULE)]` based on `builtin`.
     fn emit_base(&mut self, field: &str, content: &str, builtin: bool, param: bool) {
         let string = if builtin {
             // Built-in modules prefix their modinfo strings by `module.`.
Signature · 1 line
2.56.1