Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to target the latest .NET 8 #23

Merged
merged 3 commits into from
Dec 27, 2023
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
6 changes: 2 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@
<BaseOutputPath>$(BaseArtifactsPath)bin/$(BaseArtifactsPathSuffix)/</BaseOutputPath>
<Company>TerraFX</Company>
<ContinuousIntegrationBuild Condition="'$(GITHUB_RUN_ID)' != ''">true</ContinuousIntegrationBuild>
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsAotCompatible>true</IsAotCompatible>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<PackageOutputPath>$(BaseArtifactsPath)pkg/$(Configuration)/</PackageOutputPath>
<PackageValidationBaselineVersion>1.6.7</PackageValidationBaselineVersion>
<Product>TerraFX.Interop.Mimalloc</Product>
<RootNamespace>TerraFX.Interop</RootNamespace>
<VersionPrefix>1.6.7</VersionPrefix>
<VersionPrefix>1.6.7.1</VersionPrefix>
<VersionSuffix Condition="'$(EXCLUDE_SUFFIX_FROM_VERSION)' != 'true'">rc1</VersionSuffix>
<VersionSuffix Condition="'$(GITHUB_EVENT_NAME)' == 'pull_request'">pr</VersionSuffix>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

<!-- Package versions for package references across all projects -->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.6" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.11" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PropertyGroup>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<RootNamespace>TerraFX.Interop.Benchmarks</RootNamespace>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ try {
Create-Directory -Path $DotNetInstallDirectory

& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
& $DotNetInstallScript -Channel 7.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture -Runtime dotnet
& $DotNetInstallScript -Channel 6.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture -Runtime dotnet

$env:PATH="$DotNetInstallDirectory;$env:PATH"
}
Expand Down
2 changes: 0 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ if [[ ! -z "$architecture" ]]; then
CreateDirectory "$DotNetInstallDirectory"

. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
. "$DotNetInstallScript" --channel 7.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" --runtime dotnet
. "$DotNetInstallScript" --channel 6.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture" --runtime dotnet

PATH="$DotNetInstallDirectory:$PATH:"
fi
Expand Down
2 changes: 1 addition & 1 deletion sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<PropertyGroup>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EnablePackageValidation>true</EnablePackageValidation>
<EnablePackageValidation>false</EnablePackageValidation>
<TerraFXProjectCategory>sources</TerraFXProjectCategory>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions sources/Interop/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ dotnet_naming_rule.type_parameters_should_be_pascal_case_prefixed_with_t.severit
# disable certain parent style options since they are not applicable to interop
###############################################################################
csharp_style_expression_bodied_methods = when_on_single_line:none
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
dotnet_style_prefer_compound_assignment = true:none
dotnet_style_prefer_conditional_expression_over_assignment = true:none
dotnet_style_prefer_conditional_expression_over_return = true:none
csharp_style_prefer_pattern_matching = true:none
Expand Down
23 changes: 11 additions & 12 deletions sources/Interop/Mimalloc/Mimalloc.Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Runtime.InteropServices;
using System.Threading;
using static TerraFX.Interop.Mimalloc.mi_init_t;
using static TerraFX.Interop.Mimalloc.mi_option_t;

Expand Down Expand Up @@ -74,18 +73,18 @@ private static readonly delegate*<delegate* unmanaged[Cdecl]<void>> std_get_new_

private static readonly int HUGETLB_FLAG_ENCODE_SHIFT = IsLinux ? 26 : 0;

private static readonly int RUSAGE_SELF = 0;
private const int RUSAGE_SELF = 0;

private static readonly int MADV_DONTNEED = IsUnix ? 4 : 0;

private static readonly int MADV_FREE = IsLinux ? 8 : (IsMacOS ? 5 : 0);

private static readonly int MADV_HUGEPAGE = IsLinux ? 14 : 0;

private static readonly int MAP_ANON = MAP_ANONYMOUS;

private static readonly int MAP_ANONYMOUS = IsLinux ? 0x20 : (IsMacOS ? 0x1000 : 0);

// private static readonly int MAP_ANON = MAP_ANONYMOUS;

private static readonly void* MAP_FAILED = unchecked((void*)-1);

