Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mono/CppSharp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0e0b4cc0178574c85bae58a8dcf06e42562f3a33
Choose a base ref
..
head repository: mono/CppSharp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d90d3283e4ff309993dd4e1446119ec8e44e3961
Choose a head ref
Showing with 9 additions and 10 deletions.
  1. +6 −1 src/AST/ClassExtensions.cs
  2. +2 −8 src/Generator/Generators/CSharp/CSharpSources.cs
  3. +1 −1 src/Generator/Generators/CSharp/CSharpTypePrinter.cs
7 changes: 6 additions & 1 deletion src/AST/ClassExtensions.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

namespace CppSharp.AST
{
public static class ClassExtensions
public static class ClassExtensions
{
public static IEnumerable<Function> GetFunctionOverloads(this Class @class,
Function function)
@@ -211,6 +211,11 @@ public static bool HasDependentValueFieldInLayout(this Class @class)
b => b.Class).Any(HasDependentValueFieldInLayout);
}

public static int GetSize(this ClassLayout layout) =>
/// 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.
layout.Size == 1 && layout.DataSize == 0 ? 0 : layout.Size;

private static bool IsValueDependent(Type type)
{
var desugared = type.Desugar();
10 changes: 2 additions & 8 deletions src/Generator/Generators/CSharp/CSharpSources.cs
Original file line number Diff line number Diff line change
@@ -524,13 +524,7 @@ public void GenerateClassInternals(Class @class)
{
PushBlock(BlockKind.InternalsClass);
if (!Options.GenerateSequentialLayout || @class.IsUnion)
{
/// 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})]");
}
WriteLine($"[StructLayout(LayoutKind.Explicit, Size = {@class.Layout.GetSize()})]");
else if (@class.MaxFieldAlignment > 0)
WriteLine($"[StructLayout(LayoutKind.Sequential, Pack = {@class.MaxFieldAlignment})]");

@@ -2891,7 +2885,7 @@ public void GenerateFunctionCall(string functionName, List<Parameter> parameters
((Method) method.OriginalFunction).IsConstructor)
{
WriteLine($@"Marshal.AllocHGlobal({
((Class) method.OriginalNamespace).Layout.DataSize});");
((Class) method.OriginalNamespace).Layout.GetSize()});");
names.Insert(0, Helpers.ReturnIdentifier);
}
WriteLine("{0}({1});", functionName, string.Join(", ", names));
2 changes: 1 addition & 1 deletion src/Generator/Generators/CSharp/CSharpTypePrinter.cs
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public override TypePrinterResult VisitArrayType(ArrayType array,
return new TypePrinterResult
{
Type = "fixed byte",
NameSuffix = $"[{array.Size * @class.Layout.Size}]"
NameSuffix = $"[{array.Size * @class.Layout.GetSize()}]"
};
}