Browse Source

Upgrade to .NET 10.0.1 (#10382)

* Upgrade to .NET 10.0.1

* Avoid extra copy by pinning the internal buffer instead

---------

Co-authored-by: LLT21 <>
LLT21 1 tuần trước cách đây
mục cha
commit
761a47ac52

+ 4 - 2
frameworks/CSharp/appmpower/appmpower-odbc-my.dockerfile

@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
 RUN apt-get update
 RUN apt-get -yqq install clang zlib1g-dev
 RUN apt-get update
@@ -8,7 +8,7 @@ COPY src .
 RUN dotnet publish -c Release -o out /p:Database=mysql
 
 # Construct the actual image that will run
-FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:10.0.1 AS runtime
 
 RUN apt-get update
 # The following installs standard versions unixodbc and pgsqlodbc
@@ -51,6 +51,8 @@ RUN cp /usr/lib/x86_64-linux-gnu/libodbc* /app
 #TODOLOCAL
 #RUN cp /usr/lib/aarch64-linux-gnu/libodbc* /app
 
+#TEST: ./tfb --test appmpower-odbc-my  --type db
+
 EXPOSE 8080
 
 ENTRYPOINT ["./appMpower"]

+ 4 - 2
frameworks/CSharp/appmpower/appmpower-odbc-pg.dockerfile

@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
 RUN apt-get update
 RUN apt-get -yqq install clang zlib1g-dev
 
@@ -7,7 +7,7 @@ COPY src .
 RUN dotnet publish -c Release -o out /p:Database=postgresql
 
 # Construct the actual image that will run
-FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:10.0.1 AS runtime
 
 RUN apt-get update
 RUN apt-get install -y unixodbc-dev unixodbc odbc-postgresql
@@ -32,6 +32,8 @@ RUN cp /usr/lib/x86_64-linux-gnu/libodbc* /app
 #TODOLOCAL
 #RUN cp /usr/lib/aarch64-linux-gnu/libodbc* /app
 
+#TEST: ./tfb --test appmpower-odbc-pg  --type db
+
 EXPOSE 8080
 
 ENTRYPOINT ["./appMpower"]

+ 4 - 2
frameworks/CSharp/appmpower/appmpower.dockerfile

@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
 RUN apt-get update
 RUN apt-get -yqq install clang zlib1g-dev
 
@@ -8,7 +8,7 @@ COPY src .
 RUN dotnet publish -c Release -o out
 
 # Construct the actual image that will run
-FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
+FROM mcr.microsoft.com/dotnet/aspnet:10.0.1 AS runtime
 # Full PGO
 ENV DOTNET_TieredPGO 1 
 ENV DOTNET_TC_QuickJitForLoops 1 
@@ -18,6 +18,8 @@ ENV ASPNETCORE_URLS http://+:8080
 WORKDIR /app
 COPY --from=build /app/out ./
 
+#TEST: ./tfb --test appmpower  --type json
+
 EXPOSE 8080
 
 ENTRYPOINT ["./appMpower"]

+ 25 - 28
frameworks/CSharp/appmpower/src/appMpower.Orm/NativeMethods.cs

@@ -1,9 +1,9 @@
 using System.Runtime.InteropServices;
-using System.Text; 
-using System.Text.Json; 
-using appMpower.Orm.Data; 
-using appMpower.Orm.Objects; 
-using appMpower.Orm.Serializers; 
+using System.Text;
+using System.Text.Json;
+using appMpower.Orm.Data;
+using appMpower.Orm.Objects;
+using appMpower.Orm.Serializers;
 
 namespace appMpower.Orm;
 
@@ -11,7 +11,7 @@ public static class NativeMethods
 {
     private static JsonWriterOptions _jsonWriterOptions = new JsonWriterOptions
     {
-        Indented = false, 
+        Indented = false,
         SkipValidation = true
     };
 
@@ -24,17 +24,17 @@ public static class NativeMethods
     [UnmanagedCallersOnly(EntryPoint = "Dbms")]
     public static void Dbms(int dbms)
     {
-        Constants.Dbms = (Dbms)dbms; 
+        Constants.Dbms = (Dbms)dbms;
         DbProviderFactory.SetConnectionString();
     }
 
     [UnmanagedCallersOnly(EntryPoint = "DbProvider")]
     public static void DbProvider(int dbProvider)
     {
-        Constants.DbProvider = (DbProvider)dbProvider; 
+        Constants.DbProvider = (DbProvider)dbProvider;
         DbProviderFactory.SetConnectionString();
     }
-    
+
     [UnmanagedCallersOnly(EntryPoint = "FreeHandlePointer")]
     public static void FreeHandlePointer(IntPtr handlePointer)
     {
@@ -48,25 +48,22 @@ public static class NativeMethods
         var world = RawDb.LoadSingleQueryRow().GetAwaiter().GetResult();
 
         var memoryStream = new MemoryStream();
-        using var utf8JsonWriter = new Utf8JsonWriter(memoryStream, _jsonWriterOptions);
+        using (var utf8JsonWriter = new Utf8JsonWriter(memoryStream, _jsonWriterOptions))
+        {
+            _worldSerializer.Serialize(utf8JsonWriter, world);
+        }
 
-        _worldSerializer.Serialize(utf8JsonWriter, world);
+        // Flush everything to the MemoryStream
+        memoryStream.Flush();
+        byte[] buffer = memoryStream.GetBuffer();
+        int len = (int)memoryStream.Position;  // or (int)memoryStream.Length;
 
-        *length = (int)utf8JsonWriter.BytesCommitted; 
-        byte[] byteArray = memoryStream.ToArray();
+        *length = len;
 
-        GCHandle handle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);
-        // return the managed and byteArrayPointer pointer
-        IntPtr byteArrayPointer = handle.AddrOfPinnedObject();
+        GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
         *handlePointer = GCHandle.ToIntPtr(handle);
 
-        return byteArrayPointer;
-        /*
-        fixed(byte* b = memoryStream.ToArray())
-        {
-            return b; 
-        }
-        */
+        return handle.AddrOfPinnedObject();
     }
 
     /*
@@ -90,7 +87,7 @@ public static class NativeMethods
     [UnmanagedCallersOnly(EntryPoint = "Fortunes")]
     public static unsafe IntPtr Fortunes(int* length, IntPtr* handlePointer)
     {
-        List<Fortune> fortunes = RawDb.LoadFortunesRows().GetAwaiter().GetResult(); 
+        List<Fortune> fortunes = RawDb.LoadFortunesRows().GetAwaiter().GetResult();
 
         int totalSize = 0;
 
@@ -122,7 +119,7 @@ public static class NativeMethods
         }
 
         byte[] byteArray = buffer.ToArray();
-        *length = byteArray.Length; 
+        *length = byteArray.Length;
 
         /*
         var memoryStream = new MemoryStream();
@@ -151,7 +148,7 @@ public static class NativeMethods
 
         _worldsSerializer.Serialize(utf8JsonWriter, worlds);
 
-        *length = (int)utf8JsonWriter.BytesCommitted; 
+        *length = (int)utf8JsonWriter.BytesCommitted;
         byte[] byteArray = memoryStream.ToArray();
 
         GCHandle handle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);
@@ -171,7 +168,7 @@ public static class NativeMethods
 
         _worldsSerializer.Serialize(utf8JsonWriter, worlds);
 
-        *length = (int)utf8JsonWriter.BytesCommitted; 
+        *length = (int)utf8JsonWriter.BytesCommitted;
         byte[] byteArray = memoryStream.ToArray();
 
         GCHandle handle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);
@@ -191,7 +188,7 @@ public static class NativeMethods
 
         _worldSerializer.Serialize(utf8JsonWriter, world);
 
-        *length = (int)utf8JsonWriter.BytesCommitted; 
+        *length = (int)utf8JsonWriter.BytesCommitted;
         byte[] byteArray = memoryStream.ToArray();
 
         GCHandle handle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);

+ 2 - 2
frameworks/CSharp/appmpower/src/appMpower.Orm/appMpower.Orm.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>net9.0</TargetFramework>
+    <TargetFramework>net10.0</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
 
     <PublishAot>true</PublishAot>
@@ -41,7 +41,7 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="System.Data.Odbc" Version="9.0.6" />
+    <PackageReference Include="System.Data.Odbc" Version="10.0.1" />
   </ItemGroup>
 
 </Project>

+ 4 - 5
frameworks/CSharp/appmpower/src/appMpower/appMpower.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
-    <TargetFramework>net9.0</TargetFramework>
+    <TargetFramework>net10.0</TargetFramework>
     <OutputType>Exe</OutputType>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
@@ -11,13 +11,12 @@
 
     <!--TODOLOCAL-->
     <!--
-    <Content Include="../appMpower.Orm/bin/Release/net9.0/appMpower.Orm.dll">
+    <Content Include="../appMpower.Orm/bin/Release/net10.0/appMpower.Orm.dll">
         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content> 
     -->
-    <!--TODOLOCAL AOT-->
-    <!--
-    <Content Include="../appMpower.Orm/bin/Release/net9.0/osx-arm64/native/appMpower.Orm.dylib">
+    <!--TODOLOCAL AOT
+    <Content Include="../appMpower.Orm/bin/Release/net10.0/osx-arm64/native/appMpower.Orm.dylib">
         <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content> 
     -->