@@ -22,8 +22,8 @@ internal class ModuleObject : ExtensionType
2222
2323 // Attributes to be set on the module according to PEP302 and 451
2424 // by the import machinery.
25- static readonly HashSet < string > settableAttributes =
26- new HashSet < string > { "__spec__" , "__file__" , "__name__" , "__path__" , "__loader__" , "__package__" } ;
25+ static readonly HashSet < string ? > settableAttributes =
26+ new ( ) { "__spec__" , "__file__" , "__name__" , "__path__" , "__loader__" , "__package__" } ;
2727
2828 public ModuleObject ( string name )
2929 {
@@ -102,7 +102,6 @@ public ModuleObject(string name)
102102 {
103103 m = new ModuleObject ( qname ) ;
104104 StoreAttribute ( name , m ) ;
105- m . DecrRefCount ( ) ;
106105 return m ;
107106 }
108107
@@ -156,7 +155,6 @@ private void StoreAttribute(string name, ManagedType ob)
156155 {
157156 throw PythonException . ThrowLastAsClrException ( ) ;
158157 }
159- ob . IncrRefCount ( ) ;
160158 cache [ name ] = ob ;
161159 }
162160
@@ -221,7 +219,6 @@ internal void InitializeModuleMembers()
221219 mi [ 0 ] = method ;
222220 var m = new ModuleFunctionObject ( type , name , mi , allow_threads ) ;
223221 StoreAttribute ( name , m ) ;
224- m . DecrRefCount ( ) ;
225222 }
226223 }
227224
@@ -234,7 +231,6 @@ internal void InitializeModuleMembers()
234231 string name = property . Name ;
235232 var p = new ModulePropertyObject ( property ) ;
236233 StoreAttribute ( name , p ) ;
237- p . DecrRefCount ( ) ;
238234 }
239235 }
240236 type = type . BaseType ;
@@ -325,10 +321,6 @@ protected override void Clear()
325321 {
326322 this . dict . Dispose ( ) ;
327323 ClearObjectDict ( this . ObjectReference ) ;
328- foreach ( var attr in this . cache . Values )
329- {
330- Runtime . XDecref ( attr . pyHandle ) ;
331- }
332324 this . cache . Clear ( ) ;
333325 base . Clear ( ) ;
334326 }
@@ -356,13 +348,6 @@ protected override void OnSave(InterDomainContext context)
356348 {
357349 base . OnSave ( context ) ;
358350 System . Diagnostics . Debug . Assert ( dict == GetObjectDict ( ObjectReference ) ) ;
359- foreach ( var attr in cache . Values )
360- {
361- Runtime . XIncref ( attr . pyHandle ) ;
362- }
363- // Decref twice in tp_clear, equilibrate them.
364- Runtime . XIncref ( dict ) ;
365- Runtime . XIncref ( dict ) ;
366351 // destroy the cache(s)
367352 foreach ( var pair in cache )
368353 {
@@ -377,7 +362,6 @@ protected override void OnSave(InterDomainContext context)
377362 {
378363 throw PythonException . ThrowLastAsClrException ( ) ;
379364 }
380- pair . Value . DecrRefCount ( ) ;
381365 }
382366
383367 cache . Clear ( ) ;
@@ -386,7 +370,7 @@ protected override void OnSave(InterDomainContext context)
386370 protected override void OnLoad ( InterDomainContext context )
387371 {
388372 base . OnLoad ( context ) ;
389- SetObjectDict ( pyHandle , dict ) ;
373+ SetObjectDict ( pyHandle , new NewReference ( dict ) . Steal ( ) ) ;
390374 }
391375 }
392376
0 commit comments