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
ClassManager illegally decrefed ClassObject's refcount on shutdown
addresses #1561
  • Loading branch information
lostmsu committed Sep 22, 2021
commit 9616a6f8774380bfe1ceb663365230357475c9fb
18 changes: 18 additions & 0 deletions src/embed_tests/pyinitialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public static void LoadSpecificArgs()
}
}

// regression test for https://github.com/pythonnet/pythonnet/issues/1561
[Test]
public void ImportClassShutdownRefcount()
{
PythonEngine.Initialize();

PyObject ns = Py.Import(typeof(ImportClassShutdownRefcountClass).Namespace);
PyObject cls = ns.GetAttr(nameof(ImportClassShutdownRefcountClass));
ns.Dispose();

Assert.Less(cls.Refcount, 256);

PythonEngine.Shutdown();
Assert.Greater(cls.Refcount, 0);
}

/// <summary>
/// Failing test demonstrating current issue with OverflowException (#376)
/// and ArgumentException issue after that one is fixed.
Expand Down Expand Up @@ -182,4 +198,6 @@ public static void TestRunExitFuncs()
Assert.True(called);
}
}

public class ImportClassShutdownRefcountClass { }
}
1 change: 0 additions & 1 deletion src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ internal static void DisposePythonWrappersForClrTypes()
// since others may still referencing it.
cls.CallTypeTraverse(TraverseTypeClear, visitedPtr);
cls.CallTypeClear();
cls.DecrRefCount();
}
}
finally
Expand Down