| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 50da522 commit 86c6a7f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,32 @@ | |||
| 1 | + using System; | ||
| 2 | + | ||
| 3 | + using NUnit.Framework; | ||
| 4 | + | ||
| 5 | + using Python.Runtime; | ||
| 6 | + | ||
| 7 | + namespace Python.EmbeddingTest; | ||
| 8 | + | ||
| 9 | + public class ExtensionTypes | ||
| 10 | + { | ||
| 11 | + [OneTimeSetUp] | ||
| 12 | + public void SetUp() | ||
| 13 | + { | ||
| 14 | + PythonEngine.Initialize(); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + [OneTimeTearDown] | ||
| 18 | + public void Dispose() | ||
| 19 | + { | ||
| 20 | + PythonEngine.Shutdown(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + [Test] | ||
| 24 | + public void WeakrefIsNone_AfterBoundMethodIsGone() | ||
| 25 | + { | ||
| 26 | + using var makeref = Py.Import("weakref").GetAttr("ref"); | ||
| 27 | + var boundMethod = new UriBuilder().ToPython().GetAttr(nameof(UriBuilder.GetHashCode)); | ||
| 28 | + var weakref = makeref.Invoke(boundMethod); | ||
| 29 | + boundMethod.Dispose(); | ||
| 30 | + Assert.IsTrue(weakref.Invoke().IsNone()); | ||
| 31 | + } | ||
| 32 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,6 +86,12 @@ public unsafe static void tp_dealloc(NewReference lastRef) | |||
| 86 | 86 | ||
| 87 | 87 | public static int tp_clear(BorrowedReference ob) | |
| 88 | 88 | { | |
| 89 | + var weakrefs = Runtime.PyObject_GetWeakRefList(ob); | ||
| 90 | + if (weakrefs != null) | ||
| 91 | + { | ||
| 92 | + Runtime.PyObject_ClearWeakRefs(ob); | ||
| 93 | + } | ||
| 94 | + | ||
| 89 | 95 | if (TryFreeGCHandle(ob)) | |
| 90 | 96 | { | |
| 91 | 97 | bool deleted = loadedExtensions.Remove(ob.DangerousGetAddress()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,6 +273,12 @@ public static NewReference mp_subscript(BorrowedReference tp, BorrowedReference | |||
| 273 | 273 | /// </summary> | |
| 274 | 274 | public static void tp_dealloc(NewReference lastRef) | |
| 275 | 275 | { | |
| 276 | + var weakrefs = Runtime.PyObject_GetWeakRefList(lastRef.Borrow()); | ||
| 277 | + if (weakrefs != null) | ||
| 278 | + { | ||
| 279 | + Runtime.PyObject_ClearWeakRefs(lastRef.Borrow()); | ||
| 280 | + } | ||
| 281 | + | ||
| 276 | 282 | // Fix this when we dont cheat on the handle for subclasses! | |
| 277 | 283 | ||
| 278 | 284 | var flags = PyType.GetFlags(lastRef.Borrow()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments