| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,11 +155,10 @@ protected override void Dealloc() | |||
| 155 | 155 | base.Dealloc(); | |
| 156 | 156 | } | |
| 157 | 157 | ||
| 158 | - public static int tp_clear(IntPtr ob) | ||
| 158 | + protected override void Clear() | ||
| 159 | 159 | { | |
| 160 | - var self = (ConstructorBinding)GetManagedObject(ob); | ||
| 161 | - Runtime.Py_CLEAR(ref self.repr); | ||
| 162 | - return 0; | ||
| 160 | + Runtime.Py_CLEAR(ref this.repr); | ||
| 161 | + base.Clear(); | ||
| 163 | 162 | } | |
| 164 | 163 | ||
| 165 | 164 | public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |
@@ -254,11 +253,10 @@ protected override void Dealloc() | |||
| 254 | 253 | base.Dealloc(); | |
| 255 | 254 | } | |
| 256 | 255 | ||
| 257 | - public static int tp_clear(IntPtr ob) | ||
| 256 | + protected override void Clear() | ||
| 258 | 257 | { | |
| 259 | - var self = (BoundContructor)GetManagedObject(ob); | ||
| 260 | - Runtime.Py_CLEAR(ref self.repr); | ||
| 261 | - return 0; | ||
| 258 | + Runtime.Py_CLEAR(ref this.repr); | ||
| 259 | + base.Clear(); | ||
| 262 | 260 | } | |
| 263 | 261 | ||
| 264 | 262 | public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,11 +109,10 @@ protected override void Dealloc() | |||
| 109 | 109 | base.Dealloc(); | |
| 110 | 110 | } | |
| 111 | 111 | ||
| 112 | - public static int tp_clear(IntPtr ob) | ||
| 112 | + protected override void Clear() | ||
| 113 | 113 | { | |
| 114 | - var self = (EventBinding)GetManagedObject(ob); | ||
| 115 | - Runtime.Py_CLEAR(ref self.target); | ||
| 116 | - return 0; | ||
| 114 | + Runtime.Py_CLEAR(ref this.target); | ||
| 115 | + base.Clear(); | ||
| 117 | 116 | } | |
| 118 | 117 | } | |
| 119 | 118 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,6 +207,16 @@ protected override void Dealloc() | |||
| 207 | 207 | } | |
| 208 | 208 | base.Dealloc(); | |
| 209 | 209 | } | |
| 210 | + | ||
| 211 | + protected override void Clear() | ||
| 212 | + { | ||
| 213 | + if (this.unbound is not null) | ||
| 214 | + { | ||
| 215 | + Runtime.XDecref(this.unbound.pyHandle); | ||
| 216 | + this.unbound = null; | ||
| 217 | + } | ||
| 218 | + base.Clear(); | ||
| 219 | + } | ||
| 210 | 220 | } | |
| 211 | 221 | ||
| 212 | 222 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,9 @@ protected virtual void Dealloc() | |||
| 62 | 62 | this.FreeGCHandle(); | |
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | + /// <summary>DecRefs and nulls any fields pointing back to Python</summary> | ||
| 66 | + protected virtual void Clear() { } | ||
| 67 | + | ||
| 65 | 68 | /// <summary> | |
| 66 | 69 | /// Type __setattr__ implementation. | |
| 67 | 70 | /// </summary> | |
@@ -88,9 +91,6 @@ public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val) | |||
| 88 | 91 | } | |
| 89 | 92 | ||
| 90 | 93 | ||
| 91 | - /// <summary> | ||
| 92 | - /// Default dealloc implementation. | ||
| 93 | - /// </summary> | ||
| 94 | 94 | public static void tp_dealloc(IntPtr ob) | |
| 95 | 95 | { | |
| 96 | 96 | // Clean up a Python instance of this extension type. This | |
@@ -99,6 +99,13 @@ public static void tp_dealloc(IntPtr ob) | |||
| 99 | 99 | self?.Dealloc(); | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | + public static int tp_clear(IntPtr ob) | ||
| 103 | + { | ||
| 104 | + var self = (ExtensionType)GetManagedObject(ob); | ||
| 105 | + self?.Clear(); | ||
| 106 | + return 0; | ||
| 107 | + } | ||
| 108 | + | ||
| 102 | 109 | protected override void OnLoad(InterDomainContext context) | |
| 103 | 110 | { | |
| 104 | 111 | base.OnLoad(context); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -241,11 +241,10 @@ protected override void Dealloc() | |||
| 241 | 241 | base.Dealloc(); | |
| 242 | 242 | } | |
| 243 | 243 | ||
| 244 | - public static int tp_clear(IntPtr ob) | ||
| 244 | + protected override void Clear() | ||
| 245 | 245 | { | |
| 246 | - var self = (MethodBinding)GetManagedObject(ob); | ||
| 247 | - self.ClearMembers(); | ||
| 248 | - return 0; | ||
| 246 | + this.ClearMembers(); | ||
| 247 | + base.Clear(); | ||
| 249 | 248 | } | |
| 250 | 249 | ||
| 251 | 250 | protected override void OnSave(InterDomainContext context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -217,12 +217,11 @@ protected override void Dealloc() | |||
| 217 | 217 | base.Dealloc(); | |
| 218 | 218 | } | |
| 219 | 219 | ||
| 220 | - public static int tp_clear(IntPtr ob) | ||
| 220 | + protected override void Clear() | ||
| 221 | 221 | { | |
| 222 | - var self = (MethodObject)GetManagedObject(ob); | ||
| 223 | - self.ClearMembers(); | ||
| 224 | - ClearObjectDict(ob); | ||
| 225 | - return 0; | ||
| 222 | + this.ClearMembers(); | ||
| 223 | + ClearObjectDict(this.pyHandle); | ||
| 224 | + base.Clear(); | ||
| 226 | 225 | } | |
| 227 | 226 | ||
| 228 | 227 | protected override void OnSave(InterDomainContext context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -295,12 +295,6 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 295 | 295 | return Runtime.PyString_FromString($"<module '{self.moduleName}'>"); | |
| 296 | 296 | } | |
| 297 | 297 | ||
| 298 | - protected override void Dealloc() | ||
| 299 | - { | ||
| 300 | - tp_clear(this.pyHandle); | ||
| 301 | - base.Dealloc(); | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | 298 | public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |
| 305 | 299 | { | |
| 306 | 300 | var self = (ModuleObject)GetManagedObject(ob); | |
@@ -314,17 +308,22 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg) | |||
| 314 | 308 | return 0; | |
| 315 | 309 | } | |
| 316 | 310 | ||
| 317 | - public static int tp_clear(IntPtr ob) | ||
| 311 | + protected override void Dealloc() | ||
| 318 | 312 | { | |
| 319 | - var self = (ModuleObject)GetManagedObject(ob); | ||
| 320 | - Runtime.Py_CLEAR(ref self.dict); | ||
| 321 | - ClearObjectDict(ob); | ||
| 322 | - foreach (var attr in self.cache.Values) | ||
| 313 | + tp_clear(this.pyHandle); | ||
| 314 | + base.Dealloc(); | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + protected override void Clear() | ||
| 318 | + { | ||
| 319 | + Runtime.Py_CLEAR(ref this.dict); | ||
| 320 | + ClearObjectDict(this.pyHandle); | ||
| 321 | + foreach (var attr in this.cache.Values) | ||
| 323 | 322 | { | |
| 324 | 323 | Runtime.XDecref(attr.pyHandle); | |
| 325 | 324 | } | |
| 326 | - self.cache.Clear(); | ||
| 327 | - return 0; | ||
| 325 | + this.cache.Clear(); | ||
| 326 | + base.Clear(); | ||
| 328 | 327 | } | |
| 329 | 328 | ||
| 330 | 329 | protected override void OnSave(InterDomainContext context) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,5 +63,11 @@ protected override void Dealloc() | |||
| 63 | 63 | Runtime.Py_CLEAR(ref this.target); | |
| 64 | 64 | base.Dealloc(); | |
| 65 | 65 | } | |
| 66 | + | ||
| 67 | + protected override void Clear() | ||
| 68 | + { | ||
| 69 | + Runtime.Py_CLEAR(ref this.target); | ||
| 70 | + base.Clear(); | ||
| 71 | + } | ||
| 66 | 72 | } | |
| 67 | 73 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments