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
4 changes: 2 additions & 2 deletions src/perf_tests/Python.PerformanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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.16" GeneratePathProperty="true">
<PackageReference Include="quantconnect.pythonnet" Version="2.0.17" 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.16\lib\net5.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
<Copy SourceFiles="$(NuGetPackageRoot)quantconnect.pythonnet\2.0.17\lib\net5.0\Python.Runtime.dll" DestinationFolder="$(OutDir)baseline" />
</Target>

<Target Name="CopyNewBuild" AfterTargets="Build">
Expand Down
1 change: 1 addition & 0 deletions src/runtime/Finalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ internal IncorrectRefCountException(IntPtr ptr)

#endregion

[ForbidPythonThreads]
public void Collect() => this.DisposeAll();

internal void ThrottledCollect()
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Native/NewReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PyObject MoveToPyObject()
/// </summary>
public NewReference Move()
{
var result = new NewReference(this);
var result = DangerousFromPointer(this.DangerousGetAddress());
this.pointer = default;
return result;
}
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.16")]
[assembly: AssemblyFileVersion("2.0.16")]
[assembly: AssemblyVersion("2.0.17")]
[assembly: AssemblyFileVersion("2.0.17")]
2 changes: 1 addition & 1 deletion src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace>Python.Runtime</RootNamespace>
<AssemblyName>Python.Runtime</AssemblyName>
<PackageId>QuantConnect.pythonnet</PackageId>
<Version>2.0.16</Version>
<Version>2.0.17</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/pythonnet/pythonnet</RepositoryUrl>
Expand Down
1 change: 1 addition & 0 deletions src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops)
/// </summary>
/// <param name="runs">Total number of GC loops to run</param>
/// <returns><c>true</c> if a steady state was reached upon the requested number of tries (e.g. on the last try no objects were collected).</returns>
[ForbidPythonThreads]
public static bool TryCollectingGarbage(int runs)
=> TryCollectingGarbage(runs, forceBreakLoops: false);

Expand Down
30 changes: 30 additions & 0 deletions tests/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Test CLR class constructor support."""

import pytest
import sys

import System

Expand Down Expand Up @@ -69,3 +70,32 @@ def test_default_constructor_fallback():

with pytest.raises(TypeError):
ob = DefaultConstructorMatching("2")

def test_constructor_leak():
from System import Uri
from Python.Runtime import Runtime

uri = Uri("http://www.python.org")
Runtime.TryCollectingGarbage(20)
ref_count = sys.getrefcount(uri)

# check disabled due to GC uncertainty
# assert ref_count == 1



def test_string_constructor():
from System import String, Char, Array

ob = String('A', 10)
assert ob == 'A' * 10

arr = Array[Char](10)
for i in range(10):
arr[i] = Char(str(i))

ob = String(arr)
assert ob == "0123456789"

ob = String(arr, 5, 4)
assert ob == "5678"