@@ -51,21 +51,18 @@ internal static void Initialize()
5151
5252 internal static void RemoveTypes ( )
5353 {
54- if ( Runtime . HostedInPython )
54+ foreach ( var type in cache . Values )
5555 {
56- foreach ( var holder in _slotsHolders )
56+ if ( Runtime . HostedInPython
57+ && _slotsHolders . TryGetValue ( type , out var holder ) )
5758 {
5859 // If refcount > 1, it needs to reset the managed slot,
5960 // otherwise it can dealloc without any trick.
60- if ( holder . Key . Refcount > 1 )
61+ if ( Runtime . Refcount ( type ) > 1 )
6162 {
62- holder . Value . ResetSlots ( ) ;
63+ holder . ResetSlots ( ) ;
6364 }
6465 }
65- }
66-
67- foreach ( var type in cache . Values )
68- {
6966 type . Dispose ( ) ;
7067 }
7168 cache . Clear ( ) ;
@@ -510,7 +507,7 @@ internal static PyType CreateMetaType(Type impl, out SlotsHolder slotsHolder)
510507 {
511508 throw PythonException . ThrowLastAsClrException ( ) ;
512509 }
513-
510+
514511 BorrowedReference dict = Util . ReadRef ( type , TypeOffset . tp_dict ) ;
515512 using ( var mod = Runtime . PyString_FromString ( "clr._internal" ) )
516513 Runtime . PyDict_SetItemString ( dict , "__module__" , mod . Borrow ( ) ) ;
@@ -729,7 +726,6 @@ internal static void CopySlot(BorrowedReference from, BorrowedReference to, int
729726
730727 internal static SlotsHolder CreateSlotsHolder ( PyType type )
731728 {
732- type = new PyType ( type ) ;
733729 var holder = new SlotsHolder ( type ) ;
734730 _slotsHolders . Add ( type , holder ) ;
735731 return holder ;
@@ -832,7 +828,6 @@ public void ResetSlots()
832828 var metatype = Runtime . PyObject_TYPE ( Type ) ;
833829 ManagedType . TryFreeGCHandle ( Type , metatype ) ;
834830 }
835- Runtime . PyType_Modified ( Type ) ;
836831 }
837832
838833 public static IntPtr GetDefaultSlot ( int offset )
0 commit comments