Module discovery working for real this time
- Tested on Linux - Allocate module memory before loading anything (seg fault fixed)
This commit is contained in:
+24
-5
@@ -61,12 +61,8 @@ void stk_module_unload(size_t index)
|
|||||||
--module_count;
|
--module_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stk_module_unload_all(void)
|
void stk_module_free_memory(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
for (i = module_count; i > 0; --i)
|
|
||||||
stk_module_unload(i - 1);
|
|
||||||
|
|
||||||
free(stk_handles);
|
free(stk_handles);
|
||||||
free(stk_inits);
|
free(stk_inits);
|
||||||
free(stk_shutdowns);
|
free(stk_shutdowns);
|
||||||
@@ -75,3 +71,26 @@ void stk_module_unload_all(void)
|
|||||||
stk_inits = NULL;
|
stk_inits = NULL;
|
||||||
stk_shutdowns = NULL;
|
stk_shutdowns = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stk_module_init_memory(size_t capacity)
|
||||||
|
{
|
||||||
|
stk_handles = malloc(capacity * sizeof(void *));
|
||||||
|
stk_inits = malloc(capacity * sizeof(stk_module_func));
|
||||||
|
stk_shutdowns = malloc(capacity * sizeof(stk_module_func));
|
||||||
|
|
||||||
|
if (!stk_handles || !stk_inits || !stk_shutdowns) {
|
||||||
|
stk_module_free_memory();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stk_module_unload_all(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
for (i = module_count; i > 0; --i)
|
||||||
|
stk_module_unload(i - 1);
|
||||||
|
|
||||||
|
stk_module_free_memory();
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ size_t stk_module_count(void);
|
|||||||
int stk_module_load(const char *path);
|
int stk_module_load(const char *path);
|
||||||
void stk_module_unload(size_t index);
|
void stk_module_unload(size_t index);
|
||||||
void stk_module_unload_all(void);
|
void stk_module_unload_all(void);
|
||||||
|
int stk_module_init_memory(size_t capacity);
|
||||||
|
|
||||||
int stk_init(const char *mod_dir)
|
int stk_init(const char *mod_dir)
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,10 @@ int stk_init(const char *mod_dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
files = platform_directory_init_scan(stk_mod_dir, &file_count);
|
files = platform_directory_init_scan(stk_mod_dir, &file_count);
|
||||||
|
|
||||||
|
if (file_count > 0 && stk_module_init_memory(file_count) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (!files)
|
if (!files)
|
||||||
goto scanned;
|
goto scanned;
|
||||||
|
|
||||||
@@ -42,7 +47,7 @@ int stk_init(const char *mod_dir)
|
|||||||
|
|
||||||
scanned:
|
scanned:
|
||||||
watch_handle = platform_directory_watch_start(stk_mod_dir);
|
watch_handle = platform_directory_watch_start(stk_mod_dir);
|
||||||
stk_log(stdout, "[stk] stk initialized v%s! Loaded %zu from %s",
|
stk_log(stdout, "[stk] stk v%s initialized! Loaded %zu mods from %s",
|
||||||
STK_VERSION_STRING, module_count, stk_mod_dir);
|
STK_VERSION_STRING, module_count, stk_mod_dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user