Skip to content

Disable implicit seq to array conversion when target type is object #1901

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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: 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
1 change: 1 addition & 0 deletions src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,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
14 changes: 14 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 @@ -71,6 +72,19 @@ def test_default_constructor_fallback():
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

Expand Down