Skip to content

Commit 66272bb

Browse files
committed
respect explicit size with sequential layout
1 parent dd24e9c commit 66272bb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/mono/mono/metadata/class-init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_
23312331

23322332
instance_size = MAX (real_size, instance_size);
23332333

2334-
if (instance_size & (min_align - 1)) {
2334+
if (instance_size & (min_align - 1) && !explicit_size) {
23352335
instance_size += min_align - 1;
23362336
instance_size &= ~(min_align - 1);
23372337
}

src/mono/mono/metadata/marshal.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5749,7 +5749,7 @@ MonoMarshalType *
57495749
mono_marshal_load_type_info (MonoClass* klass)
57505750
{
57515751
int j, count = 0;
5752-
guint32 native_size = 0, min_align = 1, packing;
5752+
guint32 native_size = 0, min_align = 1, packing, explicit_size = 0;
57535753
MonoMarshalType *info;
57545754
MonoClassField* field;
57555755
gpointer iter;
@@ -5793,7 +5793,7 @@ mono_marshal_load_type_info (MonoClass* klass)
57935793
info->num_fields = count;
57945794

57955795
/* Try to find a size for this type in metadata */
5796-
mono_metadata_packing_from_typedef (m_class_get_image (klass), m_class_get_type_token (klass), NULL, &native_size);
5796+
explicit_size = mono_metadata_packing_from_typedef (m_class_get_image (klass), m_class_get_type_token (klass), NULL, &native_size);
57975797

57985798
if (m_class_get_parent (klass)) {
57995799
int parent_size = mono_class_native_size (m_class_get_parent (klass), NULL);
@@ -5879,6 +5879,9 @@ mono_marshal_load_type_info (MonoClass* klass)
58795879
align_size = FALSE;
58805880
else
58815881
min_align = MIN (min_align, packing);
5882+
} else if (layout == TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT) {
5883+
if (explicit_size && native_size == info->native_size)
5884+
align_size = FALSE;
58825885
}
58835886
}
58845887

0 commit comments

Comments
 (0)