runtime: initialise global data when the first bshell_runtime is created

This commit is contained in:
2026-06-14 20:28:07 +01:00
parent 3ace32a95b
commit 21c7092752
+19
View File
@@ -1,9 +1,23 @@
#include "scope.h"
#include <bshell/runtime/runtime.h>
#include <bshell/verb.h>
#include <stdlib.h>
#include <string.h>
static fx_once global_once = FX_ONCE_INIT;
static void cleanup_globals(void)
{
bshell_cleanup_all_verbs();
}
static void init_globals(void)
{
bshell_init_all_verbs();
bshell_table_init();
}
struct bshell_runtime *bshell_runtime_create(void)
{
struct bshell_runtime *out = malloc(sizeof *out);
@@ -16,6 +30,11 @@ struct bshell_runtime *bshell_runtime_create(void)
out->rt_global = runtime_push_scope(out, RUNTIME_SCOPE_GLOBAL, NULL);
out->rt_aliases = fx_hashtable_create();
if (fx_init_once(&global_once)) {
init_globals();
atexit(cleanup_globals);
}
return out;
}