Skip to content
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

assertion failure in ctypes in case an _anonymous_ attr appears outside _fields_ #75671

Closed
orenmn mannequin opened this issue Sep 16, 2017 · 6 comments
Closed

assertion failure in ctypes in case an _anonymous_ attr appears outside _fields_ #75671

orenmn mannequin opened this issue Sep 16, 2017 · 6 comments
Labels
3.7 (EOL) end of life topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Sep 16, 2017

BPO 31490
Nosy @serhiy-storchaka, @orenmn
PRs
  • bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_ #3615
  • [3.6] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) #3774
  • [2.7] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) #3780
  • [2.7] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) #3952
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-10-12.15:02:42.915>
    created_at = <Date 2017-09-16.09:57:38.930>
    labels = ['ctypes', '3.7', 'type-crash']
    title = 'assertion failure in ctypes in case an _anonymous_ attr appears outside _fields_'
    updated_at = <Date 2017-10-12.15:02:42.914>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2017-10-12.15:02:42.914>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-12.15:02:42.915>
    closer = 'serhiy.storchaka'
    components = ['ctypes']
    creation = <Date 2017-09-16.09:57:38.930>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31490
    keywords = ['patch']
    message_count = 6.0
    messages = ['302331', '302363', '303091', '303108', '303908', '304243']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'Oren Milman']
    pr_nums = ['3615', '3774', '3780', '3952']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31490'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Sep 16, 2017

    The following code causes an assertion failure:
    import ctypes
    class BadStruct(ctypes.Structure):
    _fields_ = []
    _anonymous_ = ['foo']
    foo = None

    this is because MakeAnonFields() (in Modules/_ctypes/stgdict.c) goes over the
    names specified in _anonymous_, and looks each name up in the class by calling
    PyObject_GetAttr().
    in case an attribute of such a name is found (i.e. PyObject_GetAttr() succeeded),
    MakeAnonFields() assumes that the attribute was created by MakeFields(), so it
    asserts the type of the attribute is PyCField_Type.

    however, PyObject_GetAttr() would succeed also in case it is a normal attribute
    specified by the user, but isn't specified in _fields_, as in the code above.
    in such a case, the type of the attribute is not PyCField_Type, and so the
    assertion fails.

    @orenmn orenmn mannequin added 3.7 (EOL) end of life topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump labels Sep 16, 2017
    @serhiy-storchaka
    Copy link
    Member

    New changeset 30b61b5 by Serhiy Storchaka (Oren Milman) in branch 'master':
    bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (bpo-3615)
    30b61b5

    @serhiy-storchaka
    Copy link
    Member

    New changeset bdb215b by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
    [3.6] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) (bpo-3774)
    bdb215b

    @serhiy-storchaka
    Copy link
    Member

    New changeset 9bfa55b by Serhiy Storchaka (Miss Islington (bot)) in branch '2.7':
    [2.7] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) (bpo-3780)
    9bfa55b

    @serhiy-storchaka
    Copy link
    Member

    In 2.7 "%U" is not recognized in the format string.

    >>> class Name(Structure):
    ...     _fields_ = []
    ...     _anonymous_ = ["x"]
    ...     x = 42
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: '%U' is specified in _anonymous_ but not in _fields_

    @serhiy-storchaka
    Copy link
    Member

    New changeset fb3bb8d by Serhiy Storchaka (Oren Milman) in branch '2.7':
    [2.7] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) (bpo-3952)
    fb3bb8d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-ctypes type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant