Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88b19cf

Browse files
committed
refactored tp_dealloc in ExtensionType and descendants
1 parent91e98a2 commit88b19cf

File tree

9 files changed

+52
-90
lines changed

9 files changed

+52
-90
lines changed

‎src/runtime/constructorbinding.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,10 @@ public static IntPtr tp_repr(IntPtr ob)
149149
returnself.repr;
150150
}
151151

152-
/// <summary>
153-
/// ConstructorBinding dealloc implementation.
154-
/// </summary>
155-
publicnewstaticvoidtp_dealloc(IntPtrob)
152+
protectedoverridevoidDealloc()
156153
{
157-
varself=(ConstructorBinding)GetManagedObject(ob);
158-
Runtime.XDecref(self.repr);
159-
self.Dealloc();
154+
Runtime.Py_CLEAR(refthis.repr);
155+
base.Dealloc();
160156
}
161157

162158
publicstaticinttp_clear(IntPtrob)
@@ -252,14 +248,10 @@ public static IntPtr tp_repr(IntPtr ob)
252248
returnself.repr;
253249
}
254250

255-
/// <summary>
256-
/// ConstructorBinding dealloc implementation.
257-
/// </summary>
258-
publicnewstaticvoidtp_dealloc(IntPtrob)
251+
protectedoverridevoidDealloc()
259252
{
260-
varself=(BoundContructor)GetManagedObject(ob);
261-
Runtime.XDecref(self.repr);
262-
self.Dealloc();
253+
Runtime.Py_CLEAR(refthis.repr);
254+
base.Dealloc();
263255
}
264256

265257
publicstaticinttp_clear(IntPtrob)

‎src/runtime/eventbinding.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,10 @@ public static IntPtr tp_repr(IntPtr ob)
103103
returnRuntime.PyString_FromString(s);
104104
}
105105

106-
107-
/// <summary>
108-
/// EventBinding dealloc implementation.
109-
/// </summary>
110-
publicnewstaticvoidtp_dealloc(IntPtrob)
106+
protectedoverridevoidDealloc()
111107
{
112-
varself=(EventBinding)GetManagedObject(ob);
113-
Runtime.XDecref(self.target);
114-
self.Dealloc();
108+
Runtime.Py_CLEAR(refthis.target);
109+
base.Dealloc();
115110
}
116111

117112
publicstaticinttp_clear(IntPtrob)

‎src/runtime/eventobject.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,14 @@ public static IntPtr tp_repr(IntPtr ob)
198198
}
199199

200200

201-
/// <summary>
202-
/// Descriptor dealloc implementation.
203-
/// </summary>
204-
publicnewstaticvoidtp_dealloc(IntPtrob)
201+
protectedoverridevoidDealloc()
205202
{
206-
varself=(EventObject)GetManagedObject(ob);
207-
if(self.unbound!=null)
203+
if(this.unboundis notnull)
208204
{
209-
Runtime.XDecref(self.unbound.pyHandle);
205+
Runtime.XDecref(this.unbound.pyHandle);
206+
this.unbound=null;
210207
}
211-
self.Dealloc();
208+
base.Dealloc();
212209
}
213210
}
214211

‎src/runtime/extensiontype.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,12 @@ void SetupGc ()
5454
}
5555

5656

57-
/// <summary>
58-
/// Common finalization code to support custom tp_deallocs.
59-
/// </summary>
60-
publicstaticvoidFinalizeObject(ManagedTypeself)
57+
protectedvirtualvoidDealloc()
6158
{
62-
ClearObjectDict(self.pyHandle);
63-
Runtime.PyObject_GC_Del(self.pyHandle);
59+
ClearObjectDict(this.pyHandle);
60+
Runtime.PyObject_GC_Del(this.pyHandle);
6461
// Not necessary for decref of `tpHandle`.
65-
self.FreeGCHandle();
66-
}
67-
68-
protectedvoidDealloc()
69-
{
70-
FinalizeObject(this);
62+
this.FreeGCHandle();
7163
}
7264

7365
/// <summary>
@@ -104,7 +96,7 @@ public static void tp_dealloc(IntPtr ob)
10496
// Clean up a Python instance of this extension type. This
10597
// frees the allocated Python object and decrefs the type.
10698
varself=(ExtensionType)GetManagedObject(ob);
107-
self.Dealloc();
99+
self?.Dealloc();
108100
}
109101

110102
protectedoverridevoidOnLoad(InterDomainContextcontext)

‎src/runtime/methodbinding.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public MethodBinding(MethodObject m, IntPtr target, IntPtr targetType)
3131
{
3232
Runtime.XIncref(targetType);
3333
}
34-
34+
3535
this.targetType=targetType;
3636

3737
this.info=null;
@@ -42,12 +42,6 @@ public MethodBinding(MethodObject m, IntPtr target) : this(m, target, IntPtr.Zer
4242
{
4343
}
4444

45-
privatevoidClearMembers()
46-
{
47-
Runtime.Py_CLEAR(reftarget);
48-
Runtime.Py_CLEAR(reftargetType);
49-
}
50-
5145
/// <summary>
5246
/// Implement binding of generic methods using the subscript syntax [].
5347
/// </summary>
@@ -235,14 +229,16 @@ public static IntPtr tp_repr(IntPtr ob)
235229
returnRuntime.PyString_FromString($"<{type} method '{name}'>");
236230
}
237231

