Tightened the source code and README documentations in the library.

This commit is contained in:
2026-09-18 12:45:39 +02:00
parent c9f887bacb
commit 9ae10590cc
97 changed files with 854 additions and 1142 deletions
+6 -13
View File
@@ -1,18 +1,14 @@
internal import CPlaydate
/// Internal C-string helpers shared by the wrappers.
///
/// Passing strings to C goes through the standard `withCString`, which hands
/// out a pointer to the string's own null-terminated storage without copying.
/// C-string helpers. Strings passed to C use `withCString`, which doesn't copy.
extension String {
/// Creates a string from a nullable C string, or `nil` if the pointer is null.
/// `nil` if `pointer` is null.
init?(playdateCString pointer: UnsafePointer<CChar>?) {
guard let pointer else { return nil }
self.init(cString: pointer)
}
/// Copies the string into a newly allocated null-terminated C string.
/// The caller owns the memory and must free it with `deallocate()`.
/// New null-terminated copy; the caller frees it with `deallocate()`.
func copiedPlaydateCString() -> UnsafeMutablePointer<CChar> {
withCString { cString in
let count = utf8.count + 1
@@ -24,12 +20,9 @@ extension String {
}
#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.
/// The pointer is later released with plain `free`, so it cannot be offset
/// to adjust alignment; the firmware allocator's natural alignment has to
/// satisfy the request, which the precondition asserts.
/// `posix_memalign(3)` for the Embedded Swift runtime; the device C library lacks it.
/// Uses `malloc` (the firmware allocator). Freed with plain `free`, so no alignment offset:
/// the precondition checks `malloc`'s alignment suffices. Traps on failure; else returns 0.
@c(posix_memalign)
public func posix_memalign(
_ memptr: UnsafeMutablePointer<UnsafeMutableRawPointer?>,