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

dotnet 9 #98

Merged
merged 3 commits into from
Dec 20, 2024
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
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<AssemblyCopyright>Copyright (c) 2006-2021 The Contributors of the Python.NET Project</AssemblyCopyright>
<AssemblyCompany>pythonnet</AssemblyCompany>
<AssemblyProduct>Python.NET</AssemblyProduct>
<LangVersion>10.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/console/Console.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<AssemblyName>nPython</AssemblyName>
<RootNamespace>Python.Runtime</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion src/embed_tests/Python.EmbeddingTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/embed_tests/StateSerialization/MethodSerialization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
/*using System.IO;
using System.Reflection;

using NUnit.Framework;
Expand Down Expand Up @@ -44,3 +44,4 @@ public class MethodTestHost
public MethodTestHost(int _) { }
public void Generic<T>(T item, T[] array, ref T @ref) { }
}
*/
6 changes: 3 additions & 3 deletions src/perf_tests/Python.PerformanceTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -13,7 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
<PackageReference Include="quantconnect.pythonnet" Version="2.0.41" GeneratePathProperty="true">
<PackageReference Include="quantconnect.pythonnet" Version="2.0.42" GeneratePathProperty="true">
<IncludeAssets>compile</IncludeAssets>
</PackageReference>
</ItemGroup>
Expand All @@ -25,7 +25,7 @@
</Target>

<Target Name="CopyBaseline" AfterTargets="Build">
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.41\lib\net6.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.42\lib\net9.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
</Target>

<Target Name="CopyNewBuild" AfterTargets="Build">
Expand Down
2 changes: 1 addition & 1 deletion src/python_tests_runner/Python.PythonTestsRunner.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 3 additions & 5 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe

static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStart, int pyArgCount, out NewReference tempObject)
{
BorrowedReference op;
tempObject = default;
// for a params method, we may have a sequence or single/multiple items
// here we look to see if the item at the paramIndex is there or not
Expand All @@ -806,20 +805,19 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
if (!Runtime.PyString_Check(item) && (Runtime.PySequence_Check(item) || (ManagedType.GetManagedObject(item) as CLRObject)?.inst is IEnumerable))
{
// it's a sequence (and not a string), so we use it as the op
op = item;
return item;
}
else
{
tempObject = Runtime.PyTuple_GetSlice(args, arrayStart, pyArgCount);
op = tempObject.Borrow();
return tempObject.Borrow();
}
}
else
{
tempObject = Runtime.PyTuple_GetSlice(args, arrayStart, pyArgCount);
op = tempObject.Borrow();
return tempObject.Borrow();
}
return op;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/Native/NewReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ref struct NewReference

