Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit92cde67

Browse files
committed
allocate space for GCHandle in instances of CLR Metatype (which are types themselves)
1 parent2450cce commit92cde67

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

‎src/runtime/typemanager.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal static IntPtr GetTypeHandle(ManagedType obj, Type type)
143143
/// </summary>
144144
internalstaticIntPtrCreateType(Typeimpl)
145145
{
146-
IntPtrtype=AllocateTypeObject(impl.Name);
146+
IntPtrtype=AllocateTypeObject(impl.Name,metatype:Runtime.PyTypeType);
147147
intob_size=ObjectOffset.Size(type);
148148

149149
// Set tp_basicsize to the size of our managed instance objects.
@@ -212,7 +212,7 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)
212212
base_=bc.pyHandle;
213213
}
214214

215-
IntPtrtype=AllocateTypeObject(name);
215+
IntPtrtype=AllocateTypeObject(name,Runtime.PyCLRMetaType);
216216

217217
Marshal.WriteIntPtr(type,TypeOffset.ob_type,Runtime.PyCLRMetaType);
218218
Runtime.XIncref(Runtime.PyCLRMetaType);
@@ -443,12 +443,15 @@ internal static IntPtr CreateMetaType(Type impl, out SlotsHolder slotsHolder)
443443
// the standard type slots, and has to subclass PyType_Type for
444444
// certain functions in the C runtime to work correctly with it.
445445

446-
IntPtrtype=AllocateTypeObject("CLR Metatype");
447-
IntPtrpy_type=Runtime.PyTypeType;
446+
IntPtrtype=AllocateTypeObject("CLR Metatype",metatype:Runtime.PyTypeType);
448447

448+
IntPtrpy_type=Runtime.PyTypeType;
449449
Marshal.WriteIntPtr(type,TypeOffset.tp_base,py_type);
450450
Runtime.XIncref(py_type);
451451

452+
intsize=TypeOffset.magic()+IntPtr.Size;
453+
Marshal.WriteIntPtr(type,TypeOffset.tp_basicsize,newIntPtr(size));
454+
452455
constintflags=TypeFlags.Default
453456
|TypeFlags.Managed
454457
|TypeFlags.HeapType
@@ -538,7 +541,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
538541
// Utility to create a subtype of a std Python type, but with
539542
// a managed type able to override implementation
540543

541-
IntPtrtype=AllocateTypeObject(name);
544+
IntPtrtype=AllocateTypeObject(name,metatype:Runtime.PyTypeType);
542545
//Marshal.WriteIntPtr(type, TypeOffset.tp_basicsize, (IntPtr)obSize);
543546
//Marshal.WriteIntPtr(type, TypeOffset.tp_itemsize, IntPtr.Zero);
544547

@@ -580,9 +583,9 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
580583
/// <summary>
581584
/// Utility method to allocate a type object &amp; do basic initialization.
582585
/// </summary>
583-
internalstaticIntPtrAllocateTypeObject(stringname)
586+
internalstaticIntPtrAllocateTypeObject(stringname,IntPtrmetatype)
584587
{
585-
IntPtrtype=Runtime.PyType_GenericAlloc(Runtime.PyTypeType,0);
588+
IntPtrtype=Runtime.PyType_GenericAlloc(metatype,0);
586589
// Clr type would not use __slots__,
587590
// and the PyMemberDef after PyHeapTypeObject will have other uses(e.g. type handle),
588591
// thus set the ob_size to 0 for avoiding slots iterations.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp