From 25616dabfd1be335412565fe6b50c8b0fd9f6ab5 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Sat, 26 Aug 2023 23:08:29 -0600 Subject: [PATCH] Error and warn functions contd. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mark things `static` and `const` as appropriate * Move “level wasn’t set up” warning to the central method * Inline `err` as the errno returns are unused for beïng cryptic --- src/cleanup.c | 21 ++++++++++----------- src/setup.c | 7 +++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/cleanup.c b/src/cleanup.c index 2fdaf72..aae75ab 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -1,23 +1,22 @@ #include "cleanup.h" -void godot_rb_cleanup_core() { - if(godot_rb_init_levels[GDEXTENSION_INITIALIZATION_CORE]) { - int err = ruby_cleanup(EXIT_SUCCESS); - if(err) - godot_rb_error("Ruby ran into a problem while exiting.", __func__, __FILE__, __LINE__); - } else - godot_rb_warn("Godot.rb hasn't set this init level up.", __func__, __FILE__, __LINE__); +static void godot_rb_cleanup_core() { + if(ruby_cleanup(EXIT_SUCCESS)) + godot_rb_error("Ruby ran into a problem while exiting.", __func__, __FILE__, __LINE__); } -void (*godot_rb_cleanup_functions[GDEXTENSION_MAX_INITIALIZATION_LEVEL])(void) = { +static void (* const godot_rb_cleanup_functions[GDEXTENSION_MAX_INITIALIZATION_LEVEL])(void) = { [GDEXTENSION_INITIALIZATION_CORE] = godot_rb_cleanup_core }; void godot_rb_cleanup(__attribute__((unused)) void* userdata, GDExtensionInitializationLevel p_level) { void (*func)(void) = godot_rb_cleanup_functions[p_level]; if(func) { printf("cleaning up Godot.rb init level %u...\n", p_level); - func(); - godot_rb_init_levels[p_level] = false; - printf("Godot.rb init level %u cleaned up.\n", p_level); + if(godot_rb_init_levels[p_level]) { + func(); + godot_rb_init_levels[p_level] = false; + printf("Godot.rb init level %u cleaned up.\n", p_level); + } else + godot_rb_warn("Godot.rb hasn't set this init level up.", __func__, __FILE__, __LINE__); } } diff --git a/src/setup.c b/src/setup.c index 959cce6..a5be0e2 100644 --- a/src/setup.c +++ b/src/setup.c @@ -1,14 +1,13 @@ #include "setup.h" static char* arg0 = "main"; -bool godot_rb_setup_core(void) { +static bool godot_rb_setup_core(void) { // On Windows, the argc/v pointers are rather return vars as their original contents are discarded. // https://github.com/ruby/ruby/blob/v3_2_2/win32/win32.c#L923-L926 int argc = 1; char** argv = &arg0; ruby_sysinit(&argc, &argv); - int err = ruby_setup(); - if(err) { + if(ruby_setup()) { godot_rb_error("Ruby ran into a problem while starting.", __func__, __FILE__, __LINE__); return false; } @@ -16,7 +15,7 @@ bool godot_rb_setup_core(void) { return true; } -bool (*godot_rb_setup_functions[GDEXTENSION_MAX_INITIALIZATION_LEVEL])(void) = { +static bool (* const godot_rb_setup_functions[GDEXTENSION_MAX_INITIALIZATION_LEVEL])(void) = { [GDEXTENSION_INITIALIZATION_CORE] = godot_rb_setup_core }; // Ruby keeps a copy of the argc/v pointers’ contents, though it seems to only use `argv[0]` occasionally.