Skip to content

Commit 25f85c9

Browse files
authored
revert layout change (#720)
* Revert "Refactor AddLayoutInfo" This reverts commit 6070fe7. * Revert "Add a ClassLayoutTable row for structs with no instance fields" This reverts commit 8f2b917.
1 parent 43336ee commit 25f85c9

File tree

2 files changed

+7
-43
lines changed

2 files changed

+7
-43
lines changed

Mono.Cecil/AssemblyWriter.cs

+7-30
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,8 @@ void AddType (TypeDefinition type)
14351435
if (type.HasInterfaces)
14361436
AddInterfaces (type);
14371437

1438-
AddLayoutInfo (type);
1438+
if (type.HasLayoutInfo)
1439+
AddLayoutInfo (type);
14391440

14401441
if (type.HasFields)
14411442
AddFields (type);
@@ -1554,36 +1555,12 @@ void AddInterfaces (TypeDefinition type)
15541555

15551556
void AddLayoutInfo (TypeDefinition type)
15561557
{
1557-
if (type.HasLayoutInfo) {
1558-
var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
1558+
var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
15591559

1560-
table.AddRow (new ClassLayoutRow (
1561-
(ushort) type.PackingSize,
1562-
(uint) type.ClassSize,
1563-
type.token.RID));
1564-
1565-
return;
1566-
}
1567-
1568-
if (type.IsValueType && HasNoInstanceField (type)) {
1569-
var table = GetTable<ClassLayoutTable> (Table.ClassLayout);
1570-
1571-
table.AddRow (new ClassLayoutRow (0, 1, type.token.RID));
1572-
}
1573-
}
1574-
1575-
static bool HasNoInstanceField (TypeDefinition type)
1576-
{
1577-
if (!type.HasFields)
1578-
return true;
1579-
1580-
var fields = type.Fields;
1581-
1582-
for (int i = 0; i < fields.Count; i++)
1583-
if (!fields [i].IsStatic)
1584-
return false;
1585-
1586-
return true;
1560+
table.AddRow (new ClassLayoutRow (
1561+
(ushort) type.PackingSize,
1562+
(uint) type.ClassSize,
1563+
type.token.RID));
15871564
}
15881565

15891566
void AddNestedTypes (TypeDefinition type)

Test/Mono.Cecil.Tests/TypeTests.cs

-13
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@ public void TypeLayout ()
3030
});
3131
}
3232

33-
[Test]
34-
public void EmptyStructLayout ()
35-
{
36-
TestModule ("hello.exe", module =>
37-
{
38-
var foo = new TypeDefinition ("", "Foo",
39-
TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit | TypeAttributes.SequentialLayout,
40-
module.ImportReference (typeof (ValueType))) ;
41-
42-
module.Types.Add (foo) ;
43-
}) ;
44-
}
45-
4633
[Test]
4734
public void SimpleInterfaces ()
4835
{

0 commit comments

Comments
 (0)