@@ -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 ) ;
@@ -443,12 +443,15 @@ internal static IntPtr CreateMetaType(Type impl, out SlotsHolder slotsHolder)
443
443
// the standard type slots, and has to subclass PyType_Type for
444
444
// certain functions in the C runtime to work correctly with it.
445
445
446
- IntPtr type = AllocateTypeObject ( "CLR Metatype" ) ;
447
- IntPtr py_type = Runtime . PyTypeType ;
446
+ IntPtr type = AllocateTypeObject ( "CLR Metatype" , metatype : Runtime . PyTypeType ) ;
448
447
448
+ IntPtr py_type = Runtime . PyTypeType ;
449
449
Marshal . WriteIntPtr ( type , TypeOffset . tp_base , py_type ) ;
450
450
Runtime . XIncref ( py_type ) ;
451
451
452
+ int size = TypeOffset . magic ( ) + IntPtr . Size ;
453
+ Marshal . WriteIntPtr ( type , TypeOffset . tp_basicsize , new IntPtr ( size ) ) ;
454
+
452
455
const int flags = TypeFlags . Default
453
456
| TypeFlags . Managed
454
457
| TypeFlags . HeapType
@@ -538,7 +541,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
538
541
// Utility to create a subtype of a std Python type, but with
539
542
// a managed type able to override implementation
540
543
541
- IntPtr type = AllocateTypeObject ( name ) ;
544
+ IntPtr type = AllocateTypeObject ( name , metatype : Runtime . PyTypeType ) ;
542
545
//Marshal.WriteIntPtr(type, TypeOffset.tp_basicsize, (IntPtr)obSize);
543
546
//Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, IntPtr.Zero);
544
547
@@ -580,9 +583,9 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
580
583
/// <summary>
581
584
/// Utility method to allocate a type object & do basic initialization.
582
585
/// </summary>
583
- internal static IntPtr AllocateTypeObject ( string name )
586
+ internal static IntPtr AllocateTypeObject ( string name , IntPtr metatype )
584
587
{
585
- IntPtr type = Runtime . PyType_GenericAlloc ( Runtime . PyTypeType , 0 ) ;
588
+ IntPtr type = Runtime . PyType_GenericAlloc ( metatype , 0 ) ;
586
589
// Clr type would not use __slots__,
587
590
// and the PyMemberDef after PyHeapTypeObject will have other uses(e.g. type handle),
588
591
// thus set the ob_size to 0 for avoiding slots iterations.