diff options
author | Thomas Heller <theller@ctypes.org> | 2006-11-24 18:45:39 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2006-11-24 18:45:39 (GMT) |
commit | 25d208bd464aa6b1bde8a30cc71327133edaeeb3 (patch) | |
tree | 9f6eb3a83b3b491bd7fe8a1165c68d6f31e9193d /Modules | |
parent | a3c77677caf9724ac2a9ba1183d3e594d78dfc5c (diff) | |
download | cpython-25d208bd464aa6b1bde8a30cc71327133edaeeb3.zip cpython-25d208bd464aa6b1bde8a30cc71327133edaeeb3.tar.gz cpython-25d208bd464aa6b1bde8a30cc71327133edaeeb3.tar.bz2 |
Fix bug #1598620: A ctypes structure cannot contain itself.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/stgdict.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index d701f9e..8fd9a1e 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -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); } |