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

Refactoring of tp_clear#1460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 2 commits intopythonnet:masterfromlosttech:PR/Clear
May 23, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
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
22 changes: 4 additions & 18 deletionssrc/runtime/constructorbinding.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -149,17 +149,10 @@ public static IntPtr tp_repr(IntPtr ob)
return self.repr;
}

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

public static int tp_clear(IntPtr ob)
{
var self = (ConstructorBinding)GetManagedObject(ob);
Runtime.Py_CLEAR(ref self.repr);
return 0;
base.Clear();
}

public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
Expand DownExpand Up@@ -248,17 +241,10 @@ public static IntPtr tp_repr(IntPtr ob)
return self.repr;
}

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

public static int tp_clear(IntPtr ob)
{
var self = (BoundContructor)GetManagedObject(ob);
Runtime.Py_CLEAR(ref self.repr);
return 0;
base.Clear();
}

public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
Expand Down
11 changes: 2 additions & 9 deletionssrc/runtime/eventbinding.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,17 +103,10 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString(s);
}

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

public static int tp_clear(IntPtr ob)
{
var self = (EventBinding)GetManagedObject(ob);
Runtime.Py_CLEAR(ref self.target);
return 0;
base.Clear();
}
}
}
4 changes: 2 additions & 2 deletionssrc/runtime/eventobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -198,14 +198,14 @@ public static IntPtr tp_repr(IntPtr ob)
}


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

Expand Down
26 changes: 21 additions & 5 deletionssrc/runtime/extensiontype.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,10 +56,21 @@ 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()
{
ClearObjectDict(this.pyHandle);
// Not necessary for decref of `tpHandle` - it is borrowed
}

/// <summary>
Expand DownExpand Up@@ -88,17 +99,22 @@ public static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val)
}


/// <summary>
/// Default dealloc implementation.
/// </summary>
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();
}

public static int tp_clear(IntPtr ob)
{
var self = (ExtensionType)GetManagedObject(ob);
self?.Clear();
return 0;
}

protected override void OnLoad(InterDomainContext context)
{
base.OnLoad(context);
Expand Down
20 changes: 4 additions & 16 deletionssrc/runtime/methodbinding.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -229,23 +229,11 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString($"<{type} method '{name}'>");
}

privatevoidClearMembers()
protected overridevoidClear()
{
Runtime.Py_CLEAR(ref target);
Runtime.Py_CLEAR(ref targetType);
}

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

public static int tp_clear(IntPtr ob)
{
var self = (MethodBinding)GetManagedObject(ob);
self.ClearMembers();
return 0;
Runtime.Py_CLEAR(ref this.target);
Runtime.Py_CLEAR(ref this.targetType);
base.Clear();
}

protected override void OnSave(InterDomainContext context)
Expand Down
24 changes: 6 additions & 18 deletionssrc/runtime/methodobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -200,29 +200,17 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString($"<method '{self.name}'>");
}

privatevoidClearMembers()
protected overridevoidClear()
{
Runtime.Py_CLEAR(ref doc);
if (unbound != null)
Runtime.Py_CLEAR(refthis.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();
}

public static int tp_clear(IntPtr ob)
{
var self = (MethodObject)GetManagedObject(ob);
self.ClearMembers();
ClearObjectDict(ob);
return 0;
base.Clear();
}

protected override void OnSave(InterDomainContext context)
Expand Down
19 changes: 6 additions & 13 deletionssrc/runtime/moduleobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -295,12 +295,6 @@ public static IntPtr tp_repr(IntPtr ob)
return Runtime.PyString_FromString($"<module '{self.moduleName}'>");
}

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

public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
{
var self = (ModuleObject)GetManagedObject(ob);
Expand All@@ -314,17 +308,16 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
return 0;
}

public static int tp_clear(IntPtr ob)
protected override void Clear()
{
var self = (ModuleObject)GetManagedObject(ob);
Runtime.Py_CLEAR(ref self.dict);
ClearObjectDict(ob);
foreach (var attr in self.cache.Values)
Runtime.Py_CLEAR(ref this.dict);
ClearObjectDict(this.pyHandle);
foreach (var attr in this.cache.Values)
{
Runtime.XDecref(attr.pyHandle);
}
self.cache.Clear();
return 0;
this.cache.Clear();
base.Clear();
}

protected override void OnSave(InterDomainContext context)
Expand Down
4 changes: 2 additions & 2 deletionssrc/runtime/overload.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,10 +58,10 @@ public static IntPtr tp_repr(IntPtr op)
return doc;
}

protected override voidDealloc()
protected override voidClear()
{
Runtime.Py_CLEAR(ref this.target);
base.Dealloc();
base.Clear();
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp