Implemented a "posix_memalign" shim on Support in the PlayDate binding target for Embedded Swift on device.

This commit is contained in:
2026-07-25 10:12:17 +02:00
parent 69813b2a76
commit 06bd50ea83
+19
View File
@@ -67,3 +67,22 @@ extension String {
return buffer
}
}
#if hasFeature(Embedded) && !os(macOS)
/// The Embedded Swift runtime allocates through `posix_memalign(3)`, which
/// the Playdate device C library does not provide. Memory comes from
/// `malloc`, which the SDK's setup code routes to the firmware allocator;
/// that allocator hands out sufficiently aligned blocks, so alignment is
/// only asserted, not adjusted.
@_cdecl("posix_memalign")
public func posix_memalign(
_ memptr: UnsafeMutablePointer<UnsafeMutableRawPointer?>,
_ alignment: Int,
_ size: Int
) -> CInt {
guard let allocation = malloc(size + alignment - 1) else { fatalError() }
precondition(Int(bitPattern: allocation) % alignment == 0)
memptr.pointee = allocation
return 0
}
#endif