Skip to content

Commit dc69728

Browse files
Merge pull request #480 from tannergooding/main
Add support for DisableRuntimeMarshalling and CallConvMemberFunction
2 parents e4813d3 + a2bc333 commit dc69728

File tree

93 files changed

+1134
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1134
-942
lines changed

sources/ClangSharp.Interop/ClangSharp.Interop.csproj

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,31 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<NoWarn>$(NoWarn);CA1069</NoWarn>
65
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
76
</PropertyGroup>
87

8+
<PropertyGroup>
9+
<!-- CA1003: Use generic event handler instances -->
10+
<!-- CA1008: Enums should have zero value -->
11+
<!-- CA1027: Mark enums with FlagsAttribute -->
12+
<!-- CA1034: Nested types should not be visible -->
13+
<!-- CA1051: Do not declare visible instance fields -->
14+
<!-- CA1069: Enums should not have duplicate values -->
15+
<!-- CA1305: Specify IFormatProvider -->
16+
<!-- CA1508: Avoid dead conditional code -->
17+
<!-- CA1707: Identifiers should not contain underscores -->
18+
<!-- CA1708: Identifiers should differ by more than case -->
19+
<!-- CA1710: Identifiers should have correct suffix -->
20+
<!-- CA1711: Identifiers should not have incorrect suffix -->
21+
<!-- CA1712: Do not prefix enum values with type name -->
22+
<!-- CA1720: Identifiers should not contain type names -->
23+
<!-- CA1721: Property names should not match get methods -->
24+
<!-- CA1724: Type names should not match namespaces -->
25+
<!-- CA1815: Override equals and operator equals on value types -->
26+
<!-- CA2225: Operator overloads have named alternates -->
27+
<NoWarn>$(NoWarn);CA1003;CA1008;CA1027;CA1034;CA1051;CA1069;CA1305;CA1508;CA1707;CA1708;CA1710;CA1711;CA1712;CA1720;CA1721;CA1724;CA1815;CA2225</NoWarn>
28+
</PropertyGroup>
29+
930
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
1031
<Compile Remove="clang.cs" />
1132
<InternalsVisibleTo Include="ClangSharp" Key="$(AssemblyOriginatorPublicKey)" />

sources/ClangSharp.Interop/Configuration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// 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.
22

33
using System;
4+
using System.Runtime.InteropServices;
5+
6+
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
47

58
namespace ClangSharp.Interop;
69

@@ -27,4 +30,4 @@ private static bool GetAppContextData(string name, bool defaultValue)
2730
return defaultValue;
2831
}
2932
}
30-
}
33+
}

sources/ClangSharp.Interop/Extensions/CXClientData.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
namespace ClangSharp.Interop;
66

