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;
#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();

View file

@ -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 {

View file

@ -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;
}

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?"
#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));