libvmz: stop manually mirroring C structs in Swift #25

Open
opened 2026-05-22 10:37:37 +00:00 by rc · 0 comments
Owner

Problem:

  • The Swift bridge manually mirrors the C VMZConfig layout as VMConfig.
  • The Swift definition is separate from lib/libvmz.h.

Why this is bad:

  • If the C header changes and the Swift mirror is not updated exactly, callers can hit silent ABI corruption.
  • Field order, padding, and type changes become high-risk.
  • This is especially risky because VMZConfig is public ABI.

Suggested fix:

  • Make Swift import the C declaration instead of duplicating the struct.
  • Alternatively route access through a tiny C shim that reads fields from the canonical C struct.
  • Add compile-time/layout checks if duplication remains unavoidable.

Relevant code:

  • lib/libvmz.h: public VMZConfig declaration.
  • lib/libvmz.swift: public struct VMConfig mirrors the C fields manually.
Problem: - The Swift bridge manually mirrors the C VMZConfig layout as VMConfig. - The Swift definition is separate from lib/libvmz.h. Why this is bad: - If the C header changes and the Swift mirror is not updated exactly, callers can hit silent ABI corruption. - Field order, padding, and type changes become high-risk. - This is especially risky because VMZConfig is public ABI. Suggested fix: - Make Swift import the C declaration instead of duplicating the struct. - Alternatively route access through a tiny C shim that reads fields from the canonical C struct. - Add compile-time/layout checks if duplication remains unavoidable. Relevant code: - lib/libvmz.h: public VMZConfig declaration. - lib/libvmz.swift: public struct VMConfig mirrors the C fields manually.
Sign in to join this conversation.
No labels
highprio
lowprio
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rc/vmz#25
No description provided.