/// <summary>Creates a <see cref="NewReference"/> pointing to the same object</summary>
[DebuggerHidden]
public NewReference(BorrowedReference reference, bool canBeNull = false)
public NewReference(scoped BorrowedReference reference, bool canBeNull = false)
{
var address = canBeNull
? reference.DangerousGetAddressOrNull()
Expand Down Expand Up @@ -157,15 +157,15 @@ public static bool IsNull(this in NewReference reference)

[Pure]
[DebuggerHidden]
public static BorrowedReference BorrowNullable(this in NewReference reference)
public static BorrowedReference BorrowNullable(this scoped in NewReference reference)
=> new(NewReference.DangerousGetAddressOrNull(reference));
[Pure]
[DebuggerHidden]
public static BorrowedReference Borrow(this in NewReference reference)
public static BorrowedReference Borrow(this scoped in NewReference reference)
=> reference.IsNull() ? throw new NullReferenceException() : reference.BorrowNullable();
[Pure]
[DebuggerHidden]
public static BorrowedReference BorrowOrThrow(this in NewReference reference)
public static BorrowedReference BorrowOrThrow(this scoped in NewReference reference)
=> reference.IsNull() ? throw PythonException.ThrowLastAsClrException() : reference.BorrowNullable();
}
}
2 changes: 1 addition & 1 deletion src/runtime/Native/StolenReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static StolenReference Take(ref IntPtr ptr)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public static StolenReference TakeNullable(ref IntPtr ptr)
public static StolenReference TakeNullable(scoped ref IntPtr ptr)
{
var stolenAddr = ptr;
ptr = IntPtr.Zero;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[assembly: InternalsVisibleTo("Python.EmbeddingTest, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]
[assembly: InternalsVisibleTo("Python.Test, PublicKey=00240000048000009400000006020000002400005253413100040000110000005ffd8f49fb44ab0641b3fd8d55e749f716e6dd901032295db641eb98ee46063cbe0d4a1d121ef0bc2af95f8a7438d7a80a3531316e6b75c2dae92fb05a99f03bf7e0c03980e1c3cfb74ba690aca2f3339ef329313bcc5dccced125a4ffdc4531dcef914602cd5878dc5fbb4d4c73ddfbc133f840231343e013762884d6143189")]

[assembly: AssemblyVersion("2.0.41")]
[assembly: AssemblyFileVersion("2.0.41")]
[assembly: AssemblyVersion("2.0.42")]
[assembly: AssemblyFileVersion("2.0.42")]
4 changes: 2 additions & 2 deletions src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<Platforms>AnyCPU</Platforms>
<RootNamespace>Python.Runtime</RootNamespace>
<AssemblyName>Python.Runtime</AssemblyName>
<PackageId>QuantConnect.pythonnet</PackageId>
<Version>2.0.41</Version>
<Version>2.0.42</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl>
Expand Down
17 changes: 4 additions & 13 deletions src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,8 @@ internal static void Initialize(bool initSigs = false)
// Initialize modules that depend on the runtime class.
AssemblyManager.Initialize();
OperatorMethod.Initialize();
if (RuntimeData.HasStashData())
{
RuntimeData.RestoreRuntimeData();
}
else
{
PyCLRMetaType = MetaType.Initialize();
ImportHook.Initialize();
}
PyCLRMetaType = MetaType.Initialize();
ImportHook.Initialize();
Exceptions.Initialize();

// Need to add the runtime directory to sys.path so that we
Expand Down Expand Up @@ -269,8 +262,6 @@ internal static void Shutdown()
{
// avoid saving dead objects
TryCollectingGarbage(runs: 3);

RuntimeData.Stash();
}

AssemblyManager.Shutdown();
Expand Down Expand Up @@ -832,7 +823,7 @@ public static int Py_Main(int argc, string[] argv)

internal static IntPtr Py_GetBuildInfo() => Delegates.Py_GetBuildInfo();

const PyCompilerFlags Utf8String = PyCompilerFlags.IGNORE_COOKIE | PyCompilerFlags.SOURCE_IS_UTF8;
private static readonly PyCompilerFlags Utf8String = PyCompilerFlags.IGNORE_COOKIE | PyCompilerFlags.SOURCE_IS_UTF8;

internal static int PyRun_SimpleString(string code)
{
Expand Down Expand Up @@ -1715,7 +1706,7 @@ internal static bool PyType_IsSameAsOrSubtype(BorrowedReference type, BorrowedRe
internal static NewReference PyType_GenericAlloc(BorrowedReference type, nint n) => Delegates.PyType_GenericAlloc(type, n);

internal static IntPtr PyType_GetSlot(BorrowedReference type, TypeSlotID slot) => Delegates.PyType_GetSlot(type, slot);
internal static NewReference PyType_FromSpecWithBases(in NativeTypeSpec spec, BorrowedReference bases) => Delegates.PyType_FromSpecWithBases(in spec, bases);
internal static NewReference PyType_FromSpecWithBases(scoped in NativeTypeSpec spec, BorrowedReference bases) => Delegates.PyType_FromSpecWithBases(in spec, bases);

/// <summary>
/// Finalize a type object. This should be called on all type objects to finish their initialization. This function is responsible for adding inherited slots from a type�s base class. Return 0 on success, or return -1 and sets an exception on error.
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/StateSerialization/RuntimeData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
/*using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -210,3 +210,4 @@ internal static IFormatter CreateFormatter()
}
}
}
*/
2 changes: 1 addition & 1 deletion src/testing/Python.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
Expand Down
Loading