Skip to content

Commit 92e8c55

Browse files
Merge pull request #637 from tannergooding/main
Ensure state is cleared and continue to multi-target .NET 8 for the interop bindings
2 parents d431b90 + 3854bf2 commit 92e8c55

File tree

12 files changed

+37
-10
lines changed

12 files changed

+37
-10
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<PackageValidationBaselineVersion>17.0.0</PackageValidationBaselineVersion>
4848
<Product>ClangSharp</Product>
4949
<RootNamespace>ClangSharp</RootNamespace>
50-
<VersionPrefix>20.1.2.3</VersionPrefix>
50+
<VersionPrefix>20.1.2.4</VersionPrefix>
5151
<VersionSuffix Condition="'$(PACKAGE_PUBLISH_MODE)' != 'stable'">rc1</VersionSuffix>
5252
<VersionSuffix Condition="'$(GITHUB_EVENT_NAME)' == 'pull_request'">pr</VersionSuffix>
5353
</PropertyGroup>

scripts/build.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ try {
182182
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
183183
Create-Directory -Path $DotNetInstallDirectory
184184

185+
& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
185186
& $DotNetInstallScript -Channel 10.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
186187

187188
$env:PATH="$DotNetInstallDirectory;$env:PATH"

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ if [[ ! -z "$architecture" ]]; then
222222
DotNetInstallDirectory="$ArtifactsDir/dotnet"
223223
CreateDirectory "$DotNetInstallDirectory"
224224

225+
. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
225226
. "$DotNetInstallScript" --channel 10.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
226227

227228
PATH="$DotNetInstallDirectory:$PATH:"

sources/ClangSharp.Interop/ClangSharp.Interop.csproj

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

44
<PropertyGroup>
5-
<TargetFrameworks>net10.0</TargetFrameworks>
5+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup>

sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<PropertyGroup>
55
<RootNamespace>ClangSharp</RootNamespace>
6-
<TargetFrameworks>net10.0</TargetFrameworks>
6+
<TargetFramework>net10.0</TargetFramework>
77
</PropertyGroup>
88

99
<PropertyGroup>

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,17 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s
16701670
_clangCommandLineArgs = clangCommandLineArgs;
16711671
_translationFlags = translationFlags;
16721672

1673+
// We need to clear any cached state from a previous translation unit as
1674+
// native handle IDs or other info may have been reused if it was disposed.
1675+
1676+
_context.Clear();
1677+
_cursorNames.Clear();
1678+
_cursorQualifiedNames.Clear();
1679+
_typeNames.Clear();
1680+
_overloadIndices.Clear();
1681+
_isExcluded.Clear();
1682+
_fileContents.Clear();
1683+
16731684
if (translationUnit.Handle.NumDiagnostics != 0)
16741685
{
16751686
var errorDiagnostics = new StringBuilder();
@@ -3465,7 +3476,7 @@ private unsafe ReadOnlySpan<byte> GetFileContents(CXTranslationUnit translationU
34653476
{
34663477
var fileContents = translationUnit.GetFileContents(file, out _);
34673478
fileContentsMetadata = ((nuint)Unsafe.AsPointer(ref MemoryMarshal.GetReference(fileContents)), (uint)fileContents.Length);
3468-
_fileContents.Add(file, fileContentsMetadata);
3479+
_fileContents[file] = fileContentsMetadata;
34693480
}
34703481

34713482
return new ReadOnlySpan<byte>((byte*)fileContentsMetadata.Address, (int)fileContentsMetadata.Length);
@@ -3481,8 +3492,8 @@ private string GetSourceRangeContents(CXTranslationUnit translationUnit, CXSourc
34813492
return string.Empty;
34823493
}
34833494

3484-
var contents = GetFileContents(translationUnit, startFile);
3485-
contents = contents.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset)));
3495+
var contents1 = GetFileContents(translationUnit, startFile);
3496+
var contents = contents1.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset)));
34863497
return Encoding.UTF8.GetString(contents);
34873498
}
34883499

sources/ClangSharp/ClangSharp.csproj

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

44
<PropertyGroup>
5-
<TargetFrameworks>net10.0</TargetFrameworks>
5+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup>

sources/ClangSharp/Cursors/Decls/FieldDecl.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX
4343
name = name[anonymousNameStartIndex..];
4444
}
4545

46+
#if NET8_0
47+
if (name.StartsWith("("))
48+
#else
4649
if (name.StartsWith('('))
50+
#endif
4751
{
4852
Debug.Assert(name.StartsWith("(anonymous enum at ", StringComparison.Ordinal) ||
4953
name.StartsWith("(anonymous struct at ", StringComparison.Ordinal) ||
@@ -52,7 +56,12 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX
5256
name.StartsWith("(unnamed struct at ", StringComparison.Ordinal) ||
5357
name.StartsWith("(unnamed union at ", StringComparison.Ordinal) ||
5458
name.StartsWith("(unnamed at ", StringComparison.Ordinal));
59+
60+
#if NET8_0
61+
Debug.Assert(name.EndsWith(")"));
62+
#else
5563
Debug.Assert(name.EndsWith(')'));
64+
#endif
5665

5766
return true;
5867
}

sources/ClangSharp/TranslationUnit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ namespace ClangSharp;
1515
public sealed unsafe class TranslationUnit : IDisposable, IEquatable<TranslationUnit>
1616
{
1717
private static readonly ConcurrentDictionary<CXTranslationUnit, WeakReference<TranslationUnit>> s_createdTranslationUnits = new ConcurrentDictionary<CXTranslationUnit, WeakReference<TranslationUnit>>();
18+
19+
#if NET8_0
20+
private static readonly object s_createTranslationUnitLock = new object();
21+
#else
1822
private static readonly Lock s_createTranslationUnitLock = new Lock();
23+
#endif
1924

2025
private readonly Dictionary<CXCursor, WeakReference<Cursor>> _createdCursors;
2126
private readonly Dictionary<CX_TemplateArgument, WeakReference<TemplateArgument>> _createdTemplateArguments;

sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackAsTool>true</PackAsTool>
77
<PublishAot>true</PublishAot>
88
<RuntimeIdentifiers>linux-arm64;linux-x64;osx-arm64;win-arm64;win-x64</RuntimeIdentifiers>
9-
<TargetFrameworks>net10.0</TargetFrameworks>
9+
<TargetFramework>net10.0</TargetFramework>
1010
</PropertyGroup>
1111

1212
<PropertyGroup Condition="'$(Configuration)' != 'Debug'">

0 commit comments

Comments
 (0)