cffi / cffi

The Common Foreign Function Interface
http://common-lisp.net/project/cffi
MIT License
440 stars 134 forks source link

FOREIGN-ARRAY-TYPE is both an aggregate and a built-in type #362

Open rssoc opened 1 year ago

rssoc commented 1 year ago

FOREIGN-ARRAY-TYPE is an alias for FOREIGN-POINTER-TYPE, however the specialization of FOREIGN-TYPE-SIZE and FOREIGN-TYPE-ALIGNMENT on FOREIGN-ARRAY-TYPE ignores that the type is ultimately backed by a pointer, and calculates it's own size and alignment based on the ELEMENT-TYPE.

On DEFCSTRUCT forms with slots that use this type, this causes a myriad of unexpected behavior (#300, #296, #171 (comment)).

Further, note that libffi does not have native support for array-types, and the suggestion at the time of writing is to unroll arrays into members of the structure. This is technically what :COUNT does, but for consistency sake (and for the future possibility of depreciating :COUNT), DEFCSTRUCT should do this for array types too.