New submission from Oren Milman: 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. ---------- components: ctypes messages: 302331 nosy: Oren Milman priority: normal severity: normal status: open title: assertion failure in ctypes in case an _anonymous_ attr appears outside _fields_ type: crash versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31490> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com