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

Do not cleantpHandle inClassBase.tp_clear - it might be used intp_dealloc#1566

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsrc/runtime/classbase.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -373,7 +373,6 @@ public static int tp_clear(IntPtr ob)
return baseClearResult;
}
}
if (self is not null) self.tpHandle = IntPtr.Zero;
return 0;
}

Expand Down
21 changes: 19 additions & 2 deletionssrc/runtime/managedtype.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,8 +28,23 @@ internal enum TrackTypes
internal IntPtr pyHandle; // PyObject *
internal IntPtr tpHandle; // PyType *

internal BorrowedReference ObjectReference => new(pyHandle);
internal BorrowedReference TypeReference => new(tpHandle);
internal BorrowedReference ObjectReference
{
get
{
Debug.Assert(pyHandle != IntPtr.Zero);
return new(pyHandle);
}
}

internal BorrowedReference TypeReference
{
get
{
Debug.Assert(tpHandle != IntPtr.Zero);
return new(tpHandle);
}
}

private static readonly Dictionary<ManagedType, TrackTypes> _managedObjs = new Dictionary<ManagedType, TrackTypes>();

Expand DownExpand Up@@ -310,6 +325,8 @@ internal static void InitGCHandle(BorrowedReference reflectedClrObject, GCHandle

internal static void SetGCHandle(BorrowedReference reflectedClrObject, BorrowedReference type, GCHandle newHandle)
{
Debug.Assert(type != null);
Debug.Assert(reflectedClrObject != null);
Debug.Assert(Runtime.PyObject_TypeCheck(reflectedClrObject, type));

int offset = Marshal.ReadInt32(type.DangerousGetAddress(), Offsets.tp_clr_inst_offset);
Expand Down
6 changes: 5 additions & 1 deletionsrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2021,7 +2021,11 @@ internal static bool PyType_Check(IntPtr ob)
internal static void PyType_Modified(BorrowedReference type) => Delegates.PyType_Modified(type);
internal static bool PyType_IsSubtype(BorrowedReference t1, IntPtr ofType)
=> PyType_IsSubtype(t1, new BorrowedReference(ofType));
internal static bool PyType_IsSubtype(BorrowedReference t1, BorrowedReference t2) => Delegates.PyType_IsSubtype(t1, t2);
internal static bool PyType_IsSubtype(BorrowedReference t1, BorrowedReference t2)
{
Debug.Assert(t1 != null && t2 != null);
return Delegates.PyType_IsSubtype(t1, t2);
}

internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp)
=> PyObject_TypeCheck(new BorrowedReference(ob), new BorrowedReference(tp));
Expand Down
16 changes: 16 additions & 0 deletionstests/test_subclass.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -290,3 +290,19 @@ def __init__(self, i, s):
assert len(calls) == 1
assert calls[0][0] == 1
assert calls[0][1] == "foo"

# regression test for https://github.com/pythonnet/pythonnet/issues/1565
def test_can_be_collected_by_gc():
from Python.Test import BaseClass

class Derived(BaseClass):
__namespace__ = 'test_can_be_collected_by_gc'

inst = Derived()
cycle = [inst]
del inst
cycle.append(cycle)
del cycle

import gc
gc.collect()

[8]ページ先頭

©2009-2025 Movatter.jp