7-
public unsafe partial struct CXClientData : IEquatable<CXClientData>
7+
public unsafe partial struct CXClientData(IntPtr handle) : IEquatable<CXClientData>
88
{
9-
public CXClientData(IntPtr handle)
10-
{
11-
Handle = handle;
12-
}
13-
14-
public IntPtr Handle { get; set; }
9+
public IntPtr Handle { get; set; } = handle;
1510

1611
public static explicit operator CXClientData(void* value) => new CXClientData((IntPtr)value);
1712

sources/ClangSharp.Interop/Extensions/CXCompileCommands.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66

77
namespace ClangSharp.Interop;
88

9-
public unsafe partial struct CXCompileCommands : IDisposable, IEquatable<CXCompileCommands>, IReadOnlyCollection<CXCompileCommand>
9+
public unsafe partial struct CXCompileCommands(IntPtr handle) : IDisposable, IEquatable<CXCompileCommands>, IReadOnlyCollection<CXCompileCommand>
1010
{
11-
public CXCompileCommands(IntPtr handle)
12-
{
13-
Handle = handle;
14-
}
15-
1611
public readonly CXCompileCommand this[uint index] => GetCommand(index);
1712

1813
public readonly int Count => (int)Size;
1914

20-
public IntPtr Handle { get; set; }
15+
public IntPtr Handle { get; set; } = handle;
2116

2217
public readonly uint Size => clang.CompileCommands_getSize(this);
2318

sources/ClangSharp.Interop/Extensions/CXDiagnostic.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44

55
namespace ClangSharp.Interop;
66

7-
public unsafe partial struct CXDiagnostic : IDisposable, IEquatable<CXDiagnostic>
7+
public unsafe partial struct CXDiagnostic(IntPtr handle) : IDisposable, IEquatable<CXDiagnostic>
88
{
9-
public CXDiagnostic(IntPtr handle)
10-
{
11-
Handle = handle;
12-
}
13-
149
public static CXDiagnosticDisplayOptions DefaultDisplayOptions => (CXDiagnosticDisplayOptions)clang.defaultDiagnosticDisplayOptions();
1510

1611
public readonly uint Category => clang.getDiagnosticCategory(this);
@@ -19,7 +14,7 @@ public CXDiagnostic(IntPtr handle)
1914

2015
public readonly CXDiagnosticSet ChildDiagnostics => (CXDiagnosticSet)clang.getChildDiagnostics(this);
2116

22-
public IntPtr Handle { get; set; }
17+
public IntPtr Handle { get; set; } = handle;
2318

2419
public readonly CXSourceLocation Location => clang.getDiagnosticLocation(this);
2520

@@ -54,7 +49,7 @@ public void Dispose()
5449

5550
public readonly CXString Format(CXDiagnosticDisplayOptions options) => clang.formatDiagnostic(this, (uint)options);
5651

57-
[Obsolete("Use " + nameof(CategoryText) + " instead.")]
52+
[Obsolete($"Use {nameof(CategoryText)} instead.")]
5853
public static CXString GetCategoryName(uint category) => clang.getDiagnosticCategoryName(category);
5954

6055
public readonly CXString GetFixIt(uint fixIt, out CXSourceRange replacementRange)

sources/ClangSharp.Interop/Internals/MarshaledString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public MarshaledString(string? input)
2020
}
2121
else
2222
{
23-
var valueBytes = (input.Length != 0) ? Encoding.UTF8.GetBytes(input) : Array.Empty<byte>();
23+
var valueBytes = (input.Length != 0) ? Encoding.UTF8.GetBytes(input) : [];
2424
length = valueBytes.Length;
2525
value = Marshal.AllocHGlobal(length + 1);
2626
Marshal.Copy(valueBytes, 0, value, length);

sources/ClangSharp.Interop/Shims/MemberNotNullWhenAttribute.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,9 @@
33
namespace System.Diagnostics.CodeAnalysis;
44

55
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
6-
internal sealed class MemberNotNullWhenAttribute : Attribute
6+
internal sealed class MemberNotNullWhenAttribute(bool returnValue, params string[] members) : Attribute
77
{
8-
public MemberNotNullWhenAttribute(bool returnValue, string member)
9-
{
10-
ReturnValue = returnValue;
11-
Members = new[] { member };
12-
}
8+
public bool ReturnValue { get; } = returnValue;
139

14-
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
15-
{
16-
ReturnValue = returnValue;
17-
Members = members;
18-
}
19-
20-
public bool ReturnValue { get; }
21-
22-
public string[] Members { get; }
10+
public string[] Members { get; } = members;
2311
}

sources/ClangSharp.Interop/clang.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImpo
2626
return nativeLibrary;
2727
}
2828

29-
if (libraryName.Equals("libclang") && TryResolveClang(assembly, searchPath, out nativeLibrary))
29+
if (libraryName.Equals("libclang", StringComparison.Ordinal) && TryResolveClang(assembly, searchPath, out nativeLibrary))
3030
{
3131
return nativeLibrary;
3232
}

sources/ClangSharp.PInvokeGenerator/Abstractions/BitfieldDesc.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
44

55
namespace ClangSharp.Abstractions;
66

7-
public struct BitfieldDesc
7+
internal struct BitfieldDesc
88
{
99
public Type TypeBacking { get; set; }
1010

1111
public List<BitfieldRegion> Regions { get; set; }
1212
}
13-
14-
public struct BitfieldRegion
15-
{
16-
public string Name { get; set; }
17-
18-
public long Offset { get; set; }
19-
20-
public long Length { get; set; }
21-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
namespace ClangSharp.Abstractions;
4+
5+
internal struct BitfieldRegion
6+
{
7+
public string Name { get; set; }
8+
9+
public long Offset { get; set; }
10+
11+
public long Length { get; set; }
12+
}

0 commit comments

Comments
 (0)