Skip to content

Commit f474a73

Browse files
committed
Fix typo and move alignment offsets to cpp file
1 parent cd7b357 commit f474a73

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

tests/CSharp/CSharp.Tests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ public void TestAlignment()
750750
Assert.That(Marshal.SizeOf(internalType), Is.EqualTo(internalType.StructLayoutAttribute.Size));
751751
}
752752

753-
foreach (var (type, offsets) in new (Type, int[])[] {
753+
foreach (var (type, offsets) in new (Type, uint[])[] {
754754
(typeof(ClassCustomTypeAlignment), CSharp.CSharp.ClassCustomTypeAlignmentOffsets),
755-
(typeof(ClassCustomObjectAligment), CSharp.CSharp.ClassCustomObjectAligmentOffsets),
755+
(typeof(ClassCustomObjectAlignment), CSharp.CSharp.ClassCustomObjectAlignmentOffsets),
756756
(typeof(ClassMicrosoftObjectAlignment), CSharp.CSharp.ClassMicrosoftObjectAlignmentOffsets),
757757
})
758758
{
@@ -761,7 +761,7 @@ public void TestAlignment()
761761
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
762762
.SkipWhile(x => x.FieldType == typeof(IntPtr))
763763
.Where(x => !x.Name.EndsWith("Padding"))
764-
.Select(field => (int)Marshal.OffsetOf(internalType, field.Name));
764+
.Select(field => (uint)Marshal.OffsetOf(internalType, field.Name));
765765

766766
Assert.That(managedOffsets, Is.EqualTo(offsets));
767767
Assert.That(Marshal.SizeOf(internalType), Is.EqualTo(internalType.StructLayoutAttribute.Size));

tests/CSharp/CSharp.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,3 +1866,25 @@ ConversionFunctions::operator short() { return field; }
18661866
ConversionFunctions::operator const short*() const { return &field; }
18671867
ConversionFunctions::operator const short&() const { return field; }
18681868
ConversionFunctions::operator const short() const { return field; }
1869+
1870+
const unsigned ClassCustomTypeAlignmentOffsets[5]
1871+
{
1872+
offsetof(ClassCustomTypeAlignment, boolean),
1873+
offsetof(ClassCustomTypeAlignment, align16),
1874+
offsetof(ClassCustomTypeAlignment, align1),
1875+
offsetof(ClassCustomTypeAlignment, dbl),
1876+
offsetof(ClassCustomTypeAlignment, align8),
1877+
};
1878+
1879+
const unsigned ClassCustomObjectAlignmentOffsets[2] {
1880+
offsetof(ClassCustomObjectAlignment, boolean),
1881+
offsetof(ClassCustomObjectAlignment, charAligned8),
1882+
};
1883+
1884+
const unsigned ClassMicrosoftObjectAlignmentOffsets[4]
1885+
{
1886+
offsetof(ClassMicrosoftObjectAlignment, u8),
1887+
offsetof(ClassMicrosoftObjectAlignment, dbl),
1888+
offsetof(ClassMicrosoftObjectAlignment, i16),
1889+
offsetof(ClassMicrosoftObjectAlignment, boolean),
1890+
};

tests/CSharp/CSharp.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,25 +1482,12 @@ struct DLL_API ClassCustomTypeAlignment
14821482
Align8 align8;
14831483
};
14841484

1485-
static constexpr const int ClassCustomTypeAlignmentOffsets[] {
1486-
offsetof(ClassCustomTypeAlignment, boolean),
1487-
offsetof(ClassCustomTypeAlignment, align16),
1488-
offsetof(ClassCustomTypeAlignment, align1),
1489-
offsetof(ClassCustomTypeAlignment, dbl),
1490-
offsetof(ClassCustomTypeAlignment, align8),
1491-
};
1492-
1493-
struct DLL_API ClassCustomObjectAligment
1485+
struct DLL_API ClassCustomObjectAlignment
14941486
{
14951487
bool boolean;
14961488
alignas(alignof(ClassCustomTypeAlignment)) char charAligned8;
14971489
};
14981490

1499-
static constexpr const int ClassCustomObjectAligmentOffsets[] {
1500-
offsetof(ClassCustomObjectAligment, boolean),
1501-
offsetof(ClassCustomObjectAligment, charAligned8),
1502-
};
1503-
15041491
struct DLL_API ClassMicrosoftObjectAlignmentBase
15051492
{
15061493
uint8_t u8;
@@ -1514,13 +1501,9 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
15141501
bool boolean;
15151502
};
15161503

1517-
static constexpr const int ClassMicrosoftObjectAlignmentOffsets[]
1518-
{
1519-
offsetof(ClassMicrosoftObjectAlignment, u8),
1520-
offsetof(ClassMicrosoftObjectAlignment, dbl),
1521-
offsetof(ClassMicrosoftObjectAlignment, i16),
1522-
offsetof(ClassMicrosoftObjectAlignment, boolean),
1523-
};
1504+
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];
1505+
DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2];
1506+
DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4];
15241507

15251508
DLL_API const char* TestCSharpString(const char* in, CS_OUT const char** out);
15261509
DLL_API const wchar_t* TestCSharpStringWide(const wchar_t* in, CS_OUT const wchar_t** out);

0 commit comments

Comments
 (0)