Introduce our own shutdown callback mechanism.

Instead of adding stuff to `_shutdown()`, we can now register a shutdown
routine from the respective `init()` function of our modules.

This also has the advantage, that we're sure they're called in reverse
order from how the initialization happened.

I didn't simply use `atexit()` because POSIX says that the number of
possible callbacks is limited (min 32) and I was not sure whether
we will maybe extend this number at one point.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-03-07 11:44:31 +01:00
parent 662a0be633
commit c5a131ee46
39 changed files with 321 additions and 327 deletions

View File

@@ -2840,6 +2840,14 @@ cmd_search_index_all(char* term)
return results;
}
static void
_cmd_uninit(void)
{
cmd_ac_uninit();
g_hash_table_destroy(commands);
g_hash_table_destroy(search_index);
}
/*
* Initialise command autocompleter and history
*/
@@ -2848,6 +2856,8 @@ cmd_init(void)
{
log_info("Initialising commands");
prof_add_shutdown_routine(_cmd_uninit);
cmd_ac_init();
search_index = g_hash_table_new_full(g_str_hash, g_str_equal, free, g_free);
@@ -2878,14 +2888,6 @@ cmd_init(void)
prefs_free_aliases(aliases);
}
void
cmd_uninit(void)
{
cmd_ac_uninit();
g_hash_table_destroy(commands);
g_hash_table_destroy(search_index);
}
gboolean
cmd_valid_tag(const char* const str)
{

View File

@@ -42,7 +42,6 @@
#include "ui/ui.h"
void cmd_init(void);
void cmd_uninit(void);
Command* cmd_get(const char* const command);
GList* cmd_get_ordered(const char* const tag);