FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Multiple assertion failures for Python classes derived from System.Exception in debug builds · Issue #1218 · pythonnet/pythonnet · GitHub

Repository navigation

Multiple assertion failures for Python classes derived from System.Exception in debug builds #1218

Closed

Description

Environment

  • Pythonnet version: 2.5.1
  • Python version: 3.8
  • Operating System: Win 10 64

Details

In debug build (DebugWinPY3) this test:

class Sub(System.Exception):

fails this assertion:

Debug.Assert(typeSize > 0 && typeSize <= ExceptionOffset.Size());

Python type object for Sub class gets an unknown extra field of size IntPtr.Size, causing it to be larger than its base type object (reflected) System.Exception.

See also #1196 (comment) for previous discussion.

@koubaa @amos402

Activity

  1. lostmsu commented on Sep 11, 2020

    MemberAuthor

    It seems that the reason is that System.Exception has no weak list associated with it:

    Marshal.ReadInt32(type, TypeOffset.tp_weaklistoffset) // type == Sub
    80
    Marshal.ReadInt32(Marshal.ReadIntPtr(type, TypeOffset.tp_base), TypeOffset.tp_weaklistoffset)
    0

  2. amos402 commented on Sep 11, 2020

    Member

    Because it used tp_basicsize as the slot to save GCHandle, you can test it on soft-shutdown branch, it should be fine.
    https://github.com/amos402/pythonnet/blob/12c0206b94173935864e0434ec22898753ffb6b5/src/runtime/interop.cs#L116-L117
    I changed the slot.

  3. lostmsu commented on Sep 11, 2020

    MemberAuthor

    @amos402 not exactly sure what you mean. The reflected System.Exception should already have a slot for GCHandle. If that would be the reason, size of Sub would be equal to size of System.Exception, but it is not.

  4. amos402 commented on Sep 11, 2020

    Member


    Trust me, it fixed.

    The reason is as I said. The size of Sub come from type(System.Exception)->tp_basicsize, they're not equal.

  5. koubaa commented on Sep 13, 2020

    Contributor

    @lostmsu @amos402 I just took Amos's interop changes from the soft shutdown branch and applied them to master, and this issue goes away. I'll submit a PR soon with this change, even if it doesn't fix my PyType_FromSpec it could still make the soft shutdown branch easier to review without these changes

  6. koubaa commented on Oct 24, 2020

    Contributor

    Fixed in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL