Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bb8fe6

Browse files
authored
Merge pull request#1873 from losttech/bugs/ctor-leak
Fixed a leak in `NewReference.Move`
2 parents863397a +469ec67 commit9bb8fe6

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

‎src/runtime/Finalizer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ internal IncorrectRefCountException(IntPtr ptr)
106106

107107
#endregion
108108

109+
[ForbidPythonThreads]
109110
publicvoidCollect()=>this.DisposeAll();
110111

111112
internalvoidThrottledCollect()

‎src/runtime/Native/NewReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PyObject MoveToPyObject()
4747
/// </summary>
4848
publicNewReferenceMove()
4949
{
50-
varresult=newNewReference(this);
50+
varresult=DangerousFromPointer(this.DangerousGetAddress());
5151
this.pointer=default;
5252
returnresult;
5353
}

‎src/runtime/Runtime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops)
359359
/// </summary>
360360
/// <param name="runs">Total number of GC loops to run</param>
361361
/// <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>
362+
[ForbidPythonThreads]
362363
publicstaticboolTryCollectingGarbage(intruns)
363364
=>TryCollectingGarbage(runs,forceBreakLoops:false);
364365

‎tests/test_constructors.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Test CLR class constructor support."""
44

55
importpytest
6+
importsys
67

78
importSystem
89

@@ -71,6 +72,19 @@ def test_default_constructor_fallback():
7172
ob=DefaultConstructorMatching("2")
7273

7374

75+
deftest_constructor_leak():
76+
fromSystemimportUri
77+
fromPython.RuntimeimportRuntime
78+
79+
uri=Uri("http://www.python.org")
80+
Runtime.TryCollectingGarbage(20)
81+
ref_count=sys.getrefcount(uri)
82+
83+
# check disabled due to GC uncertainty
84+
# assert ref_count == 1
85+
86+
87+
7488
deftest_string_constructor():
7589
fromSystemimportString,Char,Array
7690

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp