diff options
author | David Snopek <dsnopek@gmail.com> | 2023-11-16 06:14:15 -0600 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2023-11-16 06:40:06 -0600 |
commit | 5cf6d08ddaef2beb08d17760e88b64887ab35ff6 (patch) | |
tree | e838eb6ed8313d2ebf1ac9851e098d5f3d849bac | |
parent | ce9901ef54537eb81e77667f82a2adc68d1d913c (diff) | |
download | redot-engine-5cf6d08ddaef2beb08d17760e88b64887ab35ff6.tar.gz |
Check that GDExtensionCompatHashes are valid when generating extension_api.json
-rw-r--r-- | core/extension/gdextension_compat_hashes.cpp | 10 | ||||
-rw-r--r-- | core/extension/gdextension_compat_hashes.h | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/core/extension/gdextension_compat_hashes.cpp b/core/extension/gdextension_compat_hashes.cpp index 2dac4a3a5d..dd4cd20d09 100644 --- a/core/extension/gdextension_compat_hashes.cpp +++ b/core/extension/gdextension_compat_hashes.cpp @@ -32,6 +32,7 @@ #ifndef DISABLE_DEPRECATED +#include "core/object/class_db.h" #include "core/variant/variant.h" HashMap<StringName, LocalVector<GDExtensionCompatHashes::Mapping>> GDExtensionCompatHashes::mappings; @@ -52,7 +53,7 @@ bool GDExtensionCompatHashes::lookup_current_hash(const StringName &p_class, con return false; } -bool GDExtensionCompatHashes::get_legacy_hashes(const StringName &p_class, const StringName &p_method, Array &r_hashes) { +bool GDExtensionCompatHashes::get_legacy_hashes(const StringName &p_class, const StringName &p_method, Array &r_hashes, bool p_check_valid) { LocalVector<Mapping> *methods = mappings.getptr(p_class); if (!methods) { return false; @@ -61,6 +62,13 @@ bool GDExtensionCompatHashes::get_legacy_hashes(const StringName &p_class, const bool found = false; for (const Mapping &mapping : *methods) { if (mapping.method == p_method) { + if (p_check_valid) { + MethodBind *mb = ClassDB::get_method_with_compatibility(p_class, p_method, mapping.current_hash); + if (!mb) { + WARN_PRINT(vformat("Compatibility hash %d mapped to non-existent hash %d. Please update gdextension_compat_hashes.cpp.", mapping.legacy_hash, mapping.current_hash)); + continue; + } + } r_hashes.push_back(mapping.legacy_hash); found = true; } diff --git a/core/extension/gdextension_compat_hashes.h b/core/extension/gdextension_compat_hashes.h index 29393dcb2d..813859d9e6 100644 --- a/core/extension/gdextension_compat_hashes.h +++ b/core/extension/gdextension_compat_hashes.h @@ -50,7 +50,7 @@ public: static void initialize(); static void finalize(); static bool lookup_current_hash(const StringName &p_class, const StringName &p_method, uint32_t p_legacy_hash, uint32_t *r_current_hash); - static bool get_legacy_hashes(const StringName &p_class, const StringName &p_method, Array &r_hashes); + static bool get_legacy_hashes(const StringName &p_class, const StringName &p_method, Array &r_hashes, bool p_check_valid = true); }; #endif // DISABLE_DEPRECATED |