diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index df09a91a8c..522e43d5b9 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -524,7 +524,13 @@ public void GenerateClassInternals(Class @class) { PushBlock(BlockKind.InternalsClass); if (!Options.GenerateSequentialLayout || @class.IsUnion) - WriteLine($"[StructLayout(LayoutKind.Explicit, Size = {@class.Layout.Size})]"); + { + /// There's at least one ABI (System V) that gives to empty structs + /// size 1 in C++ and size 0 in C. The former causes crashes in older versions of Mono. + int size = @class.Layout.Size == 1 && @class.Layout.DataSize == 0 ? + 0 : @class.Layout.Size; + WriteLine($"[StructLayout(LayoutKind.Explicit, Size = {size})]"); + } else if (@class.MaxFieldAlignment > 0) WriteLine($"[StructLayout(LayoutKind.Sequential, Pack = {@class.MaxFieldAlignment})]"); @@ -2885,7 +2891,7 @@ public void GenerateFunctionCall(string functionName, List parameters ((Method) method.OriginalFunction).IsConstructor) { WriteLine($@"Marshal.AllocHGlobal({ - ((Class) method.OriginalNamespace).Layout.Size});"); + ((Class) method.OriginalNamespace).Layout.DataSize});"); names.Insert(0, Helpers.ReturnIdentifier); } WriteLine("{0}({1});", functionName, string.Join(", ", names)); diff --git a/src/Generator/Passes/CheckAbiParameters.cs b/src/Generator/Passes/CheckAbiParameters.cs index 396a4b0120..331ca68146 100644 --- a/src/Generator/Passes/CheckAbiParameters.cs +++ b/src/Generator/Passes/CheckAbiParameters.cs @@ -25,19 +25,6 @@ namespace CppSharp.Passes /// public class CheckAbiParameters : TranslationUnitPass { - public override bool VisitClassDecl(Class @class) - { - if (!base.VisitClassDecl(@class)) - return false; - - if (@class.IsDependent || @class.Layout.Fields.Count > 0 || @class.Fields.Count > 0) - return false; - - @class.Layout.Size = @class.Layout.DataSize = 0; - - return true; - } - public override bool VisitFunctionDecl(Function function) { if (!VisitDeclaration(function))