mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix bug #1598620: A ctypes structure cannot contain itself.
This commit is contained in:
parent
a3c77677ca
commit
25d208bd46
3 changed files with 45 additions and 3 deletions
|
@ -339,14 +339,14 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
|
|||
stgdict = PyType_stgdict(type);
|
||||
if (!stgdict)
|
||||
return -1;
|
||||
/* If this structure/union is already marked final we cannot assign
|
||||
_fields_ anymore. */
|
||||
|
||||
if (stgdict->flags & DICTFLAG_FINAL) {/* is final ? */
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"_fields_ is final");
|
||||
return -1;
|
||||
}
|
||||
/* XXX This should probably be moved to a point when all this
|
||||
stuff is sucessfully finished. */
|
||||
stgdict->flags |= DICTFLAG_FINAL; /* set final */
|
||||
|
||||
if (stgdict->ffi_type_pointer.elements)
|
||||
PyMem_Free(stgdict->ffi_type_pointer.elements);
|
||||
|
@ -480,5 +480,15 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
|
|||
stgdict->size = size;
|
||||
stgdict->align = total_align;
|
||||
stgdict->length = len; /* ADD ffi_ofs? */
|
||||
|
||||
/* We did check that this flag was NOT set above, it must not
|
||||
have been set until now. */
|
||||
if (stgdict->flags & DICTFLAG_FINAL) {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Structure or union cannot contain itself");
|
||||
return -1;
|
||||
}
|
||||
stgdict->flags |= DICTFLAG_FINAL;
|
||||
|
||||
return MakeAnonFields(type);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue