Skip to content

Start to implement PyType_FromSpec type approach #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
change CreateType
  • Loading branch information
koubaa committed Aug 1, 2020
commit 44d364e90f7cc65d50d579abb66a69df5e57bfdc
14 changes: 7 additions & 7 deletions src/runtime/typemanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ internal static IntPtr GetTypeHandle(ManagedType obj, Type type)
/// </summary>
internal static IntPtr CreateType(Type impl)
{
IntPtr type = AllocateTypeObject(impl.Name);
var slotArray = CreateSlotArray(impl);
IntPtr type = AllocateTypeObject(impl.Name, slotArray);
int ob_size = ObjectOffset.Size(type);

// Set tp_basicsize to the size of our managed instance objects.
Expand All @@ -90,13 +91,13 @@ internal static IntPtr CreateType(Type impl)
var offset = (IntPtr)ObjectOffset.TypeDictOffset(type);
Marshal.WriteIntPtr(type, TypeOffset.tp_dictoffset, offset);

InitializeSlots(type, impl);
//InitializeSlots(type, impl);

int flags = TypeFlags.Default | TypeFlags.Managed |
TypeFlags.HeapType | TypeFlags.HaveGC;
Util.WriteCLong(type, TypeOffset.tp_flags, flags);

Runtime.PyType_Ready(type);
//Runtime.PyType_Ready(type);

IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict);
IntPtr mod = Runtime.PyString_FromString("CLR");
Expand Down Expand Up @@ -883,11 +884,10 @@ internal static void InitializeNativeCodePage()
#endregion

/// <summary>
/// Given a newly allocated Python type object and a managed Type that
/// provides the implementation for the type, connect the type slots of
/// the Python object to the managed methods of the implementing Type.
/// Given a managed Type that provides the implementation for the type,
/// create a PY_TYPE_SLOT array to be used for PyType_FromSpec.
/// </summary>
internal PY_TYPE_SLOT[] InitializeSlots(Type impl)
internal static PY_TYPE_SLOT[] CreateSlotArray(Type impl)
{
// We work from the most-derived class up; make sure to get
// the most-derived slot and not to override it with a base
Expand Down