From b98838a7b9e317dcf635f9ed15610f55d7ae02c5 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Tue, 24 Feb 2026 12:46:26 -0600 Subject: [PATCH] Core: Add missing integral conversions to Variant --- core/core_builders.py | 2 +- core/math/math_defs.h | 13 +++++++++++++ core/variant/variant.cpp | 18 ++++++++++++++++++ core/variant/variant.h | 4 ++++ core/version.h | 4 +--- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/core/core_builders.py b/core/core_builders.py index d6b1a2b7af..bfae638a64 100644 --- a/core/core_builders.py +++ b/core/core_builders.py @@ -41,7 +41,7 @@ def version_hash_builder(target, source, env): #include "core/version.h" const char *const GODOT_VERSION_HASH = "{git_hash}"; -const uint64_t GODOT_VERSION_TIMESTAMP = {git_timestamp}; +const unsigned long long GODOT_VERSION_TIMESTAMP = {git_timestamp}; """.format(**source[0].read()) ) diff --git a/core/math/math_defs.h b/core/math/math_defs.h index 5a9be58c29..4213b810a2 100644 --- a/core/math/math_defs.h +++ b/core/math/math_defs.h @@ -145,3 +145,16 @@ typedef double real_t; #else typedef float real_t; #endif + +/** + * Rarely, there will be a scenario where a function/variable expects one of the builtin integral + * types that do NOT utilize the fixed-width constants. In practice, the only discrepancies are + * with `long` or `long long` (and their unsigned equivalents) not being declared when most/all + * other integral constants are. We'll account for this with `int_alt_t` and `uint_alt_t`, + * which assign to the unused fixed-width slot. As this will only be used rarely, keep the types + * scoped to `Math` instead of the global namespace. + */ +namespace Math { +using int_alt_t = std::conditional_t, long long, long>; +using uint_alt_t = std::conditional_t, unsigned long long, unsigned long>; +} //namespace Math diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 7604a1d2b4..d8b503ca74 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -1490,6 +1490,10 @@ Variant::operator int8_t() const { return _to_int(); } +Variant::operator Math::int_alt_t() const { + return _to_int(); +} + Variant::operator uint64_t() const { return _to_int(); } @@ -1506,6 +1510,10 @@ Variant::operator uint8_t() const { return _to_int(); } +Variant::operator Math::uint_alt_t() const { + return _to_int(); +} + Variant::operator ObjectID() const { if (type == INT) { return ObjectID(_data._int); @@ -2319,6 +2327,11 @@ Variant::Variant(int8_t p_int8) : _data._int = p_int8; } +Variant::Variant(Math::int_alt_t p_int_alt) : + type(INT) { + _data._int = p_int_alt; +} + Variant::Variant(uint64_t p_uint64) : type(INT) { _data._int = int64_t(p_uint64); @@ -2339,6 +2352,11 @@ Variant::Variant(uint8_t p_uint8) : _data._int = int64_t(p_uint8); } +Variant::Variant(Math::uint_alt_t p_uint_alt) : + type(INT) { + _data._int = p_uint_alt; +} + Variant::Variant(float p_float) : type(FLOAT) { _data._float = p_float; diff --git a/core/variant/variant.h b/core/variant/variant.h index 0a1ee130d3..4bc236d557 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -412,10 +412,12 @@ public: operator int32_t() const; operator int16_t() const; operator int8_t() const; + operator Math::int_alt_t() const; operator uint64_t() const; operator uint32_t() const; operator uint16_t() const; operator uint8_t() const; + operator Math::uint_alt_t() const; operator ObjectID() const; @@ -488,10 +490,12 @@ public: Variant(int32_t p_int32); Variant(int16_t p_int16); Variant(int8_t p_int8); + Variant(Math::int_alt_t p_int_alt); Variant(uint64_t p_uint64); Variant(uint32_t p_uint32); Variant(uint16_t p_uint16); Variant(uint8_t p_uint8); + Variant(Math::uint_alt_t p_uint_alt); Variant(float p_float); Variant(double p_double); Variant(const ObjectID &p_id); diff --git a/core/version.h b/core/version.h index 3b75052f10..e34870d1f1 100644 --- a/core/version.h +++ b/core/version.h @@ -32,8 +32,6 @@ #include "core/version_generated.gen.h" // IWYU pragma: export -#include // NOLINT(modernize-deprecated-headers) FIXME: MinGW compilation fails when changing to C++ Header. - // Copied from typedefs.h to stay lean. #ifndef _STR #define _STR(m_x) #m_x @@ -85,7 +83,7 @@ extern const char *const GODOT_VERSION_HASH; // Git commit date UNIX timestamp (in seconds), generated at build time in `core/version_hash.gen.cpp`. // Set to 0 if unknown. -extern const uint64_t GODOT_VERSION_TIMESTAMP; +extern const unsigned long long GODOT_VERSION_TIMESTAMP; #ifndef DISABLE_DEPRECATED // Compatibility with pre-4.5 modules.