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

Commit993707e

Browse files
committed
all Dealloc overrides simply duplicate Clear, so just call both from tp_dealloc and don't override Dealloc
1 parent786b450 commit993707e

File tree

8 files changed

+19
-72
lines changed

8 files changed

+19
-72
lines changed

‎src/runtime/constructorbinding.cs

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

152-
protectedoverridevoidDealloc()
153-
{
154-
Runtime.Py_CLEAR(refthis.repr);
155-
base.Dealloc();
156-
}
157-
158152
protectedoverridevoidClear()
159153
{
160154
Runtime.Py_CLEAR(refthis.repr);
@@ -247,12 +241,6 @@ public static IntPtr tp_repr(IntPtr ob)
247241
returnself.repr;
248242
}
249243

250-
protectedoverridevoidDealloc()
251-
{
252-
Runtime.Py_CLEAR(refthis.repr);
253-
base.Dealloc();
254-
}
255-
256244
protectedoverridevoidClear()
257245
{
258246
Runtime.Py_CLEAR(refthis.repr);

‎src/runtime/eventbinding.cs

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

106-
protectedoverridevoidDealloc()
107-
{
108-
Runtime.Py_CLEAR(refthis.target);
109-
base.Dealloc();
110-
}
111-
112106
protectedoverridevoidClear()
113107
{
114108
Runtime.Py_CLEAR(refthis.target);

‎src/runtime/eventobject.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,6 @@ public static IntPtr tp_repr(IntPtr ob)
198198
}
199199

200200

201-
protectedoverridevoidDealloc()
202-
{
203-
if(this.unboundis notnull)
204-
{
205-
Runtime.XDecref(this.unbound.pyHandle);
206-
this.unbound=null;
207-
}
208-
base.Dealloc();
209-
}
210-
211201
protectedoverridevoidClear()
212202
{
213203
if(this.unboundis notnull)

‎src/runtime/extensiontype.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,22 @@ void SetupGc ()
5656

5757
protectedvirtualvoidDealloc()
5858
{
59-
ClearObjectDict(this.pyHandle);
59+
vartype=Runtime.PyObject_TYPE(this.ObjectReference);
6060
Runtime.PyObject_GC_Del(this.pyHandle);
61-
// Not necessary for decref of `tpHandle`.
61+
// Not necessary for decref of `tpHandle` - it is borrowed
62+
6263
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());
6367
}
6468

6569
/// <summary>DecRefs and nulls any fields pointing back to Python</summary>
66-
protectedvirtualvoidClear(){}
70+
protectedvirtualvoidClear()
71+
{
72+
ClearObjectDict(this.pyHandle);
73+
// Not necessary for decref of `tpHandle` - it is borrowed
74+
}
6775

6876
/// <summary>
6977
/// Type __setattr__ implementation.
@@ -96,6 +104,7 @@ public static void tp_dealloc(IntPtr ob)
96104
// Clean up a Python instance of this extension type. This
97105
// frees the allocated Python object and decrefs the type.
98106
varself=(ExtensionType)GetManagedObject(ob);
107+
self?.Clear();
99108
self?.Dealloc();
100109
}
101110

‎src/runtime/methodbinding.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,10 @@ public static IntPtr tp_repr(IntPtr ob)
229229
returnRuntime.PyString_FromString($"<{type} method '{name}'>");
230230
}
231231

232-
privatevoidClearMembers()
233-
{
234-
Runtime.Py_CLEAR(reftarget);
235-
Runtime.Py_CLEAR(reftargetType);
236-
}
237-
238-
protectedoverridevoidDealloc()
239-
{
240-
this.ClearMembers();
241-
base.Dealloc();
242-
}
243-
244232
protectedoverridevoidClear()
245233
{
246-
this.ClearMembers();
234+
Runtime.Py_CLEAR(refthis.target);
235+
Runtime.Py_CLEAR(refthis.targetType);
247236
base.Clear();
248237
}
249238

‎src/runtime/methodobject.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,15 @@ public static IntPtr tp_repr(IntPtr ob)
200200
returnRuntime.PyString_FromString($"<method '{self.name}'>");
201201
}
202202

203-
privatevoidClearMembers()
203+
protectedoverridevoidClear()
204204
{
205-
Runtime.Py_CLEAR(refdoc);
206-
if(unbound!=null)
205+
Runtime.Py_CLEAR(refthis.doc);
206+
if(this.unbound!=null)
207207
{
208-
Runtime.XDecref(unbound.pyHandle);
209-
unbound=null;
208+
Runtime.XDecref(this.unbound.pyHandle);
209+
this.unbound=null;
210210
}
211-
}
212211

213-
protectedoverridevoidDealloc()
214-
{
215-
this.ClearMembers();
216-
ClearObjectDict(this.pyHandle);
217-
base.Dealloc();
218-
}
219-
220-
protectedoverridevoidClear()
221-
{
222-
this.ClearMembers();
223212
ClearObjectDict(this.pyHandle);
224213
base.Clear();
225214
}

‎src/runtime/moduleobject.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,6 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
308308
return0;
309309
}
310310

311-
protectedoverridevoidDealloc()
312-
{
313-
tp_clear(this.pyHandle);
314-
base.Dealloc();
315-
}
316-
317311
protectedoverridevoidClear()
318312
{
319313
Runtime.Py_CLEAR(refthis.dict);

‎src/runtime/overload.cs

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

61-
protectedoverridevoidDealloc()
62-
{
63-
Runtime.Py_CLEAR(refthis.target);
64-
base.Dealloc();
65-
}
66-
6761
protectedoverridevoidClear()
6862
{
6963
Runtime.Py_CLEAR(refthis.target);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp