Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
all Dealloc overrides simply duplicate Clear, so just call both from …
…tp_dealloc and don't override Dealloc
  • Loading branch information
lostmsu committed May 23, 2021
commit b1dbe5e927cfb5c9e2285e7a2888f4d5cea3457d
12 changes: 0 additions & 12 deletions src/runtime/constructorbinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ public static IntPtr tp_repr(IntPtr ob)
return self.repr;
}

protected override void Dealloc()
{
Runtime.Py_CLEAR(ref this.repr);
base.Dealloc();
}

protected override void Clear()
{
Runtime.Py_CLEAR(ref this.repr);
Expand Down Expand Up @@ -247,12 +241,6 @@ public static IntPtr tp_repr(IntPtr ob)
return self.repr;
}

protected override void Dealloc()
{
Runtime.Py_CLEAR(ref this.repr);
base.Dealloc();
}

protected override void Clear()
{
Runtime.Py_CLEAR(ref this.repr);
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/eventbinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString(s);
}

protected override void Dealloc()
{
Runtime.Py_CLEAR(ref this.target);
base.Dealloc();
}

protected override void Clear()
{
Runtime.Py_CLEAR(ref this.target);
Expand Down
10 changes: 0 additions & 10 deletions src/runtime/eventobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ public static IntPtr tp_repr(IntPtr ob)
}


protected override void Dealloc()
{
if (this.unbound is not null)
{
Runtime.XDecref(this.unbound.pyHandle);
this.unbound = null;
}
base.Dealloc();
}

protected override void Clear()
{
if (this.unbound is not null)
Expand Down
15 changes: 12 additions & 3 deletions src/runtime/extensiontype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ void SetupGc ()

protected virtual void Dealloc()
{
ClearObjectDict(this.pyHandle);
var type = Runtime.PyObject_TYPE(this.ObjectReference);
Runtime.PyObject_GC_Del(this.pyHandle);
// Not necessary for decref of `tpHandle`.
// Not necessary for decref of `tpHandle` - it is borrowed

this.FreeGCHandle();

// we must decref our type: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc
Runtime.XDecref(type.DangerousGetAddress());
}

/// <summary>DecRefs and nulls any fields pointing back to Python</summary>
protected virtual void Clear() { }
protected virtual void Clear()
{
ClearObjectDict(this.pyHandle);
// Not necessary for decref of `tpHandle` - it is borrowed
}

/// <summary>
/// Type __setattr__ implementation.
Expand Down Expand Up @@ -96,6 +104,7 @@ public static void tp_dealloc(IntPtr ob)
// Clean up a Python instance of this extension type. This
// frees the allocated Python object and decrefs the type.
var self = (ExtensionType)GetManagedObject(ob);
self?.Clear();
self?.Dealloc();
}

Expand Down
15 changes: 2 additions & 13 deletions src/runtime/methodbinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,10 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString($"<{type} method '{name}'>");
}

private void ClearMembers()
{
Runtime.Py_CLEAR(ref target);
Runtime.Py_CLEAR(ref targetType);
}

protected override void Dealloc()
{
this.ClearMembers();
base.Dealloc();
}

protected override void Clear()
{
this.ClearMembers();
Runtime.Py_CLEAR(ref this.target);
Runtime.Py_CLEAR(ref this.targetType);
base.Clear();
}

Expand Down
21 changes: 5 additions & 16 deletions src/runtime/methodobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,15 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString($"<method '{self.name}'>");
}

private void ClearMembers()
protected override void Clear()
{
Runtime.Py_CLEAR(ref doc);
if (unbound != null)
Runtime.Py_CLEAR(ref this.doc);
if (this.unbound != null)
{
Runtime.XDecref(unbound.pyHandle);
unbound = null;
Runtime.XDecref(this.unbound.pyHandle);
this.unbound = null;
}
}

protected override void Dealloc()
{
this.ClearMembers();
ClearObjectDict(this.pyHandle);
base.Dealloc();
}

protected override void Clear()
{
this.ClearMembers();
ClearObjectDict(this.pyHandle);
base.Clear();
}
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/moduleobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,6 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
return 0;
}

protected override void Dealloc()
{
tp_clear(this.pyHandle);
base.Dealloc();
}

protected override void Clear()
{
Runtime.Py_CLEAR(ref this.dict);
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/overload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ public static IntPtr tp_repr(IntPtr op)
return doc;
}

protected override void Dealloc()
{
Runtime.Py_CLEAR(ref this.target);
base.Dealloc();
}

protected override void Clear()
{
Runtime.Py_CLEAR(ref this.target);
Expand Down