Split SDL3 into SDL3.Raw and SDL3.Wrapped#16
Open
klukaszek wants to merge 3 commits into
Open
Conversation
* Made audio streams type-safe * Fix Wrapped.Audio phantom-type integration and example compatibility - Export format value constructors so sdlAudioSpec is usable at term level. - Fix stream device functions to unwrap phantom-typed SDLAudioStream. - Fix sizeOf hardcoded to Float in VS.Vector SDLAudioStreamPut instance. - Change Raw callback setters to accept FunPtr directly for proper lifetime management. - Add separate Get/Put callback tracking IORefs to prevent cross-orphaning. - Fix polymorphic streamCallbackRefs unsafePerformIO footgun by using monomorphic Raw types. - Add SomeSDLAudioSpec existential for runtime-discovered formats. - Add sdlGetAudioStreamDataBytes and sdlPutAudioStreamDataBytes escape hatches. - Wrap sdlMixAudio, sdlGetAudioFormatName, sdlGetSilenceValueForFormat with phantom types. - Fix sdlOpenAudioDeviceStream callback ambiguity when passing Nothing. - Update AudioExample and WAVExample to compile and run with new API. - Optimize VS.Vector instances for SDLAudioStreamGet and SDLAudioStreamPut by using new raw pointer functions (sdlGetAudioStreamDataPtr, sdlPutAudioStreamDataPtr), achieving zero-copy with unsafeFreeze. - Fix memory management in Raw.Audio by using Stdinc.free (SDL_free) for buffers allocated by SDL. - Make sdlMixAudio safe by requiring mutable destination buffers (VSM.IOVector) and using explicit scoping for type-safe sample sizes. --------- Co-authored-by: Kyle Lukaszek <kylelukaszek@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR restructures the library around explicit
SDL3.Raw.*andSDL3.Wrapped.*layers.The main goals are:
SDL3.*modulesMonadIOwhere appropriate without forcing users to think in Haskell-specific resource vocabularyWhat Changed
SDL3.Raw.*module tree for low-level FFI-shaped bindings.SDL3.Wrapped.*module tree for the higher-level/default API.SDL3.*modules as compatibility-facing modules that re-export the wrapped layer.SDL3.Rawas an umbrella re-export for migration users who want the raw layer directly.DISTRIBUTION.mdreferences from the repo.API / Behavior Notes
This is not just a directory move. Some modules needed real follow-up design work during the split.
Examples:
Surfaceno longer defaults to exposing raw surface pointers through the wrapped API.Hints,Events,System,Mouse,Tray, andAudionow manage callback lifetime more deliberately in the wrapped layer.IOStream,Process,Storage,Camera,Gamepad,Haptic,AsyncIO, andMutexwere normalized so wrapped code does not default toPtr SDL...handles for owned SDL objects.Initgot a callback cleanup fix forsdlRunOnMainThread.HintsandEventshad callback-removal correctness issues fixed as part of the split.TrayandSurfaceintegration was updated so tray icons use the wrapped surface API cleanly.Examples
The examples were updated to keep building and to use the new wrapped API surface where needed, especially around GPU/surface usage.
Verification
Verified during this work with:
cabal build lib:sdl3cabal runsmoke tests including wrapped non-GPU and GPU examplesSDL3.Rawimport smoke test compiled through CabalFollow-Up
This is intentionally being left in limbo for review because it is a large structural PR with broad API impact. I experimented with both Claude and Codex while working on this over the course of a bit. Any criticisms, concerns, and comments are welcome, as I was not even sure if I originally wanted to release this branch.
Things still worth a follow-up:
SDL3.Rawshould be documented more explicitly in the README