Fix passing/getting packed structs to/from foreign functions.

Fixes #16574.