summaryrefslogtreecommitdiff
path: root/Modules/_ctypes/stgdict.c
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2019-10-31 08:03:54 +0000
committerGitHub <noreply@github.com>2019-10-31 08:03:54 +0000
commit79d4ed102a5069c6cebaed2627cb1645637f0429 (patch)
treed163eaefd7890bff55c1ca81d9666705634c79b3 /Modules/_ctypes/stgdict.c
parentbdac32e9fe25fdb97a7172a93aabd1ffead89462 (diff)
downloadcpython-git-79d4ed102a5069c6cebaed2627cb1645637f0429.tar.gz
bpo-16575: Add checks for unions passed by value to functions. (GH-16799)
Diffstat (limited to 'Modules/_ctypes/stgdict.c')
-rw-r--r--Modules/_ctypes/stgdict.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 97bcf5539a..1d45ade5ef 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -440,6 +440,13 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
PyMem_Free(stgdict->ffi_type_pointer.elements);
basedict = PyType_stgdict((PyObject *)((PyTypeObject *)type)->tp_base);
+ if (basedict) {
+ stgdict->flags |= (basedict->flags &
+ (TYPEFLAG_HASUNION | TYPEFLAG_HASBITFIELD));
+ }
+ if (!isStruct) {
+ stgdict->flags |= TYPEFLAG_HASUNION;
+ }
if (basedict && !use_broken_old_ctypes_semantics) {
size = offset = basedict->size;
align = basedict->align;
@@ -515,8 +522,10 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
stgdict->flags |= TYPEFLAG_HASPOINTER;
+ stgdict->flags |= dict->flags & (TYPEFLAG_HASUNION | TYPEFLAG_HASBITFIELD);
dict->flags |= DICTFLAG_FINAL; /* mark field type final */
if (PyTuple_Size(pair) == 3) { /* bits specified */
+ stgdict->flags |= TYPEFLAG_HASBITFIELD;
switch(dict->ffi_type_pointer.type) {
case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16: