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

On shutdown from Python release all slot holders#1712

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
filmor merged 3 commits intopythonnet:masterfromlosttech:bugs/ShutdownSegFault
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
do not attempt to manually delete derived class instances after TypeM…
…anager is terminated and Python is shutting down
  • Loading branch information
@lostmsu
lostmsu committedApr 7, 2022
commite9cbb87073e75500b3392ad057c06a132fb5ed3c
1 change: 1 addition & 0 deletionspythonnet.sln
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo", "Repo", "{441A0123-F
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-4534-B280-B858D651B2E5}"
ProjectSection(SolutionItems) = preProject
.github\workflows\ARM.yml = .github\workflows\ARM.yml
.github\workflows\main.yml = .github\workflows\main.yml
.github\workflows\nuget-preview.yml = .github\workflows\nuget-preview.yml
EndProjectSection
Expand Down
9 changes: 6 additions & 3 deletionssrc/runtime/Runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,8 +54,9 @@ private static string GetDefaultDllName(Version version)
}

private static bool _isInitialized = false;

internal static bool IsInitialized => _isInitialized;
private static bool _typesInitialized = false;
internal static bool TypeManagerInitialized => _typesInitialized;
internal static readonly bool Is32Bit = IntPtr.Size == 4;

// .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
Expand DownExpand Up@@ -151,6 +152,7 @@ internal static void Initialize(bool initSigs = false)
ClassManager.Reset();
ClassDerivedObject.Reset();
TypeManager.Initialize();
_typesInitialized = true;

// Initialize modules that depend on the runtime class.
AssemblyManager.Initialize();
Expand DownExpand Up@@ -272,6 +274,7 @@ internal static void Shutdown()
NullGCHandles(ExtensionType.loadedExtensions);
ClassManager.RemoveClasses();
TypeManager.RemoveTypes();
_typesInitialized = false;

MetaType.Release();
PyCLRMetaType.Dispose();
Expand All@@ -291,9 +294,10 @@ internal static void Shutdown()
Finalizer.Shutdown();
InternString.Shutdown();

ResetPyMembers();

if (!HostedInPython)
{
ResetPyMembers();
GC.Collect();
GC.WaitForPendingFinalizers();
PyGILState_Release(state);
Expand All@@ -310,7 +314,6 @@ internal static void Shutdown()
}
else
{
ResetPyMembers();
PyGILState_Release(state);
}
}
Expand Down
1 change: 1 addition & 0 deletionssrc/runtime/TypeManager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -832,6 +832,7 @@ public void ResetSlots()
var metatype = Runtime.PyObject_TYPE(Type);
ManagedType.TryFreeGCHandle(Type, metatype);
}
Runtime.PyType_Modified(Type);
}

public static IntPtr GetDefaultSlot(int offset)
Expand Down
20 changes: 10 additions & 10 deletionssrc/runtime/Types/ClassDerived.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,10 +59,7 @@ protected override NewReference NewObjectToPython(object obj, BorrowedReference
// Decrement the python object's reference count.
// This doesn't actually destroy the object, it just sets the reference to this object
// to be a weak reference and it will be destroyed when the C# object is destroyed.
if (!self.IsNull())
{
Runtime.XDecref(self.Steal());
}
Runtime.XDecref(self.Steal());

return Converter.ToPython(obj, type.Value);
}
Expand DownExpand Up@@ -942,13 +939,16 @@ internal static void Finalize(IntPtr derived)

var type = Runtime.PyObject_TYPE(@ref.Borrow());

// rare case when it's needed
// matches correspdonging PyObject_GC_UnTrack
// in ClassDerivedObject.tp_dealloc
Runtime.PyObject_GC_Del(@ref.Steal());
if (!Runtime.HostedInPython || Runtime.TypeManagerInitialized)
{
// rare case when it's needed
// matches correspdonging PyObject_GC_UnTrack
// in ClassDerivedObject.tp_dealloc
Runtime.PyObject_GC_Del(@ref.Steal());

// must decref our type
Runtime.XDecref(StolenReference.DangerousFromPointer(type.DangerousGetAddress()));
// must decref our type
Runtime.XDecref(StolenReference.DangerousFromPointer(type.DangerousGetAddress()));
}
}

internal static FieldInfo? GetPyObjField(Type type) => type.GetField(PyObjName, PyObjFlags);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp