🌐 AI搜索 & 代理 主页
Skip to content
Closed
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
Apply unified mechanism for GetManagedObjectType
  • Loading branch information
amos402 committed Oct 22, 2020
commit f08813c7dc013bc104be6848609bb7d2279580fb
14 changes: 4 additions & 10 deletions src/runtime/managedtype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,12 @@ internal static ManagedType GetManagedObject(IntPtr ob)
/// </summary>
internal static ManagedType GetManagedObjectType(IntPtr ob)
{
if (ob != IntPtr.Zero)
if (ob == IntPtr.Zero)
{
IntPtr tp = Runtime.PyObject_TYPE(ob);
var flags = Util.ReadCLong(tp, TypeOffset.tp_flags);
if ((flags & TypeFlags.Managed) != 0)
{
tp = Marshal.ReadIntPtr(tp, TypeOffset.magic());
var gc = (GCHandle)tp;
return (ManagedType)gc.Target;
}
return null;
}
return null;
IntPtr tp = Runtime.PyObject_TYPE(ob);
return GetManagedObject(tp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code is not equivalent to the original code. The original code did ob.type.tp_flags.HasFlag(Managed), and the new code only does ob.type.type.tp_flags.HasFlag(Managed).
I believe the old check might also need to be necessary.

Copy link
Member Author

@amos402 amos402 Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not equivalent. It becomes simple and faster since the memory model been unified.
You can treat the old code was a trick: ob may be a type or an object. You can also see I removed the code on the bellow

        public bool IsTypeObject()
        {
            return pyHandle == tpHandle;
        }

For now, if the type of ob is managed, then the ob must be a managed object, it's obvious on the logic.

}


Expand Down