| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,14 +149,10 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 149 | 149 | return self.repr; | |
| 150 | 150 | } | |
| 151 | 151 | ||
| 152 | - /// <summary> | ||
| 153 | - /// ConstructorBinding dealloc implementation. | ||
| 154 | - /// </summary> | ||
| 155 | - public new static void tp_dealloc(IntPtr ob) | ||
| 152 | + protected override void Dealloc() | ||
| 156 | 153 | { | |
| 157 | - var self = (ConstructorBinding)GetManagedObject(ob); | ||
| 158 | - Runtime.XDecref(self.repr); | ||
| 159 | - self.Dealloc(); | ||
| 154 | + Runtime.Py_CLEAR(ref this.repr); | ||
| 155 | + base.Dealloc(); | ||
| 160 | 156 | } | |
| 161 | 157 | ||
| 162 | 158 | public static int tp_clear(IntPtr ob) | |
@@ -252,14 +248,10 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 252 | 248 | return self.repr; | |
| 253 | 249 | } | |
| 254 | 250 | ||
| 255 | - /// <summary> | ||
| 256 | - /// ConstructorBinding dealloc implementation. | ||
| 257 | - /// </summary> | ||
| 258 | - public new static void tp_dealloc(IntPtr ob) | ||
| 251 | + protected override void Dealloc() | ||
| 259 | 252 | { | |
| 260 | - var self = (BoundContructor)GetManagedObject(ob); | ||
| 261 | - Runtime.XDecref(self.repr); | ||
| 262 | - self.Dealloc(); | ||
| 253 | + Runtime.Py_CLEAR(ref this.repr); | ||
| 254 | + base.Dealloc(); | ||
| 263 | 255 | } | |
| 264 | 256 | ||
| 265 | 257 | public static int tp_clear(IntPtr ob) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,15 +103,10 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 103 | 103 | return Runtime.PyString_FromString(s); | |
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | - | ||
| 107 | - /// <summary> | ||
| 108 | - /// EventBinding dealloc implementation. | ||
| 109 | - /// </summary> | ||
| 110 | - public new static void tp_dealloc(IntPtr ob) | ||
| 106 | + protected override void Dealloc() | ||
| 111 | 107 | { | |
| 112 | - var self = (EventBinding)GetManagedObject(ob); | ||
| 113 | - Runtime.XDecref(self.target); | ||
| 114 | - self.Dealloc(); | ||
| 108 | + Runtime.Py_CLEAR(ref this.target); | ||
| 109 | + base.Dealloc(); | ||
| 115 | 110 | } | |
| 116 | 111 | ||
| 117 | 112 | public static int tp_clear(IntPtr ob) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,17 +198,14 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 198 | 198 | } | |
| 199 | 199 | ||
| 200 | 200 | ||
| 201 | - /// <summary> | ||
| 202 | - /// Descriptor dealloc implementation. | ||
| 203 | - /// </summary> | ||
| 204 | - public new static void tp_dealloc(IntPtr ob) | ||
| 201 | + protected override void Dealloc() | ||
| 205 | 202 | { | |
| 206 | - var self = (EventObject)GetManagedObject(ob); | ||
| 207 | - if (self.unbound != null) | ||
| 203 | + if (this.unbound is not null) | ||
| 208 | 204 | { | |
| 209 | - Runtime.XDecref(self.unbound.pyHandle); | ||
| 205 | + Runtime.XDecref(this.unbound.pyHandle); | ||
| 206 | + this.unbound = null; | ||
| 210 | 207 | } | |
| 211 | - self.Dealloc(); | ||
| 208 | + base.Dealloc(); | ||
| 212 | 209 | } | |
| 213 | 210 | } | |
| 214 | 211 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,20 +54,12 @@ void SetupGc () | |||
| 54 | 54 | } | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | - /// <summary> | ||
| 58 | - /// Common finalization code to support custom tp_deallocs. | ||
| 59 | - /// </summary> | ||
| 60 | - public static void FinalizeObject(ManagedType self) | ||
| 57 | + protected virtual void Dealloc() | ||
| 61 | 58 | { | |
| 62 | - ClearObjectDict(self.pyHandle); | ||
| 63 | - Runtime.PyObject_GC_Del(self.pyHandle); | ||
| 59 | + ClearObjectDict(this.pyHandle); | ||
| 60 | + Runtime.PyObject_GC_Del(this.pyHandle); | ||
| 64 | 61 | // Not necessary for decref of `tpHandle`. | |
| 65 | - self.FreeGCHandle(); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - protected void Dealloc() | ||
| 69 | - { | ||
| 70 | - FinalizeObject(this); | ||
| 62 | + this.FreeGCHandle(); | ||
| 71 | 63 | } | |
| 72 | 64 | ||
| 73 | 65 | /// <summary> | |
@@ -104,7 +96,7 @@ public static void tp_dealloc(IntPtr ob) | |||
| 104 | 96 | // Clean up a Python instance of this extension type. This | |
| 105 | 97 | // frees the allocated Python object and decrefs the type. | |
| 106 | 98 | var self = (ExtensionType)GetManagedObject(ob); | |
| 107 | - self.Dealloc(); | ||
| 99 | + self?.Dealloc(); | ||
| 108 | 100 | } | |
| 109 | 101 | ||
| 110 | 102 | protected override void OnLoad(InterDomainContext context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ public MethodBinding(MethodObject m, IntPtr target, IntPtr targetType) | |||
| 31 | 31 | { | |
| 32 | 32 | Runtime.XIncref(targetType); | |
| 33 | 33 | } | |
| 34 | - | ||
| 34 | + | ||
| 35 | 35 | this.targetType = targetType; | |
| 36 | 36 | ||
| 37 | 37 | this.info = null; | |
@@ -42,12 +42,6 @@ public MethodBinding(MethodObject m, IntPtr target) : this(m, target, IntPtr.Zer | |||
| 42 | 42 | { | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | - private void ClearMembers() | ||
| 46 | - { | ||
| 47 | - Runtime.Py_CLEAR(ref target); | ||
| 48 | - Runtime.Py_CLEAR(ref targetType); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | 45 | /// <summary> | |
| 52 | 46 | /// Implement binding of generic methods using the subscript syntax []. | |
| 53 | 47 | /// </summary> | |
@@ -235,14 +229,16 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 235 | 229 | return Runtime.PyString_FromString($"<{type} method '{name}'>"); | |
| 236 | 230 | } | |
| 237 | 231 | ||
| 238 | - /// <summary> | ||
| 239 | - /// MethodBinding dealloc implementation. | ||
| 240 | - /// </summary> | ||
| 241 | - public new static void tp_dealloc(IntPtr ob) | ||
| 232 | + private void ClearMembers() | ||
| 242 | 233 | { | |
| 243 | - var self = (MethodBinding)GetManagedObject(ob); | ||
| 244 | - self.ClearMembers(); | ||
| 245 | - self.Dealloc(); | ||
| 234 | + Runtime.Py_CLEAR(ref target); | ||
| 235 | + Runtime.Py_CLEAR(ref targetType); | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + protected override void Dealloc() | ||
| 239 | + { | ||
| 240 | + this.ClearMembers(); | ||
| 241 | + base.Dealloc(); | ||
| 246 | 242 | } | |
| 247 | 243 | ||
| 248 | 244 | public static int tp_clear(IntPtr ob) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,16 +120,6 @@ internal bool IsStatic() | |||
| 120 | 120 | return is_static; | |
| 121 | 121 | } | |
| 122 | 122 | ||
| 123 | - private void ClearMembers() | ||
| 124 | - { | ||
| 125 | - Runtime.Py_CLEAR(ref doc); | ||
| 126 | - if (unbound != null) | ||
| 127 | - { | ||
| 128 | - Runtime.XDecref(unbound.pyHandle); | ||
| 129 | - unbound = null; | ||
| 130 | - } | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | 123 | /// <summary> | |
| 134 | 124 | /// Descriptor __getattribute__ implementation. | |
| 135 | 125 | /// </summary> | |
@@ -210,15 +200,21 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 210 | 200 | return Runtime.PyString_FromString($"<method '{self.name}'>"); | |
| 211 | 201 | } | |
| 212 | 202 | ||
| 213 | - /// <summary> | ||
| 214 | - /// Descriptor dealloc implementation. | ||
| 215 | - /// </summary> | ||
| 216 | - public new static void tp_dealloc(IntPtr ob) | ||
| 203 | + private void ClearMembers() | ||
| 217 | 204 | { | |
| 218 | - var self = (MethodObject)GetManagedObject(ob); | ||
| 219 | - self.ClearMembers(); | ||
| 220 | - ClearObjectDict(ob); | ||
| 221 | - self.Dealloc(); | ||
| 205 | + Runtime.Py_CLEAR(ref doc); | ||
| 206 | + if (unbound != null) | ||
| 207 | + { | ||
| 208 | + Runtime.XDecref(unbound.pyHandle); | ||
| 209 | + unbound = null; | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + protected override void Dealloc() | ||
| 214 | + { | ||
| 215 | + this.ClearMembers(); | ||
| 216 | + ClearObjectDict(this.pyHandle); | ||
| 217 | + base.Dealloc(); | ||
| 222 | 218 | } | |
| 223 | 219 | ||
| 224 | 220 | public static int tp_clear(IntPtr ob) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -274,7 +274,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) | |||
| 274 | 274 | Exceptions.SetError(e); | |
| 275 | 275 | return IntPtr.Zero; | |
| 276 | 276 | } | |
| 277 | - | ||
| 277 | + | ||
| 278 | 278 | ||
| 279 | 279 | if (attr == null) | |
| 280 | 280 | { | |
@@ -295,11 +295,10 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 295 | 295 | return Runtime.PyString_FromString($"<module '{self.moduleName}'>"); | |
| 296 | 296 | } | |
| 297 | 297 | ||
| 298 | - public new static void tp_dealloc(IntPtr ob) | ||
| 298 | + protected override void Dealloc() | ||
| 299 | 299 | { | |
| 300 | - var self = (ModuleObject)GetManagedObject(ob); | ||
| 301 | - tp_clear(ob); | ||
| 302 | - self.Dealloc(); | ||
| 300 | + tp_clear(this.pyHandle); | ||
| 301 | + base.Dealloc(); | ||
| 303 | 302 | } | |
| 304 | 303 | ||
| 305 | 304 | public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |
@@ -345,7 +344,7 @@ protected override void OnSave(InterDomainContext context) | |||
| 345 | 344 | if ((Runtime.PyDict_DelItemString(DictRef, pair.Key) == -1) && | |
| 346 | 345 | (Exceptions.ExceptionMatches(Exceptions.KeyError))) | |
| 347 | 346 | { | |
| 348 | - // Trying to remove a key that's not in the dictionary | ||
| 347 | + // Trying to remove a key that's not in the dictionary | ||
| 349 | 348 | // raises an error. We don't care about it. | |
| 350 | 349 | Runtime.PyErr_Clear(); | |
| 351 | 350 | } | |
@@ -496,7 +495,7 @@ public static Assembly AddReference(string name) | |||
| 496 | 495 | /// clr.GetClrType(IComparable) gives you the Type for IComparable, | |
| 497 | 496 | /// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C# | |
| 498 | 497 | /// or clr.GetClrType(IComparable) in IronPython. | |
| 499 | - /// | ||
| 498 | + /// | ||
| 500 | 499 | /// </summary> | |
| 501 | 500 | /// <param name="type"></param> | |
| 502 | 501 | /// <returns>The Type object</returns> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -153,7 +153,6 @@ static void ValidateRequiredOffsetsPresent(PropertyInfo[] offsetProperties) | |||
| 153 | 153 | "__instancecheck__", | |
| 154 | 154 | "__subclasscheck__", | |
| 155 | 155 | "AddReference", | |
| 156 | - "FinalizeObject", | ||
| 157 | 156 | "FindAssembly", | |
| 158 | 157 | "get_SuppressDocs", | |
| 159 | 158 | "get_SuppressOverloads", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,14 +58,10 @@ public static IntPtr tp_repr(IntPtr op) | |||
| 58 | 58 | return doc; | |
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | - /// <summary> | ||
| 62 | - /// OverloadMapper dealloc implementation. | ||
| 63 | - /// </summary> | ||
| 64 | - public new static void tp_dealloc(IntPtr ob) | ||
| 61 | + protected override void Dealloc() | ||
| 65 | 62 | { | |
| 66 | - var self = (OverloadMapper)GetManagedObject(ob); | ||
| 67 | - Runtime.XDecref(self.target); | ||
| 68 | - self.Dealloc(); | ||
| 63 | + Runtime.XDecref(this.target); | ||
| 64 | + base.Dealloc(); | ||
| 69 | 65 | } | |
| 70 | 66 | } | |
| 71 | 67 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments