Skip to content

Commit

Permalink
Error and warn functions contd.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ParadoxV5 committed Aug 27, 2023
1 parent 58e634b commit 25616da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
21 changes: 10 additions & 11 deletions src/cleanup.c
Original file line number Diff line number Diff line change
@@ -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__);
}
}
7 changes: 3 additions & 4 deletions src/setup.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#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;
}
ruby_script("godot_rb.c");
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.
Expand Down

0 comments on commit 25616da

Please sign in to comment.