10000 Define slots before initialization · hollisticgit/pythonnet@8668579 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8668579

Browse files
committed
Define slots before initialization
1 parent 5636262 commit 8668579

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/runtime/PythonTypes/PyType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private static StolenReference FromSpec(TypeSpec spec, PyTuple? bases = null)
155155
using var nativeSpec = new NativeTypeSpec(spec);
156156
var basesRef = bases is null ? default : bases.Reference;
157157
var result = Runtime.PyType_FromSpecWithBases(in nativeSpec, basesRef);
158+
// Runtime.PyErr_Print();
158159
return result.StealOrThrow();
159160
}
160161
}

src/runtime/TypeManager.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,20 @@ internal static PyType CreateMetatypeWithGCHandleOffset()
475475
int size = Util.ReadInt32(Runtime.PyTypeType, TypeOffset.tp_basicsize)
476476
+ IntPtr.Size // tp_clr_inst_offset
477477
;
478-
var result = new PyType(new TypeSpec("clr._internal.GCOffsetBase", basicSize: size,
479-
new TypeSpec.Slot[]
480-
{
481-
482-
},
483-
TypeFlags.Default | TypeFlags.HeapType | TypeFlags.HaveGC),
484-
bases: new PyTuple(new[] { py_type }));
485478

486-
SetRequiredSlots(result, seen: new HashSet<string>());
487-
488-
Runtime.PyType_Modified(result);
479+
var slots = new[] {
480+
new TypeSpec.Slot(TypeSlotID.tp_traverse, subtype_traverse),
481+
new TypeSpec.Slot(TypeSlotID.tp_clear, subtype_clear)
482+
};
483+
var result = new PyType(
484+
new TypeSpec(
485+
"clr._internal.GCOffsetBase",
486+
basicSize: size,
487+
slots: slots,
488+
TypeFlags.Default | TypeFlags.HeapType | TypeFlags.HaveGC
489+
),
490+
bases: new PyTuple(new[] { py_type })
491+
);
489492

490493
return result;
491494
}

0 commit comments

Comments
 (0)
0