Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit 49d98e8

Browse files
committed
Clear tp_dict of ModuleObject
1 parent bdc0f72 commit 49d98e8

File tree

5 files changed

+5
-23
lines changed

5 files changed

+5
-23
lines changed

src/runtime/classbase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ public static int tp_clear(IntPtr ob)
300300
ClearObjectDict(ob);
301301
}
302302
self.tpHandle = IntPtr.Zero;
303-
Runtime.Py_CLEAR(ref self.tpHandle);
304303
return 0;
305304
}
306305
}

src/runtime/constructorbinding.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ internal class ConstructorBinding : ExtensionType
2929
public ConstructorBinding(Type type, IntPtr pyTypeHndl, ConstructorBinder ctorBinder)
3030
{
3131
this.type = type;
32-
Runtime.XIncref(pyTypeHndl);
33-
this.pyTypeHndl = pyTypeHndl;
32+
this.pyTypeHndl = pyTypeHndl; // steal a type reference
3433
this.ctorBinder = ctorBinder;
3534
repr = IntPtr.Zero;
3635
}
@@ -144,7 +143,6 @@ public static IntPtr tp_repr(IntPtr ob)
144143
{
145144
var self = (ConstructorBinding)GetManagedObject(ob);
146145
Runtime.XDecref(self.repr);
147-
Runtime.XDecref(self.pyTypeHndl);
148146
self.Dealloc();
149147
}
150148

@@ -179,8 +177,7 @@ internal class BoundContructor : ExtensionType
179177
public BoundContructor(Type type, IntPtr pyTypeHndl, ConstructorBinder ctorBinder, ConstructorInfo ci)
180178
{
181179
this.type = type;
182-
Runtime.XIncref(pyTypeHndl);
183-
this.pyTypeHndl = pyTypeHndl;
180+
this.pyTypeHndl = pyTypeHndl; // steal a type reference
184181
this.ctorBinder = ctorBinder;
185182
ctorInfo = ci;
186183
repr = IntPtr.Zero;
@@ -241,7 +238,6 @@ public static IntPtr tp_repr(IntPtr ob)
241238
{
242239
var self = (BoundContructor)GetManagedObject(ob);
243240
Runtime.XDecref(self.repr);
244-
Runtime.XDecref(self.pyTypeHndl);
245241
self.Dealloc();
246242
}
247243

src/runtime/interop.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,17 +515,6 @@ internal static ThunkInfo GetThunk(MethodInfo method, string funcType = null)
515515
}
516516

517517

518-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
519-
internal struct Thunk
520-
{
521-
public Delegate fn;
522-
523-
public Thunk(Delegate d)
524-
{
525-
fn = d;
526-
}
527-
}
528-
529518
internal class ThunkInfo
530519
{
531520
public readonly Delegate Target;

src/runtime/moduleobject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public ModuleObject(string name)
5353
Runtime.XDecref(pyfilename);
5454
Runtime.XDecref(pydocstring);
5555

56+
Runtime.XIncref(dict);
5657
Marshal.WriteIntPtr(pyHandle, ObjectOffset.DictOffset(pyHandle), dict);
5758

5859
InitializeModuleMembers();
@@ -328,8 +329,8 @@ public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
328329
public static int tp_clear(IntPtr ob)
329330
{
330331
var self = (ModuleObject)GetManagedObject(ob);
331-
Runtime.XDecref(self.dict);
332-
self.dict = IntPtr.Zero;
332+
Runtime.Py_CLEAR(ref self.dict);
333+
ClearObjectDict(ob);
333334
foreach (var attr in self.cache.Values)
334335
{
335336
Runtime.XDecref(attr.pyHandle);

src/runtime/typemanager.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,6 @@ private void ResetSlots()
11121112
Runtime.XDecref(tp_bases);
11131113
tp_bases = Runtime.PyTuple_New(0);
11141114
Marshal.WriteIntPtr(_type, TypeOffset.tp_bases, tp_bases);
1115-
1116-
// FIXME: release dict;
1117-
Marshal.WriteIntPtr(_type, TypeOffset.tp_dictoffset, IntPtr.Zero);
11181115
}
11191116

11201117
private static void OnDestruct(IntPtr ob)

0 commit comments

Comments
 (0)