private static readonly int MAP_FIXED = IsUnix ? 0x10 : 0;
Expand All @@ -102,13 +101,13 @@ private static readonly delegate*<delegate* unmanaged[Cdecl]<void>> std_get_new_

private static readonly nuint MPOL_PREFERRED = IsLinux ? 1u : 0u;

private static readonly int PROT_NONE = 0x0;
private const int PROT_NONE = 0x0;

private static readonly int PROT_READ = IsUnix ? 0x1 : 0;

private static readonly int PROT_WRITE = IsUnix ? 0x2 : 0;

private static readonly int R_OK = IsUnix ? 4 : 0;
// private static readonly int R_OK = IsUnix ? 4 : 0;

private static readonly int SUPERPAGE_SIZE_2MB = IsMacOS ? 2 : 0;

Expand Down Expand Up @@ -163,7 +162,7 @@ private static readonly delegate*<delegate* unmanaged[Cdecl]<void>> std_get_new_
private static readonly int MI_INTPTR_SHIFT = Environment.Is64BitProcess ? 3 : 2;

private static readonly nuint MI_INTPTR_SIZE = (nuint)1 << MI_INTPTR_SHIFT;
private static readonly nuint MI_INTPTR_BITS = MI_INTPTR_SIZE * 8;
// private static readonly nuint MI_INTPTR_BITS = MI_INTPTR_SIZE * 8;

// Main tuning parameters for segment and page sizes
// Sizes for 64-bit, divide by two for 32-bit
Expand All @@ -183,8 +182,8 @@ private static readonly delegate*<delegate* unmanaged[Cdecl]<void>> std_get_new_
private static readonly nuint MI_LARGE_PAGE_SIZE = (nuint)1 << MI_LARGE_PAGE_SHIFT;

private static readonly nuint MI_SMALL_PAGES_PER_SEGMENT = MI_SEGMENT_SIZE / MI_SMALL_PAGE_SIZE;
private static readonly nuint MI_MEDIUM_PAGES_PER_SEGMENT = MI_SEGMENT_SIZE / MI_MEDIUM_PAGE_SIZE;
private static readonly nuint MI_LARGE_PAGES_PER_SEGMENT = MI_SEGMENT_SIZE / MI_LARGE_PAGE_SIZE;
// private static readonly nuint MI_MEDIUM_PAGES_PER_SEGMENT = MI_SEGMENT_SIZE / MI_MEDIUM_PAGE_SIZE;
// private static readonly nuint MI_LARGE_PAGES_PER_SEGMENT = MI_SEGMENT_SIZE / MI_LARGE_PAGE_SIZE;

// The max object size are checked to not waste more than 12.5% internally over the page sizes.
// (Except for large pages since huge objects are allocated in 4MiB chunks)
Expand Down Expand Up @@ -309,7 +308,7 @@ private static readonly delegate*<delegate* unmanaged[Cdecl]<void>> std_get_new_
// may lead to allocation itself on some platforms)
// --------------------------------------------------------

private static mi_stats_t _mi_stats_main = default;
private static mi_stats_t _mi_stats_main;

private static readonly mi_heap_t._pages_free_direct_e__FixedBuffer* _mi_heap_empty_pages_free_direct = create_mi_heap_empty_pages_free_direct();

Expand Down Expand Up @@ -377,8 +376,8 @@ Arena allocation
private static readonly nuint os_page_size = get_os_page_size();

// minimal allocation granularity
[NativeTypeName("size_t")]
private static readonly nuint os_alloc_granularity = get_os_alloc_granularity();
// [NativeTypeName("size_t")]
// private static readonly nuint os_alloc_granularity = get_os_alloc_granularity();

// if non-zero, use large page allocation
[NativeTypeName("size_t")]
Expand Down
4 changes: 3 additions & 1 deletion sources/Interop/Mimalloc/Mimalloc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Runtime.InteropServices;
using static TerraFX.Interop.Mimalloc.mi_option_t;

[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]

namespace TerraFX.Interop.Mimalloc;

public static unsafe partial class Mimalloc
Expand Down Expand Up @@ -447,7 +449,7 @@ private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImpo
return nativeLibrary;
}

