diff --git a/src/runtime/ManagedTypes.cd b/src/runtime/ManagedTypes.cd index 9c0f73b4f..385ae7117 100644 --- a/src/runtime/ManagedTypes.cd +++ b/src/runtime/ManagedTypes.cd @@ -29,9 +29,9 @@ - + - AAAACAAAAAAABABAAAAACAAAABAJAAAAAAAAAAIAAAQ= + AAAACAAAAAAABABAAAAACAAAABAJAEAAAAAAAAIAAAA= constructorbinding.cs @@ -52,7 +52,7 @@ - AAAACAAAAAAABAAAAAAACAAAABAJAAAAAAAAAAIAEAQ= + AAAACAAAAAAABAAAAAAACAAAABAJAEAAAAAAAAIAEAA= constructorbinding.cs @@ -64,7 +64,15 @@ - + + + + + + + + + AAAAAAAAAAAADAAAIAAAEABAAAAAAAACAAAAAAIAAAQ= eventbinding.cs @@ -87,12 +95,12 @@ - AAAAAAAAAAAAAAAAAAAAAAECAAAAAEEBAAAAAAABAAQ= + AAAAAAAAAAAAAAAAAAAAAAACAAAAAEEBAAAAAAABAAQ= extensiontype.cs - + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAIBEAA= fieldobject.cs @@ -120,21 +128,29 @@ - + + + + + + + + + EAAAAAAAAIAADABAIAAAAAAAAAgBAAAAUgAAAAIAAAQ= methodbinding.cs - + FIADAAAAAAAIBAAAIAAIAAAIAAgFAAAAUAAgAAIAEAQ= methodobject.cs - + AAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAIAAAA= modulefunctionobject.cs @@ -148,18 +164,33 @@ - + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= modulepropertyobject.cs - + AAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAQAAAAAIBEAg= propertyobject.cs + + + + + + + + + + + + AAAAAAAAAAAAAAAAIAAAAAAAAAABAAAAAgAAAAIAAAQ= + overload.cs + + \ No newline at end of file diff --git a/src/runtime/constructorbinding.cs b/src/runtime/constructorbinding.cs index 6706c2b48..ab4a7af0a 100644 --- a/src/runtime/constructorbinding.cs +++ b/src/runtime/constructorbinding.cs @@ -149,14 +149,10 @@ public static IntPtr tp_repr(IntPtr ob) return self.repr; } - /// - /// ConstructorBinding dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (ConstructorBinding)GetManagedObject(ob); - Runtime.XDecref(self.repr); - self.Dealloc(); + Runtime.Py_CLEAR(ref this.repr); + base.Dealloc(); } public static int tp_clear(IntPtr ob) @@ -252,14 +248,10 @@ public static IntPtr tp_repr(IntPtr ob) return self.repr; } - /// - /// ConstructorBinding dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (BoundContructor)GetManagedObject(ob); - Runtime.XDecref(self.repr); - self.Dealloc(); + Runtime.Py_CLEAR(ref this.repr); + base.Dealloc(); } public static int tp_clear(IntPtr ob) diff --git a/src/runtime/eventbinding.cs b/src/runtime/eventbinding.cs index 3f5b7b007..60b9bba92 100644 --- a/src/runtime/eventbinding.cs +++ b/src/runtime/eventbinding.cs @@ -103,15 +103,10 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromString(s); } - - /// - /// EventBinding dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (EventBinding)GetManagedObject(ob); - Runtime.XDecref(self.target); - self.Dealloc(); + Runtime.Py_CLEAR(ref this.target); + base.Dealloc(); } public static int tp_clear(IntPtr ob) diff --git a/src/runtime/eventobject.cs b/src/runtime/eventobject.cs index 4dc785ddd..e9bd98821 100644 --- a/src/runtime/eventobject.cs +++ b/src/runtime/eventobject.cs @@ -198,17 +198,14 @@ public static IntPtr tp_repr(IntPtr ob) } - /// - /// Descriptor dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (EventObject)GetManagedObject(ob); - if (self.unbound != null) + if (this.unbound is not null) { - Runtime.XDecref(self.unbound.pyHandle); + Runtime.XDecref(this.unbound.pyHandle); + this.unbound = null; } - self.Dealloc(); + base.Dealloc(); } } diff --git a/src/runtime/extensiontype.cs b/src/runtime/extensiontype.cs index 34a82fe37..db9eb0f72 100644 --- a/src/runtime/extensiontype.cs +++ b/src/runtime/extensiontype.cs @@ -54,20 +54,12 @@ void SetupGc () } - /// - /// Common finalization code to support custom tp_deallocs. - /// - public static void FinalizeObject(ManagedType self) + protected virtual void Dealloc() { - ClearObjectDict(self.pyHandle); - Runtime.PyObject_GC_Del(self.pyHandle); + ClearObjectDict(this.pyHandle); + Runtime.PyObject_GC_Del(this.pyHandle); // Not necessary for decref of `tpHandle`. - self.FreeGCHandle(); - } - - protected void Dealloc() - { - FinalizeObject(this); + this.FreeGCHandle(); } /// @@ -104,7 +96,7 @@ public static void tp_dealloc(IntPtr ob) // Clean up a Python instance of this extension type. This // frees the allocated Python object and decrefs the type. var self = (ExtensionType)GetManagedObject(ob); - self.Dealloc(); + self?.Dealloc(); } protected override void OnLoad(InterDomainContext context) diff --git a/src/runtime/methodbinding.cs b/src/runtime/methodbinding.cs index f33015ba4..783717189 100644 --- a/src/runtime/methodbinding.cs +++ b/src/runtime/methodbinding.cs @@ -31,7 +31,7 @@ public MethodBinding(MethodObject m, IntPtr target, IntPtr targetType) { Runtime.XIncref(targetType); } - + this.targetType = targetType; this.info = null; @@ -42,12 +42,6 @@ public MethodBinding(MethodObject m, IntPtr target) : this(m, target, IntPtr.Zer { } - private void ClearMembers() - { - Runtime.Py_CLEAR(ref target); - Runtime.Py_CLEAR(ref targetType); - } - /// /// Implement binding of generic methods using the subscript syntax []. /// @@ -235,14 +229,16 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromString($"<{type} method '{name}'>"); } - /// - /// MethodBinding dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + private void ClearMembers() { - var self = (MethodBinding)GetManagedObject(ob); - self.ClearMembers(); - self.Dealloc(); + Runtime.Py_CLEAR(ref target); + Runtime.Py_CLEAR(ref targetType); + } + + protected override void Dealloc() + { + this.ClearMembers(); + base.Dealloc(); } public static int tp_clear(IntPtr ob) diff --git a/src/runtime/methodobject.cs b/src/runtime/methodobject.cs index 37c01f5c5..5fa965f1b 100644 --- a/src/runtime/methodobject.cs +++ b/src/runtime/methodobject.cs @@ -120,16 +120,6 @@ internal bool IsStatic() return is_static; } - private void ClearMembers() - { - Runtime.Py_CLEAR(ref doc); - if (unbound != null) - { - Runtime.XDecref(unbound.pyHandle); - unbound = null; - } - } - /// /// Descriptor __getattribute__ implementation. /// @@ -210,15 +200,21 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromString($""); } - /// - /// Descriptor dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + private void ClearMembers() { - var self = (MethodObject)GetManagedObject(ob); - self.ClearMembers(); - ClearObjectDict(ob); - self.Dealloc(); + Runtime.Py_CLEAR(ref doc); + if (unbound != null) + { + Runtime.XDecref(unbound.pyHandle); + unbound = null; + } + } + + protected override void Dealloc() + { + this.ClearMembers(); + ClearObjectDict(this.pyHandle); + base.Dealloc(); } public static int tp_clear(IntPtr ob) diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index 3c4e02a23..1ab014c2a 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -274,7 +274,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) Exceptions.SetError(e); return IntPtr.Zero; } - + if (attr == null) { @@ -295,11 +295,10 @@ public static IntPtr tp_repr(IntPtr ob) return Runtime.PyString_FromString($""); } - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (ModuleObject)GetManagedObject(ob); - tp_clear(ob); - self.Dealloc(); + tp_clear(this.pyHandle); + base.Dealloc(); } public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) @@ -345,7 +344,7 @@ protected override void OnSave(InterDomainContext context) if ((Runtime.PyDict_DelItemString(DictRef, pair.Key) == -1) && (Exceptions.ExceptionMatches(Exceptions.KeyError))) { - // Trying to remove a key that's not in the dictionary + // Trying to remove a key that's not in the dictionary // raises an error. We don't care about it. Runtime.PyErr_Clear(); } @@ -496,7 +495,7 @@ public static Assembly AddReference(string name) /// clr.GetClrType(IComparable) gives you the Type for IComparable, /// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C# /// or clr.GetClrType(IComparable) in IronPython. - /// + /// /// /// /// The Type object diff --git a/src/runtime/native/TypeOffset.cs b/src/runtime/native/TypeOffset.cs index 4e5a726bc..a73a9ae43 100644 --- a/src/runtime/native/TypeOffset.cs +++ b/src/runtime/native/TypeOffset.cs @@ -153,7 +153,6 @@ static void ValidateRequiredOffsetsPresent(PropertyInfo[] offsetProperties) "__instancecheck__", "__subclasscheck__", "AddReference", - "FinalizeObject", "FindAssembly", "get_SuppressDocs", "get_SuppressOverloads", diff --git a/src/runtime/overload.cs b/src/runtime/overload.cs index e9fa91d3b..48fabca4a 100644 --- a/src/runtime/overload.cs +++ b/src/runtime/overload.cs @@ -58,14 +58,10 @@ public static IntPtr tp_repr(IntPtr op) return doc; } - /// - /// OverloadMapper dealloc implementation. - /// - public new static void tp_dealloc(IntPtr ob) + protected override void Dealloc() { - var self = (OverloadMapper)GetManagedObject(ob); - Runtime.XDecref(self.target); - self.Dealloc(); + Runtime.Py_CLEAR(ref this.target); + base.Dealloc(); } } }