Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3266,7 +3266,7 @@ private void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr unaryExprOrT
}

needsCast = IsType<BuiltinType>(unaryExprOrTypeTraitExpr, parentType, out var builtinType) &&
((builtinType.Kind == CXType_UInt) || (builtinType.Kind == CXType_ULong));
(builtinType.Kind is CXType_UInt or CXType_ULong or CXType_ULongLong);
needsCast &= !IsSupportedFixedSizedBufferType(typeName);
needsCast &= !IsType<EnumType>(unaryExprOrTypeTraitExpr, argumentType);
needsCast |= parentTypeIsVariableSized;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace ClangSharp.Test
{
public unsafe partial struct XrEventDataBuffer
{
[NativeTypeName("const void *")]
public void* next;
}

public static unsafe partial class Methods
{
[NativeTypeName("#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)")]
public static readonly nuint XR_MAX_EVENT_DATA_SIZE = unchecked((nuint)((uint)(sizeof(XrEventDataBuffer))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace ClangSharp.Test
{
public unsafe partial struct XrEventDataBuffer
{
[NativeTypeName("const void *")]
public void* next;
}

public static unsafe partial class Methods
{
[NativeTypeName("#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)")]
public static readonly ulong XR_MAX_EVENT_DATA_SIZE = (uint)(sizeof(XrEventDataBuffer));
}
}
42 changes: 42 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/SizeOfMacroTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System.Threading.Tasks;
using ClangSharp.UnitTests.Baseline;
using NUnit.Framework;

namespace ClangSharp.UnitTests;

public sealed class SizeOfMacroTestTest : StandaloneBaselineTest
{
protected override string Area => "SizeOfMacroTestTest";

[Test]
[Platform("win")]
public Task RuntimeSizeofMacroTestWindows()
{
var inputContents = """
typedef struct XrEventDataBuffer {
const void* next;
} XrEventDataBuffer;

#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)
""";

return ValidateGeneratedCSharpLatestWindowsBaselineAsync(inputContents);
}

[Test]
[Platform("unix")]
public Task RuntimeSizeofMacroTestUnix()
{
var inputContents = """
typedef struct XrEventDataBuffer {
const void* next;
} XrEventDataBuffer;

#define XR_MAX_EVENT_DATA_SIZE sizeof(XrEventDataBuffer)
""";

return ValidateGeneratedCSharpLatestUnixBaselineAsync(inputContents);
}
}
Loading