diff options
-rw-r--r-- | core/io/marshalls.cpp | 3 | ||||
-rw-r--r-- | doc/classes/File.xml | 28 | ||||
-rw-r--r-- | modules/mono/csharp_script.cpp | 2 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_assembly.cpp | 4 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_field.cpp | 4 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.cpp | 55 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.h | 19 |
7 files changed, 48 insertions, 67 deletions
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 0834d6c321..d388a622de 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1140,8 +1140,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(0, buf); buf += 4; - r_len += 4; } + r_len += 4; + } else { _encode_string(obj->get_class(), buf, r_len); diff --git a/doc/classes/File.xml b/doc/classes/File.xml index e1a024270e..fd71f42a04 100644 --- a/doc/classes/File.xml +++ b/doc/classes/File.xml @@ -37,7 +37,7 @@ <return type="bool"> </return> <description> - Return whether the file cursor reached the end of the file. + Returns [code]true[/code] if the file cursor reached the end of the file. </description> </method> <method name="file_exists" qualifiers="const"> @@ -46,7 +46,7 @@ <argument index="0" name="path" type="String"> </argument> <description> - Get whether or not the file in the specified path exists. + Returns [code]true[/code] if the file in the specified path exists. </description> </method> <method name="get_16" qualifiers="const"> @@ -113,7 +113,7 @@ <return type="bool"> </return> <description> - Get whether endian swap is enabled for this file. + Returns [code]true[/code] if endian swap is enabled for this file. </description> </method> <method name="get_error" qualifiers="const"> @@ -134,7 +134,7 @@ <return type="int"> </return> <description> - Return the size of the file in bytes. + Returns the size of the file in bytes. </description> </method> <method name="get_line" qualifiers="const"> @@ -150,7 +150,7 @@ <argument index="0" name="path" type="String"> </argument> <description> - Return a md5 String representing the file at the given path or an empty [String] on failure. + Returns a MD5 String representing the file at the given path or an empty [String] on failure. </description> </method> <method name="get_modified_time" qualifiers="const"> @@ -159,6 +159,7 @@ <argument index="0" name="file" type="String"> </argument> <description> + Returns the modified time in unix timestamp of the [code]file[/code] or returns a [String] "ERROR IN [code]file[/code]". This unix timestamp can be converted to datetime by using [method OS.get_datetime_from_unix_time]. </description> </method> <method name="get_pascal_string"> @@ -172,7 +173,7 @@ <return type="int"> </return> <description> - Return the file cursor position. + Returns the file cursor position. </description> </method> <method name="get_real" qualifiers="const"> @@ -188,7 +189,7 @@ <argument index="0" name="path" type="String"> </argument> <description> - Return a sha256 String representing the file at the given path or an empty [String] on failure. + Returns a SHA-256 String representing the file at the given path or an empty [String] on failure. </description> </method> <method name="get_var" qualifiers="const"> @@ -202,7 +203,7 @@ <return type="bool"> </return> <description> - Return whether the file is currently opened. + Returns [code]true[/code] if the file is currently opened. </description> </method> <method name="open"> @@ -279,7 +280,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> - Set whether to swap the endianness of the file. Enable this if you're dealing with files written in big endian machines. + If [code]true[/code] the file's endianness is swapped. Use this if you're dealing with files written in big endian machines. Note that this is about the file format, not CPU type. This is always reseted to [code]false[/code] whenever you open the file. </description> </method> @@ -394,16 +395,16 @@ </methods> <constants> <constant name="READ" value="1"> - Open the file for reading. + Open the file for read operations. </constant> <constant name="WRITE" value="2"> - Open the file for writing. Create it if the file not exists and truncate if it exists. + Open the file for write operations. Create it if the file does not exist and truncate if it exists. </constant> <constant name="READ_WRITE" value="3"> - Open the file for reading and writing, without truncating the file. + Open the file for read and write operations. Does not truncate the file. </constant> <constant name="WRITE_READ" value="7"> - Open the file for reading and writing. Create it if the file not exists and truncate if it exists. + Open the file for read and write operations. Create it if the file does not exist and truncate if it exists. </constant> <constant name="COMPRESSION_FASTLZ" value="0"> Use the FastLZ compression method. @@ -415,6 +416,7 @@ Use the Zstd compression method. </constant> <constant name="COMPRESSION_GZIP" value="3"> + Use the GZip compression method. </constant> </constants> </class> diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 7de90dfbc3..fe78ce423c 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -782,7 +782,7 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) { if (method) { MonoObject *ret = method->invoke(mono_object, args); - if (ret && UNBOX_BOOLEAN(ret)) + if (ret && GDMonoMarshal::unbox<MonoBoolean>(ret) == true) return true; } diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp index a623b34b68..4b370295f3 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.cpp +++ b/modules/mono/mono_gd/gd_mono_assembly.cpp @@ -52,12 +52,12 @@ MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, void *user_d if (no_search) return NULL; - no_search = true; // Avoid the recursion madness - GDMonoAssembly **loaded_asm = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name); if (loaded_asm) return (*loaded_asm)->get_assembly(); + no_search = true; // Avoid the recursion madness + String path; MonoAssembly *res = NULL; diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 0c64380e31..c2d8eeaa32 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -279,11 +279,11 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) { } bool GDMonoField::get_bool_value(MonoObject *p_object) { - return UNBOX_BOOLEAN(get_value(p_object)); + return (bool)GDMonoMarshal::unbox<MonoBoolean>(get_value(p_object)); } int GDMonoField::get_int_value(MonoObject *p_object) { - return UNBOX_INT32(get_value(p_object)); + return GDMonoMarshal::unbox<int32_t>(get_value(p_object)); } String GDMonoField::get_string_value(MonoObject *p_object) { diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index b5419952de..b64915109f 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -41,11 +41,11 @@ namespace GDMonoMarshal { return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(m_t), raw); \ } -#define RETURN_UNBOXED_STRUCT(m_t, m_var_in) \ - { \ - float *raw = UNBOX_FLOAT_PTR(m_var_in); \ - MARSHALLED_IN(m_t, raw, ret); \ - return ret; \ +#define RETURN_UNBOXED_STRUCT(m_t, m_var_in) \ + { \ + float *raw = (float *)mono_object_unbox(m_var_in); \ + MARSHALLED_IN(m_t, raw, ret); \ + return ret; \ } Variant::Type managed_to_variant_type(const ManagedType &p_type) { @@ -453,30 +453,30 @@ Variant mono_object_to_variant(MonoObject *p_obj) { Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { switch (p_type.type_encoding) { case MONO_TYPE_BOOLEAN: - return (bool)UNBOX_BOOLEAN(p_obj); + return (bool)unbox<MonoBoolean>(p_obj); case MONO_TYPE_I1: - return UNBOX_INT8(p_obj); + return unbox<int8_t>(p_obj); case MONO_TYPE_I2: - return UNBOX_INT16(p_obj); + return unbox<int16_t>(p_obj); case MONO_TYPE_I4: - return UNBOX_INT32(p_obj); + return unbox<int32_t>(p_obj); case MONO_TYPE_I8: - return UNBOX_INT64(p_obj); + return unbox<int64_t>(p_obj); case MONO_TYPE_U1: - return UNBOX_UINT8(p_obj); + return unbox<uint8_t>(p_obj); case MONO_TYPE_U2: - return UNBOX_UINT16(p_obj); + return unbox<uint16_t>(p_obj); case MONO_TYPE_U4: - return UNBOX_UINT32(p_obj); + return unbox<uint32_t>(p_obj); case MONO_TYPE_U8: - return UNBOX_UINT64(p_obj); + return unbox<uint64_t>(p_obj); case MONO_TYPE_R4: - return UNBOX_FLOAT(p_obj); + return unbox<float>(p_obj); case MONO_TYPE_R8: - return UNBOX_DOUBLE(p_obj); + return unbox<double>(p_obj); case MONO_TYPE_STRING: { String str = mono_string_to_godot((MonoString *)p_obj); @@ -554,29 +554,18 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { // GodotObject if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) { - GDMonoField *ptr_field = CACHED_FIELD(GodotObject, ptr); - - ERR_FAIL_NULL_V(ptr_field, Variant()); - - void *ptr_to_unmanaged = UNBOX_PTR(ptr_field->get_value(p_obj)); - - if (!ptr_to_unmanaged) // IntPtr.Zero - return Variant(); - - Object *object_ptr = static_cast<Object *>(ptr_to_unmanaged); - - if (!object_ptr) - return Variant(); - - return object_ptr; + Object *ptr = unbox<Object *>(CACHED_FIELD(GodotObject, ptr)->get_value(p_obj)); + return ptr ? Variant(ptr) : Variant(); } if (CACHED_CLASS(NodePath) == type_class) { - return UNBOX_PTR(CACHED_FIELD(NodePath, ptr)->get_value(p_obj)); + NodePath *ptr = unbox<NodePath *>(CACHED_FIELD(NodePath, ptr)->get_value(p_obj)); + return ptr ? Variant(*ptr) : Variant(); } if (CACHED_CLASS(RID) == type_class) { - return UNBOX_PTR(CACHED_FIELD(RID, ptr)->get_value(p_obj)); + RID *ptr = unbox<RID *>(CACHED_FIELD(RID, ptr)->get_value(p_obj)); + return ptr ? Variant(*ptr) : Variant(); } } break; diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index 5fbafa0acb..38dd22357d 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -36,21 +36,10 @@ namespace GDMonoMarshal { -#define UNBOX_CHAR_PTR(x) (char *)mono_object_unbox(x) -#define UNBOX_FLOAT_PTR(x) (float *)mono_object_unbox(x) - -#define UNBOX_DOUBLE(x) *(double *)mono_object_unbox(x) -#define UNBOX_FLOAT(x) *(float *)mono_object_unbox(x) -#define UNBOX_INT64(x) *(int64_t *)mono_object_unbox(x) -#define UNBOX_INT32(x) *(int32_t *)mono_object_unbox(x) -#define UNBOX_INT16(x) *(int16_t *)mono_object_unbox(x) -#define UNBOX_INT8(x) *(int8_t *)mono_object_unbox(x) -#define UNBOX_UINT64(x) *(uint64_t *)mono_object_unbox(x) -#define UNBOX_UINT32(x) *(uint32_t *)mono_object_unbox(x) -#define UNBOX_UINT16(x) *(uint16_t *)mono_object_unbox(x) -#define UNBOX_UINT8(x) *(uint8_t *)mono_object_unbox(x) -#define UNBOX_BOOLEAN(x) *(MonoBoolean *)mono_object_unbox(x) -#define UNBOX_PTR(x) mono_object_unbox(x) +template <typename T> +T unbox(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) |