2017-10-02 21:24:00 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gd_mono_utils.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-10-02 21:24:00 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
#include "gd_mono_utils.h"
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
#include <mono/metadata/debug-helpers.h>
|
2018-06-26 19:03:42 +00:00
|
|
|
#include <mono/metadata/exception.h>
|
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
#include "core/debugger/engine_debugger.h"
|
|
|
|
#include "core/debugger/script_debugger.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/object/reference.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/dir_access.h"
|
2020-02-26 10:28:13 +00:00
|
|
|
#include "core/os/mutex.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/os.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2019-07-24 21:13:24 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-02-24 05:21:15 +00:00
|
|
|
#include "editor/debugger/editor_debugger_node.h"
|
2019-07-24 21:13:24 +00:00
|
|
|
#endif
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
#include "../csharp_script.h"
|
2018-06-26 19:03:42 +00:00
|
|
|
#include "../utils/macros.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
#include "gd_mono.h"
|
2019-11-10 16:10:38 +00:00
|
|
|
#include "gd_mono_cache.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
#include "gd_mono_class.h"
|
|
|
|
#include "gd_mono_marshal.h"
|
|
|
|
|
|
|
|
namespace GDMonoUtils {
|
|
|
|
|
|
|
|
MonoObject *unmanaged_get_managed(Object *unmanaged) {
|
2020-07-05 17:19:36 +00:00
|
|
|
if (!unmanaged) {
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2019-02-03 05:35:22 +00:00
|
|
|
|
|
|
|
if (unmanaged->get_script_instance()) {
|
|
|
|
CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(unmanaged->get_script_instance());
|
|
|
|
|
|
|
|
if (cs_instance) {
|
|
|
|
return cs_instance->get_mono_object();
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
2019-02-03 05:35:22 +00:00
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
// If the owner does not have a CSharpInstance...
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
void *data = unmanaged->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index());
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(data, nullptr);
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->value();
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
if (!script_binding.inited) {
|
2020-02-26 10:28:13 +00:00
|
|
|
MutexLock lock(CSharpLanguage::get_singleton()->get_language_bind_mutex());
|
2019-02-04 19:39:02 +00:00
|
|
|
|
|
|
|
if (!script_binding.inited) { // Other thread may have set it up
|
|
|
|
// Already had a binding that needs to be setup
|
|
|
|
CSharpLanguage::get_singleton()->setup_csharp_script_binding(script_binding, unmanaged);
|
2019-02-03 05:35:22 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(!script_binding.inited, nullptr);
|
2019-02-04 19:39:02 +00:00
|
|
|
}
|
2019-02-03 05:35:22 +00:00
|
|
|
}
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-12-11 16:08:40 +00:00
|
|
|
MonoGCHandleData &gchandle = script_binding.gchandle;
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-12-11 16:08:40 +00:00
|
|
|
MonoObject *target = gchandle.get_target();
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2020-07-05 17:19:36 +00:00
|
|
|
if (target) {
|
2019-02-03 05:35:22 +00:00
|
|
|
return target;
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2019-02-03 05:35:22 +00:00
|
|
|
|
|
|
|
CSharpLanguage::get_singleton()->release_script_gchandle(gchandle);
|
|
|
|
|
|
|
|
// Create a new one
|
2018-09-12 00:41:54 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
2019-02-03 05:35:22 +00:00
|
|
|
CRASH_COND(script_binding.type_name == StringName());
|
2020-04-01 23:20:12 +00:00
|
|
|
CRASH_COND(script_binding.wrapper_class == nullptr);
|
2018-09-12 00:41:54 +00:00
|
|
|
#endif
|
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
MonoObject *mono_object = GDMonoUtils::create_managed_for_godot_object(script_binding.wrapper_class, script_binding.type_name, unmanaged);
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-12-11 16:08:40 +00:00
|
|
|
gchandle = MonoGCHandleData::new_strong_handle(mono_object);
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
// Tie managed to unmanaged
|
|
|
|
Reference *ref = Object::cast_to<Reference>(unmanaged);
|
2018-09-12 00:41:54 +00:00
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
if (ref) {
|
|
|
|
// Unsafe refcount increment. The managed instance also counts as a reference.
|
|
|
|
// This way if the unmanaged world has no references to our owner
|
|
|
|
// but the managed instance is alive, the refcount will be 1 instead of 0.
|
|
|
|
// See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr)
|
|
|
|
ref->reference();
|
2020-01-13 20:00:07 +00:00
|
|
|
CSharpLanguage::get_singleton()->post_unsafe_reference(ref);
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 05:35:22 +00:00
|
|
|
return mono_object;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_main_thread(MonoThread *p_thread) {
|
|
|
|
mono_thread_set_main(p_thread);
|
|
|
|
}
|
|
|
|
|
2020-01-16 16:11:13 +00:00
|
|
|
MonoThread *attach_current_thread() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(!GDMono::get_singleton()->is_runtime_initialized(), nullptr);
|
2020-01-16 16:11:13 +00:00
|
|
|
MonoDomain *scripts_domain = GDMono::get_singleton()->get_scripts_domain();
|
2020-03-18 16:40:04 +00:00
|
|
|
#ifndef GD_MONO_SINGLE_APPDOMAIN
|
2020-01-16 16:11:13 +00:00
|
|
|
MonoThread *mono_thread = mono_thread_attach(scripts_domain ? scripts_domain : mono_get_root_domain());
|
2020-03-18 16:40:04 +00:00
|
|
|
#else
|
|
|
|
// The scripts domain is the root domain
|
|
|
|
MonoThread *mono_thread = mono_thread_attach(scripts_domain);
|
|
|
|
#endif
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_thread, nullptr);
|
2020-01-16 16:11:13 +00:00
|
|
|
return mono_thread;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void detach_current_thread() {
|
|
|
|
ERR_FAIL_COND(!GDMono::get_singleton()->is_runtime_initialized());
|
|
|
|
MonoThread *mono_thread = mono_thread_current();
|
|
|
|
ERR_FAIL_NULL(mono_thread);
|
|
|
|
mono_thread_detach(mono_thread);
|
|
|
|
}
|
|
|
|
|
2020-01-16 16:11:13 +00:00
|
|
|
void detach_current_thread(MonoThread *p_mono_thread) {
|
|
|
|
ERR_FAIL_COND(!GDMono::get_singleton()->is_runtime_initialized());
|
|
|
|
ERR_FAIL_NULL(p_mono_thread);
|
|
|
|
mono_thread_detach(p_mono_thread);
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
MonoThread *get_current_thread() {
|
|
|
|
return mono_thread_current();
|
|
|
|
}
|
|
|
|
|
2020-01-16 16:11:13 +00:00
|
|
|
bool is_thread_attached() {
|
2020-04-01 23:20:12 +00:00
|
|
|
return mono_domain_get() != nullptr;
|
2020-01-16 16:11:13 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 16:08:40 +00:00
|
|
|
uint32_t new_strong_gchandle(MonoObject *p_object) {
|
|
|
|
return mono_gchandle_new(p_object, /* pinned: */ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t new_strong_gchandle_pinned(MonoObject *p_object) {
|
|
|
|
return mono_gchandle_new(p_object, /* pinned: */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t new_weak_gchandle(MonoObject *p_object) {
|
|
|
|
return mono_gchandle_new_weakref(p_object, /* track_resurrection: */ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_gchandle(uint32_t p_gchandle) {
|
|
|
|
mono_gchandle_free(p_gchandle);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:06:04 +00:00
|
|
|
void runtime_object_init(MonoObject *p_this_obj, GDMonoClass *p_class, MonoException **r_exc) {
|
|
|
|
GDMonoMethod *ctor = p_class->get_method(".ctor", 0);
|
|
|
|
ERR_FAIL_NULL(ctor);
|
2020-04-01 23:20:12 +00:00
|
|
|
ctor->invoke_raw(p_this_obj, nullptr, r_exc);
|
2018-07-18 21:07:57 +00:00
|
|
|
}
|
|
|
|
|
2020-03-14 18:20:17 +00:00
|
|
|
bool mono_delegate_equal(MonoDelegate *p_a, MonoDelegate *p_b) {
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-03-14 18:20:17 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(Delegate, Equals).invoke((MonoObject *)p_a, (MonoObject *)p_b, &exc);
|
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
GDMonoClass *get_object_class(MonoObject *p_object) {
|
|
|
|
return GDMono::get_singleton()->get_class(mono_object_get_class(p_object));
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *type_get_proxy_class(const StringName &p_type) {
|
|
|
|
String class_name = p_type;
|
|
|
|
|
2020-07-05 17:19:36 +00:00
|
|
|
if (class_name[0] == '_') {
|
2017-10-02 21:24:00 +00:00
|
|
|
class_name = class_name.substr(1, class_name.length());
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2018-02-22 12:13:51 +00:00
|
|
|
GDMonoClass *klass = GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, class_name);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2019-02-19 21:36:27 +00:00
|
|
|
if (klass && klass->is_static()) {
|
|
|
|
// A static class means this is a Godot singleton class. If an instance is needed we use Godot.Object.
|
2019-11-10 16:10:38 +00:00
|
|
|
return GDMonoCache::cached_data.class_GodotObject;
|
2019-02-19 21:36:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!klass) {
|
|
|
|
return GDMono::get_singleton()->get_editor_api_assembly()->get_class(BINDINGS_NAMESPACE, class_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *get_class_native_base(GDMonoClass *p_class) {
|
|
|
|
GDMonoClass *klass = p_class;
|
|
|
|
|
|
|
|
do {
|
|
|
|
const GDMonoAssembly *assembly = klass->get_assembly();
|
2020-07-05 17:19:36 +00:00
|
|
|
|
|
|
|
if (assembly == GDMono::get_singleton()->get_core_api_assembly()) {
|
2017-10-02 21:24:00 +00:00
|
|
|
return klass;
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-07-05 17:19:36 +00:00
|
|
|
if (assembly == GDMono::get_singleton()->get_editor_api_assembly()) {
|
2017-10-02 21:24:00 +00:00
|
|
|
return klass;
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
2020-04-01 23:20:12 +00:00
|
|
|
} while ((klass = klass->get_parent_class()) != nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
return nullptr;
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringName &p_native, Object *p_object) {
|
2019-08-09 01:39:45 +00:00
|
|
|
bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), p_native);
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V_MSG(!parent_is_object_class, nullptr,
|
2019-08-09 01:39:45 +00:00
|
|
|
"Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'.");
|
2017-10-02 21:24:00 +00:00
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
CACHED_FIELD(GodotObject, ptr)->set_value_raw(mono_object, p_object);
|
|
|
|
|
|
|
|
// Construct
|
2019-05-20 22:06:04 +00:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, p_class);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2020-03-14 18:20:17 +00:00
|
|
|
MonoObject *create_managed_from(const StringName &p_from) {
|
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), CACHED_CLASS_RAW(StringName));
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2020-03-14 18:20:17 +00:00
|
|
|
|
|
|
|
// Construct
|
|
|
|
GDMonoUtils::runtime_object_init(mono_object, CACHED_CLASS(StringName));
|
|
|
|
|
|
|
|
CACHED_FIELD(StringName, ptr)->set_value_raw(mono_object, memnew(StringName(p_from)));
|
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
MonoObject *create_managed_from(const NodePath &p_from) {
|
2019-07-03 07:44:53 +00:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), CACHED_CLASS_RAW(NodePath));
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
// Construct
|
2019-05-20 22:06:04 +00:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, CACHED_CLASS(NodePath));
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
CACHED_FIELD(NodePath, ptr)->set_value_raw(mono_object, memnew(NodePath(p_from)));
|
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_from(const RID &p_from) {
|
2019-07-03 07:44:53 +00:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), CACHED_CLASS_RAW(RID));
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
// Construct
|
2019-05-20 22:06:04 +00:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, CACHED_CLASS(RID));
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
CACHED_FIELD(RID, ptr)->set_value_raw(mono_object, memnew(RID(p_from)));
|
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2018-07-18 21:07:57 +00:00
|
|
|
MonoObject *create_managed_from(const Array &p_from, GDMonoClass *p_class) {
|
2019-07-03 07:44:53 +00:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
// Search constructor that takes a pointer as parameter
|
|
|
|
MonoMethod *m;
|
2020-04-01 23:20:12 +00:00
|
|
|
void *iter = nullptr;
|
2018-07-18 21:07:57 +00:00
|
|
|
while ((m = mono_class_get_methods(p_class->get_mono_ptr(), &iter))) {
|
|
|
|
if (strcmp(mono_method_get_name(m), ".ctor") == 0) {
|
|
|
|
MonoMethodSignature *sig = mono_method_signature(m);
|
2020-04-01 23:20:12 +00:00
|
|
|
void *front = nullptr;
|
2018-07-18 21:07:57 +00:00
|
|
|
if (mono_signature_get_param_count(sig) == 1 &&
|
|
|
|
mono_class_from_mono_type(mono_signature_get_params(sig, &front)) == CACHED_CLASS(IntPtr)->get_mono_ptr()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
CRASH_COND(m == nullptr);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
Array *new_array = memnew(Array(p_from));
|
|
|
|
void *args[1] = { &new_array };
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2018-07-31 17:40:38 +00:00
|
|
|
GDMonoUtils::runtime_invoke(m, mono_object, args, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_from(const Dictionary &p_from, GDMonoClass *p_class) {
|
2019-07-03 07:44:53 +00:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_NULL_V(mono_object, nullptr);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
// Search constructor that takes a pointer as parameter
|
|
|
|
MonoMethod *m;
|
2020-04-01 23:20:12 +00:00
|
|
|
void *iter = nullptr;
|
2018-07-18 21:07:57 +00:00
|
|
|
while ((m = mono_class_get_methods(p_class->get_mono_ptr(), &iter))) {
|
|
|
|
if (strcmp(mono_method_get_name(m), ".ctor") == 0) {
|
|
|
|
MonoMethodSignature *sig = mono_method_signature(m);
|
2020-04-01 23:20:12 +00:00
|
|
|
void *front = nullptr;
|
2018-07-18 21:07:57 +00:00
|
|
|
if (mono_signature_get_param_count(sig) == 1 &&
|
|
|
|
mono_class_from_mono_type(mono_signature_get_params(sig, &front)) == CACHED_CLASS(IntPtr)->get_mono_ptr()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
CRASH_COND(m == nullptr);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
Dictionary *new_dict = memnew(Dictionary(p_from));
|
|
|
|
void *args[1] = { &new_dict };
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2018-07-31 17:40:38 +00:00
|
|
|
GDMonoUtils::runtime_invoke(m, mono_object, args, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2018-07-18 21:07:57 +00:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
MonoDomain *create_domain(const String &p_friendly_name) {
|
2019-10-10 23:23:35 +00:00
|
|
|
print_verbose("Mono: Creating domain '" + p_friendly_name + "'...");
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoDomain *domain = mono_domain_create_appdomain((char *)p_friendly_name.utf8().get_data(), nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
if (domain) {
|
|
|
|
// Workaround to avoid this exception:
|
|
|
|
// System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system.
|
|
|
|
// ---> System.ArgumentException: The 'ExeConfigFilename' argument cannot be null.
|
|
|
|
mono_domain_set_config(domain, ".", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
String get_type_desc(MonoType *p_type) {
|
|
|
|
return mono_type_full_name(p_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_type_desc(MonoReflectionType *p_reftype) {
|
|
|
|
return get_type_desc(mono_reflection_type_get_type(p_reftype));
|
|
|
|
}
|
|
|
|
|
2018-07-18 21:07:57 +00:00
|
|
|
String get_exception_name_and_message(MonoException *p_exc) {
|
2017-10-02 21:24:00 +00:00
|
|
|
String res;
|
|
|
|
|
2018-07-18 21:07:57 +00:00
|
|
|
MonoClass *klass = mono_object_get_class((MonoObject *)p_exc);
|
2017-10-02 21:24:00 +00:00
|
|
|
MonoType *type = mono_class_get_type(klass);
|
|
|
|
|
|
|
|
char *full_name = mono_type_full_name(type);
|
|
|
|
res += full_name;
|
|
|
|
mono_free(full_name);
|
|
|
|
|
|
|
|
res += ": ";
|
|
|
|
|
|
|
|
MonoProperty *prop = mono_class_get_property_from_name(klass, "Message");
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoString *msg = (MonoString *)property_get_value(prop, (MonoObject *)p_exc, nullptr, nullptr);
|
2017-10-02 21:24:00 +00:00
|
|
|
res += GDMonoMarshal::mono_string_to_godot(msg);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2018-01-04 20:05:46 +00:00
|
|
|
|
2018-06-26 19:03:42 +00:00
|
|
|
void debug_print_unhandled_exception(MonoException *p_exc) {
|
|
|
|
print_unhandled_exception(p_exc);
|
|
|
|
debug_send_unhandled_exception_error(p_exc);
|
2018-01-09 16:19:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:03:42 +00:00
|
|
|
void debug_send_unhandled_exception_error(MonoException *p_exc) {
|
2018-01-09 16:19:03 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2020-02-27 02:30:20 +00:00
|
|
|
if (!EngineDebugger::is_active()) {
|
2019-07-24 21:13:24 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
2019-11-06 16:03:04 +00:00
|
|
|
ERR_PRINT(GDMonoUtils::get_exception_name_and_message(p_exc));
|
2019-07-24 21:13:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-01-12 18:23:11 +00:00
|
|
|
return;
|
2019-07-24 21:13:24 +00:00
|
|
|
}
|
2018-01-12 18:23:11 +00:00
|
|
|
|
2020-03-14 18:20:17 +00:00
|
|
|
static thread_local bool _recursion_flag_ = false;
|
2020-07-05 17:19:36 +00:00
|
|
|
if (_recursion_flag_) {
|
2020-03-14 18:20:17 +00:00
|
|
|
return;
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2020-03-14 18:20:17 +00:00
|
|
|
_recursion_flag_ = true;
|
|
|
|
SCOPE_EXIT { _recursion_flag_ = false; };
|
2018-06-26 19:03:42 +00:00
|
|
|
|
2018-02-24 15:36:48 +00:00
|
|
|
ScriptLanguage::StackInfo separator;
|
2018-06-26 19:03:42 +00:00
|
|
|
separator.file = String();
|
2018-02-27 09:36:58 +00:00
|
|
|
separator.func = "--- " + RTR("End of inner exception stack trace") + " ---";
|
2018-02-24 15:36:48 +00:00
|
|
|
separator.line = 0;
|
2018-01-09 16:19:03 +00:00
|
|
|
|
2018-02-24 15:36:48 +00:00
|
|
|
Vector<ScriptLanguage::StackInfo> si;
|
2018-06-26 19:03:42 +00:00
|
|
|
String exc_msg;
|
2018-02-24 15:36:48 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
while (p_exc != nullptr) {
|
2018-02-24 15:36:48 +00:00
|
|
|
GDMonoClass *st_klass = CACHED_CLASS(System_Diagnostics_StackTrace);
|
|
|
|
MonoObject *stack_trace = mono_object_new(mono_domain_get(), st_klass->get_mono_ptr());
|
|
|
|
|
|
|
|
MonoBoolean need_file_info = true;
|
|
|
|
void *ctor_args[2] = { p_exc, &need_file_info };
|
2018-01-09 16:19:03 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *unexpected_exc = nullptr;
|
2018-02-24 15:36:48 +00:00
|
|
|
CACHED_METHOD(System_Diagnostics_StackTrace, ctor_Exception_bool)->invoke_raw(stack_trace, ctor_args, &unexpected_exc);
|
2018-01-09 16:19:03 +00:00
|
|
|
|
2018-06-26 19:03:42 +00:00
|
|
|
if (unexpected_exc) {
|
|
|
|
GDMonoInternals::unhandled_exception(unexpected_exc);
|
2019-07-24 21:13:24 +00:00
|
|
|
return;
|
2018-01-09 16:19:03 +00:00
|
|
|
}
|
|
|
|
|
2018-02-24 15:36:48 +00:00
|
|
|
Vector<ScriptLanguage::StackInfo> _si;
|
2020-04-01 23:20:12 +00:00
|
|
|
if (stack_trace != nullptr) {
|
2018-02-24 15:36:48 +00:00
|
|
|
_si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace);
|
2020-07-05 17:19:36 +00:00
|
|
|
for (int i = _si.size() - 1; i >= 0; i--) {
|
2018-02-24 15:36:48 +00:00
|
|
|
si.insert(0, _si[i]);
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2018-02-24 15:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exc_msg += (exc_msg.length() > 0 ? " ---> " : "") + GDMonoUtils::get_exception_name_and_message(p_exc);
|
|
|
|
|
2018-06-26 19:03:42 +00:00
|
|
|
GDMonoClass *exc_class = GDMono::get_singleton()->get_class(mono_get_exception_class());
|
|
|
|
GDMonoProperty *inner_exc_prop = exc_class->get_property("InnerException");
|
2020-04-01 23:20:12 +00:00
|
|
|
CRASH_COND(inner_exc_prop == nullptr);
|
2018-06-26 19:03:42 +00:00
|
|
|
|
|
|
|
MonoObject *inner_exc = inner_exc_prop->get_value((MonoObject *)p_exc);
|
2020-07-05 17:19:36 +00:00
|
|
|
if (inner_exc != nullptr) {
|
2018-02-24 15:36:48 +00:00
|
|
|
si.insert(0, separator);
|
2020-07-05 17:19:36 +00:00
|
|
|
}
|
2018-06-26 19:03:42 +00:00
|
|
|
|
|
|
|
p_exc = (MonoException *)inner_exc;
|
2018-02-24 15:36:48 +00:00
|
|
|
}
|
2018-01-09 16:19:03 +00:00
|
|
|
|
|
|
|
String file = si.size() ? si[0].file : __FILE__;
|
|
|
|
String func = si.size() ? si[0].func : FUNCTION_STR;
|
|
|
|
int line = si.size() ? si[0].line : __LINE__;
|
|
|
|
String error_msg = "Unhandled exception";
|
|
|
|
|
2020-02-27 02:30:20 +00:00
|
|
|
EngineDebugger::get_script_debugger()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si);
|
2018-01-09 16:19:03 +00:00
|
|
|
#endif
|
2018-01-04 20:05:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:03:42 +00:00
|
|
|
void debug_unhandled_exception(MonoException *p_exc) {
|
|
|
|
GDMonoInternals::unhandled_exception(p_exc); // prints the exception as well
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_unhandled_exception(MonoException *p_exc) {
|
|
|
|
mono_print_unhandled_exception((MonoObject *)p_exc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_pending_exception(MonoException *p_exc) {
|
2019-07-03 07:44:53 +00:00
|
|
|
#ifdef NO_PENDING_EXCEPTIONS
|
|
|
|
debug_unhandled_exception(p_exc);
|
|
|
|
#else
|
2018-06-26 19:03:42 +00:00
|
|
|
if (get_runtime_invoke_count() == 0) {
|
|
|
|
debug_unhandled_exception(p_exc);
|
2020-12-04 23:38:24 +00:00
|
|
|
return;
|
2018-06-26 19:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mono_runtime_set_pending_exception(p_exc, false)) {
|
2019-11-06 16:03:04 +00:00
|
|
|
ERR_PRINT("Exception thrown from managed code, but it could not be set as pending:");
|
2018-06-26 19:03:42 +00:00
|
|
|
GDMonoUtils::debug_print_unhandled_exception(p_exc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-14 18:20:17 +00:00
|
|
|
thread_local int current_invoke_count = 0;
|
2018-06-26 19:03:42 +00:00
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoObject *runtime_invoke(MonoMethod *p_method, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoObject *ret = mono_runtime_invoke(p_method, p_obj, p_params, (MonoObject **)r_exc);
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoString *object_to_string(MonoObject *p_obj, MonoException **r_exc) {
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoString *ret = mono_object_to_string(p_obj, (MonoObject **)r_exc);
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
void property_set_value(MonoProperty *p_prop, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 00:05:19 +00:00
|
|
|
mono_property_set_value(p_prop, p_obj, p_params, (MonoObject **)r_exc);
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoObject *property_get_value(MonoProperty *p_prop, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 00:05:19 +00:00
|
|
|
MonoObject *ret = mono_property_get_value(p_prop, p_obj, p_params, (MonoObject **)r_exc);
|
2018-07-31 17:40:38 +00:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-09-12 16:54:20 +00:00
|
|
|
uint64_t unbox_enum_value(MonoObject *p_boxed, MonoType *p_enum_basetype, bool &r_error) {
|
|
|
|
r_error = false;
|
|
|
|
switch (mono_type_get_type(p_enum_basetype)) {
|
|
|
|
case MONO_TYPE_BOOLEAN:
|
|
|
|
return (bool)GDMonoMarshal::unbox<MonoBoolean>(p_boxed) ? 1 : 0;
|
|
|
|
case MONO_TYPE_CHAR:
|
|
|
|
return GDMonoMarshal::unbox<uint16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U1:
|
|
|
|
return GDMonoMarshal::unbox<uint8_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U2:
|
|
|
|
return GDMonoMarshal::unbox<uint16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U4:
|
|
|
|
return GDMonoMarshal::unbox<uint32_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U8:
|
|
|
|
return GDMonoMarshal::unbox<uint64_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I1:
|
|
|
|
return GDMonoMarshal::unbox<int8_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I2:
|
|
|
|
return GDMonoMarshal::unbox<int16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I4:
|
|
|
|
return GDMonoMarshal::unbox<int32_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I8:
|
|
|
|
return GDMonoMarshal::unbox<int64_t>(p_boxed);
|
|
|
|
default:
|
|
|
|
r_error = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 19:43:06 +00:00
|
|
|
void dispose(MonoObject *p_mono_object, MonoException **r_exc) {
|
2019-11-10 16:10:38 +00:00
|
|
|
CACHED_METHOD_THUNK(GodotObject, Dispose).invoke(p_mono_object, r_exc);
|
2018-11-30 19:43:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-18 02:14:21 +00:00
|
|
|
namespace Marshal {
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
#ifdef MONO_GLUE_ENABLED
|
|
|
|
#ifdef TOOLS_ENABLED
|
2020-05-10 10:56:01 +00:00
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{ \
|
|
|
|
if (!GDMonoCache::cached_data.godot_api_cache_updated) \
|
|
|
|
return m_ret; \
|
2019-07-03 07:44:53 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{ return m_ret; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool type_is_generic_array(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2019-11-10 16:10:38 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericArray).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
bool type_is_generic_dictionary(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2019-11-10 16:10:38 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericDictionary).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
bool type_is_system_generic_list(MonoReflectionType *p_reftype) {
|
2019-07-03 07:44:53 +00:00
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsSystemGenericList).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-21 17:09:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
bool type_is_system_generic_dictionary(MonoReflectionType *p_reftype) {
|
2019-07-03 07:44:53 +00:00
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsSystemGenericDictionary).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-21 17:09:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
bool type_is_generic_ienumerable(MonoReflectionType *p_reftype) {
|
2019-07-03 07:44:53 +00:00
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericIEnumerable).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
bool type_is_generic_icollection(MonoReflectionType *p_reftype) {
|
2019-07-03 07:44:53 +00:00
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericICollection).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
bool type_is_generic_idictionary(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
MonoBoolean res = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericIDictionary).invoke(p_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2020-04-23 00:19:32 +00:00
|
|
|
return (bool)res;
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
void array_get_element_type(MonoReflectionType *p_array_reftype, MonoReflectionType **r_elem_reftype) {
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
CACHED_METHOD_THUNK(MarshalUtils, ArrayGetElementType).invoke(p_array_reftype, r_elem_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 00:19:32 +00:00
|
|
|
void dictionary_get_key_value_types(MonoReflectionType *p_dict_reftype, MonoReflectionType **r_key_reftype, MonoReflectionType **r_value_reftype) {
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoException *exc = nullptr;
|
2020-04-23 00:19:32 +00:00
|
|
|
CACHED_METHOD_THUNK(MarshalUtils, DictionaryGetKeyValueTypes).invoke(p_dict_reftype, r_key_reftype, r_value_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 02:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *make_generic_array_type(MonoReflectionType *p_elem_reftype) {
|
2020-04-01 23:20:12 +00:00
|
|
|
NO_GLUE_RET(nullptr);
|
|
|
|
MonoException *exc = nullptr;
|
2019-11-10 16:10:38 +00:00
|
|
|
MonoReflectionType *reftype = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericArrayType).invoke(p_elem_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 02:14:21 +00:00
|
|
|
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) {
|
2020-04-01 23:20:12 +00:00
|
|
|
NO_GLUE_RET(nullptr);
|
|
|
|
MonoException *exc = nullptr;
|
2019-11-10 16:10:38 +00:00
|
|
|
MonoReflectionType *reftype = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericDictionaryType).invoke(p_key_reftype, p_value_reftype, &exc);
|
2019-07-03 07:44:53 +00:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 02:14:21 +00:00
|
|
|
return GDMono::get_singleton()->get_class(mono_class_from_mono_type(mono_reflection_type_get_type(reftype)));
|
|
|
|
}
|
|
|
|
} // namespace Marshal
|
|
|
|
|
2020-05-12 15:01:17 +00:00
|
|
|
ScopeThreadAttach::ScopeThreadAttach() {
|
2020-01-16 16:11:13 +00:00
|
|
|
if (likely(GDMono::get_singleton()->is_runtime_initialized()) && unlikely(!mono_domain_get())) {
|
|
|
|
mono_thread = GDMonoUtils::attach_current_thread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeThreadAttach::~ScopeThreadAttach() {
|
|
|
|
if (unlikely(mono_thread)) {
|
|
|
|
GDMonoUtils::detach_current_thread(mono_thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 18:20:17 +00:00
|
|
|
StringName get_native_godot_class_name(GDMonoClass *p_class) {
|
2020-04-01 23:20:12 +00:00
|
|
|
MonoObject *native_name_obj = p_class->get_field(BINDINGS_NATIVE_NAME_FIELD)->get_value(nullptr);
|
2020-03-14 18:20:17 +00:00
|
|
|
StringName *ptr = GDMonoMarshal::unbox<StringName *>(CACHED_FIELD(StringName, ptr)->get_value(native_name_obj));
|
|
|
|
return ptr ? *ptr : StringName();
|
|
|
|
}
|
2017-11-17 02:09:00 +00:00
|
|
|
} // namespace GDMonoUtils
|