Skip to content

Reworked ManagedType to not keep python references to self #2

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

Merged
merged 45 commits into from
Dec 9, 2021

Conversation

lostmsu
Copy link

@lostmsu lostmsu commented Oct 29, 2021

Remove pyHandle and tpHandle fields in ManagedType which used to make instances of ManagedType self-referential.

ManagedType now provides Alloc, that creates a Python wrapper around the instance and returns a strong reference to it. That reference is explicitly passed around everywhere pyHandle was needed (usually as BorrowedReference ob).

With reference loops gone (one notable exception is PythonDerivedType that still requires it for .NET to be able to access Python implementation and vice versa), reference tracking is simplified. Lists of all wrapped .NET objects is stored in CLRObject.reflectedObjects and all extension types in ExtensionType.loadedExtensions for cross-domain support replacing "track types".

PyObject disposal and finalization and PythonDerivedType finalization have been reworked to permit them when and only when both Python runtime and Python.NET engine are in appropriate states.

A few minor bugs were fixed.

@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch 3 times, most recently from 978fd25 to 78fc99d Compare October 29, 2021 22:55
@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from 78fc99d to 78a18ba Compare October 30, 2021 02:04
@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from 78a18ba to 1a4ada7 Compare October 30, 2021 02:09
@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from 04b5d9e to fd36721 Compare November 23, 2021 23:34
@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from fd36721 to cb58147 Compare November 23, 2021 23:46
@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from 69be9b2 to a8ef06c Compare November 24, 2021 04:26
@lostmsu
Copy link
Author

lostmsu commented Nov 25, 2021

@filmor this seems to be working (at least tests are passing).

The diff starts on top of pythonnet#1603

I wish it were smaller, but the old code that supported app domains for 3.8 and below just does not work for 3.9 and 3.10 (it made assumptions about internal GC data structures, that are no longer valid).

@lostmsu lostmsu force-pushed the ManagedType-DontKeepBorrowedRefs branch from fad8f0b to d6edace Compare November 25, 2021 04:22
namespace Python.Runtime;

[Serializable]
internal class EventHandlerCollection: Dictionary<object, List<Handler>>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly moved from eventobject.cs

remote analyzer workaround
}

private static void ResotreModules(IntPtr dummyGC)
private static void ResotreModules()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

@lostmsu lostmsu merged commit 2e040ea into precise-API-references Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants