Modules: refactor module option handling for static allocation

Moves module option structs out of global config and removes dynamic allocation, using static buffers and size assertions for safer, simpler management.

Refactors module initialization and destruction to work with isolated option structs, eliminating the need for the previous modules container and related code.

Unifies module option header usage and updates detection logic to leverage statically-sized option buffers, improving encapsulation and maintainability.

Simplifies module function signatures and reduces coupling between modules and config.

Enhances future extensibility and reliability by enforcing max size constraints and removing unnecessary indirections.
This commit is contained in:
李通洲
2025-08-04 14:25:14 +08:00
parent 559082806b
commit 75d2c668d0
289 changed files with 1449 additions and 1672 deletions
+2 -3
View File
@@ -1,14 +1,13 @@
#pragma once
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
#include "common/option.h"
typedef struct FFUsersOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
bool compact;
bool myselfOnly;
} FFUsersOptions;
static_assert(sizeof(FFUsersOptions) <= FF_OPTION_MAX_SIZE, "FFUsersOptions size exceeds maximum allowed size");
+13 -14
View File
@@ -185,6 +185,19 @@ void ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyj
}
}
void ffInitUsersOptions(FFUsersOptions* options)
{
ffOptionInitModuleArg(&options->moduleArgs, "");
options->compact = false;
options->myselfOnly = false;
}
void ffDestroyUsersOptions(FFUsersOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}
FFModuleBaseInfo ffUsersModuleInfo = {
.name = FF_USERS_MODULE_NAME,
.description = "Print users currently logged in",
@@ -210,17 +223,3 @@ FFModuleBaseInfo ffUsersModuleInfo = {
{"Years fraction after login", "years-fraction"},
}))
};
void ffInitUsersOptions(FFUsersOptions* options)
{
options->moduleInfo = ffUsersModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "");
options->compact = false;
options->myselfOnly = false;
}
void ffDestroyUsersOptions(FFUsersOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
}
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include "fastfetch.h"
#include "option.h"
#define FF_USERS_MODULE_NAME "Users"