@@ -143,7 +143,7 @@ internal static IntPtr GetTypeHandle(ManagedType obj, Type type)
143
143
/// </summary>
144
144
internal static IntPtr CreateType ( Type impl )
145
145
{
146
- IntPtr type = AllocateTypeObject ( impl . Name ) ;
146
+ IntPtr type = AllocateTypeObject ( impl . Name , metatype : Runtime . PyTypeType ) ;
147
147
int ob_size = ObjectOffset . Size ( type ) ;
148
148
149
149
// Set tp_basicsize to the size of our managed instance objects.
@@ -212,7 +212,7 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)
212
212
base_ = bc . pyHandle ;
213
213
}
214
214
215
- IntPtr type = AllocateTypeObject ( name ) ;
215
+ IntPtr type = AllocateTypeObject ( name , Runtime . PyCLRMetaType ) ;
216
216
217
217
Marshal . WriteIntPtr ( type , TypeOffset . ob_type , Runtime . PyCLRMetaType ) ;
218
218
Runtime . XIncref ( Runtime . PyCLRMetaType ) ;
@@ -427,12 +427,15 @@ internal static IntPtr CreateMetaType(Type impl, out SlotsHolder slotsHolder)
427
427
// the standard type slots, and has to subclass PyType_Type for
428
428
// certain functions in the C runtime to work correctly with it.
429
429
430
- IntPtr type = AllocateTypeObject ( "CLR Metatype" ) ;
431
- IntPtr py_type = Runtime . PyTypeType ;
430
+ IntPtr type = AllocateTypeObject ( "CLR Metatype" , metatype : Runtime . PyTypeType ) ;
432
431
432
+ IntPtr py_type = Runtime . PyTypeType ;
433
433
Marshal . WriteIntPtr ( type , TypeOffset . tp_base , py_type ) ;
434
434
Runtime . XIncref ( py_type ) ;
435
435
436
+ int size = TypeOffset . magic ( ) + IntPtr . Size ;
437
+ Marshal . WriteIntPtr ( type , TypeOffset . tp_basicsize , new IntPtr ( size ) ) ;
438
+
436
439
const int flags = TypeFlags . Default
437
440
| TypeFlags . Managed
438
441
| TypeFlags . HeapType
@@ -522,7 +525,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
522
525
// Utility to create a subtype of a std Python type, but with
523
526
// a managed type able to override implementation
524
527
525
- IntPtr type = AllocateTypeObject ( name ) ;
528
+ IntPtr type = AllocateTypeObject ( name , metatype : Runtime . PyTypeType ) ;
526
529
//Marshal.WriteIntPtr(type, TypeOffset.tp_basicsize, (IntPtr)obSize);
527
530
//Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, IntPtr.Zero);
528
531
@@ -564,9 +567,9 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
564
567
/// <summary>
565
568
/// Utility method to allocate a type object & do basic initialization.
566
569
/// </summary>
567
- internal static IntPtr AllocateTypeObject ( string name )
570
+ internal static IntPtr AllocateTypeObject ( string name , IntPtr metatype )
568
571
{
569
- IntPtr type = Runtime . PyType_GenericAlloc ( Runtime . PyTypeType , 0 ) ;
572
+ IntPtr type = Runtime . PyType_GenericAlloc ( metatype , 0 ) ;
570
573
// Clr type would not use __slots__,
571
574
// and the PyMemberDef after PyHeapTypeObject will have other uses(e.g. type handle),
572
575
// thus set the ob_size to 0 for avoiding slots iterations.
0 commit comments