Skip to content

Commit e269cf0

Browse files
committed
when initialized from Python, reset slots implemented in CLR: CLR might shut down and unload corresponding methods before Python terminates
1 parent c8f0f09 commit e269cf0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/runtime/runtime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ internal static void Shutdown(ShutdownMode mode)
314314

315315
NullGCHandles(ExtensionType.loadedExtensions);
316316
ClassManager.RemoveClasses();
317-
TypeManager.RemoveTypes();
317+
TypeManager.RemoveTypes(mode);
318318

319319
MetaType.Release();
320320
PyCLRMetaType.Dispose();

src/runtime/typemanager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ internal static void Initialize()
4545
pythonBaseTypeProvider = PythonEngine.InteropConfiguration.pythonBaseTypeProviders;
4646
}
4747

48-
internal static void RemoveTypes()
48+
internal static void RemoveTypes(ShutdownMode shutdownMode)
4949
{
5050
foreach (var type in cache.Values)
5151
{
52-
//SlotsHolder holder;
53-
//if (_slotsHolders.TryGetValue(type, out holder))
54-
//{
55-
// // If refcount > 1, it needs to reset the managed slot,
56-
// // otherwise it can dealloc without any trick.
57-
// if (Runtime.Refcount(type) > 1)
58-
// {
59-
// holder.ResetSlots();
60-
// }
61-
//}
52+
if (shutdownMode == ShutdownMode.Extension
53+
&& _slotsHolders.TryGetValue(type, out var holder))
54+
{
55+
// If refcount > 1, it needs to reset the managed slot,
56+
// otherwise it can dealloc without any trick.
57+
if (Runtime.Refcount(type) > 1)
58+
{
59+
holder.ResetSlots();
60+
}
61+
}
6262
type.Dispose();
6363
}
6464
cache.Clear();

0 commit comments

Comments
 (0)