8000 apply amos interop changes from soft shutdown by koubaa · Pull Request #1219 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

apply amos interop changes from soft shutdown #1219

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 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
koubaa committed Sep 17, 2020
commit bb1ebe3f67a3d72f056d3f9ab4a6231d7920a642
2 changes: 1 addition & 1 deletion src/runtime/clrobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal CLRObject(object ob, IntPtr tp)
IntPtr py = Runtime.PyType_GenericAlloc(tp, 0);

long flags = Util.ReadCLong(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Subclass) != 0)
if ((flags & (int)TypeFlags.Subclass) != 0)
{
IntPtr dict = Marshal.ReadIntPtr(py, ObjectOffset.TypeDictOffset(tp));
if (dict == IntPtr.Zero)
Expand Down
60 changes: 28 additions & 32 deletions src/runtime/interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,11 @@ static ManagedDataOffsets()
size = fields.Length * IntPtr.Size;
}

public static int GetSlotOffset(string name)
{
return NameMapping[name];
}

private static int BaseOffset(IntPtr type)
{
Debug.Assert(type != IntPtr.Zero);
int typeSize = Marshal.ReadInt32(type, TypeOffset.tp_basicsize);
Debug.Assert(typeSize > 0);
Debug.Assert(typeSize > 0 && typeSize <= ExceptionOffset.Size());
return typeSize;
}
public static int DataOffset(IntPtr type)
Expand Down Expand Up @@ -358,38 +353,39 @@ public static void FreeModuleDef(IntPtr ptr)
/// Note that the two values reserved for stackless have been put
/// to good use as PythonNet specific flags (Managed and Subclass)
/// </summary>
internal class TypeFlags
[Flags]
internal enum TypeFlags
{
public const int HeapType = (1 << 9);
public const int BaseType = (1 << 10);
public const int Ready = (1 << 12);
public const int Readying = (1 << 13);
public const int HaveGC = (1 << 14);
HeapType = (1 << 9),
BaseType = (1 << 10),
Ready = (1 << 12),
Readying = (1 << 13),
HaveGC = (1 << 14),
// 15 and 16 are reserved for stackless
public const int HaveStacklessExtension = 0;
HaveStacklessExtension = 0,
/* XXX Reusing reserved constants */
public const int Managed = (1 << 15); // PythonNet specific
public const int Subclass = (1 << 16); // PythonNet specific
public const int HaveIndex = (1 << 17);
Managed = (1 << 15), // PythonNet specific
Subclass = (1 << 16), // PythonNet specific
HaveIndex = (1 << 17),
/* Objects support nb_index in PyNumberMethods */
public const int HaveVersionTag = (1 << 18);
public const int ValidVersionTag = (1 << 19);
public const int IsAbstract = (1 << 20);
public const int HaveNewBuffer = (1 << 21);
HaveVersionTag = (1 << 18),
ValidVersionTag = (1 << 19),
IsAbstract = (1 << 20),
HaveNewBuffer = (1 << 21),
// TODO: Implement FastSubclass functions
public const int IntSubclass = (1 << 23);
public const int LongSubclass = (1 << 24);
public const int ListSubclass = (1 << 25);
public const int TupleSubclass = (1 << 26);
public const int StringSubclass = (1 << 27);
public const int UnicodeSubclass = (1 << 28);
public const int DictSubclass = (1 << 29);
public const int BaseExceptionSubclass = (1 << 30);
public const int TypeSubclass = (1 << 31);

public const int Default = (
IntSubclass = (1 << 23),
LongSubclass = (1 << 24),
ListSubclass = (1 << 25),
TupleSubclass = (1 << 26),
StringSubclass = (1 << 27),
UnicodeSubclass = (1 << 28),
DictSubclass = (1 << 29),
BaseExceptionSubclass = (1 << 30),
TypeSubclass = (1 << 31),

Default = (
HaveStacklessExtension |
HaveVersionTag);
HaveVersionTag)
}


Expand Down
4 changes: 2 additions & 2 deletions src/runtime/managedtype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static ManagedType GetManagedObject(IntPtr ob)
}

var flags = Util.ReadCLong(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Managed) != 0)
if ((flags & (int)TypeFlags.Managed) != 0)
{
IntPtr op = tp == ob
? Marshal.ReadIntPtr(tp, TypeOffset.magic())
Expand Down Expand Up @@ -68,7 +68,7 @@ internal static bool IsManagedType(IntPtr ob)
}

var flags = Util.ReadCLong(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Managed) != 0)
if ((flags & (int)TypeFlags.Managed) != 0)
{
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/metatype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
return IntPtr.Zero;
}

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

TypeManager.CopySlot(base_type, type, TypeOffset.tp_dealloc);

Expand Down Expand Up @@ -238,7 +238,7 @@ public static void tp_dealloc(IntPtr tp)
// Fix this when we dont cheat on the handle for subclasses!

var flags = Util.ReadCLong(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Subclass) == 0)
if ((flags & (int)TypeFlags.Subclass) == 0)
{
IntPtr gc = Marshal.ReadIntPtr(tp, TypeOffset.magic());
((GCHandle)gc).Free();
Expand Down
16 changes: 8 additions & 8 deletions src/runtime/typemanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ internal static IntPtr CreateType(Type impl)

InitializeSlots(type, impl);

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

Runtime.PyType_Ready(type);

Expand Down Expand Up @@ -170,12 +170,12 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)
Runtime.XIncref(base_);
}

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

// Leverage followup initialization from the Python runtime. Note
// that the type of the new type must PyType_Type at the time we
Expand Down Expand Up @@ -342,11 +342,11 @@ internal static IntPtr CreateMetaType(Type impl)

InitializeSlots(type, impl);

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

// We need space for 3 PyMethodDef structs, each of them
// 4 int-ptrs in size.
Expand Down Expand Up @@ -401,11 +401,11 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl)
Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_);
Runtime.XIncref(base_);

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

CopySlot(base_, type, TypeOffset.tp_traverse);
CopySlot(base_, type, TypeOffset.tp_clear);
Expand Down
0