| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,12 +149,6 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 149 | 149 | return self.repr; | |
| 150 | 150 | } | |
| 151 | 151 | ||
| 152 | - protected override void Dealloc() | ||
| 153 | - { | ||
| 154 | - Runtime.Py_CLEAR(ref this.repr); | ||
| 155 | - base.Dealloc(); | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | 152 | protected override void Clear() | |
| 159 | 153 | { | |
| 160 | 154 | Runtime.Py_CLEAR(ref this.repr); | |
@@ -247,12 +241,6 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 247 | 241 | return self.repr; | |
| 248 | 242 | } | |
| 249 | 243 | ||
| 250 | - protected override void Dealloc() | ||
| 251 | - { | ||
| 252 | - Runtime.Py_CLEAR(ref this.repr); | ||
| 253 | - base.Dealloc(); | ||
| 254 | - } | ||
| 255 | - | ||
| 256 | 244 | protected override void Clear() | |
| 257 | 245 | { | |
| 258 | 246 | Runtime.Py_CLEAR(ref this.repr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,12 +103,6 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 103 | 103 | return Runtime.PyString_FromString(s); | |
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | - protected override void Dealloc() | ||
| 107 | - { | ||
| 108 | - Runtime.Py_CLEAR(ref this.target); | ||
| 109 | - base.Dealloc(); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | 106 | protected override void Clear() | |
| 113 | 107 | { | |
| 114 | 108 | Runtime.Py_CLEAR(ref this.target); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,16 +198,6 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 198 | 198 | } | |
| 199 | 199 | ||
| 200 | 200 | ||
| 201 | - protected override void Dealloc() | ||
| 202 | - { | ||
| 203 | - if (this.unbound is not null) | ||
| 204 | - { | ||
| 205 | - Runtime.XDecref(this.unbound.pyHandle); | ||
| 206 | - this.unbound = null; | ||
| 207 | - } | ||
| 208 | - base.Dealloc(); | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | 201 | protected override void Clear() | |
| 212 | 202 | { | |
| 213 | 203 | if (this.unbound is not null) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,14 +56,22 @@ void SetupGc () | |||
| 56 | 56 | ||
| 57 | 57 | protected virtual void Dealloc() | |
| 58 | 58 | { | |
| 59 | - ClearObjectDict(this.pyHandle); | ||
| 59 | + var type = Runtime.PyObject_TYPE(this.ObjectReference); | ||
| 60 | 60 | Runtime.PyObject_GC_Del(this.pyHandle); | |
| 61 | - // Not necessary for decref of `tpHandle`. | ||
| 61 | + // Not necessary for decref of `tpHandle` - it is borrowed | ||
| 62 | + | ||
| 62 | 63 | this.FreeGCHandle(); | |
| 64 | + | ||
| 65 | + // we must decref our type: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc | ||
| 66 | + Runtime.XDecref(type.DangerousGetAddress()); | ||
| 63 | 67 | } | |
| 64 | 68 | ||
| 65 | 69 | /// <summary>DecRefs and nulls any fields pointing back to Python</summary> | |
| 66 | - protected virtual void Clear() { } | ||
| 70 | + protected virtual void Clear() | ||
| 71 | + { | ||
| 72 | + ClearObjectDict(this.pyHandle); | ||
| 73 | + // Not necessary for decref of `tpHandle` - it is borrowed | ||
| 74 | + } | ||
| 67 | 75 | ||
| 68 | 76 | /// <summary> | |
| 69 | 77 | /// Type __setattr__ implementation. | |
@@ -96,6 +104,7 @@ public static void tp_dealloc(IntPtr ob) | |||
| 96 | 104 | // Clean up a Python instance of this extension type. This | |
| 97 | 105 | // frees the allocated Python object and decrefs the type. | |
| 98 | 106 | var self = (ExtensionType)GetManagedObject(ob); | |
| 107 | + self?.Clear(); | ||
| 99 | 108 | self?.Dealloc(); | |
| 100 | 109 | } | |
| 101 | 110 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,21 +229,10 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 229 | 229 | return Runtime.PyString_FromString($"<{type} method '{name}'>"); | |
| 230 | 230 | } | |
| 231 | 231 | ||
| 232 | - private void ClearMembers() | ||
| 233 | - { | ||
| 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(); | ||
| 242 | - } | ||
| 243 | - | ||
| 244 | 232 | protected override void Clear() | |
| 245 | 233 | { | |
| 246 | - this.ClearMembers(); | ||
| 234 | + Runtime.Py_CLEAR(ref this.target); | ||
| 235 | + Runtime.Py_CLEAR(ref this.targetType); | ||
| 247 | 236 | base.Clear(); | |
| 248 | 237 | } | |
| 249 | 238 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -200,26 +200,15 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 200 | 200 | return Runtime.PyString_FromString($"<method '{self.name}'>"); | |
| 201 | 201 | } | |
| 202 | 202 | ||
| 203 | - private void ClearMembers() | ||
| 203 | + protected override void Clear() | ||
| 204 | 204 | { | |
| 205 | - Runtime.Py_CLEAR(ref doc); | ||
| 206 | - if (unbound != null) | ||
| 205 | + Runtime.Py_CLEAR(ref this.doc); | ||
| 206 | + if (this.unbound != null) | ||
| 207 | 207 | { | |
| 208 | - Runtime.XDecref(unbound.pyHandle); | ||
| 209 | - unbound = null; | ||
| 208 | + Runtime.XDecref(this.unbound.pyHandle); | ||
| 209 | + this.unbound = null; | ||
| 210 | 210 | } | |
| 211 | - } | ||
| 212 | 211 | ||
| 213 | - protected override void Dealloc() | ||
| 214 | - { | ||
| 215 | - this.ClearMembers(); | ||
| 216 | - ClearObjectDict(this.pyHandle); | ||
| 217 | - base.Dealloc(); | ||
| 218 | - } | ||
| 219 | - | ||
| 220 | - protected override void Clear() | ||
| 221 | - { | ||
| 222 | - this.ClearMembers(); | ||
| 223 | 212 | ClearObjectDict(this.pyHandle); | |
| 224 | 213 | base.Clear(); | |
| 225 | 214 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -308,12 +308,6 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |||
| 308 | 308 | return 0; | |
| 309 | 309 | } | |
| 310 | 310 | ||
| 311 | - protected override void Dealloc() | ||
| 312 | - { | ||
| 313 | - tp_clear(this.pyHandle); | ||
| 314 | - base.Dealloc(); | ||
| 315 | - } | ||
| 316 | - | ||
| 317 | 311 | protected override void Clear() | |
| 318 | 312 | { | |
| 319 | 313 | Runtime.Py_CLEAR(ref this.dict); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,12 +58,6 @@ public static IntPtr tp_repr(IntPtr op) | |||
| 58 | 58 | return doc; | |
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | - protected override void Dealloc() | ||
| 62 | - { | ||
| 63 | - Runtime.Py_CLEAR(ref this.target); | ||
| 64 | - base.Dealloc(); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | 61 | protected override void Clear() | |
| 68 | 62 | { | |
| 69 | 63 | Runtime.Py_CLEAR(ref this.target); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments