1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Mono: Change BindingsGenerator singleton to avoid StringName leaks

This commit is contained in:
Ignacio Etcheverry
2018-01-01 03:04:49 +01:00
parent b271aa48e4
commit fe391393d4
4 changed files with 30 additions and 18 deletions

View File

@@ -124,6 +124,14 @@ void CSharpLanguage::finish() {
finalizing = true; finalizing = true;
#ifdef TOOLS_ENABLED
// Must be here, to avoid StringName leaks
if (BindingsGenerator::singleton) {
memdelete(BindingsGenerator::singleton);
BindingsGenerator::singleton = NULL;
}
#endif
// Release gchandle bindings before finalizing mono runtime // Release gchandle bindings before finalizing mono runtime
gchandle_bindings.clear(); gchandle_bindings.clear();

View File

@@ -108,6 +108,8 @@ const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN = "\t%0 %1_in
bool BindingsGenerator::verbose_output = false; bool BindingsGenerator::verbose_output = false;
BindingsGenerator *BindingsGenerator::singleton = NULL;
static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_upper = false) { static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_upper = false) {
String ret; String ret;
@@ -2466,8 +2468,7 @@ void BindingsGenerator::_populate_global_constants() {
} }
} }
BindingsGenerator::BindingsGenerator() : void BindingsGenerator::initialize() {
name_cache(NameCache::get_singleton()) {
EditorHelp::generate_doc(); EditorHelp::generate_doc();
@@ -2509,7 +2510,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args)
const List<String>::Element *path_elem = elem->next(); const List<String>::Element *path_elem = elem->next();
if (path_elem) { if (path_elem) {
if (get_singleton().generate_glue(path_elem->get()) != OK) if (get_singleton()->generate_glue(path_elem->get()) != OK)
ERR_PRINT("Mono glue generation failed"); ERR_PRINT("Mono glue generation failed");
elem = elem->next(); elem = elem->next();
} else { } else {
@@ -2523,7 +2524,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args)
const List<String>::Element *path_elem = elem->next(); const List<String>::Element *path_elem = elem->next();
if (path_elem) { if (path_elem) {
if (get_singleton().generate_cs_core_project(path_elem->get()) != OK) if (get_singleton()->generate_cs_core_project(path_elem->get()) != OK)
ERR_PRINT("Generation of solution and C# project for the Core API failed"); ERR_PRINT("Generation of solution and C# project for the Core API failed");
elem = elem->next(); elem = elem->next();
} else { } else {
@@ -2538,7 +2539,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args)
if (path_elem) { if (path_elem) {
if (path_elem->next()) { if (path_elem->next()) {
if (get_singleton().generate_cs_editor_project(path_elem->get(), path_elem->next()->get()) != OK) if (get_singleton()->generate_cs_editor_project(path_elem->get(), path_elem->next()->get()) != OK)
ERR_PRINT("Generation of solution and C# project for the Editor API failed"); ERR_PRINT("Generation of solution and C# project for the Editor API failed");
elem = path_elem->next(); elem = path_elem->next();
} else { } else {

View File

@@ -145,7 +145,7 @@ class BindingsGenerator {
} }
MethodInterface() { MethodInterface() {
return_type = NameCache::get_singleton().type_void; return_type = BindingsGenerator::get_singleton()->name_cache.type_void;
is_vararg = false; is_vararg = false;
is_virtual = false; is_virtual = false;
requires_object_call = false; requires_object_call = false;
@@ -469,16 +469,11 @@ class BindingsGenerator {
enum_Error = StaticCString::create("Error"); enum_Error = StaticCString::create("Error");
} }
static NameCache &get_singleton() {
static NameCache singleton;
return singleton;
}
NameCache(const NameCache &); NameCache(const NameCache &);
NameCache &operator=(const NameCache &); NameCache &operator=(const NameCache &);
}; };
const NameCache &name_cache; NameCache name_cache;
const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) { const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) {
const List<InternalCall>::Element *it = p_list.front(); const List<InternalCall>::Element *it = p_list.front();
@@ -525,18 +520,26 @@ class BindingsGenerator {
Error _save_file(const String &path, const List<String> &content); Error _save_file(const String &path, const List<String> &content);
BindingsGenerator(); BindingsGenerator() {}
BindingsGenerator(const BindingsGenerator &); BindingsGenerator(const BindingsGenerator &);
BindingsGenerator &operator=(const BindingsGenerator &); BindingsGenerator &operator=(const BindingsGenerator &);
friend class CSharpLanguage;
static BindingsGenerator *singleton;
public: public:
Error generate_cs_core_project(const String &p_output_dir, bool p_verbose_output = true); Error generate_cs_core_project(const String &p_output_dir, bool p_verbose_output = true);
Error generate_cs_editor_project(const String &p_output_dir, const String &p_core_dll_path, bool p_verbose_output = true); Error generate_cs_editor_project(const String &p_output_dir, const String &p_core_dll_path, bool p_verbose_output = true);
Error generate_glue(const String &p_output_dir); Error generate_glue(const String &p_output_dir);
static BindingsGenerator &get_singleton() { void initialize();
static BindingsGenerator singleton;
_FORCE_INLINE_ static BindingsGenerator *get_singleton() {
if (!singleton) {
singleton = memnew(BindingsGenerator);
singleton->initialize();
}
return singleton; return singleton;
} }

View File

@@ -238,12 +238,12 @@ bool GodotSharpBuilds::make_api_sln(GodotSharpBuilds::APIType p_api_type) {
#error "How am I supposed to generate the bindings?" #error "How am I supposed to generate the bindings?"
#endif #endif
BindingsGenerator &gen = BindingsGenerator::get_singleton(); BindingsGenerator *gen = BindingsGenerator::get_singleton();
bool gen_verbose = OS::get_singleton()->is_stdout_verbose(); bool gen_verbose = OS::get_singleton()->is_stdout_verbose();
Error err = p_api_type == API_CORE ? Error err = p_api_type == API_CORE ?
gen.generate_cs_core_project(api_sln_dir, gen_verbose) : gen->generate_cs_core_project(api_sln_dir, gen_verbose) :
gen.generate_cs_editor_project(api_sln_dir, core_api_assembly, gen_verbose); gen->generate_cs_editor_project(api_sln_dir, core_api_assembly, gen_verbose);
if (err != OK) { if (err != OK) {
show_build_error_dialog("Failed to generate " + api_name + " solution. Error: " + itos(err)); show_build_error_dialog("Failed to generate " + api_name + " solution. Error: " + itos(err));