Skip to content

Commit 40470e6

Browse files
committed
Merge pull request #112290 from dsnopek/variant-call-compat-methods
GDExtension: Add system for builtin method compatibility
2 parents a6e7084 + bc9f3c7 commit 40470e6

16 files changed

+311
-74
lines changed

core/extension/extension_api_dump.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,17 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
797797
d2["is_static"] = Variant::is_builtin_method_static(type, method_name);
798798
d2["hash"] = Variant::get_builtin_method_hash(type, method_name);
799799

800+
Vector<uint32_t> compat_hashes = Variant::get_builtin_method_compatibility_hashes(type, method_name);
801+
Array compatibility;
802+
if (compat_hashes.size()) {
803+
for (int j = 0; j < compat_hashes.size(); j++) {
804+
compatibility.push_back(compat_hashes[j]);
805+
}
806+
}
807+
if (compatibility.size() > 0) {
808+
d2["hash_compatibility"] = compatibility;
809+
}
810+
800811
Vector<Variant> default_args = Variant::get_builtin_method_default_arguments(type, method_name);
801812

802813
Array arguments;

core/extension/gdextension_interface.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,11 @@ static GDExtensionPtrOperatorEvaluator gdextension_variant_get_ptr_operator_eval
817817
}
818818
static GDExtensionPtrBuiltInMethod gdextension_variant_get_ptr_builtin_method(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_method, GDExtensionInt p_hash) {
819819
const StringName method = *reinterpret_cast<const StringName *>(p_method);
820-
uint32_t hash = Variant::get_builtin_method_hash(Variant::Type(p_type), method);
821-
if (hash != p_hash) {
822-
ERR_PRINT_ONCE("Error getting method " + method + ", hash mismatch.");
823-
return nullptr;
820+
GDExtensionPtrBuiltInMethod ptr = (GDExtensionPtrBuiltInMethod)Variant::get_ptr_builtin_method_with_compatibility(Variant::Type(p_type), method, p_hash);
821+
if (!ptr) {
822+
ERR_PRINT("Error getting method " + method + ", missing or hash mismatch.");
824823
}
825-
826-
return (GDExtensionPtrBuiltInMethod)Variant::get_ptr_builtin_method(Variant::Type(p_type), method);
824+
return ptr;
827825
}
828826
static GDExtensionPtrConstructor gdextension_variant_get_ptr_constructor(GDExtensionVariantType p_type, int32_t p_constructor) {
829827
return (GDExtensionPtrConstructor)Variant::get_ptr_constructor(Variant::Type(p_type), p_constructor);

core/templates/vector.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,16 @@ class Vector {
184184
return span().bisect(p_value, p_before, Comparator{ args... });
185185
}
186186

187-
Vector<T> duplicate() {
187+
Vector<T> duplicate() const {
188188
return *this;
189189
}
190190

191+
#ifndef DISABLE_DEPRECATED
192+
Vector<T> _duplicate_bind_compat_112290() {
193+
return *this;
194+
}
195+
#endif // DISABLE_DEPRECATED
196+
191197
void ordered_insert(const T &p_val) {
192198
Size i;
193199
for (i = 0; i < _cowdata.size(); i++) {

core/variant/variant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ class Variant {
645645

646646
static ValidatedBuiltInMethod get_validated_builtin_method(Variant::Type p_type, const StringName &p_method);
647647
static PTRBuiltInMethod get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method);
648+
static PTRBuiltInMethod get_ptr_builtin_method_with_compatibility(Variant::Type p_type, const StringName &p_method, uint32_t p_hash);
648649

649650
static MethodInfo get_builtin_method_info(Variant::Type p_type, const StringName &p_method);
650651
static int get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method);
@@ -659,6 +660,7 @@ class Variant {
659660
static void get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list);
660661
static int get_builtin_method_count(Variant::Type p_type);
661662
static uint32_t get_builtin_method_hash(Variant::Type p_type, const StringName &p_method);
663+
static Vector<uint32_t> get_builtin_method_compatibility_hashes(Variant::Type p_type, const StringName &p_method);
662664

663665
void callp(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error);
664666

core/variant/variant_call.cpp

Lines changed: 260 additions & 57 deletions
Large diffs are not rendered by default.

doc/classes/PackedByteArray.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
[b]Note:[/b] Decompression is not guaranteed to work with data not compressed by Godot, for example if data compressed with the deflate compression mode lacks a checksum or header.
214214
</description>
215215
</method>
216-
<method name="duplicate">
216+
<method name="duplicate" qualifiers="const">
217217
<return type="PackedByteArray" />
218218
<description>
219219
Creates a copy of the array, and returns it.

doc/classes/PackedColorArray.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Returns the number of times an element is in the array.
7474
</description>
7575
</method>
76-
<method name="duplicate">
76+
<method name="duplicate" qualifiers="const">
7777
<return type="PackedColorArray" />
7878
<description>
7979
Creates a copy of the array, and returns it.

doc/classes/PackedFloat32Array.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
7272
</description>
7373
</method>
74-
<method name="duplicate">
74+
<method name="duplicate" qualifiers="const">
7575
<return type="PackedFloat32Array" />
7676
<description>
7777
Creates a copy of the array, and returns it.

doc/classes/PackedFloat64Array.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
[b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this method may not be accurate if NaNs are included.
7373
</description>
7474
</method>
75-
<method name="duplicate">
75+
<method name="duplicate" qualifiers="const">
7676
<return type="PackedFloat64Array" />
7777
<description>
7878
Creates a copy of the array, and returns it.

doc/classes/PackedInt32Array.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
Returns the number of times an element is in the array.
7070
</description>
7171
</method>
72-
<method name="duplicate">
72+
<method name="duplicate" qualifiers="const">
7373
<return type="PackedInt32Array" />
7474
<description>
7575
Creates a copy of the array, and returns it.

0 commit comments

Comments
 (0)