Issue 31490: assertion failure in ctypes in case an anonymous attr appears outside fields (original) (raw)

Created on 2017-09-16 09:57 by Oren Milman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)

msg302331 - (view)

Author: Oren Milman (Oren Milman) *

Date: 2017-09-16 09:57

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.

msg302363 - (view)

Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer)

Date: 2017-09-17 10:45

New changeset 30b61b51e05d2d43e8e2e783b0a9df738535423b 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. (#3615) https://github.com/python/cpython/commit/30b61b51e05d2d43e8e2e783b0a9df738535423b

msg303091 - (view)

Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer)

Date: 2017-09-27 04:37

New changeset bdb215b18a42360b6a9c82876fa71f19ca1a416d 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) (#3774) https://github.com/python/cpython/commit/bdb215b18a42360b6a9c82876fa71f19ca1a416d

msg303108 - (view)

Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer)

Date: 2017-09-27 06:52

New changeset 9bfa55bfea60553831e99dbbca6a7c7d1065fd4b 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) (#3780) https://github.com/python/cpython/commit/9bfa55bfea60553831e99dbbca6a7c7d1065fd4b

msg303908 - (view)

Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer)

Date: 2017-10-08 12:02

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 "", line 1, in AttributeError: '%U' is specified in anonymous but not in fields

msg304243 - (view)

Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer)

Date: 2017-10-12 14:39

New changeset fb3bb8d5d5d70acaaa0fdec15c137544fdd4463f 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) (#3952) https://github.com/python/cpython/commit/fb3bb8d5d5d70acaaa0fdec15c137544fdd4463f

History

Date

User

Action

Args

2022-04-11 14:58:52

admin

set

github: 75671

2017-10-12 15:02:42

serhiy.storchaka

set

status: open -> closed
stage: patch review -> resolved

2017-10-12 14:39:03

serhiy.storchaka

set

messages: +

2017-10-11 13:24:32

Oren Milman

set

stage: resolved -> patch review
pull_requests: + <pull%5Frequest3927>

2017-10-08 12:02:58

serhiy.storchaka

set

status: closed -> open

messages: +

2017-09-27 06:53:22

serhiy.storchaka

set

status: open -> closed
resolution: fixed
stage: patch review -> resolved

2017-09-27 06:52:46

serhiy.storchaka

set

messages: +

2017-09-27 05:51:08

python-dev

set

pull_requests: + <pull%5Frequest3767>

2017-09-27 04:37:39

serhiy.storchaka

set

messages: +

2017-09-26 23:24:06

python-dev

set

pull_requests: + <pull%5Frequest3761>

2017-09-17 10:46:13

serhiy.storchaka

set

versions: + Python 2.7, Python 3.6

2017-09-17 10:45:40

serhiy.storchaka

set

nosy: + serhiy.storchaka
messages: +

2017-09-16 11:33:24

Oren Milman

set

keywords: + patch
stage: patch review
pull_requests: + <pull%5Frequest3606>

2017-09-16 09:57:38

Oren Milman

create