if (libraryName.Equals("libc") && TryResolveLibc(assembly, searchPath, out nativeLibrary))
if (libraryName.Equals("libc", StringComparison.OrdinalIgnoreCase) && TryResolveLibc(assembly, searchPath, out nativeLibrary))
{
return nativeLibrary;
}
Expand Down
35 changes: 34 additions & 1 deletion sources/Interop/Mimalloc/TerraFX.Interop.Mimalloc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,40 @@
<PropertyGroup>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<RootNamespace>TerraFX.Interop</RootNamespace>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<!-- CA1003: Use generic event handler instances -->
<!-- CA1008: Enums should have zero value -->
<!-- CA1024: Use properties where appropriate -->
<!-- CA1027: Mark enums with FlagsAttribute -->
<!-- CA1028: Enum storage should be Int32 -->
<!-- CA1030: Use events where appropriate -->
<!-- CA1034: Nested types should not be visible -->
<!-- CA1040: Avoid empty interfaces -->
<!-- CA1041: Provide ObsoleteAttribute message -->
<!-- CA1051: Do not declare visible instance fields -->
<!-- CA1069: Enums should not have duplicate values -->
<!-- CA1305: Specify IFormatProvider -->
<!-- CA1401: P/Invokes should not be visible -->
<!-- CA1700: Do not name enum values 'Reserved' -->
<!-- CA1707: Identifiers should not contain underscores -->
<!-- CA1708: Identifiers should differ by more than case -->
<!-- CA1711: Identifiers should not have incorrect suffix -->
<!-- CA1712: Do not prefix enum values with type name -->
<!-- CA1715: Identifiers should have correct prefix -->
<!-- CA1716: Identifiers should not match keywords -->
<!-- CA1720: Identifiers should not contain type names -->
<!-- CA1724: Type names should not match namespaces -->
<!-- CA1815: Override equals and operator equals on value types -->
<!-- CA2201: Do not raise reserved exception types -->
<!-- CA2217: Do not mark enums with FlagsAttribute -->
<!-- CA2225: Operator overloads have named alternates -->
<!-- CS1591: Missing XML comment for publicly visible type or member -->
<!-- CS8981: The type name only contains lower-cased ascii characters -->
<!-- SYSLIB1054: Use LibraryImportAttribute instead of DllImportAttribute to generate p/invoke marshalling code at compile time. -->
<NoWarn>$(NoWarn);CA1003;CA1008;CA1024;CA1027;CA1028;CA1030;CA1034;CA1040;CA1041;CA1051;CA1069;CA1305;CA1401;CA1700;CA1707;CA1708;CA1711;CA1712;CA1715;CA1716;CA1720;CA1724;CA1815;CA2201;CA2217;CA2225;CS1591;CS8981;SYSLIB1054</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading;
using static TerraFX.Interop.Mimalloc.mi_delayed_t;
using static TerraFX.Interop.Mimalloc.mi_page_kind_t;

Expand All @@ -23,7 +22,7 @@ private static void mi_trace_message([NativeTypeName("const char*")] string fmt,
}
}

private const ushort MI_CACHE_LINE = 64;
// private const ushort MI_CACHE_LINE = 64;

// "options.c"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This file includes code based on the mimalloc-internal.h file from https://github.com/microsoft/mimalloc
// The original code is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace TerraFX.Interop.Mimalloc;
Expand Down
4 changes: 2 additions & 2 deletions sources/Interop/Mimalloc/src/options/Mimalloc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private static partial void mi_option_init(ref mi_option_desc_t desc)

if (s is not null)
{
switch (s.ToUpper())
switch (s.ToUpperInvariant())
{
case "":
case "1":
Expand Down Expand Up @@ -341,7 +341,7 @@ private static partial void mi_option_init(ref mi_option_desc_t desc)
}
}

mi_assert_internal((MI_DEBUG > 1) && (desc.init != UNINIT));
// mi_assert_internal((MI_DEBUG > 1) && (desc.init != UNINIT));
}
else
{
Expand Down
1 change: 0 additions & 1 deletion sources/Interop/Mimalloc/src/region/Mimalloc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This file includes code based on the region.c file from https://github.com/microsoft/mimalloc
// The original code is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using System;
using System.Runtime.CompilerServices;
using static TerraFX.Interop.Mimalloc.mi_option_t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<RootNamespace>TerraFX.Interop.UnitTests</RootNamespace>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down