From 150e45071bb3547d465f5da586db5905d1076951 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Tue, 20 Aug 2024 14:53:22 +0200 Subject: [PATCH 1/7] Avoid hardcoded type conversion for metadata The engine uses the names `int` and `float` to refer to the 64-bit types, so in the bindings generator we have a hardcoded conversion for those types. But this type conversion should not be used for metadata. Even though the underlying type should still be 64-bit for interop, metadata is meant to specify the correct type to expose. So if metadata says `float` it means the type is really meant to be a 32-bit `float` and not `double`. Other hardcoded type conversions (`int` and `Nil`) won't ever be metadata. This change corrects the `float` type, to use the right type in the generated C++ code. Before we were always using `double` due to this type conversion. (cherry picked from commit 48291990817fbaa8cc2d0307a16d7345bf62da52) --- binding_generator.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index e7609b2c..79a8132d 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -2719,8 +2719,6 @@ def correct_type(type_name, meta=None, use_alias=True): if meta is not None: if "int" in meta: return f"{meta}_t" - elif meta in type_conversion: - return type_conversion[type_name] else: return meta if type_name in type_conversion: From 26cb3292a01db8dcd4e2ba1c7d477fc7736be5db Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Wed, 21 Aug 2024 20:19:33 +0200 Subject: [PATCH 2/7] Fix incorrect generation of some C++ operators --- binding_generator.py | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 79a8132d..dc89f4ce 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -852,14 +852,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl if "operators" in builtin_api: for operator in builtin_api["operators"]: - if operator["name"] not in ["in", "xor"]: + if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;' + f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;' ) else: result.append( - f'\t{correct_type(operator["return_type"])} operator{operator["name"].replace("unary", "")}() const;' + f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;' ) # Copy assignment. @@ -1291,10 +1291,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl if "operators" in builtin_api: for operator in builtin_api["operators"]: - if operator["name"] not in ["in", "xor"]: + if is_valid_cpp_operator(operator["name"]): if "right_type" in operator: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{' + f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{' ) (encode, arg_name) = get_encoded_arg("other", operator["right_type"], None) result += encode @@ -1304,7 +1304,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl result.append("}") else: result.append( - f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"].replace("unary", "")}() const {{' + f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{' ) result.append( f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr)nullptr);' @@ -2830,6 +2830,38 @@ def get_operator_id_name(op): return op_id_map[op] +def get_operator_cpp_name(op): + op_cpp_map = { + "==": "==", + "!=": "!=", + "<": "<", + "<=": "<=", + ">": ">", + ">=": ">=", + "+": "+", + "-": "-", + "*": "*", + "/": "/", + "unary-": "-", + "unary+": "+", + "%": "%", + "<<": "<<", + ">>": ">>", + "&": "&", + "|": "|", + "^": "^", + "~": "~", + "and": "&&", + "or": "||", + "not": "!", + } + return op_cpp_map[op] + + +def is_valid_cpp_operator(op): + return op not in ["**", "xor", "in"] + + def get_default_value_for_type(type_name): if type_name == "int": return "0" From c823e84ff2449ac20e22430b6c8e3beceedd124e Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Sat, 10 Aug 2024 17:59:03 +0200 Subject: [PATCH 3/7] Correct type for `char16` and `char32` meta --- binding_generator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index dc89f4ce..17bb8066 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -2719,6 +2719,8 @@ def correct_type(type_name, meta=None, use_alias=True): if meta is not None: if "int" in meta: return f"{meta}_t" + elif "char" in meta: + return f"{meta}_t" else: return meta if type_name in type_conversion: From 762db4e4d6eb4ed496a5f5c05442e49b2750d96d Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Wed, 21 Aug 2024 18:31:12 -0700 Subject: [PATCH 4/7] Fix missing MAKE_TYPED_ARRAY_INFO for Packed*Arrays (cherry picked from commit 10c3d1bc5f7f68bb4e260f32b9a8b529d23873ba) --- include/godot_cpp/core/type_info.hpp | 19 ++++++++++--------- test/src/example.cpp | 14 ++++++++++++++ test/src/example.h | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/include/godot_cpp/core/type_info.hpp b/include/godot_cpp/core/type_info.hpp index f368988e..b78f7e73 100644 --- a/include/godot_cpp/core/type_info.hpp +++ b/include/godot_cpp/core/type_info.hpp @@ -397,16 +397,17 @@ MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE) MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL) MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY) MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY) +MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY) /* -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_BYTE_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_INT32_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_INT64_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_FLOAT32_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_FLOAT64_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_STRING_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_VECTOR2_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_VECTOR3_ARRAY) -MAKE_TYPED_ARRAY_INFO(Vector, Variant::PACKED_COLOR_ARRAY) MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING) */ diff --git a/test/src/example.cpp b/test/src/example.cpp index a9418898..84dc176c 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -204,6 +204,7 @@ void Example::_bind_methods() { ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility); ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &Example::test_string_is_forty_two); ClassDB::bind_method(D_METHOD("test_string_resize"), &Example::test_string_resize); + ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &Example::test_typed_array_of_packed); ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops); ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list); @@ -424,6 +425,19 @@ String Example::test_string_resize(String p_string) const { return p_string; } +TypedArray Example::test_typed_array_of_packed() const { + TypedArray arr; + PackedInt32Array packed_arr1; + packed_arr1.push_back(1); + packed_arr1.push_back(2); + arr.push_back(packed_arr1); + PackedInt32Array packed_arr2; + packed_arr2.push_back(3); + packed_arr2.push_back(4); + arr.push_back(packed_arr2); + return arr; +} + int Example::test_vector_ops() const { PackedInt32Array arr; arr.push_back(10); diff --git a/test/src/example.h b/test/src/example.h index 7f3dfaa6..59c907a1 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -134,6 +134,7 @@ public: String test_str_utility() const; bool test_string_is_forty_two(const String &p_str) const; String test_string_resize(String p_original) const; + TypedArray test_typed_array_of_packed() const; int test_vector_ops() const; int test_vector_init_list() const; From 37d255af6c7a34bc30d772f86dc04903857bc18b Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sat, 24 Aug 2024 11:56:27 +0200 Subject: [PATCH 5/7] [Web/SCons] Use CCFLAGS for SIDE_MODULE option Was using CPPFLAGS, but should use the explicit scons CCFLAGS which makes it clear they are applied to both the C and C++ compiler. CPPFLAGS was also fine (they are preprocessor flags, also applied to both C and C++), but we should try to stay consistent with what we do in Godot. (cherry picked from commit f36acd8e312c916c7e53364e1b0bd8eec3e4410e) --- tools/web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/web.py b/tools/web.py index dea42b26..c8f07c55 100644 --- a/tools/web.py +++ b/tools/web.py @@ -39,7 +39,7 @@ def generate(env): env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"]) # Build as side module (shared library). - env.Append(CPPFLAGS=["-sSIDE_MODULE=1"]) + env.Append(CCFLAGS=["-sSIDE_MODULE=1"]) env.Append(LINKFLAGS=["-sSIDE_MODULE=1"]) # Force wasm longjmp mode. From 842a7f621f464797aab474e56772338da255d85c Mon Sep 17 00:00:00 2001 From: "George L. Albany" Date: Sun, 25 Aug 2024 07:55:58 +0000 Subject: [PATCH 6/7] Fix GCC 14 -Wtemplate-id-cdtor warning As was fixed with godotengine/godot#91208 (cherry picked from commit 7b31f39beaca1a98307402f53d69f3657f3bed86) --- include/godot_cpp/templates/safe_refcount.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/godot_cpp/templates/safe_refcount.hpp b/include/godot_cpp/templates/safe_refcount.hpp index 12e6840a..98cb04b2 100644 --- a/include/godot_cpp/templates/safe_refcount.hpp +++ b/include/godot_cpp/templates/safe_refcount.hpp @@ -132,7 +132,7 @@ public: } } - _ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast(0)) { + _ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast(0)) { set(p_value); } }; From 1ac33c906e3fd543585d9f16eab5ebf84d1844ec Mon Sep 17 00:00:00 2001 From: David Snopek Date: Mon, 15 Jul 2024 11:57:53 -0500 Subject: [PATCH 7/7] Add a test to ensure that library path is absolute (cherry picked from commit 92ace04989bdf8d7d94846f059eeccd723f9b885) --- test/project/main.gd | 6 ++++++ test/src/example.cpp | 8 ++++++++ test/src/example.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/test/project/main.gd b/test/project/main.gd index dadd4de6..b2625b9a 100644 --- a/test/project/main.gd +++ b/test/project/main.gd @@ -270,6 +270,12 @@ func _ready(): assert_equal(example_child.get_value1(), 11) assert_equal(example_child.get_value2(), 22) + # Test that the extension's library path is absolute and valid. + var library_path = Example.test_library_path() + assert_equal(library_path.begins_with("res://"), false) + assert_equal(library_path, ProjectSettings.globalize_path(library_path)) + assert_equal(FileAccess.file_exists(library_path), true) + exit_with_status() func _on_Example_custom_signal(signal_name, value): diff --git a/test/src/example.cpp b/test/src/example.cpp index 84dc176c..8075f551 100644 --- a/test/src/example.cpp +++ b/test/src/example.cpp @@ -249,6 +249,8 @@ void Example::_bind_methods() { ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static); ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2); + ClassDB::bind_static_method("Example", D_METHOD("test_library_path"), &Example::test_library_path); + { MethodInfo mi; mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument")); @@ -709,6 +711,12 @@ String Example::test_use_engine_singleton() const { return OS::get_singleton()->get_name(); } +String Example::test_library_path() { + String library_path; + internal::gdextension_interface_get_library_path(internal::library, library_path._native_ptr()); + return library_path; +} + void ExampleRuntime::_bind_methods() { ClassDB::bind_method(D_METHOD("set_prop_value", "value"), &ExampleRuntime::set_prop_value); ClassDB::bind_method(D_METHOD("get_prop_value"), &ExampleRuntime::get_prop_value); diff --git a/test/src/example.h b/test/src/example.h index 59c907a1..6d88cf11 100644 --- a/test/src/example.h +++ b/test/src/example.h @@ -195,6 +195,8 @@ public: GDVIRTUAL1(_do_something_virtual_with_control, Control *); String test_use_engine_singleton() const; + + static String test_library_path(); }; VARIANT_ENUM_CAST(Example::Constants);