@@ -150,7 +150,7 @@ internal static IntPtr GetTypeHandle(ManagedType obj, Type type)
150
150
/// </summary>
151
151
internal static IntPtr CreateType ( Type impl )
152
152
{
153
- IntPtr type = AllocateTypeObject ( impl . Name ) ;
153
+ IntPtr type = AllocateTypeObject ( impl . Name , metatype : Runtime . PyTypeType ) ;
154
154
int ob_size = ObjectOffset . Size ( type ) ;
155
155
156
156
// Set tp_basicsize to the size of our managed instance objects.
@@ -223,7 +223,7 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)
223
223
base_ = bc . pyHandle ;
224
224
}
225
225
226
- IntPtr type = AllocateTypeObject ( name ) ;
226
+ IntPtr type = AllocateTypeObject ( name , Runtime . PyCLRMetaType ) ;
227
227
228
228
Marshal . WriteIntPtr ( type , TypeOffset . ob_type , Runtime . PyCLRMetaType ) ;
229
229
Runtime . XIncref ( Runtime . PyCLRMetaType ) ;
@@ -438,12 +438,15 @@ internal static IntPtr CreateMetaType(Type impl, out SlotsHolder slotsHolder)
438
438
// the standard type slots, and has to subclass PyType_Type for
439
439
// certain functions in the C runtime to work correctly with it.
440
440
441
- IntPtr type = AllocateTypeObject ( "CLR Metatype" ) ;
442
- IntPtr py_type = Runtime . PyTypeType ;
441
+ IntPtr type = AllocateTypeObject ( "CLR Metatype" , metatype : Runtime . PyTypeType ) ;
443
442
443
+ IntPtr py_type = Runtime . PyTypeType ;
444
444
Marshal . WriteIntPtr ( type , TypeOffset . tp_base , py_type ) ;
445
445
Runtime . XIncref ( py_type ) ;
446
446
447
+ int size = TypeOffset . magic ( ) + IntPtr . Size ;
448
+ Marshal . WriteIntPtr ( type , TypeOffset . tp_basicsize , new IntPtr ( size ) ) ;
449
+
447
450
const int flags = TypeFlags . Default
448
451
| TypeFlags . Managed
449
452
| TypeFlags . HeapType
@@ -536,7 +539,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
536
539
// Utility to create a subtype of a std Python type, but with
537
540
// a managed type able to override implementation
538
541
539
- IntPtr type = AllocateTypeObject ( name ) ;
542
+ IntPtr type = AllocateTypeObject ( name , metatype : Runtime . PyTypeType ) ;
540
543
//Marshal.WriteIntPtr(type, TypeOffset.tp_basicsize, (IntPtr)obSize);
541
544
//Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, IntPtr.Zero);
542
545
@@ -582,9 +585,9 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
582
585
/// <summary>
583
586
/// Utility method to allocate a type object & do basic initialization.
584
587
/// </summary>
585
- internal static IntPtr AllocateTypeObject ( string name )
588
+ internal static IntPtr AllocateTypeObject ( string name , IntPtr metatype )
586
589
{
587
- IntPtr type = Runtime . PyType_GenericAlloc ( Runtime . PyTypeType , 0 ) ;
590
+ IntPtr type = Runtime . PyType_GenericAlloc ( metatype , 0 ) ;
588
591
// Clr type would not use __slots__,
589
592
// and the PyMemberDef after PyHeapTypeObject will have other uses(e.g. type handle),
590
593
// thus set the ob_size to 0 for avoiding slots iterations.
0 commit comments