238-
/// <summary>
239-
/// MethodBinding dealloc implementation.
240-
/// </summary>
241-
publicnewstaticvoidtp_dealloc(IntPtrob)
232+
privatevoidClearMembers()
242233
{
243-
varself=(MethodBinding)GetManagedObject(ob);
244-
self.ClearMembers();
245-
self.Dealloc();
234+
Runtime.Py_CLEAR(reftarget);
235+
Runtime.Py_CLEAR(reftargetType);
236+
}
237+
238+
protectedoverridevoidDealloc()
239+
{
240+
this.ClearMembers();
241+
base.Dealloc();
246242
}
247243

248244
publicstaticinttp_clear(IntPtrob)

‎src/runtime/methodobject.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ internal bool IsStatic()
120120
returnis_static;
121121
}
122122

123-
privatevoidClearMembers()
124-
{
125-
Runtime.Py_CLEAR(refdoc);
126-
if(unbound!=null)
127-
{
128-
Runtime.XDecref(unbound.pyHandle);
129-
unbound=null;
130-
}
131-
}
132-
133123
/// <summary>
134124
/// Descriptor __getattribute__ implementation.
135125
/// </summary>
@@ -210,15 +200,21 @@ public static IntPtr tp_repr(IntPtr ob)
210200
returnRuntime.PyString_FromString($"<method '{self.name}'>");
211201
}
212202

213-
/// <summary>
214-
/// Descriptor dealloc implementation.
215-
/// </summary>
216-
publicnewstaticvoidtp_dealloc(IntPtrob)
203+
privatevoidClearMembers()
217204
{
218-
varself=(MethodObject)GetManagedObject(ob);
219-
self.ClearMembers();
220-
ClearObjectDict(ob);
221-
self.Dealloc();
205+
Runtime.Py_CLEAR(refdoc);
206+
if(unbound!=null)
207+
{
208+
Runtime.XDecref(unbound.pyHandle);
209+
unbound=null;
210+
}
211+
}
212+
213+
protectedoverridevoidDealloc()
214+
{
215+
this.ClearMembers();
216+
ClearObjectDict(this.pyHandle);
217+
base.Dealloc();
222218
}
223219

224220
publicstaticinttp_clear(IntPtrob)

‎src/runtime/moduleobject.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
274274
Exceptions.SetError(e);
275275
returnIntPtr.Zero;
276276
}
277-
277+
278278

279279
if(attr==null)
280280
{
@@ -295,11 +295,10 @@ public static IntPtr tp_repr(IntPtr ob)
295295
returnRuntime.PyString_FromString($"<module '{self.moduleName}'>");
296296
}
297297

298-
publicnewstaticvoidtp_dealloc(IntPtrob)
298+
protectedoverridevoidDealloc()
299299
{
300-
varself=(ModuleObject)GetManagedObject(ob);
301-
tp_clear(ob);
302-
self.Dealloc();
300+
tp_clear(this.pyHandle);
301+
base.Dealloc();
303302
}
304303

305304
publicstaticinttp_traverse(IntPtrob,IntPtrvisit,IntPtrarg)
@@ -345,7 +344,7 @@ protected override void OnSave(InterDomainContext context)
345344
if((Runtime.PyDict_DelItemString(DictRef,pair.Key)==-1)&&
346345
(Exceptions.ExceptionMatches(Exceptions.KeyError)))
347346
{
348-
// Trying to remove a key that's not in the dictionary
347+
// Trying to remove a key that's not in the dictionary
349348
// raises an error. We don't care about it.
350349
Runtime.PyErr_Clear();
351350
}
@@ -496,7 +495,7 @@ public static Assembly AddReference(string name)
496495
/// clr.GetClrType(IComparable) gives you the Type for IComparable,
497496
/// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C#
498497
/// or clr.GetClrType(IComparable) in IronPython.
499-
///
498+
///
500499
/// </summary>
501500
/// <param name="type"></param>
502501
/// <returns>The Type object</returns>

‎src/runtime/native/TypeOffset.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ static void ValidateRequiredOffsetsPresent(PropertyInfo[] offsetProperties)
153153
"__instancecheck__",
154154
"__subclasscheck__",
155155
"AddReference",
156-
"FinalizeObject",
157156
"FindAssembly",
158157
"get_SuppressDocs",
159158
"get_SuppressOverloads",

‎src/runtime/overload.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,10 @@ public static IntPtr tp_repr(IntPtr op)
5858
returndoc;
5959
}
6060

61-
/// <summary>
62-
/// OverloadMapper dealloc implementation.
63-
/// </summary>
64-
publicnewstaticvoidtp_dealloc(IntPtrob)
61+
protectedoverridevoidDealloc()
6562
{
66-
varself=(OverloadMapper)GetManagedObject(ob);
67-
Runtime.XDecref(self.target);
68-
self.Dealloc();
63+
Runtime.Py_CLEAR(refthis.target);
64+
base.Dealloc();
6965
}
7066
}
7167
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp