diff options
Diffstat (limited to 'modules/mono/mono_gd/gd_mono.h')
-rw-r--r-- | modules/mono/mono_gd/gd_mono.h | 132 |
1 files changed, 80 insertions, 52 deletions
diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h index 0c5503d28e..343d68bc2d 100644 --- a/modules/mono/mono_gd/gd_mono.h +++ b/modules/mono/mono_gd/gd_mono.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -78,93 +78,104 @@ struct Version { String to_string(Type p_type); } // namespace APIAssembly -#define SCRIPTS_DOMAIN GDMono::get_singleton()->get_scripts_domain() -#ifdef TOOLS_ENABLED -#define TOOLS_DOMAIN GDMono::get_singleton()->get_tools_domain() -#endif - class GDMono { +public: + enum UnhandledExceptionPolicy { + POLICY_TERMINATE_APP, + POLICY_LOG_ERROR + }; + +private: bool runtime_initialized; bool finalizing_scripts_domain; MonoDomain *root_domain; MonoDomain *scripts_domain; -#ifdef TOOLS_ENABLED - MonoDomain *tools_domain; -#endif bool core_api_assembly_out_of_sync; +#ifdef TOOLS_ENABLED bool editor_api_assembly_out_of_sync; +#endif GDMonoAssembly *corlib_assembly; GDMonoAssembly *core_api_assembly; GDMonoAssembly *project_assembly; #ifdef TOOLS_ENABLED GDMonoAssembly *editor_api_assembly; - GDMonoAssembly *editor_tools_assembly; + GDMonoAssembly *tools_assembly; + GDMonoAssembly *tools_project_editor_assembly; #endif HashMap<uint32_t, HashMap<String, GDMonoAssembly *> > assemblies; + UnhandledExceptionPolicy unhandled_exception_policy; + void _domain_assemblies_cleanup(uint32_t p_domain_id); + bool _are_api_assemblies_out_of_sync(); + bool _load_corlib_assembly(); bool _load_core_api_assembly(); #ifdef TOOLS_ENABLED bool _load_editor_api_assembly(); - bool _load_editor_tools_assembly(); + bool _load_tools_assemblies(); #endif bool _load_project_assembly(); - bool _load_api_assemblies(); + bool _try_load_api_assemblies(); + void _load_api_assemblies(); -#ifdef TOOLS_ENABLED - String _get_api_assembly_metadata_path(); -#endif + void _install_trace_listener(); void _register_internal_calls(); Error _load_scripts_domain(); Error _unload_scripts_domain(); -#ifdef TOOLS_ENABLED - Error _load_tools_domain(); -#endif - -#ifdef DEBUG_METHODS_ENABLED uint64_t api_core_hash; #ifdef TOOLS_ENABLED uint64_t api_editor_hash; #endif void _initialize_and_check_api_hashes(); -#endif GDMonoLog *gdmono_log; -#ifdef WINDOWS_ENABLED +#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) MonoRegInfo mono_reg_info; #endif + void add_mono_shared_libs_dir_to_path(); + protected: static GDMono *singleton; public: #ifdef DEBUG_METHODS_ENABLED - uint64_t get_api_core_hash() { return api_core_hash; } + uint64_t get_api_core_hash() { + if (api_core_hash == 0) + api_core_hash = ClassDB::get_api_hash(ClassDB::API_CORE); + return api_core_hash; + } #ifdef TOOLS_ENABLED - uint64_t get_api_editor_hash() { return api_editor_hash; } -#endif -#endif + uint64_t get_api_editor_hash() { + if (api_editor_hash == 0) + api_editor_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); + return api_editor_hash; + } +#endif // TOOLS_ENABLED +#endif // DEBUG_METHODS_ENABLED #ifdef TOOLS_ENABLED - void metadata_set_api_assembly_invalidated(APIAssembly::Type p_api_type, bool p_invalidated); - bool metadata_is_api_assembly_invalidated(APIAssembly::Type p_api_type); + bool copy_prebuilt_api_assembly(APIAssembly::Type p_api_type, const String &p_config); + String update_api_assemblies_from_prebuilt(); #endif static GDMono *get_singleton() { return singleton; } - static void unhandled_exception_hook(MonoObject *p_exc, void *p_user_data); + GD_NORETURN static void unhandled_exception_hook(MonoObject *p_exc, void *p_user_data); + + UnhandledExceptionPolicy get_unhandled_exception_policy() const { return unhandled_exception_policy; } // Do not use these, unless you know what you're doing void add_assembly(uint32_t p_domain_id, GDMonoAssembly *p_assembly); @@ -172,45 +183,51 @@ public: _FORCE_INLINE_ bool is_runtime_initialized() const { return runtime_initialized && !mono_runtime_is_shutting_down() /* stays true after shutdown finished */; } + _FORCE_INLINE_ bool is_finalizing_scripts_domain() { return finalizing_scripts_domain; } + _FORCE_INLINE_ MonoDomain *get_scripts_domain() { return scripts_domain; } -#ifdef TOOLS_ENABLED - _FORCE_INLINE_ MonoDomain *get_tools_domain() { return tools_domain; } -#endif _FORCE_INLINE_ GDMonoAssembly *get_corlib_assembly() const { return corlib_assembly; } _FORCE_INLINE_ GDMonoAssembly *get_core_api_assembly() const { return core_api_assembly; } _FORCE_INLINE_ GDMonoAssembly *get_project_assembly() const { return project_assembly; } #ifdef TOOLS_ENABLED _FORCE_INLINE_ GDMonoAssembly *get_editor_api_assembly() const { return editor_api_assembly; } - _FORCE_INLINE_ GDMonoAssembly *get_editor_tools_assembly() const { return editor_tools_assembly; } + _FORCE_INLINE_ GDMonoAssembly *get_tools_assembly() const { return tools_assembly; } + _FORCE_INLINE_ GDMonoAssembly *get_tools_project_editor_assembly() const { return tools_project_editor_assembly; } #endif -#ifdef WINDOWS_ENABLED +#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) const MonoRegInfo &get_mono_reg_info() { return mono_reg_info; } #endif GDMonoClass *get_class(MonoClass *p_raw_class); + GDMonoClass *get_class(const StringName &p_namespace, const StringName &p_name); -#ifdef TOOLS_ENABLED +#ifdef GD_MONO_HOT_RELOAD Error reload_scripts_domain(); #endif bool load_assembly(const String &p_name, GDMonoAssembly **r_assembly, bool p_refonly = false); bool load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMonoAssembly **r_assembly, bool p_refonly = false); + bool load_assembly_from(const String &p_name, const String &p_path, GDMonoAssembly **r_assembly, bool p_refonly = false); + Error finalize_and_unload_domain(MonoDomain *p_domain); void initialize(); + void initialize_load_assemblies(); GDMono(); ~GDMono(); }; -class GDMonoScopeDomain { +namespace gdmono { + +class ScopeDomain { MonoDomain *prev_domain; public: - GDMonoScopeDomain(MonoDomain *p_domain) { + ScopeDomain(MonoDomain *p_domain) { MonoDomain *prev_domain = mono_domain_get(); if (prev_domain != p_domain) { this->prev_domain = prev_domain; @@ -220,33 +237,47 @@ public: } } - ~GDMonoScopeDomain() { + ~ScopeDomain() { if (prev_domain) mono_domain_set(prev_domain, false); } }; -#define _GDMONO_SCOPE_DOMAIN_(m_mono_domain) \ - GDMonoScopeDomain __gdmono__scope__domain__(m_mono_domain); \ +class ScopeExitDomainUnload { + MonoDomain *domain; + +public: + ScopeExitDomainUnload(MonoDomain *p_domain) : + domain(p_domain) { + } + + ~ScopeExitDomainUnload() { + if (domain) + GDMono::get_singleton()->finalize_and_unload_domain(domain); + } +}; + +} // namespace gdmono + +#define _GDMONO_SCOPE_DOMAIN_(m_mono_domain) \ + gdmono::ScopeDomain __gdmono__scope__domain__(m_mono_domain); \ (void)__gdmono__scope__domain__; +#define _GDMONO_SCOPE_EXIT_DOMAIN_UNLOAD_(m_mono_domain) \ + gdmono::ScopeExitDomainUnload __gdmono__scope__exit__domain__unload__(m_mono_domain); \ + (void)__gdmono__scope__exit__domain__unload__; + class _GodotSharp : public Object { - GDCLASS(_GodotSharp, Object) + GDCLASS(_GodotSharp, Object); friend class GDMono; - void _dispose_callback(); - bool _is_domain_finalizing_for_unload(int32_t p_domain_id); List<NodePath *> np_delete_queue; List<RID *> rid_delete_queue; - bool queue_empty; - -#ifndef NO_THREADS - Mutex *queue_mutex; -#endif + void _reload_assemblies(bool p_soft_reload); protected: static _GodotSharp *singleton; @@ -270,9 +301,6 @@ public: bool is_runtime_shutting_down(); bool is_runtime_initialized(); - void queue_dispose(NodePath *p_node_path); - void queue_dispose(RID *p_rid); - _GodotSharp(); ~_GodotSharp(); }; |