From d255cc9e4ded8b9e4fef670e14a71a5ea39c6bdb Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sun, 17 May 2020 16:11:49 +0300 Subject: [PATCH] Fix GDNative Variant type size on 32-bit platforms, add size checking static asserts. [3.2] --- modules/gdnative/gdnative/aabb.cpp | 2 ++ modules/gdnative/gdnative/array.cpp | 2 ++ modules/gdnative/gdnative/basis.cpp | 2 ++ modules/gdnative/gdnative/color.cpp | 2 ++ modules/gdnative/gdnative/dictionary.cpp | 2 ++ modules/gdnative/gdnative/node_path.cpp | 2 ++ modules/gdnative/gdnative/plane.cpp | 2 ++ modules/gdnative/gdnative/pool_arrays.cpp | 8 ++++++++ modules/gdnative/gdnative/quat.cpp | 2 ++ modules/gdnative/gdnative/rect2.cpp | 2 ++ modules/gdnative/gdnative/rid.cpp | 2 ++ modules/gdnative/gdnative/string.cpp | 4 ++++ modules/gdnative/gdnative/string_name.cpp | 2 ++ modules/gdnative/gdnative/transform.cpp | 2 ++ modules/gdnative/gdnative/transform2d.cpp | 2 ++ modules/gdnative/gdnative/variant.cpp | 2 ++ modules/gdnative/gdnative/vector2.cpp | 2 ++ modules/gdnative/gdnative/vector3.cpp | 2 ++ modules/gdnative/include/gdnative/variant.h | 2 +- 19 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/gdnative/gdnative/aabb.cpp b/modules/gdnative/gdnative/aabb.cpp index 246e5d4e8d2..7f22c7dfe34 100644 --- a/modules/gdnative/gdnative/aabb.cpp +++ b/modules/gdnative/gdnative/aabb.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_aabb) == sizeof(AABB), "AABB size mismatch"); + void GDAPI godot_aabb_new(godot_aabb *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) { const Vector3 *pos = (const Vector3 *)p_pos; const Vector3 *size = (const Vector3 *)p_size; diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp index 4a0308edecd..01acce05b90 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -42,6 +42,8 @@ extern "C" { #endif +static_assert(sizeof(godot_array) == sizeof(Array), "Array size mismatch"); + void GDAPI godot_array_new(godot_array *r_dest) { Array *dest = (Array *)r_dest; memnew_placement(dest, Array); diff --git a/modules/gdnative/gdnative/basis.cpp b/modules/gdnative/gdnative/basis.cpp index 4f489287b99..990fd3795d1 100644 --- a/modules/gdnative/gdnative/basis.cpp +++ b/modules/gdnative/gdnative/basis.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_basis) == sizeof(Basis), "Basis size mismatch"); + void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis) { const Vector3 *x_axis = (const Vector3 *)p_x_axis; const Vector3 *y_axis = (const Vector3 *)p_y_axis; diff --git a/modules/gdnative/gdnative/color.cpp b/modules/gdnative/gdnative/color.cpp index 24587ce4a14..5049549a05f 100644 --- a/modules/gdnative/gdnative/color.cpp +++ b/modules/gdnative/gdnative/color.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_color) == sizeof(Color), "Color size mismatch"); + void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) { Color *dest = (Color *)r_dest; diff --git a/modules/gdnative/gdnative/dictionary.cpp b/modules/gdnative/gdnative/dictionary.cpp index b145b88934b..a1269748151 100644 --- a/modules/gdnative/gdnative/dictionary.cpp +++ b/modules/gdnative/gdnative/dictionary.cpp @@ -39,6 +39,8 @@ extern "C" { #endif +static_assert(sizeof(godot_dictionary) == sizeof(Dictionary), "Dictionary size mismatch"); + void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { Dictionary *dest = (Dictionary *)r_dest; memnew_placement(dest, Dictionary); diff --git a/modules/gdnative/gdnative/node_path.cpp b/modules/gdnative/gdnative/node_path.cpp index 93f43835c88..88ed650ebee 100644 --- a/modules/gdnative/gdnative/node_path.cpp +++ b/modules/gdnative/gdnative/node_path.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_node_path) == sizeof(NodePath), "NodePath size mismatch"); + void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) { NodePath *dest = (NodePath *)r_dest; const String *from = (const String *)p_from; diff --git a/modules/gdnative/gdnative/plane.cpp b/modules/gdnative/gdnative/plane.cpp index 17221fe0815..0eef49e30ca 100644 --- a/modules/gdnative/gdnative/plane.cpp +++ b/modules/gdnative/gdnative/plane.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_plane) == sizeof(Plane), "Plane size mismatch"); + void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) { Plane *dest = (Plane *)r_dest; diff --git a/modules/gdnative/gdnative/pool_arrays.cpp b/modules/gdnative/gdnative/pool_arrays.cpp index bae1290d59f..8d929b2cc05 100644 --- a/modules/gdnative/gdnative/pool_arrays.cpp +++ b/modules/gdnative/gdnative/pool_arrays.cpp @@ -42,6 +42,14 @@ extern "C" { #endif +static_assert(sizeof(godot_pool_byte_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_int_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_real_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_string_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_vector2_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_vector3_array) == sizeof(PoolVector), "PoolVector size mismatch"); +static_assert(sizeof(godot_pool_color_array) == sizeof(PoolVector), "PoolVector size mismatch"); + #define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) // byte diff --git a/modules/gdnative/gdnative/quat.cpp b/modules/gdnative/gdnative/quat.cpp index be30b89e5fe..a8708847f87 100644 --- a/modules/gdnative/gdnative/quat.cpp +++ b/modules/gdnative/gdnative/quat.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_quat) == sizeof(Quat), "Quat size mismatch"); + void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) { Quat *dest = (Quat *)r_dest; diff --git a/modules/gdnative/gdnative/rect2.cpp b/modules/gdnative/gdnative/rect2.cpp index 906b4f09326..d489d0d8413 100644 --- a/modules/gdnative/gdnative/rect2.cpp +++ b/modules/gdnative/gdnative/rect2.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_rect2) == sizeof(Rect2), "Rect2 size mismatch"); + void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { const Vector2 *position = (const Vector2 *)p_pos; const Vector2 *size = (const Vector2 *)p_size; diff --git a/modules/gdnative/gdnative/rid.cpp b/modules/gdnative/gdnative/rid.cpp index 7ea80123a3d..d7a63f33a72 100644 --- a/modules/gdnative/gdnative/rid.cpp +++ b/modules/gdnative/gdnative/rid.cpp @@ -38,6 +38,8 @@ extern "C" { #endif +static_assert(sizeof(godot_rid) == sizeof(RID), "RID size mismatch"); + void GDAPI godot_rid_new(godot_rid *r_dest) { RID *dest = (RID *)r_dest; memnew_placement(dest, RID); diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 414b9b9eaf2..79a23c3dda2 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -40,6 +40,10 @@ extern "C" { #endif +static_assert(sizeof(godot_char_string) == sizeof(CharString), "CharString size mismatch"); +static_assert(sizeof(godot_string) == sizeof(String), "String size mismatch"); +static_assert(sizeof(godot_char_type) == sizeof(CharType), "CharType size mismatch"); + godot_int GDAPI godot_char_string_length(const godot_char_string *p_cs) { const CharString *cs = (const CharString *)p_cs; diff --git a/modules/gdnative/gdnative/string_name.cpp b/modules/gdnative/gdnative/string_name.cpp index 1abb4486b1d..7bbaaeeaa03 100644 --- a/modules/gdnative/gdnative/string_name.cpp +++ b/modules/gdnative/gdnative/string_name.cpp @@ -39,6 +39,8 @@ extern "C" { #endif +static_assert(sizeof(godot_string_name) == sizeof(StringName), "StringName size mismatch"); + void GDAPI godot_string_name_new(godot_string_name *r_dest, const godot_string *p_name) { StringName *dest = (StringName *)r_dest; const String *name = (const String *)p_name; diff --git a/modules/gdnative/gdnative/transform.cpp b/modules/gdnative/gdnative/transform.cpp index c9b3e37fb2e..d19de93e9b8 100644 --- a/modules/gdnative/gdnative/transform.cpp +++ b/modules/gdnative/gdnative/transform.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_transform) == sizeof(Transform), "Transform size mismatch"); + void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin) { const Vector3 *x_axis = (const Vector3 *)p_x_axis; const Vector3 *y_axis = (const Vector3 *)p_y_axis; diff --git a/modules/gdnative/gdnative/transform2d.cpp b/modules/gdnative/gdnative/transform2d.cpp index 26a71333b14..c0f7878eb09 100644 --- a/modules/gdnative/gdnative/transform2d.cpp +++ b/modules/gdnative/gdnative/transform2d.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_transform2d) == sizeof(Transform2D), "Transform2D size mismatch"); + void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) { const Vector2 *pos = (const Vector2 *)p_pos; Transform2D *dest = (Transform2D *)r_dest; diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index 11b6448e340..ccf85e35292 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_variant) == sizeof(Variant), "Variant size mismatch"); + // Workaround GCC ICE on armv7hl which was affected GCC 6.0 up to 8.0 (GH-16100). // It was fixed upstream in 8.1, and a fix was backported to 7.4. // This can be removed once no supported distro ships with versions older than 7.4. diff --git a/modules/gdnative/gdnative/vector2.cpp b/modules/gdnative/gdnative/vector2.cpp index e9e2a8edf83..5331f1be6e1 100644 --- a/modules/gdnative/gdnative/vector2.cpp +++ b/modules/gdnative/gdnative/vector2.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_vector2) == sizeof(Vector2), "Vector2 size mismatch"); + void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) { Vector2 *dest = (Vector2 *)r_dest; diff --git a/modules/gdnative/gdnative/vector3.cpp b/modules/gdnative/gdnative/vector3.cpp index e34a9370a57..89351a12ad0 100644 --- a/modules/gdnative/gdnative/vector3.cpp +++ b/modules/gdnative/gdnative/vector3.cpp @@ -37,6 +37,8 @@ extern "C" { #endif +static_assert(sizeof(godot_vector3) == sizeof(Vector3), "Vector3 size mismatch"); + void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) { Vector3 *dest = (Vector3 *)r_dest; diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index c65f7a28d2b..5da6d97181e 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -37,7 +37,7 @@ extern "C" { #include -#define GODOT_VARIANT_SIZE (16 + sizeof(void *)) +#define GODOT_VARIANT_SIZE (16 + sizeof(int64_t)) #ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED