Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<PackageValidationBaselineVersion>17.0.0</PackageValidationBaselineVersion>
<Product>ClangSharp</Product>
<RootNamespace>ClangSharp</RootNamespace>
<VersionPrefix>20.1.2.3</VersionPrefix>
<VersionPrefix>20.1.2.4</VersionPrefix>
<VersionSuffix Condition="'$(PACKAGE_PUBLISH_MODE)' != 'stable'">rc1</VersionSuffix>
<VersionSuffix Condition="'$(GITHUB_EVENT_NAME)' == 'pull_request'">pr</VersionSuffix>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ try {
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
Create-Directory -Path $DotNetInstallDirectory

& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
& $DotNetInstallScript -Channel 10.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture

$env:PATH="$DotNetInstallDirectory;$env:PATH"
Expand Down
1 change: 1 addition & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ if [[ ! -z "$architecture" ]]; then
DotNetInstallDirectory="$ArtifactsDir/dotnet"
CreateDirectory "$DotNetInstallDirectory"

. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
. "$DotNetInstallScript" --channel 10.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"

PATH="$DotNetInstallDirectory:$PATH:"
Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharp.Interop/ClangSharp.Interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<RootNamespace>ClangSharp</RootNamespace>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
17 changes: 14 additions & 3 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,17 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s
_clangCommandLineArgs = clangCommandLineArgs;
_translationFlags = translationFlags;

// We need to clear any cached state from a previous translation unit as
// native handle IDs or other info may have been reused if it was disposed.

_context.Clear();
_cursorNames.Clear();
_cursorQualifiedNames.Clear();
_typeNames.Clear();
_overloadIndices.Clear();
_isExcluded.Clear();
_fileContents.Clear();

if (translationUnit.Handle.NumDiagnostics != 0)
{
var errorDiagnostics = new StringBuilder();
Expand Down Expand Up @@ -3465,7 +3476,7 @@ private unsafe ReadOnlySpan<byte> GetFileContents(CXTranslationUnit translationU
{
var fileContents = translationUnit.GetFileContents(file, out _);
fileContentsMetadata = ((nuint)Unsafe.AsPointer(ref MemoryMarshal.GetReference(fileContents)), (uint)fileContents.Length);
_fileContents.Add(file, fileContentsMetadata);
_fileContents[file] = fileContentsMetadata;
}

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

var contents = GetFileContents(translationUnit, startFile);
contents = contents.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset)));
var contents1 = GetFileContents(translationUnit, startFile);
var contents = contents1.Slice(unchecked((int)startOffset), unchecked((int)(endOffset - startOffset)));
return Encoding.UTF8.GetString(contents);
}

Expand Down
2 changes: 1 addition & 1 deletion sources/ClangSharp/ClangSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions sources/ClangSharp/Cursors/Decls/FieldDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX
name = name[anonymousNameStartIndex..];
}

#if NET8_0
if (name.StartsWith("("))
#else
if (name.StartsWith('('))
#endif
{
Debug.Assert(name.StartsWith("(anonymous enum at ", StringComparison.Ordinal) ||
name.StartsWith("(anonymous struct at ", StringComparison.Ordinal) ||
Expand All @@ -52,7 +56,12 @@ private protected FieldDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX
name.StartsWith("(unnamed struct at ", StringComparison.Ordinal) ||
name.StartsWith("(unnamed union at ", StringComparison.Ordinal) ||
name.StartsWith("(unnamed at ", StringComparison.Ordinal));

#if NET8_0
Debug.Assert(name.EndsWith(")"));
#else
Debug.Assert(name.EndsWith(')'));
#endif

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions sources/ClangSharp/TranslationUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ namespace ClangSharp;
public sealed unsafe class TranslationUnit : IDisposable, IEquatable<TranslationUnit>
{
private static readonly ConcurrentDictionary<CXTranslationUnit, WeakReference<TranslationUnit>> s_createdTranslationUnits = new ConcurrentDictionary<CXTranslationUnit, WeakReference<TranslationUnit>>();

#if NET8_0
private static readonly object s_createTranslationUnitLock = new object();
#else
private static readonly Lock s_createTranslationUnitLock = new Lock();
#endif

private readonly Dictionary<CXCursor, WeakReference<Cursor>> _createdCursors;
private readonly Dictionary<CX_TemplateArgument, WeakReference<TemplateArgument>> _createdTemplateArguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackAsTool>true</PackAsTool>
<PublishAot>true</PublishAot>
<RuntimeIdentifiers>linux-arm64;linux-x64;osx-arm64;win-arm64;win-x64</RuntimeIdentifiers>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<RootNamespace>ClangSharp.UnitTests</RootNamespace>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/ClangSharp.UnitTests/ClangSharp.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down