diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2018-01-01 03:04:49 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2018-01-01 03:05:19 +0100 |
commit | fe391393d4f907f110875e6571d6ba20a102ddee (patch) | |
tree | 5d378eaf3db90193fbb68e2f18b7498aa80a20d3 /modules | |
parent | b271aa48e4e0af3d9abb998ac9c03eae3b65825a (diff) |
Mono: Change BindingsGenerator singleton to avoid StringName leaks
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mono/csharp_script.cpp | 8 | ||||
-rw-r--r-- | modules/mono/editor/bindings_generator.cpp | 11 | ||||
-rw-r--r-- | modules/mono/editor/bindings_generator.h | 23 | ||||
-rw-r--r-- | modules/mono/editor/godotsharp_builds.cpp | 6 |
4 files changed, 30 insertions, 18 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 2de113f05d..61dedbf1d7 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -124,6 +124,14 @@ void CSharpLanguage::finish() { 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 gchandle_bindings.clear(); diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 08f565d92a..cd12afb5dd 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -108,6 +108,8 @@ const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN = "\t%0 %1_in 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) { String ret; @@ -2466,8 +2468,7 @@ void BindingsGenerator::_populate_global_constants() { } } -BindingsGenerator::BindingsGenerator() : - name_cache(NameCache::get_singleton()) { +void BindingsGenerator::initialize() { 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(); 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"); elem = elem->next(); } else { @@ -2523,7 +2524,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) const List<String>::Element *path_elem = elem->next(); 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"); elem = elem->next(); } else { @@ -2538,7 +2539,7 @@ void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) if (path_elem) { 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"); elem = path_elem->next(); } else { diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index eac00690ff..5934f3f27f 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -145,7 +145,7 @@ class BindingsGenerator { } MethodInterface() { - return_type = NameCache::get_singleton().type_void; + return_type = BindingsGenerator::get_singleton()->name_cache.type_void; is_vararg = false; is_virtual = false; requires_object_call = false; @@ -469,16 +469,11 @@ class BindingsGenerator { enum_Error = StaticCString::create("Error"); } - static NameCache &get_singleton() { - static NameCache singleton; - return singleton; - } - NameCache(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 *it = p_list.front(); @@ -525,18 +520,26 @@ class BindingsGenerator { Error _save_file(const String &path, const List<String> &content); - BindingsGenerator(); + BindingsGenerator() {} BindingsGenerator(const BindingsGenerator &); BindingsGenerator &operator=(const BindingsGenerator &); + friend class CSharpLanguage; + static BindingsGenerator *singleton; + public: 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_glue(const String &p_output_dir); - static BindingsGenerator &get_singleton() { - static BindingsGenerator singleton; + void initialize(); + + _FORCE_INLINE_ static BindingsGenerator *get_singleton() { + if (!singleton) { + singleton = memnew(BindingsGenerator); + singleton->initialize(); + } return singleton; } diff --git a/modules/mono/editor/godotsharp_builds.cpp b/modules/mono/editor/godotsharp_builds.cpp index 3750a2b02a..3c06537816 100644 --- a/modules/mono/editor/godotsharp_builds.cpp +++ b/modules/mono/editor/godotsharp_builds.cpp @@ -238,12 +238,12 @@ bool GodotSharpBuilds::make_api_sln(GodotSharpBuilds::APIType p_api_type) { #error "How am I supposed to generate the bindings?" #endif - BindingsGenerator &gen = BindingsGenerator::get_singleton(); + BindingsGenerator *gen = BindingsGenerator::get_singleton(); bool gen_verbose = OS::get_singleton()->is_stdout_verbose(); Error err = p_api_type == API_CORE ? - 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_core_project(api_sln_dir, gen_verbose) : + gen->generate_cs_editor_project(api_sln_dir, core_api_assembly, gen_verbose); if (err != OK) { show_build_error_dialog("Failed to generate " + api_name + " solution. Error: " + itos(err)); |