Elektrine lite

← Feed

@json@micro.sadlerjw.com

Post #1606372

2026-04-22 01:18 UTC

I need Swift / C interop help! I want to import a C library into my Swift project. Its type definitions _lie_ about their layout. Some structs have a field `some_c_type data[1];' but the array is actually dynamically sized at runtime. I've marked these structs as SWIFT_NONCOPYABLE and when compiling in Debug mode that's fine. The address of Swift variables of this type are consistent with the address of the C allocation. (1/3)

Replies (1)

  • @json@micro.sadlerjw.com 2026-04-22 01:18

    In Release mode, it seems that Swift is copying the memory or aliasing it or something - the address of the Swift variable is different than the address of the C allocation. And because the compiler thinks the struct's field is an array of length 1, it doesn't know to copy/alias the right amount of memory. I feel there must be a way to tell the compiler "just use the C memory as-is, where-is" (which is what happens in Debug mode). Anyone have any ideas? (2/3)

    Open ##2841646