ITADN

SDL_IOStream backed by stdin / stdout / stderr

#15893OpensleeptightAnsiC 创建于 2026-06-27
S
sleeptightAnsiCcommented
_followup from https://github.com/libsdl-org/SDL_shadercross/issues/220:_ > > > > [...] it seems like SDL3 doesn't expose any stdin/out/err abstraction for SDL_IOStream... Am I blind or SDL really doesn't support it? > > > > > > Yeah SDL really does not have this. SDL2 used to have SDL_RWfromFP, but it was ["removed from SDL3, to prevent incompatible C runtime issues"](https://github.com/libsdl-org/sdl2-compat/blob/cf62e9ad153f4cac3c5e1a782ba357c2e5bd350c/src/sdl2_compat.c#L3725). IMO that was misguided; the "C runtime issues" should've been just documented (and realistically it's only a potential issue on windows anyway). > > > > > > The [migration guide](https://github.com/libsdl-org/SDL/blob/4bebbec9d442a63f592cdb310b1172f535f72e7d/docs/README-migration.md?plain=1#L1522-L1626) has a somewhat incomplete/outdated port of it for SDL3, which I've [copied into my project and fixed up](https://github.com/taisei-project/taisei/blob/46b19f2b95a73b2731fd4117a4321de49ebb71d9/src/rwops/rwops_stdiofp.c). I also only needed it to open standard output and error streams. SDL3 really needs a way to access those if RWfromFP isn't coming back. > > > > TBH, the idea of SDL_RWFromFP accepting opaque FILE* is definitely bug prone and I fully understand why it was removed. However, if the implementation of stdin/out/err comes from SDL itself (and gets fully abstracted behind SDL_IOStream) I think it would be fine. On platforms where this functionality misbehaves, it could be disabled or hidden behind optional hint. I might be missing the bigger picture though. > > > > Also, it's worth noting that [SDL_process.h](https://github.com/libsdl-org/SDL/blob/8554d1c23cfaca7fe02d1fc2eea207a9a54bf635/include/SDL3/SDL_process.h#L30-L34) has the concept of reading/writing to subprocess streams, but since pure SDL3 app cannot use stdin/out without hacks, it's really inconvenient to reuse SDL for build/utility/cli tools that are intended to be invoked as subprocess (not the case for shadercross, but it's weird SDL wouldn't support this) > > No more bug prone than exposing the FILE* via SDL_PROP_IOSTREAM_STDIO_FILE_POINTER, i.e. works perfectly fine if you know what you're doing. Sometimes you need to get past the abstraction. Though I agree a dedicated interface for std streams is needed regardless. I understand the workaround already exist but it requires linking with libc/CRT and dealing with problems that come from it. SDL is supposed to abstract such problems away, so the lack of stdin/our/err abstraction is a bit inconvenient. Apologies, if this was already discussed elsewhere.
2 条评论