From 2fbf4ca24ad43c3bbbe81a421102cbaf13376775 Mon Sep 17 00:00:00 2001 From: anth64 Date: Thu, 29 Jan 2026 22:40:25 +0100 Subject: [PATCH] feat(module): implement module initialization status check * Add STK_MOD_INIT_SUCCESS and STK_MOD_INIT_FAILURE macros to stk.h. * Update stk_module_load to validate module initialization before finalizing the load. * Unload library if the init func fails, return error. --- include/stk.h | 5 +++++ src/module.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/stk.h b/include/stk.h index af7f789..58af9a8 100644 --- a/include/stk.h +++ b/include/stk.h @@ -4,11 +4,16 @@ #include "stk_version.h" #include +/* Buffers */ #define STK_MOD_DIR_BUFFER 256 #define STK_MOD_ID_BUFFER 64 #define STK_PATH_MAX 256 #define STK_PATH_MAX_OS 4096 +/* Modules */ +#define STK_MOD_INIT_SUCCESS 0 +#define STK_MOD_INIT_FAILURE 1 + #if defined(__linux__) || defined(_WIN32) #define STK_EVENT_BUFFER 4096 #endif diff --git a/src/module.c b/src/module.c index d732bb2..79a50ab 100644 --- a/src/module.c +++ b/src/module.c @@ -104,11 +104,13 @@ int stk_module_load(const char *path, int index) return -2; } - if (index == -1) - index = module_count; - extract_module_id(path, module_id); + if (init_func() != STK_MOD_INIT_SUCCESS) { + platform_unload_library(handle); + return -3; + } + strncpy(stk_module_ids[index], module_id, STK_MOD_ID_BUFFER - 1); stk_module_ids[index][STK_MOD_ID_BUFFER - 1] = '\0'; @@ -116,8 +118,6 @@ int stk_module_load(const char *path, int index) stk_inits[index] = init_func; stk_shutdowns[index] = shutdown_func; - init_func(); /* TODO eventually return an int for success */ - return 0; }