summaryrefslogtreecommitdiff
path: root/modules/mono/mono_gd
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/mono_gd')
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp84
-rw-r--r--modules/mono/mono_gd/gd_mono_android.cpp116
-rw-r--r--modules/mono/mono_gd/gd_mono_android.h18
-rw-r--r--modules/mono/mono_gd/gd_mono_assembly.cpp1
-rw-r--r--modules/mono/mono_gd/gd_mono_cache.cpp282
-rw-r--r--modules/mono/mono_gd/gd_mono_cache.h174
-rw-r--r--modules/mono/mono_gd/gd_mono_class.cpp7
-rw-r--r--modules/mono/mono_gd/gd_mono_class.h2
-rw-r--r--modules/mono/mono_gd/gd_mono_field.cpp6
-rw-r--r--modules/mono/mono_gd/gd_mono_header.h6
-rw-r--r--modules/mono/mono_gd/gd_mono_log.cpp63
-rw-r--r--modules/mono/mono_gd/gd_mono_log.h14
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.cpp9
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.h5
-rw-r--r--modules/mono/mono_gd/gd_mono_method.cpp6
-rw-r--r--modules/mono/mono_gd/gd_mono_method.h4
-rw-r--r--modules/mono/mono_gd/gd_mono_method_thunk.h302
-rw-r--r--modules/mono/mono_gd/gd_mono_property.cpp2
-rw-r--r--modules/mono/mono_gd/gd_mono_utils.cpp315
-rw-r--r--modules/mono/mono_gd/gd_mono_utils.h281
20 files changed, 1061 insertions, 636 deletions
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index 504b8d41d0..384ef08cd0 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -46,6 +46,7 @@
#include "../csharp_script.h"
#include "../godotsharp_dirs.h"
#include "../utils/path_utils.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
#include "gd_mono_utils.h"
@@ -56,13 +57,26 @@
#ifdef ANDROID_ENABLED
#include "android_mono_config.h"
+#include "gd_mono_android.h"
#endif
+// TODO:
+// This has turn into a gigantic mess. There's too much going on here. Too much #ifdef as well.
+// It's just painful to read... It needs to be re-structured. Please, clean this up, future me.
+
GDMono *GDMono::singleton = NULL;
namespace {
-void setup_runtime_main_args() {
+#if defined(JAVASCRIPT_ENABLED)
+extern "C" {
+void mono_wasm_load_runtime(const char *managed_path, int enable_debugging);
+}
+#endif
+
+#if !defined(JAVASCRIPT_ENABLED)
+
+void gd_mono_setup_runtime_main_args() {
CharString execpath = OS::get_singleton()->get_executable_path().utf8();
List<String> cmdline_args = OS::get_singleton()->get_cmdline_args();
@@ -83,7 +97,7 @@ void setup_runtime_main_args() {
mono_runtime_set_main_args(main_args.size(), main_args.ptrw());
}
-void gdmono_profiler_init() {
+void gd_mono_profiler_init() {
String profiler_args = GLOBAL_DEF("mono/profiler/args", "log:calls,alloc,sample,output=output.mlpd");
bool profiler_enabled = GLOBAL_DEF("mono/profiler/enabled", false);
if (profiler_enabled) {
@@ -91,9 +105,9 @@ void gdmono_profiler_init() {
}
}
-#ifdef DEBUG_ENABLED
+#if defined(DEBUG_ENABLED)
-bool _wait_for_debugger_msecs(uint32_t p_msecs) {
+bool gd_mono_wait_for_debugger_msecs(uint32_t p_msecs) {
do {
if (mono_is_debugger_attached())
@@ -115,7 +129,7 @@ bool _wait_for_debugger_msecs(uint32_t p_msecs) {
return mono_is_debugger_attached();
}
-void gdmono_debug_init() {
+void gd_mono_debug_init() {
mono_debug_init(MONO_DEBUG_FORMAT_MONO);
@@ -151,11 +165,37 @@ void gdmono_debug_init() {
mono_jit_parse_options(2, (char **)options);
}
+#endif // defined(DEBUG_ENABLED)
+#endif // !defined(JAVASCRIPT_ENABLED)
+
+#if defined(JAVASCRIPT_ENABLED)
+MonoDomain *gd_initialize_mono_runtime() {
+ const char *vfs_prefix = "managed";
+ int enable_debugging = 0;
+
+#ifdef DEBUG_ENABLED
+ enable_debugging = 1;
+#endif
+
+ mono_wasm_load_runtime(vfs_prefix, enable_debugging);
+
+ return mono_get_root_domain();
+}
+#else
+MonoDomain *gd_initialize_mono_runtime() {
+#ifdef DEBUG_ENABLED
+ gd_mono_debug_init();
+#endif
+
+ return mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319");
+}
#endif
} // namespace
void GDMono::add_mono_shared_libs_dir_to_path() {
+ // TODO: Replace this with a mono_dl_fallback
+
// By default Mono seems to search shared libraries in the following directories:
// Current working directory, @executable_path@ and PATH
// The parent directory of the image file (assembly where the dllimport method is declared)
@@ -279,11 +319,17 @@ void GDMono::initialize() {
config_dir = bundled_config_dir;
#endif // TOOLS_ENABLED
+#if !defined(JAVASCRIPT_ENABLED)
// Leak if we call mono_set_dirs more than once
mono_set_dirs(assembly_rootdir.length() ? assembly_rootdir.utf8().get_data() : NULL,
config_dir.length() ? config_dir.utf8().get_data() : NULL);
add_mono_shared_libs_dir_to_path();
+#endif
+
+#if defined(ANDROID_ENABLED)
+ GDMonoAndroid::register_android_dl_fallback();
+#endif
{
PropertyInfo exc_policy_prop = PropertyInfo(Variant::INT, "mono/unhandled_exception_policy", PROPERTY_HINT_ENUM,
@@ -299,10 +345,8 @@ void GDMono::initialize() {
GDMonoAssembly::initialize();
- gdmono_profiler_init();
-
-#ifdef DEBUG_ENABLED
- gdmono_debug_init();
+#if !defined(JAVASCRIPT_ENABLED)
+ gd_mono_profiler_init();
#endif
#ifdef ANDROID_ENABLED
@@ -326,12 +370,14 @@ void GDMono::initialize() {
}
#endif
- root_domain = mono_jit_init_version("GodotEngine.RootDomain", "v4.0.30319");
+ root_domain = gd_initialize_mono_runtime();
ERR_FAIL_NULL_MSG(root_domain, "Mono: Failed to initialize runtime.");
GDMonoUtils::set_main_thread(GDMonoUtils::get_current_thread());
- setup_runtime_main_args(); // Required for System.Environment.GetCommandLineArgs
+#if !defined(JAVASCRIPT_ENABLED)
+ gd_mono_setup_runtime_main_args(); // Required for System.Environment.GetCommandLineArgs
+#endif
runtime_initialized = true;
@@ -344,8 +390,8 @@ void GDMono::initialize() {
Error domain_load_err = _load_scripts_domain();
ERR_FAIL_COND_MSG(domain_load_err != OK, "Mono: Failed to load scripts domain.");
-#ifdef DEBUG_ENABLED
- bool debugger_attached = _wait_for_debugger_msecs(500);
+#if defined(DEBUG_ENABLED) && !defined(JAVASCRIPT_ENABLED)
+ bool debugger_attached = gd_mono_wait_for_debugger_msecs(500);
if (!debugger_attached && OS::get_singleton()->is_stdout_verbose())
print_error("Mono: Debugger wait timeout");
#endif
@@ -381,7 +427,7 @@ void GDMono::initialize_load_assemblies() {
}
bool GDMono::_are_api_assemblies_out_of_sync() {
- bool out_of_sync = core_api_assembly.assembly && (core_api_assembly.out_of_sync || !GDMonoUtils::mono_cache.godot_api_cache_updated);
+ bool out_of_sync = core_api_assembly.assembly && (core_api_assembly.out_of_sync || !GDMonoCache::cached_data.godot_api_cache_updated);
#ifdef TOOLS_ENABLED
if (!out_of_sync)
out_of_sync = editor_api_assembly.assembly && editor_api_assembly.out_of_sync;
@@ -561,7 +607,7 @@ bool GDMono::_load_corlib_assembly() {
bool success = load_assembly("mscorlib", &corlib_assembly);
if (success)
- GDMonoUtils::update_corlib_cache();
+ GDMonoCache::update_corlib_cache();
return success;
}
@@ -834,9 +880,9 @@ bool GDMono::_try_load_api_assemblies(LoadedApiAssembly &r_core_api_assembly, Lo
}
bool GDMono::_on_core_api_assembly_loaded() {
- GDMonoUtils::update_godot_api_cache();
+ GDMonoCache::update_godot_api_cache();
- if (!GDMonoUtils::mono_cache.godot_api_cache_updated)
+ if (!GDMonoCache::cached_data.godot_api_cache_updated)
return false;
get_singleton()->_install_trace_listener();
@@ -884,7 +930,7 @@ void GDMono::_load_api_assemblies() {
if (_are_api_assemblies_out_of_sync()) {
if (core_api_assembly.out_of_sync) {
ERR_PRINT("The assembly '" CORE_API_ASSEMBLY_NAME "' is out of sync.");
- } else if (!GDMonoUtils::mono_cache.godot_api_cache_updated) {
+ } else if (!GDMonoCache::cached_data.godot_api_cache_updated) {
ERR_PRINT("The loaded assembly '" CORE_API_ASSEMBLY_NAME "' is in sync, but the cache update failed.");
}
@@ -984,7 +1030,7 @@ Error GDMono::_unload_scripts_domain() {
mono_gc_collect(mono_gc_max_generation());
- GDMonoUtils::clear_godot_api_cache();
+ GDMonoCache::clear_godot_api_cache();
_domain_assemblies_cleanup(mono_domain_get_id(scripts_domain));
diff --git a/modules/mono/mono_gd/gd_mono_android.cpp b/modules/mono/mono_gd/gd_mono_android.cpp
new file mode 100644
index 0000000000..42983e1821
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_android.cpp
@@ -0,0 +1,116 @@
+#include "gd_mono_android.h"
+
+#if defined(ANDROID_ENABLED)
+
+#include <dlfcn.h> // dlopen, dlsym
+#include <mono/utils/mono-dl-fallback.h>
+
+#include "core/os/os.h"
+#include "core/ustring.h"
+#include "platform/android/thread_jandroid.h"
+
+#include "../utils/path_utils.h"
+#include "../utils/string_utils.h"
+
+namespace GDMonoAndroid {
+
+String app_native_lib_dir_cache;
+
+String determine_app_native_lib_dir() {
+ JNIEnv *env = ThreadAndroid::get_env();
+
+ jclass activityThreadClass = env->FindClass("android/app/ActivityThread");
+ jmethodID currentActivityThread = env->GetStaticMethodID(activityThreadClass, "currentActivityThread", "()Landroid/app/ActivityThread;");
+ jobject activityThread = env->CallStaticObjectMethod(activityThreadClass, currentActivityThread);
+ jmethodID getApplication = env->GetMethodID(activityThreadClass, "getApplication", "()Landroid/app/Application;");
+ jobject ctx = env->CallObjectMethod(activityThread, getApplication);
+
+ jmethodID getApplicationInfo = env->GetMethodID(env->GetObjectClass(ctx), "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
+ jobject applicationInfo = env->CallObjectMethod(ctx, getApplicationInfo);
+ jfieldID nativeLibraryDirField = env->GetFieldID(env->GetObjectClass(applicationInfo), "nativeLibraryDir", "Ljava/lang/String;");
+ jstring nativeLibraryDir = (jstring)env->GetObjectField(applicationInfo, nativeLibraryDirField);
+
+ String result;
+
+ const char *const nativeLibraryDir_utf8 = env->GetStringUTFChars(nativeLibraryDir, NULL);
+ if (nativeLibraryDir_utf8) {
+ result.parse_utf8(nativeLibraryDir_utf8);
+ env->ReleaseStringUTFChars(nativeLibraryDir, nativeLibraryDir_utf8);
+ }
+
+ return result;
+}
+
+String get_app_native_lib_dir() {
+ if (app_native_lib_dir_cache.empty())
+ app_native_lib_dir_cache = determine_app_native_lib_dir();
+ return app_native_lib_dir_cache;
+}
+
+int gd_mono_convert_dl_flags(int flags) {
+ // from mono's runtime-bootstrap.c
+
+ int lflags = flags & MONO_DL_LOCAL ? 0 : RTLD_GLOBAL;
+
+ if (flags & MONO_DL_LAZY)
+ lflags |= RTLD_LAZY;
+ else
+ lflags |= RTLD_NOW;
+
+ return lflags;
+}
+
+void *gd_mono_android_dlopen(const char *p_name, int p_flags, char **r_err, void *p_user_data) {
+ String name = String::utf8(p_name);
+
+ if (name.ends_with(".dll.so") || name.ends_with(".exe.so")) {
+ String app_native_lib_dir = get_app_native_lib_dir();
+
+ String orig_so_name = name.get_file();
+ String so_name = "lib-aot-" + orig_so_name;
+ String so_path = path::join(app_native_lib_dir, so_name);
+
+ if (!FileAccess::exists(so_path)) {
+ if (OS::get_singleton()->is_stdout_verbose())
+ OS::get_singleton()->print("Cannot find shared library: '%s'\n", so_path.utf8().get_data());
+ return NULL;
+ }
+
+ int lflags = gd_mono_convert_dl_flags(p_flags);
+
+ void *handle = dlopen(so_path.utf8().get_data(), lflags);
+
+ if (!handle) {
+ if (OS::get_singleton()->is_stdout_verbose())
+ OS::get_singleton()->print("Failed to open shared library: '%s'. Error: '%s'\n", so_path.utf8().get_data(), dlerror());
+ return NULL;
+ }
+
+ if (OS::get_singleton()->is_stdout_verbose())
+ OS::get_singleton()->print("Successfully loaded AOT shared library: '%s'\n", so_path.utf8().get_data());
+
+ return handle;
+ }
+
+ return NULL;
+}
+
+void *gd_mono_android_dlsym(void *p_handle, const char *p_name, char **r_err, void *p_user_data) {
+ void *sym_addr = dlsym(p_handle, p_name);
+
+ if (sym_addr)
+ return sym_addr;
+
+ if (r_err)
+ *r_err = str_format_new("%s\n", dlerror());
+
+ return NULL;
+}
+
+void register_android_dl_fallback() {
+ mono_dl_fallback_register(gd_mono_android_dlopen, gd_mono_android_dlsym, NULL, NULL);
+}
+
+} // namespace GDMonoAndroid
+
+#endif
diff --git a/modules/mono/mono_gd/gd_mono_android.h b/modules/mono/mono_gd/gd_mono_android.h
new file mode 100644
index 0000000000..52705fbd2d
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_android.h
@@ -0,0 +1,18 @@
+#ifndef GD_MONO_ANDROID_H
+#define GD_MONO_ANDROID_H
+
+#if defined(ANDROID_ENABLED)
+
+#include "core/ustring.h"
+
+namespace GDMonoAndroid {
+
+String get_app_native_lib_dir();
+
+void register_android_dl_fallback();
+
+} // namespace GDMonoAndroid
+
+#endif // ANDROID_ENABLED
+
+#endif // GD_MONO_ANDROID_H
diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp
index a82bb42731..91842420b7 100644
--- a/modules/mono/mono_gd/gd_mono_assembly.cpp
+++ b/modules/mono/mono_gd/gd_mono_assembly.cpp
@@ -39,6 +39,7 @@
#include "core/project_settings.h"
#include "../godotsharp_dirs.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
bool GDMonoAssembly::no_search = false;
diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp
new file mode 100644
index 0000000000..3422e4ff58
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_cache.cpp
@@ -0,0 +1,282 @@
+#include "gd_mono_cache.h"
+
+#include "gd_mono.h"
+#include "gd_mono_class.h"
+#include "gd_mono_marshal.h"
+#include "gd_mono_method.h"
+#include "gd_mono_utils.h"
+
+namespace GDMonoCache {
+
+CachedData cached_data;
+
+#define CACHE_AND_CHECK(m_var, m_val) \
+ { \
+ CRASH_COND(m_var != NULL); \
+ m_var = m_val; \
+ ERR_FAIL_COND_MSG(m_var == NULL, "Mono Cache: Member " #m_var " is null."); \
+ }
+
+#define CACHE_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(cached_data.class_##m_class, m_val)
+#define CACHE_NS_CLASS_AND_CHECK(m_ns, m_class, m_val) CACHE_AND_CHECK(cached_data.class_##m_ns##_##m_class, m_val)
+#define CACHE_RAW_MONO_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(cached_data.rawclass_##m_class, m_val)
+#define CACHE_FIELD_AND_CHECK(m_class, m_field, m_val) CACHE_AND_CHECK(cached_data.field_##m_class##_##m_field, m_val)
+#define CACHE_METHOD_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(cached_data.method_##m_class##_##m_method, m_val)
+#define CACHE_PROPERTY_AND_CHECK(m_class, m_property, m_val) CACHE_AND_CHECK(cached_data.property_##m_class##_##m_property, m_val)
+
+#define CACHE_METHOD_THUNK_AND_CHECK_IMPL(m_var, m_val) \
+ { \
+ CRASH_COND(!m_var.is_null()); \
+ ERR_FAIL_COND_MSG(m_val == NULL, "Mono Cache: Method for member " #m_var " is null."); \
+ m_var.set_from_method(m_val); \
+ ERR_FAIL_COND_MSG(m_var.is_null(), "Mono Cache: Member " #m_var " is null."); \
+ }
+
+#define CACHE_METHOD_THUNK_AND_CHECK(m_class, m_method, m_val) CACHE_METHOD_THUNK_AND_CHECK_IMPL(cached_data.methodthunk_##m_class##_##m_method, m_val)
+
+void CachedData::clear_corlib_cache() {
+
+ corlib_cache_updated = false;
+
+ class_MonoObject = NULL;
+ class_bool = NULL;
+ class_int8_t = NULL;
+ class_int16_t = NULL;
+ class_int32_t = NULL;
+ class_int64_t = NULL;
+ class_uint8_t = NULL;
+ class_uint16_t = NULL;
+ class_uint32_t = NULL;
+ class_uint64_t = NULL;
+ class_float = NULL;
+ class_double = NULL;
+ class_String = NULL;
+ class_IntPtr = NULL;
+
+ class_System_Collections_IEnumerable = NULL;
+ class_System_Collections_IDictionary = NULL;
+
+#ifdef DEBUG_ENABLED
+ class_System_Diagnostics_StackTrace = NULL;
+ methodthunk_System_Diagnostics_StackTrace_GetFrames.nullify();
+ method_System_Diagnostics_StackTrace_ctor_bool = NULL;
+ method_System_Diagnostics_StackTrace_ctor_Exception_bool = NULL;
+#endif
+
+ class_KeyNotFoundException = NULL;
+}
+
+void CachedData::clear_godot_api_cache() {
+
+ godot_api_cache_updated = false;
+
+ rawclass_Dictionary = NULL;
+
+ class_Vector2 = NULL;
+ class_Rect2 = NULL;
+ class_Transform2D = NULL;
+ class_Vector3 = NULL;
+ class_Basis = NULL;
+ class_Quat = NULL;
+ class_Transform = NULL;
+ class_AABB = NULL;
+ class_Color = NULL;
+ class_Plane = NULL;
+ class_NodePath = NULL;
+ class_RID = NULL;
+ class_GodotObject = NULL;
+ class_GodotResource = NULL;
+ class_Node = NULL;
+ class_Control = NULL;
+ class_Spatial = NULL;
+ class_WeakRef = NULL;
+ class_Array = NULL;
+ class_Dictionary = NULL;
+ class_MarshalUtils = NULL;
+ class_ISerializationListener = NULL;
+
+#ifdef DEBUG_ENABLED
+ class_DebuggingUtils = NULL;
+ methodthunk_DebuggingUtils_GetStackFrameInfo.nullify();
+#endif
+
+ class_ExportAttribute = NULL;
+ field_ExportAttribute_hint = NULL;
+ field_ExportAttribute_hintString = NULL;
+ class_SignalAttribute = NULL;
+ class_ToolAttribute = NULL;
+ class_RemoteAttribute = NULL;
+ class_SyncAttribute = NULL;
+ class_MasterAttribute = NULL;
+ class_PuppetAttribute = NULL;
+ class_SlaveAttribute = NULL;
+ class_RemoteSyncAttribute = NULL;
+ class_MasterSyncAttribute = NULL;
+ class_PuppetSyncAttribute = NULL;
+ class_GodotMethodAttribute = NULL;
+ field_GodotMethodAttribute_methodName = NULL;
+
+ field_GodotObject_ptr = NULL;
+ field_NodePath_ptr = NULL;
+ field_Image_ptr = NULL;
+ field_RID_ptr = NULL;
+
+ methodthunk_GodotObject_Dispose.nullify();
+ methodthunk_Array_GetPtr.nullify();
+ methodthunk_Dictionary_GetPtr.nullify();
+ methodthunk_SignalAwaiter_SignalCallback.nullify();
+ methodthunk_SignalAwaiter_FailureCallback.nullify();
+ methodthunk_GodotTaskScheduler_Activate.nullify();
+
+ // Start of MarshalUtils methods
+
+ methodthunk_MarshalUtils_TypeIsGenericArray.nullify();
+ methodthunk_MarshalUtils_TypeIsGenericDictionary.nullify();
+
+ methodthunk_MarshalUtils_ArrayGetElementType.nullify();
+ methodthunk_MarshalUtils_DictionaryGetKeyValueTypes.nullify();
+
+ methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType.nullify();
+ methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType.nullify();
+ methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType_with_info.nullify();
+ methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType_with_info.nullify();
+
+ methodthunk_MarshalUtils_MakeGenericArrayType.nullify();
+ methodthunk_MarshalUtils_MakeGenericDictionaryType.nullify();
+
+ methodthunk_MarshalUtils_EnumerableToArray.nullify();
+ methodthunk_MarshalUtils_IDictionaryToDictionary.nullify();
+ methodthunk_MarshalUtils_GenericIDictionaryToDictionary.nullify();
+
+ // End of MarshalUtils methods
+
+ task_scheduler_handle = Ref<MonoGCHandle>();
+}
+
+#define GODOT_API_CLASS(m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, #m_class))
+#define GODOT_API_NS_CLASS(m_ns, m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(m_ns, #m_class))
+
+void update_corlib_cache() {
+
+ CACHE_CLASS_AND_CHECK(MonoObject, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_object_class()));
+ CACHE_CLASS_AND_CHECK(bool, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_boolean_class()));
+ CACHE_CLASS_AND_CHECK(int8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_sbyte_class()));
+ CACHE_CLASS_AND_CHECK(int16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int16_class()));
+ CACHE_CLASS_AND_CHECK(int32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int32_class()));
+ CACHE_CLASS_AND_CHECK(int64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int64_class()));
+ CACHE_CLASS_AND_CHECK(uint8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_byte_class()));
+ CACHE_CLASS_AND_CHECK(uint16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint16_class()));
+ CACHE_CLASS_AND_CHECK(uint32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint32_class()));
+ CACHE_CLASS_AND_CHECK(uint64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint64_class()));
+ CACHE_CLASS_AND_CHECK(float, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_single_class()));
+ CACHE_CLASS_AND_CHECK(double, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_double_class()));
+ CACHE_CLASS_AND_CHECK(String, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_string_class()));
+ CACHE_CLASS_AND_CHECK(IntPtr, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_intptr_class()));
+
+ CACHE_CLASS_AND_CHECK(System_Collections_IEnumerable, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IEnumerable"));
+ CACHE_CLASS_AND_CHECK(System_Collections_IDictionary, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IDictionary"));
+
+#ifdef DEBUG_ENABLED
+ CACHE_CLASS_AND_CHECK(System_Diagnostics_StackTrace, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Diagnostics", "StackTrace"));
+ CACHE_METHOD_THUNK_AND_CHECK(System_Diagnostics_StackTrace, GetFrames, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method("GetFrames"));
+ CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(bool)", true));
+ CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_Exception_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(System.Exception,bool)", true));
+#endif
+
+ CACHE_CLASS_AND_CHECK(KeyNotFoundException, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections.Generic", "KeyNotFoundException"));
+
+ cached_data.corlib_cache_updated = true;
+}
+
+void update_godot_api_cache() {
+
+ CACHE_CLASS_AND_CHECK(Vector2, GODOT_API_CLASS(Vector2));
+ CACHE_CLASS_AND_CHECK(Rect2, GODOT_API_CLASS(Rect2));
+ CACHE_CLASS_AND_CHECK(Transform2D, GODOT_API_CLASS(Transform2D));
+ CACHE_CLASS_AND_CHECK(Vector3, GODOT_API_CLASS(Vector3));
+ CACHE_CLASS_AND_CHECK(Basis, GODOT_API_CLASS(Basis));
+ CACHE_CLASS_AND_CHECK(Quat, GODOT_API_CLASS(Quat));
+ CACHE_CLASS_AND_CHECK(Transform, GODOT_API_CLASS(Transform));
+ CACHE_CLASS_AND_CHECK(AABB, GODOT_API_CLASS(AABB));
+ CACHE_CLASS_AND_CHECK(Color, GODOT_API_CLASS(Color));
+ CACHE_CLASS_AND_CHECK(Plane, GODOT_API_CLASS(Plane));
+ CACHE_CLASS_AND_CHECK(NodePath, GODOT_API_CLASS(NodePath));
+ CACHE_CLASS_AND_CHECK(RID, GODOT_API_CLASS(RID));
+ CACHE_CLASS_AND_CHECK(GodotObject, GODOT_API_CLASS(Object));
+ CACHE_CLASS_AND_CHECK(GodotResource, GODOT_API_CLASS(Resource));
+ CACHE_CLASS_AND_CHECK(Node, GODOT_API_CLASS(Node));
+ CACHE_CLASS_AND_CHECK(Control, GODOT_API_CLASS(Control));
+ CACHE_CLASS_AND_CHECK(Spatial, GODOT_API_CLASS(Spatial));
+ CACHE_CLASS_AND_CHECK(WeakRef, GODOT_API_CLASS(WeakRef));
+ CACHE_CLASS_AND_CHECK(Array, GODOT_API_NS_CLASS(BINDINGS_NAMESPACE_COLLECTIONS, Array));
+ CACHE_CLASS_AND_CHECK(Dictionary, GODOT_API_NS_CLASS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary));
+ CACHE_CLASS_AND_CHECK(MarshalUtils, GODOT_API_CLASS(MarshalUtils));
+ CACHE_CLASS_AND_CHECK(ISerializationListener, GODOT_API_CLASS(ISerializationListener));
+
+#ifdef DEBUG_ENABLED
+ CACHE_CLASS_AND_CHECK(DebuggingUtils, GODOT_API_CLASS(DebuggingUtils));
+#endif
+
+ // Attributes
+ CACHE_CLASS_AND_CHECK(ExportAttribute, GODOT_API_CLASS(ExportAttribute));
+ CACHE_FIELD_AND_CHECK(ExportAttribute, hint, CACHED_CLASS(ExportAttribute)->get_field("hint"));
+ CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString"));
+ CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute));
+ CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute));
+ CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute));
+ CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute));
+ CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute));
+ CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute));
+ CACHE_CLASS_AND_CHECK(SlaveAttribute, GODOT_API_CLASS(SlaveAttribute));
+ CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute));
+ CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute));
+ CACHE_CLASS_AND_CHECK(PuppetSyncAttribute, GODOT_API_CLASS(PuppetSyncAttribute));
+ CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute));
+ CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName"));
+
+ CACHE_FIELD_AND_CHECK(GodotObject, ptr, CACHED_CLASS(GodotObject)->get_field(BINDINGS_PTR_FIELD));
+ CACHE_FIELD_AND_CHECK(NodePath, ptr, CACHED_CLASS(NodePath)->get_field(BINDINGS_PTR_FIELD));
+ CACHE_FIELD_AND_CHECK(RID, ptr, CACHED_CLASS(RID)->get_field(BINDINGS_PTR_FIELD));
+
+ CACHE_METHOD_THUNK_AND_CHECK(GodotObject, Dispose, CACHED_CLASS(GodotObject)->get_method("Dispose", 0));
+ CACHE_METHOD_THUNK_AND_CHECK(Array, GetPtr, GODOT_API_NS_CLASS(BINDINGS_NAMESPACE_COLLECTIONS, Array)->get_method("GetPtr", 0));
+ CACHE_METHOD_THUNK_AND_CHECK(Dictionary, GetPtr, GODOT_API_NS_CLASS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary)->get_method("GetPtr", 0));
+ CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, SignalCallback, GODOT_API_CLASS(SignalAwaiter)->get_method("SignalCallback", 1));
+ CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, FailureCallback, GODOT_API_CLASS(SignalAwaiter)->get_method("FailureCallback", 0));
+ CACHE_METHOD_THUNK_AND_CHECK(GodotTaskScheduler, Activate, GODOT_API_CLASS(GodotTaskScheduler)->get_method("Activate", 0));
+
+ // Start of MarshalUtils methods
+
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericArray, GODOT_API_CLASS(MarshalUtils)->get_method("TypeIsGenericArray", 1));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericDictionary, GODOT_API_CLASS(MarshalUtils)->get_method("TypeIsGenericDictionary", 1));
+
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, ArrayGetElementType, GODOT_API_CLASS(MarshalUtils)->get_method("ArrayGetElementType", 2));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, DictionaryGetKeyValueTypes, GODOT_API_CLASS(MarshalUtils)->get_method("DictionaryGetKeyValueTypes", 3));
+
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType, GODOT_API_CLASS(MarshalUtils)->get_method("GenericIEnumerableIsAssignableFromType", 1));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType, GODOT_API_CLASS(MarshalUtils)->get_method("GenericIDictionaryIsAssignableFromType", 1));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info, GODOT_API_CLASS(MarshalUtils)->get_method("GenericIEnumerableIsAssignableFromType", 2));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info, GODOT_API_CLASS(MarshalUtils)->get_method("GenericIDictionaryIsAssignableFromType", 3));
+
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericArrayType, GODOT_API_CLASS(MarshalUtils)->get_method("MakeGenericArrayType", 1));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericDictionaryType, GODOT_API_CLASS(MarshalUtils)->get_method("MakeGenericDictionaryType", 2));
+
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, EnumerableToArray, GODOT_API_CLASS(MarshalUtils)->get_method("EnumerableToArray", 2));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, IDictionaryToDictionary, GODOT_API_CLASS(MarshalUtils)->get_method("IDictionaryToDictionary", 2));
+ CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryToDictionary, GODOT_API_CLASS(MarshalUtils)->get_method("GenericIDictionaryToDictionary", 2));
+
+ // End of MarshalUtils methods
+
+#ifdef DEBUG_ENABLED
+ CACHE_METHOD_THUNK_AND_CHECK(DebuggingUtils, GetStackFrameInfo, GODOT_API_CLASS(DebuggingUtils)->get_method("GetStackFrameInfo", 4));
+#endif
+
+ // TODO Move to CSharpLanguage::init() and do handle disposal
+ MonoObject *task_scheduler = mono_object_new(mono_domain_get(), GODOT_API_CLASS(GodotTaskScheduler)->get_mono_ptr());
+ GDMonoUtils::runtime_object_init(task_scheduler, GODOT_API_CLASS(GodotTaskScheduler));
+ cached_data.task_scheduler_handle = MonoGCHandle::create_strong(task_scheduler);
+
+ cached_data.godot_api_cache_updated = true;
+}
+
+} // namespace GDMonoCache
diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h
new file mode 100644
index 0000000000..0ad7fb607c
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_cache.h
@@ -0,0 +1,174 @@
+#ifndef GD_MONO_CACHE_H
+#define GD_MONO_CACHE_H
+
+#include "gd_mono_header.h"
+#include "gd_mono_method_thunk.h"
+
+namespace GDMonoCache {
+
+struct CachedData {
+
+ // -----------------------------------------------
+ // corlib classes
+
+ // Let's use the no-namespace format for these too
+ GDMonoClass *class_MonoObject;
+ GDMonoClass *class_bool;
+ GDMonoClass *class_int8_t;
+ GDMonoClass *class_int16_t;
+ GDMonoClass *class_int32_t;
+ GDMonoClass *class_int64_t;
+ GDMonoClass *class_uint8_t;
+ GDMonoClass *class_uint16_t;
+ GDMonoClass *class_uint32_t;
+ GDMonoClass *class_uint64_t;
+ GDMonoClass *class_float;
+ GDMonoClass *class_double;
+ GDMonoClass *class_String;
+ GDMonoClass *class_IntPtr;
+
+ GDMonoClass *class_System_Collections_IEnumerable;
+ GDMonoClass *class_System_Collections_IDictionary;
+
+#ifdef DEBUG_ENABLED
+ GDMonoClass *class_System_Diagnostics_StackTrace;
+ GDMonoMethodThunkR<MonoArray *, MonoObject *> methodthunk_System_Diagnostics_StackTrace_GetFrames;
+ GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_bool;
+ GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_Exception_bool;
+#endif
+
+ GDMonoClass *class_KeyNotFoundException;
+
+ MonoClass *rawclass_Dictionary;
+ // -----------------------------------------------
+
+ GDMonoClass *class_Vector2;
+ GDMonoClass *class_Rect2;
+ GDMonoClass *class_Transform2D;
+ GDMonoClass *class_Vector3;
+ GDMonoClass *class_Basis;
+ GDMonoClass *class_Quat;
+ GDMonoClass *class_Transform;
+ GDMonoClass *class_AABB;
+ GDMonoClass *class_Color;
+ GDMonoClass *class_Plane;
+ GDMonoClass *class_NodePath;
+ GDMonoClass *class_RID;
+ GDMonoClass *class_GodotObject;
+ GDMonoClass *class_GodotResource;
+ GDMonoClass *class_Node;
+ GDMonoClass *class_Control;
+ GDMonoClass *class_Spatial;
+ GDMonoClass *class_WeakRef;
+ GDMonoClass *class_Array;
+ GDMonoClass *class_Dictionary;
+ GDMonoClass *class_MarshalUtils;
+ GDMonoClass *class_ISerializationListener;
+
+#ifdef DEBUG_ENABLED
+ GDMonoClass *class_DebuggingUtils;
+ GDMonoMethodThunk<MonoObject *, MonoString **, int *, MonoString **> methodthunk_DebuggingUtils_GetStackFrameInfo;
+#endif
+
+ GDMonoClass *class_ExportAttribute;
+ GDMonoField *field_ExportAttribute_hint;
+ GDMonoField *field_ExportAttribute_hintString;
+ GDMonoClass *class_SignalAttribute;
+ GDMonoClass *class_ToolAttribute;
+ GDMonoClass *class_RemoteAttribute;
+ GDMonoClass *class_SyncAttribute;
+ GDMonoClass *class_RemoteSyncAttribute;
+ GDMonoClass *class_MasterSyncAttribute;
+ GDMonoClass *class_PuppetSyncAttribute;
+ GDMonoClass *class_MasterAttribute;
+ GDMonoClass *class_PuppetAttribute;
+ GDMonoClass *class_SlaveAttribute;
+ GDMonoClass *class_GodotMethodAttribute;
+ GDMonoField *field_GodotMethodAttribute_methodName;
+
+ GDMonoField *field_GodotObject_ptr;
+ GDMonoField *field_NodePath_ptr;
+ GDMonoField *field_Image_ptr;
+ GDMonoField *field_RID_ptr;
+
+ GDMonoMethodThunk<MonoObject *> methodthunk_GodotObject_Dispose;
+ GDMonoMethodThunkR<Array *, MonoObject *> methodthunk_Array_GetPtr;
+ GDMonoMethodThunkR<Dictionary *, MonoObject *> methodthunk_Dictionary_GetPtr;
+ GDMonoMethodThunk<MonoObject *, MonoArray *> methodthunk_SignalAwaiter_SignalCallback;
+ GDMonoMethodThunk<MonoObject *> methodthunk_SignalAwaiter_FailureCallback;
+ GDMonoMethodThunk<MonoObject *> methodthunk_GodotTaskScheduler_Activate;
+
+ // Start of MarshalUtils methods
+
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericArray;
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_TypeIsGenericDictionary;
+
+ GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_ArrayGetElementType;
+ GDMonoMethodThunk<MonoReflectionType *, MonoReflectionType **, MonoReflectionType **> methodthunk_MarshalUtils_DictionaryGetKeyValueTypes;
+
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType;
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *> methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType;
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *, MonoReflectionType **> methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType_with_info;
+ GDMonoMethodThunkR<MonoBoolean, MonoReflectionType *, MonoReflectionType **, MonoReflectionType **> methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType_with_info;
+
+ GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericArrayType;
+ GDMonoMethodThunkR<MonoReflectionType *, MonoReflectionType *, MonoReflectionType *> methodthunk_MarshalUtils_MakeGenericDictionaryType;
+
+ GDMonoMethodThunk<MonoObject *, Array *> methodthunk_MarshalUtils_EnumerableToArray;
+ GDMonoMethodThunk<MonoObject *, Dictionary *> methodthunk_MarshalUtils_IDictionaryToDictionary;
+ GDMonoMethodThunk<MonoObject *, Dictionary *> methodthunk_MarshalUtils_GenericIDictionaryToDictionary;
+
+ // End of MarshalUtils methods
+
+ Ref<MonoGCHandle> task_scheduler_handle;
+
+ bool corlib_cache_updated;
+ bool godot_api_cache_updated;
+
+ void clear_corlib_cache();
+ void clear_godot_api_cache();
+
+ CachedData() {
+ clear_corlib_cache();
+ clear_godot_api_cache();
+ }
+};
+
+extern CachedData cached_data;
+
+void update_corlib_cache();
+void update_godot_api_cache();
+
+inline void clear_corlib_cache() {
+ cached_data.clear_corlib_cache();
+}
+
+inline void clear_godot_api_cache() {
+ cached_data.clear_godot_api_cache();
+}
+
+_FORCE_INLINE_ bool tools_godot_api_check() {
+#ifdef TOOLS_ENABLED
+ return cached_data.godot_api_cache_updated;
+#else
+ return true; // Assume it's updated if this was called, otherwise it's a bug
+#endif
+}
+
+} // namespace GDMonoCache
+
+#define CACHED_CLASS(m_class) (GDMonoCache::cached_data.class_##m_class)
+#define CACHED_CLASS_RAW(m_class) (GDMonoCache::cached_data.class_##m_class->get_mono_ptr())
+#define CACHED_RAW_MONO_CLASS(m_class) (GDMonoCache::cached_data.rawclass_##m_class)
+#define CACHED_FIELD(m_class, m_field) (GDMonoCache::cached_data.field_##m_class##_##m_field)
+#define CACHED_METHOD(m_class, m_method) (GDMonoCache::cached_data.method_##m_class##_##m_method)
+#define CACHED_METHOD_THUNK(m_class, m_method) (GDMonoCache::cached_data.methodthunk_##m_class##_##m_method)
+#define CACHED_PROPERTY(m_class, m_property) (GDMonoCache::cached_data.property_##m_class##_##m_property)
+
+#ifdef REAL_T_IS_DOUBLE
+#define REAL_T_MONOCLASS CACHED_CLASS_RAW(double)
+#else
+#define REAL_T_MONOCLASS CACHED_CLASS_RAW(float)
+#endif
+
+#endif // GD_MONO_CACHE_H
diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp
index 89a88fcfb2..fb9b6be3d4 100644
--- a/modules/mono/mono_gd/gd_mono_class.cpp
+++ b/modules/mono/mono_gd/gd_mono_class.cpp
@@ -33,6 +33,7 @@
#include <mono/metadata/attrdefs.h>
#include "gd_mono_assembly.h"
+#include "gd_mono_cache.h"
#include "gd_mono_marshal.h"
String GDMonoClass::get_full_name(MonoClass *p_mono_class) {
@@ -332,12 +333,6 @@ GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, boo
return get_method(method);
}
-void *GDMonoClass::get_method_thunk(const StringName &p_name, int p_params_count) {
-
- GDMonoMethod *method = get_method(p_name, p_params_count);
- return method ? method->get_thunk() : NULL;
-}
-
GDMonoField *GDMonoClass::get_field(const StringName &p_name) {
Map<StringName, GDMonoField *>::Element *result = fields.find(p_name);
diff --git a/modules/mono/mono_gd/gd_mono_class.h b/modules/mono/mono_gd/gd_mono_class.h
index 40e1574927..562c337822 100644
--- a/modules/mono/mono_gd/gd_mono_class.h
+++ b/modules/mono/mono_gd/gd_mono_class.h
@@ -144,8 +144,6 @@ public:
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count);
GDMonoMethod *get_method_with_desc(const String &p_description, bool p_include_namespace);
- void *get_method_thunk(const StringName &p_name, int p_params_count = 0);
-
GDMonoField *get_field(const StringName &p_name);
const Vector<GDMonoField *> &get_all_fields();
diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp
index 7b8e6f89e9..d84359b1ab 100644
--- a/modules/mono/mono_gd/gd_mono_field.cpp
+++ b/modules/mono/mono_gd/gd_mono_field.cpp
@@ -32,8 +32,10 @@
#include <mono/metadata/attrdefs.h>
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
+#include "gd_mono_utils.h"
void GDMonoField::set_value_raw(MonoObject *p_object, void *p_ptr) {
mono_field_set_value(p_object, mono_field, &p_ptr);
@@ -337,7 +339,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
}
if (type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) {
- if (GDMonoUtils::tools_godot_api_check()) {
+ if (GDMonoCache::tools_godot_api_check()) {
MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), CACHED_CLASS(Array));
mono_field_set_value(p_object, mono_field, managed);
break;
@@ -491,7 +493,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
}
if (type.type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) {
- if (GDMonoUtils::tools_godot_api_check()) {
+ if (GDMonoCache::tools_godot_api_check()) {
MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), CACHED_CLASS(Array));
mono_field_set_value(p_object, mono_field, managed);
break;
diff --git a/modules/mono/mono_gd/gd_mono_header.h b/modules/mono/mono_gd/gd_mono_header.h
index d7962eac8b..173e1613bf 100644
--- a/modules/mono/mono_gd/gd_mono_header.h
+++ b/modules/mono/mono_gd/gd_mono_header.h
@@ -33,6 +33,12 @@
#include "core/int_types.h"
+#ifdef WIN32
+#define GD_MONO_STDCALL __stdcall
+#else
+#define GD_MONO_STDCALL
+#endif
+
class GDMonoAssembly;
class GDMonoClass;
class GDMonoField;
diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp
index 7b3421fdb3..261b800619 100644
--- a/modules/mono/mono_gd/gd_mono_log.cpp
+++ b/modules/mono/mono_gd/gd_mono_log.cpp
@@ -30,7 +30,6 @@
#include "gd_mono_log.h"
-#include <mono/utils/mono-logger.h>
#include <stdlib.h> // abort
#include "core/os/dir_access.h"
@@ -39,7 +38,19 @@
#include "../godotsharp_dirs.h"
#include "../utils/string_utils.h"
-static int log_level_get_id(const char *p_log_level) {
+static CharString get_default_log_level() {
+#ifdef DEBUG_ENABLED
+ return String("info").utf8();
+#else
+ return String("warning").utf8();
+#endif
+}
+
+GDMonoLog *GDMonoLog::singleton = NULL;
+
+#if !defined(JAVASCRIPT_ENABLED)
+
+static int get_log_level_id(const char *p_log_level) {
const char *valid_log_levels[] = { "error", "critical", "warning", "message", "info", "debug", NULL };
@@ -53,11 +64,11 @@ static int log_level_get_id(const char *p_log_level) {
return -1;
}
-static void mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data) {
+void GDMonoLog::mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *) {
- FileAccess *f = GDMonoLog::get_singleton()->get_log_file();
+ FileAccess *f = GDMonoLog::get_singleton()->log_file;
- if (GDMonoLog::get_singleton()->get_log_level_id() >= log_level_get_id(log_level)) {
+ if (GDMonoLog::get_singleton()->log_level_id >= get_log_level_id(log_level)) {
String text(message);
text += " (in domain ";
text += log_domain;
@@ -72,7 +83,7 @@ static void mono_log_callback(const char *log_domain, const char *log_level, con
}
if (fatal) {
- ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: '" + GDMonoLog::get_singleton()->get_log_file_path() + "'.");
+ ERR_PRINTS("Mono: FATAL ERROR, ABORTING! Logfile: '" + GDMonoLog::get_singleton()->log_file_path + "'.");
// Make sure to flush before aborting
f->flush();
f->close();
@@ -82,8 +93,6 @@ static void mono_log_callback(const char *log_domain, const char *log_level, con
}
}
-GDMonoLog *GDMonoLog::singleton = NULL;
-
bool GDMonoLog::_try_create_logs_dir(const String &p_logs_dir) {
if (!DirAccess::exists(p_logs_dir)) {
@@ -129,17 +138,13 @@ void GDMonoLog::initialize() {
CharString log_level = OS::get_singleton()->get_environment("GODOT_MONO_LOG_LEVEL").utf8();
- if (log_level.length() != 0 && log_level_get_id(log_level.get_data()) == -1) {
+ if (log_level.length() != 0 && get_log_level_id(log_level.get_data()) == -1) {
ERR_PRINTS(String() + "Mono: Ignoring invalid log level (GODOT_MONO_LOG_LEVEL): '" + log_level.get_data() + "'.");
log_level = CharString();
}
if (log_level.length() == 0) {
-#ifdef DEBUG_ENABLED
- log_level = String("info").utf8();
-#else
- log_level = String("warning").utf8();
-#endif
+ log_level = get_default_log_level();
}
String logs_dir = GodotSharpDirs::get_mono_logs_dir();
@@ -149,11 +154,14 @@ void GDMonoLog::initialize() {
OS::Date date_now = OS::get_singleton()->get_date();
OS::Time time_now = OS::get_singleton()->get_time();
- int pid = OS::get_singleton()->get_process_id();
- String log_file_name = str_format("%d_%02d_%02d %02d.%02d.%02d (%d).txt",
+ String log_file_name = str_format("%d_%02d_%02d %02d.%02d.%02d",
date_now.year, date_now.month, date_now.day,
- time_now.hour, time_now.min, time_now.sec, pid);
+ time_now.hour, time_now.min, time_now.sec);
+
+ log_file_name += str_format(" (%d)", OS::get_singleton()->get_process_id());
+
+ log_file_name += ".txt";
log_file_path = logs_dir.plus_file(log_file_name);
@@ -164,7 +172,7 @@ void GDMonoLog::initialize() {
}
mono_trace_set_level_string(log_level.get_data());
- log_level_id = log_level_get_id(log_level.get_data());
+ log_level_id = get_log_level_id(log_level.get_data());
if (log_file) {
OS::get_singleton()->print("Mono: Logfile is: %s\n", log_file_path.utf8().get_data());
@@ -190,3 +198,22 @@ GDMonoLog::~GDMonoLog() {
memdelete(log_file);
}
}
+
+#else
+
+void GDMonoLog::initialize() {
+ CharString log_level = get_default_log_level();
+ mono_trace_set_level_string(log_level.get_data());
+}
+
+GDMonoLog::GDMonoLog() {
+
+ singleton = this;
+}
+
+GDMonoLog::~GDMonoLog() {
+
+ singleton = NULL;
+}
+
+#endif // !defined(JAVASCRIPT_ENABLED)
diff --git a/modules/mono/mono_gd/gd_mono_log.h b/modules/mono/mono_gd/gd_mono_log.h
index 91d0557aa3..4cd5a662fb 100644
--- a/modules/mono/mono_gd/gd_mono_log.h
+++ b/modules/mono/mono_gd/gd_mono_log.h
@@ -31,10 +31,17 @@
#ifndef GD_MONO_LOG_H
#define GD_MONO_LOG_H
+#include <mono/utils/mono-logger.h>
+
+#include "core/typedefs.h"
+
+#if !defined(JAVASCRIPT_ENABLED)
#include "core/os/file_access.h"
+#endif
class GDMonoLog {
+#if !defined(JAVASCRIPT_ENABLED)
int log_level_id;
FileAccess *log_file;
@@ -43,6 +50,9 @@ class GDMonoLog {
bool _try_create_logs_dir(const String &p_logs_dir);
void _delete_old_log_files(const String &p_logs_dir);
+ static void mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data);
+#endif
+
static GDMonoLog *singleton;
public:
@@ -50,10 +60,6 @@ public:
void initialize();
- _FORCE_INLINE_ FileAccess *get_log_file() { return log_file; }
- _FORCE_INLINE_ String get_log_file_path() { return log_file_path; }
- _FORCE_INLINE_ int get_log_level_id() { return log_level_id; }
-
GDMonoLog();
~GDMonoLog();
};
diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp
index 7aac691102..3827960e6b 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.cpp
+++ b/modules/mono/mono_gd/gd_mono_marshal.cpp
@@ -31,6 +31,7 @@
#include "gd_mono_marshal.h"
#include "gd_mono.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
namespace GDMonoMarshal {
@@ -556,7 +557,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
}
if (type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) {
- if (GDMonoUtils::tools_godot_api_check()) {
+ if (GDMonoCache::tools_godot_api_check()) {
return GDMonoUtils::create_managed_from(p_var->operator Array(), CACHED_CLASS(Array));
} else {
return (MonoObject *)GDMonoMarshal::Array_to_mono_array(p_var->operator Array());
@@ -683,7 +684,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
}
if (p_type.type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) {
- if (GDMonoUtils::tools_godot_api_check()) {
+ if (GDMonoCache::tools_godot_api_check()) {
return GDMonoUtils::create_managed_from(p_var->operator Array(), CACHED_CLASS(Array));
} else {
return (MonoObject *)GDMonoMarshal::Array_to_mono_array(p_var->operator Array());
@@ -834,14 +835,14 @@ Variant mono_object_to_variant(MonoObject *p_obj) {
if (CACHED_CLASS(Array) == type_class) {
MonoException *exc = NULL;
- Array *ptr = invoke_method_thunk(CACHED_METHOD_THUNK(Array, GetPtr), p_obj, &exc);
+ Array *ptr = CACHED_METHOD_THUNK(Array, GetPtr).invoke(p_obj, &exc);
UNHANDLED_EXCEPTION(exc);
return ptr ? Variant(*ptr) : Variant();
}
if (CACHED_CLASS(Dictionary) == type_class) {
MonoException *exc = NULL;
- Dictionary *ptr = invoke_method_thunk(CACHED_METHOD_THUNK(Dictionary, GetPtr), p_obj, &exc);
+ Dictionary *ptr = CACHED_METHOD_THUNK(Dictionary, GetPtr).invoke(p_obj, &exc);
UNHANDLED_EXCEPTION(exc);
return ptr ? Variant(*ptr) : Variant();
}
diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h
index 3fa958ac32..53eae45320 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.h
+++ b/modules/mono/mono_gd/gd_mono_marshal.h
@@ -43,6 +43,11 @@ T unbox(MonoObject *p_obj) {
return *(T *)mono_object_unbox(p_obj);
}
+template <typename T>
+T *unbox_addr(MonoObject *p_obj) {
+ return (T *)mono_object_unbox(p_obj);
+}
+
#define BOX_DOUBLE(x) mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(double), &x)
#define BOX_FLOAT(x) mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(float), &x)
#define BOX_INT64(x) mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(int64_t), &x)
diff --git a/modules/mono/mono_gd/gd_mono_method.cpp b/modules/mono/mono_gd/gd_mono_method.cpp
index 968b316a3e..080b3a676a 100644
--- a/modules/mono/mono_gd/gd_mono_method.cpp
+++ b/modules/mono/mono_gd/gd_mono_method.cpp
@@ -30,8 +30,10 @@
#include "gd_mono_method.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
+#include "gd_mono_utils.h"
#include <mono/metadata/attrdefs.h>
@@ -99,10 +101,6 @@ IMonoClassMember::Visibility GDMonoMethod::get_visibility() {
}
}
-void *GDMonoMethod::get_thunk() {
- return mono_method_get_unmanaged_thunk(mono_method);
-}
-
MonoObject *GDMonoMethod::invoke(MonoObject *p_object, const Variant **p_params, MonoException **r_exc) {
if (get_return_type().type_encoding != MONO_TYPE_VOID || get_parameters_count() > 0) {
MonoArray *params = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(MonoObject), get_parameters_count());
diff --git a/modules/mono/mono_gd/gd_mono_method.h b/modules/mono/mono_gd/gd_mono_method.h
index 2fc8628f27..abbae92e29 100644
--- a/modules/mono/mono_gd/gd_mono_method.h
+++ b/modules/mono/mono_gd/gd_mono_method.h
@@ -71,11 +71,11 @@ public:
virtual MonoObject *get_attribute(GDMonoClass *p_attr_class) GD_FINAL;
void fetch_attributes();
+ _FORCE_INLINE_ MonoMethod *get_mono_ptr() { return mono_method; }
+
_FORCE_INLINE_ int get_parameters_count() { return params_count; }
_FORCE_INLINE_ ManagedType get_return_type() { return return_type; }
- void *get_thunk();
-
MonoObject *invoke(MonoObject *p_object, const Variant **p_params, MonoException **r_exc = NULL);
MonoObject *invoke(MonoObject *p_object, MonoException **r_exc = NULL);
MonoObject *invoke_raw(MonoObject *p_object, void **p_params, MonoException **r_exc = NULL);
diff --git a/modules/mono/mono_gd/gd_mono_method_thunk.h b/modules/mono/mono_gd/gd_mono_method_thunk.h
new file mode 100644
index 0000000000..9fe9e724f2
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_method_thunk.h
@@ -0,0 +1,302 @@
+#ifndef GD_MONO_METHOD_THUNK_H
+#define GD_MONO_METHOD_THUNK_H
+
+#include <type_traits>
+
+#include "gd_mono_class.h"
+#include "gd_mono_header.h"
+#include "gd_mono_marshal.h"
+#include "gd_mono_method.h"
+#include "gd_mono_utils.h"
+
+#if !defined(JAVASCRIPT_ENABLED)
+#define HAVE_METHOD_THUNKS
+#endif
+
+#ifdef HAVE_METHOD_THUNKS
+
+template <class... ParamTypes>
+struct GDMonoMethodThunk {
+
+ typedef void(GD_MONO_STDCALL *M)(ParamTypes... p_args, MonoException **);
+
+ M mono_method_thunk;
+
+public:
+ _FORCE_INLINE_ void invoke(ParamTypes... p_args, MonoException **r_exc) {
+ GD_MONO_BEGIN_RUNTIME_INVOKE;
+ mono_method_thunk(p_args..., r_exc);
+ GD_MONO_END_RUNTIME_INVOKE;
+ }
+
+ _FORCE_INLINE_ bool is_null() {
+ return mono_method_thunk == NULL;
+ }
+
+ _FORCE_INLINE_ void nullify() {
+ mono_method_thunk = NULL;
+ }
+
+ _FORCE_INLINE_ void set_from_method(GDMonoMethod *p_mono_method) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(p_mono_method == NULL);
+ CRASH_COND(p_mono_method->get_return_type().type_encoding != MONO_TYPE_VOID);
+
+ if (p_mono_method->is_static()) {
+ CRASH_COND(p_mono_method->get_parameters_count() != sizeof...(ParamTypes));
+ } else {
+ CRASH_COND(p_mono_method->get_parameters_count() != (sizeof...(ParamTypes) - 1));
+ }
+#endif
+ mono_method_thunk = (M)mono_method_get_unmanaged_thunk(p_mono_method->get_mono_ptr());
+ }
+
+ GDMonoMethodThunk() :
+ mono_method_thunk(NULL) {
+ }
+
+ explicit GDMonoMethodThunk(GDMonoMethod *p_mono_method) {
+ set_from_method(p_mono_method);
+ }
+};
+
+template <class R, class... ParamTypes>
+struct GDMonoMethodThunkR {
+
+ typedef R(GD_MONO_STDCALL *M)(ParamTypes... p_args, MonoException **);
+
+ M mono_method_thunk;
+
+public:
+ _FORCE_INLINE_ R invoke(ParamTypes... p_args, MonoException **r_exc) {
+ GD_MONO_BEGIN_RUNTIME_INVOKE;
+ R r = mono_method_thunk(p_args..., r_exc);
+ GD_MONO_END_RUNTIME_INVOKE;
+ return r;
+ }
+
+ _FORCE_INLINE_ bool is_null() {
+ return mono_method_thunk == NULL;
+ }
+
+ _FORCE_INLINE_ void nullify() {
+ mono_method_thunk = NULL;
+ }
+
+ _FORCE_INLINE_ void set_from_method(GDMonoMethod *p_mono_method) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(p_mono_method == NULL);
+ CRASH_COND(p_mono_method->get_return_type().type_encoding == MONO_TYPE_VOID);
+
+ if (p_mono_method->is_static()) {
+ CRASH_COND(p_mono_method->get_parameters_count() != sizeof...(ParamTypes));
+ } else {
+ CRASH_COND(p_mono_method->get_parameters_count() != (sizeof...(ParamTypes) - 1));
+ }
+#endif
+ mono_method_thunk = (M)mono_method_get_unmanaged_thunk(p_mono_method->get_mono_ptr());
+ }
+
+ GDMonoMethodThunkR() :
+ mono_method_thunk(NULL) {
+ }
+
+ explicit GDMonoMethodThunkR(GDMonoMethod *p_mono_method) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(p_mono_method == NULL);
+#endif
+ mono_method_thunk = (M)mono_method_get_unmanaged_thunk(p_mono_method->get_mono_ptr());
+ }
+};
+
+#else
+
+template <unsigned int ThunkParamCount, class P1, class... ParamTypes>
+struct VariadicInvokeMonoMethodImpl {
+ static void invoke(GDMonoMethod *p_mono_method, P1 p_arg1, ParamTypes... p_args, MonoException **r_exc) {
+ if (p_mono_method->is_static()) {
+ void *args[ThunkParamCount] = { p_arg1, p_args... };
+ p_mono_method->invoke_raw(NULL, args, r_exc);
+ } else {
+ void *args[ThunkParamCount] = { p_args... };
+ p_mono_method->invoke_raw((MonoObject *)p_arg1, args, r_exc);
+ }
+ }
+};
+
+template <unsigned int ThunkParamCount, class... ParamTypes>
+struct VariadicInvokeMonoMethod {
+ static void invoke(GDMonoMethod *p_mono_method, ParamTypes... p_args, MonoException **r_exc) {
+ VariadicInvokeMonoMethodImpl<ThunkParamCount, ParamTypes...>::invoke(p_mono_method, p_args..., r_exc);
+ }
+};
+
+template <>
+struct VariadicInvokeMonoMethod<0> {
+ static void invoke(GDMonoMethod *p_mono_method, MonoException **r_exc) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(!p_mono_method->is_static());
+#endif
+ p_mono_method->invoke_raw(NULL, NULL, r_exc);
+ }
+};
+
+template <class P1>
+struct VariadicInvokeMonoMethod<1, P1> {
+ static void invoke(GDMonoMethod *p_mono_method, P1 p_arg1, MonoException **r_exc) {
+ if (p_mono_method->is_static()) {
+ void *args[1] = { p_arg1 };
+ p_mono_method->invoke_raw(NULL, args, r_exc);
+ } else {
+ p_mono_method->invoke_raw((MonoObject *)p_arg1, NULL, r_exc);
+ }
+ }
+};
+
+template <class R>
+R unbox_if_needed(MonoObject *p_val, const ManagedType &, typename std::enable_if<!std::is_pointer<R>::value>::type * = 0) {
+ return GDMonoMarshal::unbox<R>(p_val);
+}
+
+template <class R>
+R unbox_if_needed(MonoObject *p_val, const ManagedType &p_type, typename std::enable_if<std::is_pointer<R>::value>::type * = 0) {
+ if (mono_class_is_valuetype(p_type.type_class->get_mono_ptr())) {
+ return GDMonoMarshal::unbox<R>(p_val);
+ } else {
+ // If it's not a value type, we assume 'R' is a pointer to 'MonoObject' or a compatible type, like 'MonoException'.
+ return (R)p_val;
+ }
+}
+
+template <unsigned int ThunkParamCount, class R, class P1, class... ParamTypes>
+struct VariadicInvokeMonoMethodRImpl {
+ static R invoke(GDMonoMethod *p_mono_method, P1 p_arg1, ParamTypes... p_args, MonoException **r_exc) {
+ if (p_mono_method->is_static()) {
+ void *args[ThunkParamCount] = { p_arg1, p_args... };
+ MonoObject *r = p_mono_method->invoke_raw(NULL, args, r_exc);
+ return unbox_if_needed<R>(r, p_mono_method->get_return_type());
+ } else {
+ void *args[ThunkParamCount] = { p_args... };
+ MonoObject *r = p_mono_method->invoke_raw((MonoObject *)p_arg1, args, r_exc);
+ return unbox_if_needed<R>(r, p_mono_method->get_return_type());
+ }
+ }
+};
+
+template <unsigned int ThunkParamCount, class R, class... ParamTypes>
+struct VariadicInvokeMonoMethodR {
+ static R invoke(GDMonoMethod *p_mono_method, ParamTypes... p_args, MonoException **r_exc) {
+ return VariadicInvokeMonoMethodRImpl<ThunkParamCount, R, ParamTypes...>::invoke(p_mono_method, p_args..., r_exc);
+ }
+};
+
+template <class R>
+struct VariadicInvokeMonoMethodR<0, R> {
+ static R invoke(GDMonoMethod *p_mono_method, MonoException **r_exc) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(!p_mono_method->is_static());
+#endif
+ MonoObject *r = p_mono_method->invoke_raw(NULL, NULL, r_exc);
+ return unbox_if_needed<R>(r, p_mono_method->get_return_type());
+ }
+};
+
+template <class R, class P1>
+struct VariadicInvokeMonoMethodR<1, R, P1> {
+ static R invoke(GDMonoMethod *p_mono_method, P1 p_arg1, MonoException **r_exc) {
+ if (p_mono_method->is_static()) {
+ void *args[1] = { p_arg1 };
+ MonoObject *r = p_mono_method->invoke_raw(NULL, args, r_exc);
+ return unbox_if_needed<R>(r, p_mono_method->get_return_type());
+ } else {
+ MonoObject *r = p_mono_method->invoke_raw((MonoObject *)p_arg1, NULL, r_exc);
+ return unbox_if_needed<R>(r, p_mono_method->get_return_type());
+ }
+ }
+};
+
+template <class... ParamTypes>
+struct GDMonoMethodThunk {
+
+ GDMonoMethod *mono_method;
+
+public:
+ _FORCE_INLINE_ void invoke(ParamTypes... p_args, MonoException **r_exc) {
+ VariadicInvokeMonoMethod<sizeof...(ParamTypes), ParamTypes...>::invoke(mono_method, p_args..., r_exc);
+ }
+
+ _FORCE_INLINE_ bool is_null() {
+ return mono_method == NULL;
+ }
+
+ _FORCE_INLINE_ void nullify() {
+ mono_method = NULL;
+ }
+
+ _FORCE_INLINE_ void set_from_method(GDMonoMethod *p_mono_method) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(p_mono_method == NULL);
+ CRASH_COND(p_mono_method->get_return_type().type_encoding != MONO_TYPE_VOID);
+
+ if (p_mono_method->is_static()) {
+ CRASH_COND(p_mono_method->get_parameters_count() != sizeof...(ParamTypes));
+ } else {
+ CRASH_COND(p_mono_method->get_parameters_count() != (sizeof...(ParamTypes) - 1));
+ }
+#endif
+ mono_method = p_mono_method;
+ }
+
+ GDMonoMethodThunk() :
+ mono_method(NULL) {
+ }
+
+ explicit GDMonoMethodThunk(GDMonoMethod *p_mono_method) {
+ set_from_method(p_mono_method);
+ }
+};
+
+template <class R, class... ParamTypes>
+struct GDMonoMethodThunkR {
+
+ GDMonoMethod *mono_method;
+
+public:
+ _FORCE_INLINE_ R invoke(ParamTypes... p_args, MonoException **r_exc) {
+ return VariadicInvokeMonoMethodR<sizeof...(ParamTypes), R, ParamTypes...>::invoke(mono_method, p_args..., r_exc);
+ }
+
+ _FORCE_INLINE_ bool is_null() {
+ return mono_method == NULL;
+ }
+
+ _FORCE_INLINE_ void nullify() {
+ mono_method = NULL;
+ }
+
+ _FORCE_INLINE_ void set_from_method(GDMonoMethod *p_mono_method) {
+#ifdef DEBUG_ENABLED
+ CRASH_COND(p_mono_method == NULL);
+ CRASH_COND(p_mono_method->get_return_type().type_encoding == MONO_TYPE_VOID);
+
+ if (p_mono_method->is_static()) {
+ CRASH_COND(p_mono_method->get_parameters_count() != sizeof...(ParamTypes));
+ } else {
+ CRASH_COND(p_mono_method->get_parameters_count() != (sizeof...(ParamTypes) - 1));
+ }
+#endif
+ mono_method = p_mono_method;
+ }
+
+ GDMonoMethodThunkR() :
+ mono_method(NULL) {
+ }
+
+ explicit GDMonoMethodThunkR(GDMonoMethod *p_mono_method) {
+ set_from_method(p_mono_method);
+ }
+};
+
+#endif
+
+#endif // GD_MONO_METHOD_THUNK_H
diff --git a/modules/mono/mono_gd/gd_mono_property.cpp b/modules/mono/mono_gd/gd_mono_property.cpp
index f1da00638f..277fe10087 100644
--- a/modules/mono/mono_gd/gd_mono_property.cpp
+++ b/modules/mono/mono_gd/gd_mono_property.cpp
@@ -30,8 +30,10 @@
#include "gd_mono_property.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
+#include "gd_mono_utils.h"
#include <mono/metadata/attrdefs.h>
diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp
index 6504fbe423..8d7aaa97f2 100644
--- a/modules/mono/mono_gd/gd_mono_utils.cpp
+++ b/modules/mono/mono_gd/gd_mono_utils.cpp
@@ -45,273 +45,13 @@
#include "../utils/macros.h"
#include "../utils/mutex_utils.h"
#include "gd_mono.h"
+#include "gd_mono_cache.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
+#include "gd_mono_method_thunk.h"
namespace GDMonoUtils {
-MonoCache mono_cache;
-
-#define CACHE_AND_CHECK(m_var, m_val) \
- { \
- CRASH_COND(m_var != NULL); \
- m_var = m_val; \
- ERR_FAIL_COND_MSG(!m_var, "Mono Cache: Member " #m_var " is null."); \
- }
-
-#define CACHE_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.class_##m_class, m_val)
-#define CACHE_NS_CLASS_AND_CHECK(m_ns, m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.class_##m_ns##_##m_class, m_val)
-#define CACHE_RAW_MONO_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.rawclass_##m_class, m_val)
-#define CACHE_FIELD_AND_CHECK(m_class, m_field, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.field_##m_class##_##m_field, m_val)
-#define CACHE_METHOD_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.method_##m_class##_##m_method, m_val)
-#define CACHE_METHOD_THUNK_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.methodthunk_##m_class##_##m_method, m_val)
-#define CACHE_PROPERTY_AND_CHECK(m_class, m_property, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.property_##m_class##_##m_property, m_val)
-
-void MonoCache::clear_corlib_cache() {
-
- corlib_cache_updated = false;
-
- class_MonoObject = NULL;
- class_bool = NULL;
- class_int8_t = NULL;
- class_int16_t = NULL;
- class_int32_t = NULL;
- class_int64_t = NULL;
- class_uint8_t = NULL;
- class_uint16_t = NULL;
- class_uint32_t = NULL;
- class_uint64_t = NULL;
- class_float = NULL;
- class_double = NULL;
- class_String = NULL;
- class_IntPtr = NULL;
-
- class_System_Collections_IEnumerable = NULL;
- class_System_Collections_IDictionary = NULL;
-
-#ifdef DEBUG_ENABLED
- class_System_Diagnostics_StackTrace = NULL;
- methodthunk_System_Diagnostics_StackTrace_GetFrames = NULL;
- method_System_Diagnostics_StackTrace_ctor_bool = NULL;
- method_System_Diagnostics_StackTrace_ctor_Exception_bool = NULL;
-#endif
-
- class_KeyNotFoundException = NULL;
-}
-
-void MonoCache::clear_godot_api_cache() {
-
- godot_api_cache_updated = false;
-
- rawclass_Dictionary = NULL;
-
- class_Vector2 = NULL;
- class_Rect2 = NULL;
- class_Transform2D = NULL;
- class_Vector3 = NULL;
- class_Basis = NULL;
- class_Quat = NULL;
- class_Transform = NULL;
- class_AABB = NULL;
- class_Color = NULL;
- class_Plane = NULL;
- class_NodePath = NULL;
- class_RID = NULL;
- class_GodotObject = NULL;
- class_GodotResource = NULL;
- class_Node = NULL;
- class_Control = NULL;
- class_Spatial = NULL;
- class_WeakRef = NULL;
- class_Array = NULL;
- class_Dictionary = NULL;
- class_MarshalUtils = NULL;
- class_ISerializationListener = NULL;
-
-#ifdef DEBUG_ENABLED
- class_DebuggingUtils = NULL;
- methodthunk_DebuggingUtils_GetStackFrameInfo = NULL;
-#endif
-
- class_ExportAttribute = NULL;
- field_ExportAttribute_hint = NULL;
- field_ExportAttribute_hintString = NULL;
- class_SignalAttribute = NULL;
- class_ToolAttribute = NULL;
- class_RemoteAttribute = NULL;
- class_SyncAttribute = NULL;
- class_MasterAttribute = NULL;
- class_PuppetAttribute = NULL;
- class_SlaveAttribute = NULL;
- class_RemoteSyncAttribute = NULL;
- class_MasterSyncAttribute = NULL;
- class_PuppetSyncAttribute = NULL;
- class_GodotMethodAttribute = NULL;
- field_GodotMethodAttribute_methodName = NULL;
-
- field_GodotObject_ptr = NULL;
- field_NodePath_ptr = NULL;
- field_Image_ptr = NULL;
- field_RID_ptr = NULL;
-
- methodthunk_GodotObject_Dispose = NULL;
- methodthunk_Array_GetPtr = NULL;
- methodthunk_Dictionary_GetPtr = NULL;
- methodthunk_SignalAwaiter_SignalCallback = NULL;
- methodthunk_SignalAwaiter_FailureCallback = NULL;
- methodthunk_GodotTaskScheduler_Activate = NULL;
-
- // Start of MarshalUtils methods
-
- methodthunk_MarshalUtils_TypeIsGenericArray = NULL;
- methodthunk_MarshalUtils_TypeIsGenericDictionary = NULL;
-
- methodthunk_MarshalUtils_ArrayGetElementType = NULL;
- methodthunk_MarshalUtils_DictionaryGetKeyValueTypes = NULL;
-
- methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType = NULL;
- methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType = NULL;
- methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType_with_info = NULL;
- methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType_with_info = NULL;
-
- methodthunk_MarshalUtils_MakeGenericArrayType = NULL;
- methodthunk_MarshalUtils_MakeGenericDictionaryType = NULL;
-
- methodthunk_MarshalUtils_EnumerableToArray = NULL;
- methodthunk_MarshalUtils_IDictionaryToDictionary = NULL;
- methodthunk_MarshalUtils_GenericIDictionaryToDictionary = NULL;
-
- // End of MarshalUtils methods
-
- task_scheduler_handle = Ref<MonoGCHandle>();
-}
-
-#define GODOT_API_CLASS(m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, #m_class))
-#define GODOT_API_NS_CLAS(m_ns, m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(m_ns, #m_class))
-
-void update_corlib_cache() {
-
- CACHE_CLASS_AND_CHECK(MonoObject, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_object_class()));
- CACHE_CLASS_AND_CHECK(bool, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_boolean_class()));
- CACHE_CLASS_AND_CHECK(int8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_sbyte_class()));
- CACHE_CLASS_AND_CHECK(int16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int16_class()));
- CACHE_CLASS_AND_CHECK(int32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int32_class()));
- CACHE_CLASS_AND_CHECK(int64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int64_class()));
- CACHE_CLASS_AND_CHECK(uint8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_byte_class()));
- CACHE_CLASS_AND_CHECK(uint16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint16_class()));
- CACHE_CLASS_AND_CHECK(uint32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint32_class()));
- CACHE_CLASS_AND_CHECK(uint64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint64_class()));
- CACHE_CLASS_AND_CHECK(float, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_single_class()));
- CACHE_CLASS_AND_CHECK(double, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_double_class()));
- CACHE_CLASS_AND_CHECK(String, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_string_class()));
- CACHE_CLASS_AND_CHECK(IntPtr, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_intptr_class()));
-
- CACHE_CLASS_AND_CHECK(System_Collections_IEnumerable, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IEnumerable"));
- CACHE_CLASS_AND_CHECK(System_Collections_IDictionary, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IDictionary"));
-
-#ifdef DEBUG_ENABLED
- CACHE_CLASS_AND_CHECK(System_Diagnostics_StackTrace, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Diagnostics", "StackTrace"));
- CACHE_METHOD_THUNK_AND_CHECK(System_Diagnostics_StackTrace, GetFrames, (StackTrace_GetFrames)CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_thunk("GetFrames"));
- CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(bool)", true));
- CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_Exception_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(System.Exception,bool)", true));
-#endif
-
- CACHE_CLASS_AND_CHECK(KeyNotFoundException, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections.Generic", "KeyNotFoundException"));
-
- mono_cache.corlib_cache_updated = true;
-}
-
-void update_godot_api_cache() {
-
- CACHE_CLASS_AND_CHECK(Vector2, GODOT_API_CLASS(Vector2));
- CACHE_CLASS_AND_CHECK(Rect2, GODOT_API_CLASS(Rect2));
- CACHE_CLASS_AND_CHECK(Transform2D, GODOT_API_CLASS(Transform2D));
- CACHE_CLASS_AND_CHECK(Vector3, GODOT_API_CLASS(Vector3));
- CACHE_CLASS_AND_CHECK(Basis, GODOT_API_CLASS(Basis));
- CACHE_CLASS_AND_CHECK(Quat, GODOT_API_CLASS(Quat));
- CACHE_CLASS_AND_CHECK(Transform, GODOT_API_CLASS(Transform));
- CACHE_CLASS_AND_CHECK(AABB, GODOT_API_CLASS(AABB));
- CACHE_CLASS_AND_CHECK(Color, GODOT_API_CLASS(Color));
- CACHE_CLASS_AND_CHECK(Plane, GODOT_API_CLASS(Plane));
- CACHE_CLASS_AND_CHECK(NodePath, GODOT_API_CLASS(NodePath));
- CACHE_CLASS_AND_CHECK(RID, GODOT_API_CLASS(RID));
- CACHE_CLASS_AND_CHECK(GodotObject, GODOT_API_CLASS(Object));
- CACHE_CLASS_AND_CHECK(GodotResource, GODOT_API_CLASS(Resource));
- CACHE_CLASS_AND_CHECK(Node, GODOT_API_CLASS(Node));
- CACHE_CLASS_AND_CHECK(Control, GODOT_API_CLASS(Control));
- CACHE_CLASS_AND_CHECK(Spatial, GODOT_API_CLASS(Spatial));
- CACHE_CLASS_AND_CHECK(WeakRef, GODOT_API_CLASS(WeakRef));
- CACHE_CLASS_AND_CHECK(Array, GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Array));
- CACHE_CLASS_AND_CHECK(Dictionary, GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary));
- CACHE_CLASS_AND_CHECK(MarshalUtils, GODOT_API_CLASS(MarshalUtils));
- CACHE_CLASS_AND_CHECK(ISerializationListener, GODOT_API_CLASS(ISerializationListener));
-
-#ifdef DEBUG_ENABLED
- CACHE_CLASS_AND_CHECK(DebuggingUtils, GODOT_API_CLASS(DebuggingUtils));
-#endif
-
- // Attributes
- CACHE_CLASS_AND_CHECK(ExportAttribute, GODOT_API_CLASS(ExportAttribute));
- CACHE_FIELD_AND_CHECK(ExportAttribute, hint, CACHED_CLASS(ExportAttribute)->get_field("hint"));
- CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString"));
- CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute));
- CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute));
- CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute));
- CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute));
- CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute));
- CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute));
- CACHE_CLASS_AND_CHECK(SlaveAttribute, GODOT_API_CLASS(SlaveAttribute));
- CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute));
- CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute));
- CACHE_CLASS_AND_CHECK(PuppetSyncAttribute, GODOT_API_CLASS(PuppetSyncAttribute));
- CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute));
- CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName"));
-
- CACHE_FIELD_AND_CHECK(GodotObject, ptr, CACHED_CLASS(GodotObject)->get_field(BINDINGS_PTR_FIELD));
- CACHE_FIELD_AND_CHECK(NodePath, ptr, CACHED_CLASS(NodePath)->get_field(BINDINGS_PTR_FIELD));
- CACHE_FIELD_AND_CHECK(RID, ptr, CACHED_CLASS(RID)->get_field(BINDINGS_PTR_FIELD));
-
- CACHE_METHOD_THUNK_AND_CHECK(GodotObject, Dispose, (GodotObject_Dispose)CACHED_CLASS(GodotObject)->get_method_thunk("Dispose", 0));
- CACHE_METHOD_THUNK_AND_CHECK(Array, GetPtr, (Array_GetPtr)GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Array)->get_method_thunk("GetPtr", 0));
- CACHE_METHOD_THUNK_AND_CHECK(Dictionary, GetPtr, (Dictionary_GetPtr)GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary)->get_method_thunk("GetPtr", 0));
- CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, SignalCallback, (SignalAwaiter_SignalCallback)GODOT_API_CLASS(SignalAwaiter)->get_method_thunk("SignalCallback", 1));
- CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, FailureCallback, (SignalAwaiter_FailureCallback)GODOT_API_CLASS(SignalAwaiter)->get_method_thunk("FailureCallback", 0));
- CACHE_METHOD_THUNK_AND_CHECK(GodotTaskScheduler, Activate, (GodotTaskScheduler_Activate)GODOT_API_CLASS(GodotTaskScheduler)->get_method_thunk("Activate", 0));
-
- // Start of MarshalUtils methods
-
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericArray, (TypeIsGenericArray)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("TypeIsGenericArray", 1));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericDictionary, (TypeIsGenericDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("TypeIsGenericDictionary", 1));
-
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, ArrayGetElementType, (ArrayGetElementType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("ArrayGetElementType", 2));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, DictionaryGetKeyValueTypes, (DictionaryGetKeyValueTypes)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("DictionaryGetKeyValueTypes", 3));
-
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType, (GenericIEnumerableIsAssignableFromType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIEnumerableIsAssignableFromType", 1));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType, (GenericIDictionaryIsAssignableFromType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryIsAssignableFromType", 1));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info, (GenericIEnumerableIsAssignableFromType_with_info)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIEnumerableIsAssignableFromType", 2));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info, (GenericIDictionaryIsAssignableFromType_with_info)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryIsAssignableFromType", 3));
-
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericArrayType, (MakeGenericArrayType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("MakeGenericArrayType", 1));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericDictionaryType, (MakeGenericDictionaryType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("MakeGenericDictionaryType", 2));
-
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, EnumerableToArray, (EnumerableToArray)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("EnumerableToArray", 2));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, IDictionaryToDictionary, (IDictionaryToDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("IDictionaryToDictionary", 2));
- CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryToDictionary, (GenericIDictionaryToDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryToDictionary", 2));
-
- // End of MarshalUtils methods
-
-#ifdef DEBUG_ENABLED
- CACHE_METHOD_THUNK_AND_CHECK(DebuggingUtils, GetStackFrameInfo, (DebugUtils_StackFrameInfo)GODOT_API_CLASS(DebuggingUtils)->get_method_thunk("GetStackFrameInfo", 4));
-#endif
-
- // TODO Move to CSharpLanguage::init() and do handle disposal
- MonoObject *task_scheduler = mono_object_new(mono_domain_get(), GODOT_API_CLASS(GodotTaskScheduler)->get_mono_ptr());
- GDMonoUtils::runtime_object_init(task_scheduler, GODOT_API_CLASS(GodotTaskScheduler));
- mono_cache.task_scheduler_handle = MonoGCHandle::create_strong(task_scheduler);
-
- mono_cache.godot_api_cache_updated = true;
-}
-
MonoObject *unmanaged_get_managed(Object *unmanaged) {
if (!unmanaged)
@@ -386,7 +126,7 @@ void set_main_thread(MonoThread *p_thread) {
void attach_current_thread() {
ERR_FAIL_COND(!GDMono::get_singleton()->is_runtime_initialized());
- MonoThread *mono_thread = mono_thread_attach(mono_domain_get());
+ MonoThread *mono_thread = mono_thread_attach(mono_get_root_domain());
ERR_FAIL_NULL(mono_thread);
}
@@ -421,7 +161,7 @@ GDMonoClass *type_get_proxy_class(const StringName &p_type) {
if (klass && klass->is_static()) {
// A static class means this is a Godot singleton class. If an instance is needed we use Godot.Object.
- return mono_cache.class_GodotObject;
+ return GDMonoCache::cached_data.class_GodotObject;
}
#ifdef TOOLS_ENABLED
@@ -751,16 +491,16 @@ uint64_t unbox_enum_value(MonoObject *p_boxed, MonoType *p_enum_basetype, bool &
}
void dispose(MonoObject *p_mono_object, MonoException **r_exc) {
- invoke_method_thunk(CACHED_METHOD_THUNK(GodotObject, Dispose), p_mono_object, r_exc);
+ CACHED_METHOD_THUNK(GodotObject, Dispose).invoke(p_mono_object, r_exc);
}
namespace Marshal {
#ifdef MONO_GLUE_ENABLED
#ifdef TOOLS_ENABLED
-#define NO_GLUE_RET(m_ret) \
- { \
- if (!mono_cache.godot_api_cache_updated) return m_ret; \
+#define NO_GLUE_RET(m_ret) \
+ { \
+ if (!GDMonoCache::cached_data.godot_api_cache_updated) return m_ret; \
}
#else
#define NO_GLUE_RET(m_ret) \
@@ -773,68 +513,60 @@ namespace Marshal {
bool type_is_generic_array(MonoReflectionType *p_reftype) {
NO_GLUE_RET(false);
- TypeIsGenericArray thunk = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericArray);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericArray).invoke(p_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
bool type_is_generic_dictionary(MonoReflectionType *p_reftype) {
NO_GLUE_RET(false);
- TypeIsGenericDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericDictionary);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericDictionary).invoke(p_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
void array_get_element_type(MonoReflectionType *p_array_reftype, MonoReflectionType **r_elem_reftype) {
- ArrayGetElementType thunk = CACHED_METHOD_THUNK(MarshalUtils, ArrayGetElementType);
MonoException *exc = NULL;
- invoke_method_thunk(thunk, p_array_reftype, r_elem_reftype, &exc);
+ CACHED_METHOD_THUNK(MarshalUtils, ArrayGetElementType).invoke(p_array_reftype, r_elem_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
}
void dictionary_get_key_value_types(MonoReflectionType *p_dict_reftype, MonoReflectionType **r_key_reftype, MonoReflectionType **r_value_reftype) {
- DictionaryGetKeyValueTypes thunk = CACHED_METHOD_THUNK(MarshalUtils, DictionaryGetKeyValueTypes);
MonoException *exc = NULL;
- invoke_method_thunk(thunk, p_dict_reftype, r_key_reftype, r_value_reftype, &exc);
+ CACHED_METHOD_THUNK(MarshalUtils, DictionaryGetKeyValueTypes).invoke(p_dict_reftype, r_key_reftype, r_value_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
}
bool generic_ienumerable_is_assignable_from(MonoReflectionType *p_reftype) {
NO_GLUE_RET(false);
- GenericIEnumerableIsAssignableFromType thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType).invoke(p_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
bool generic_idictionary_is_assignable_from(MonoReflectionType *p_reftype) {
NO_GLUE_RET(false);
- GenericIDictionaryIsAssignableFromType thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType).invoke(p_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
bool generic_ienumerable_is_assignable_from(MonoReflectionType *p_reftype, MonoReflectionType **r_elem_reftype) {
NO_GLUE_RET(false);
- GenericIEnumerableIsAssignableFromType_with_info thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, r_elem_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info).invoke(p_reftype, r_elem_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
bool generic_idictionary_is_assignable_from(MonoReflectionType *p_reftype, MonoReflectionType **r_key_reftype, MonoReflectionType **r_value_reftype) {
NO_GLUE_RET(false);
- GenericIDictionaryIsAssignableFromType_with_info thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info);
MonoException *exc = NULL;
- MonoBoolean res = invoke_method_thunk(thunk, p_reftype, r_key_reftype, r_value_reftype, &exc);
+ MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info).invoke(p_reftype, r_key_reftype, r_value_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return (bool)res;
}
@@ -842,9 +574,8 @@ bool generic_idictionary_is_assignable_from(MonoReflectionType *p_reftype, MonoR
Array enumerable_to_array(MonoObject *p_enumerable) {
NO_GLUE_RET(Array());
Array result;
- EnumerableToArray thunk = CACHED_METHOD_THUNK(MarshalUtils, EnumerableToArray);
MonoException *exc = NULL;
- invoke_method_thunk(thunk, p_enumerable, &result, &exc);
+ CACHED_METHOD_THUNK(MarshalUtils, EnumerableToArray).invoke(p_enumerable, &result, &exc);
UNHANDLED_EXCEPTION(exc);
return result;
}
@@ -852,9 +583,8 @@ Array enumerable_to_array(MonoObject *p_enumerable) {
Dictionary idictionary_to_dictionary(MonoObject *p_idictionary) {
NO_GLUE_RET(Dictionary());
Dictionary result;
- IDictionaryToDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, IDictionaryToDictionary);
MonoException *exc = NULL;
- invoke_method_thunk(thunk, p_idictionary, &result, &exc);
+ CACHED_METHOD_THUNK(MarshalUtils, IDictionaryToDictionary).invoke(p_idictionary, &result, &exc);
UNHANDLED_EXCEPTION(exc);
return result;
}
@@ -862,27 +592,24 @@ Dictionary idictionary_to_dictionary(MonoObject *p_idictionary) {
Dictionary generic_idictionary_to_dictionary(MonoObject *p_generic_idictionary) {
NO_GLUE_RET(Dictionary());
Dictionary result;
- GenericIDictionaryToDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryToDictionary);
MonoException *exc = NULL;
- invoke_method_thunk(thunk, p_generic_idictionary, &result, &exc);
+ CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryToDictionary).invoke(p_generic_idictionary, &result, &exc);
UNHANDLED_EXCEPTION(exc);
return result;
}
GDMonoClass *make_generic_array_type(MonoReflectionType *p_elem_reftype) {
NO_GLUE_RET(NULL);
- MakeGenericArrayType thunk = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericArrayType);
MonoException *exc = NULL;
- MonoReflectionType *reftype = invoke_method_thunk(thunk, p_elem_reftype, &exc);
+ MonoReflectionType *reftype = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericArrayType).invoke(p_elem_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return GDMono::get_singleton()->get_class(mono_class_from_mono_type(mono_reflection_type_get_type(reftype)));
}
GDMonoClass *make_generic_dictionary_type(MonoReflectionType *p_key_reftype, MonoReflectionType *p_value_reftype) {
NO_GLUE_RET(NULL);
- MakeGenericDictionaryType thunk = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericDictionaryType);
MonoException *exc = NULL;
- MonoReflectionType *reftype = invoke_method_thunk(thunk, p_key_reftype, p_value_reftype, &exc);
+ MonoReflectionType *reftype = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericDictionaryType).invoke(p_key_reftype, p_value_reftype, &exc);
UNHANDLED_EXCEPTION(exc);
return GDMono::get_singleton()->get_class(mono_class_from_mono_type(mono_reflection_type_get_type(reftype)));
}
diff --git a/modules/mono/mono_gd/gd_mono_utils.h b/modules/mono/mono_gd/gd_mono_utils.h
index d73743bf0b..848df843fe 100644
--- a/modules/mono/mono_gd/gd_mono_utils.h
+++ b/modules/mono/mono_gd/gd_mono_utils.h
@@ -49,33 +49,6 @@
namespace GDMonoUtils {
-typedef void (*GodotObject_Dispose)(MonoObject *, MonoException **);
-typedef Array *(*Array_GetPtr)(MonoObject *, MonoException **);
-typedef Dictionary *(*Dictionary_GetPtr)(MonoObject *, MonoException **);
-typedef MonoObject *(*SignalAwaiter_SignalCallback)(MonoObject *, MonoArray *, MonoException **);
-typedef MonoObject *(*SignalAwaiter_FailureCallback)(MonoObject *, MonoException **);
-typedef MonoObject *(*GodotTaskScheduler_Activate)(MonoObject *, MonoException **);
-typedef MonoArray *(*StackTrace_GetFrames)(MonoObject *, MonoException **);
-typedef void (*DebugUtils_StackFrameInfo)(MonoObject *, MonoString **, int *, MonoString **, MonoException **);
-
-typedef MonoBoolean (*TypeIsGenericArray)(MonoReflectionType *, MonoException **);
-typedef MonoBoolean (*TypeIsGenericDictionary)(MonoReflectionType *, MonoException **);
-
-typedef void (*ArrayGetElementType)(MonoReflectionType *, MonoReflectionType **, MonoException **);
-typedef void (*DictionaryGetKeyValueTypes)(MonoReflectionType *, MonoReflectionType **, MonoReflectionType **, MonoException **);
-
-typedef MonoBoolean (*GenericIEnumerableIsAssignableFromType)(MonoReflectionType *, MonoException **);
-typedef MonoBoolean (*GenericIDictionaryIsAssignableFromType)(MonoReflectionType *, MonoException **);
-typedef MonoBoolean (*GenericIEnumerableIsAssignableFromType_with_info)(MonoReflectionType *, MonoReflectionType **, MonoException **);
-typedef MonoBoolean (*GenericIDictionaryIsAssignableFromType_with_info)(MonoReflectionType *, MonoReflectionType **, MonoReflectionType **, MonoException **);
-
-typedef MonoReflectionType *(*MakeGenericArrayType)(MonoReflectionType *, MonoException **);
-typedef MonoReflectionType *(*MakeGenericDictionaryType)(MonoReflectionType *, MonoReflectionType *, MonoException **);
-
-typedef void (*EnumerableToArray)(MonoObject *, Array *, MonoException **);
-typedef void (*IDictionaryToDictionary)(MonoObject *, Dictionary *, MonoException **);
-typedef void (*GenericIDictionaryToDictionary)(MonoObject *, Dictionary *, MonoException **);
-
namespace Marshal {
bool type_is_generic_array(MonoReflectionType *p_reftype);
@@ -98,157 +71,6 @@ Dictionary generic_idictionary_to_dictionary(MonoObject *p_generic_idictionary);
} // namespace Marshal
-// End of MarshalUtils methods
-
-struct MonoCache {
-
- // -----------------------------------------------
- // corlib classes
-
- // Let's use the no-namespace format for these too
- GDMonoClass *class_MonoObject;
- GDMonoClass *class_bool;
- GDMonoClass *class_int8_t;
- GDMonoClass *class_int16_t;
- GDMonoClass *class_int32_t;
- GDMonoClass *class_int64_t;
- GDMonoClass *class_uint8_t;
- GDMonoClass *class_uint16_t;
- GDMonoClass *class_uint32_t;
- GDMonoClass *class_uint64_t;
- GDMonoClass *class_float;
- GDMonoClass *class_double;
- GDMonoClass *class_String;
- GDMonoClass *class_IntPtr;
-
- GDMonoClass *class_System_Collections_IEnumerable;
- GDMonoClass *class_System_Collections_IDictionary;
-
-#ifdef DEBUG_ENABLED
- GDMonoClass *class_System_Diagnostics_StackTrace;
- StackTrace_GetFrames methodthunk_System_Diagnostics_StackTrace_GetFrames;
- GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_bool;
- GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_Exception_bool;
-#endif
-
- GDMonoClass *class_KeyNotFoundException;
-
- MonoClass *rawclass_Dictionary;
- // -----------------------------------------------
-
- GDMonoClass *class_Vector2;
- GDMonoClass *class_Rect2;
- GDMonoClass *class_Transform2D;
- GDMonoClass *class_Vector3;
- GDMonoClass *class_Basis;
- GDMonoClass *class_Quat;
- GDMonoClass *class_Transform;
- GDMonoClass *class_AABB;
- GDMonoClass *class_Color;
- GDMonoClass *class_Plane;
- GDMonoClass *class_NodePath;
- GDMonoClass *class_RID;
- GDMonoClass *class_GodotObject;
- GDMonoClass *class_GodotResource;
- GDMonoClass *class_Node;
- GDMonoClass *class_Control;
- GDMonoClass *class_Spatial;
- GDMonoClass *class_WeakRef;
- GDMonoClass *class_Array;
- GDMonoClass *class_Dictionary;
- GDMonoClass *class_MarshalUtils;
- GDMonoClass *class_ISerializationListener;
-
-#ifdef DEBUG_ENABLED
- GDMonoClass *class_DebuggingUtils;
- DebugUtils_StackFrameInfo methodthunk_DebuggingUtils_GetStackFrameInfo;
-#endif
-
- GDMonoClass *class_ExportAttribute;
- GDMonoField *field_ExportAttribute_hint;
- GDMonoField *field_ExportAttribute_hintString;
- GDMonoClass *class_SignalAttribute;
- GDMonoClass *class_ToolAttribute;
- GDMonoClass *class_RemoteAttribute;
- GDMonoClass *class_SyncAttribute;
- GDMonoClass *class_RemoteSyncAttribute;
- GDMonoClass *class_MasterSyncAttribute;
- GDMonoClass *class_PuppetSyncAttribute;
- GDMonoClass *class_MasterAttribute;
- GDMonoClass *class_PuppetAttribute;
- GDMonoClass *class_SlaveAttribute;
- GDMonoClass *class_GodotMethodAttribute;
- GDMonoField *field_GodotMethodAttribute_methodName;
-
- GDMonoField *field_GodotObject_ptr;
- GDMonoField *field_NodePath_ptr;
- GDMonoField *field_Image_ptr;
- GDMonoField *field_RID_ptr;
-
- GodotObject_Dispose methodthunk_GodotObject_Dispose;
- Array_GetPtr methodthunk_Array_GetPtr;
- Dictionary_GetPtr methodthunk_Dictionary_GetPtr;
- SignalAwaiter_SignalCallback methodthunk_SignalAwaiter_SignalCallback;
- SignalAwaiter_FailureCallback methodthunk_SignalAwaiter_FailureCallback;
- GodotTaskScheduler_Activate methodthunk_GodotTaskScheduler_Activate;
-
- // Start of MarshalUtils methods
-
- TypeIsGenericArray methodthunk_MarshalUtils_TypeIsGenericArray;
- TypeIsGenericDictionary methodthunk_MarshalUtils_TypeIsGenericDictionary;
-
- ArrayGetElementType methodthunk_MarshalUtils_ArrayGetElementType;
- DictionaryGetKeyValueTypes methodthunk_MarshalUtils_DictionaryGetKeyValueTypes;
-
- GenericIEnumerableIsAssignableFromType methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType;
- GenericIDictionaryIsAssignableFromType methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType;
- GenericIEnumerableIsAssignableFromType_with_info methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType_with_info;
- GenericIDictionaryIsAssignableFromType_with_info methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType_with_info;
-
- MakeGenericArrayType methodthunk_MarshalUtils_MakeGenericArrayType;
- MakeGenericDictionaryType methodthunk_MarshalUtils_MakeGenericDictionaryType;
-
- EnumerableToArray methodthunk_MarshalUtils_EnumerableToArray;
- IDictionaryToDictionary methodthunk_MarshalUtils_IDictionaryToDictionary;
- GenericIDictionaryToDictionary methodthunk_MarshalUtils_GenericIDictionaryToDictionary;
-
- // End of MarshalUtils methods
-
- Ref<MonoGCHandle> task_scheduler_handle;
-
- bool corlib_cache_updated;
- bool godot_api_cache_updated;
-
- void clear_corlib_cache();
- void clear_godot_api_cache();
-
- MonoCache() {
- clear_corlib_cache();
- clear_godot_api_cache();
- }
-};
-
-extern MonoCache mono_cache;
-
-void update_corlib_cache();
-void update_godot_api_cache();
-
-inline void clear_corlib_cache() {
- mono_cache.clear_corlib_cache();
-}
-
-inline void clear_godot_api_cache() {
- mono_cache.clear_godot_api_cache();
-}
-
-_FORCE_INLINE_ bool tools_godot_api_check() {
-#ifdef TOOLS_ENABLED
- return mono_cache.godot_api_cache_updated;
-#else
- return true; // Assume it's updated if this was called, otherwise it's a bug
-#endif
-}
-
_FORCE_INLINE_ void hash_combine(uint32_t &p_hash, const uint32_t &p_with_hash) {
p_hash ^= p_with_hash + 0x9e3779b9 + (p_hash << 6) + (p_hash >> 2);
}
@@ -324,20 +146,6 @@ void dispose(MonoObject *p_mono_object, MonoException **r_exc);
#define NATIVE_GDMONOCLASS_NAME(m_class) (GDMonoMarshal::mono_string_to_godot((MonoString *)m_class->get_field(BINDINGS_NATIVE_NAME_FIELD)->get_value(NULL)))
-#define CACHED_CLASS(m_class) (GDMonoUtils::mono_cache.class_##m_class)
-#define CACHED_CLASS_RAW(m_class) (GDMonoUtils::mono_cache.class_##m_class->get_mono_ptr())
-#define CACHED_RAW_MONO_CLASS(m_class) (GDMonoUtils::mono_cache.rawclass_##m_class)
-#define CACHED_FIELD(m_class, m_field) (GDMonoUtils::mono_cache.field_##m_class##_##m_field)
-#define CACHED_METHOD(m_class, m_method) (GDMonoUtils::mono_cache.method_##m_class##_##m_method)
-#define CACHED_METHOD_THUNK(m_class, m_method) (GDMonoUtils::mono_cache.methodthunk_##m_class##_##m_method)
-#define CACHED_PROPERTY(m_class, m_property) (GDMonoUtils::mono_cache.property_##m_class##_##m_property)
-
-#ifdef REAL_T_IS_DOUBLE
-#define REAL_T_MONOCLASS CACHED_CLASS_RAW(double)
-#else
-#define REAL_T_MONOCLASS CACHED_CLASS_RAW(float)
-#endif
-
#define GD_MONO_BEGIN_RUNTIME_INVOKE \
int &_runtime_invoke_count_ref = GDMonoUtils::get_runtime_invoke_count_ref(); \
_runtime_invoke_count_ref += 1;
@@ -345,93 +153,4 @@ void dispose(MonoObject *p_mono_object, MonoException **r_exc);
#define GD_MONO_END_RUNTIME_INVOKE \
_runtime_invoke_count_ref -= 1;
-inline void invoke_method_thunk(void (*p_method_thunk)()) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk();
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R>
-R invoke_method_thunk(R (*p_method_thunk)()) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk();
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
-template <class P1>
-void invoke_method_thunk(void (*p_method_thunk)(P1), P1 p_arg1) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk(p_arg1);
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R, class P1>
-R invoke_method_thunk(R (*p_method_thunk)(P1), P1 p_arg1) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk(p_arg1);
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
-template <class P1, class P2>
-void invoke_method_thunk(void (*p_method_thunk)(P1, P2), P1 p_arg1, P2 p_arg2) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk(p_arg1, p_arg2);
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R, class P1, class P2>
-R invoke_method_thunk(R (*p_method_thunk)(P1, P2), P1 p_arg1, P2 p_arg2) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk(p_arg1, p_arg2);
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
-template <class P1, class P2, class P3>
-void invoke_method_thunk(void (*p_method_thunk)(P1, P2, P3), P1 p_arg1, P2 p_arg2, P3 p_arg3) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk(p_arg1, p_arg2, p_arg3);
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R, class P1, class P2, class P3>
-R invoke_method_thunk(R (*p_method_thunk)(P1, P2, P3), P1 p_arg1, P2 p_arg2, P3 p_arg3) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk(p_arg1, p_arg2, p_arg3);
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
-template <class P1, class P2, class P3, class P4>
-void invoke_method_thunk(void (*p_method_thunk)(P1, P2, P3, P4), P1 p_arg1, P2 p_arg2, P3 p_arg3, P4 p_arg4) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk(p_arg1, p_arg2, p_arg3, p_arg4);
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R, class P1, class P2, class P3, class P4>
-R invoke_method_thunk(R (*p_method_thunk)(P1, P2, P3, P4), P1 p_arg1, P2 p_arg2, P3 p_arg3, P4 p_arg4) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk(p_arg1, p_arg2, p_arg3, p_arg4);
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
-template <class P1, class P2, class P3, class P4, class P5>
-void invoke_method_thunk(void (*p_method_thunk)(P1, P2, P3, P4, P5), P1 p_arg1, P2 p_arg2, P3 p_arg3, P4 p_arg4, P5 p_arg5) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- p_method_thunk(p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- GD_MONO_END_RUNTIME_INVOKE;
-}
-
-template <class R, class P1, class P2, class P3, class P4, class P5>
-R invoke_method_thunk(R (*p_method_thunk)(P1, P2, P3, P4, P5), P1 p_arg1, P2 p_arg2, P3 p_arg3, P4 p_arg4, P5 p_arg5) {
- GD_MONO_BEGIN_RUNTIME_INVOKE;
- R r = p_method_thunk(p_arg1, p_arg2, p_arg3, p_arg4, p_arg5);
- GD_MONO_END_RUNTIME_INVOKE;
- return r;
-}
-
#endif // GD_MONOUTILS_H