Skip to content

Commit 37305c7

Browse files
committed
gh-148573: correct allocation of complex types in the ctypes
Old code relying on implementation detail, that elements[1] for the FFI_TYPE_COMPLEX was never read. But this type actually shares same assumption as the FFI_TYPE_STRUCT: the elements field is a NULL-terminated array of pointers to ffi_type objects. So far for primitive types - only complex types have this struct field as non-NULL (two element array).
1 parent 820c5d8 commit 37305c7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,8 @@ PyCSimpleType_init(PyObject *self, PyObject *args, PyObject *kwds)
23822382
stginfo->ffi_type_pointer = *fmt->pffi_type;
23832383
}
23842384
else {
2385-
const size_t els_size = sizeof(fmt->pffi_type->elements);
2385+
assert(fmt->pffi_type->type == FFI_TYPE_COMPLEX);
2386+
const size_t els_size = sizeof(2 * sizeof(ffi_type *));
23862387
stginfo->ffi_type_pointer.size = fmt->pffi_type->size;
23872388
stginfo->ffi_type_pointer.alignment = fmt->pffi_type->alignment;
23882389
stginfo->ffi_type_pointer.type = fmt->pffi_type->type;

0 commit comments

Comments
 (0)