Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translated sdl.zig file is incorrectly big-endian #10

Open
rohlem opened this issue Aug 11, 2021 · 2 comments
Open

translated sdl.zig file is incorrectly big-endian #10

rohlem opened this issue Aug 11, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@rohlem
Copy link
Contributor

rohlem commented Aug 11, 2021

Not sure why this is happening, but the src/binding/sdl.zig looks like it assumes big endian.

Symptoms (the ones I've found, I'm kind of new to SDL though, there might be more):

  • Audio formats AUDIO_{U,S,F}{16,32}SYS should alias the native byte ordering, but they alias MSB instead of LSB constants.
  • SDL_Swap{LE,BE}{16,32,64} and SDL_SwapFloat{LE,BE} should be no-op for native ordering and only swap for foreign ordering, again it's reversed.

These are observable in the current master branch, it's the same when locally regenerated on my x86_64 (little-endian) windows machine.


Not sure if it's the same issue, but notably, my file also contains some definitions that identify it as a windows instead of a linux build (SDL_SENSOR_WINDOWS, missing the SDL_HAPTIC_LINUX constant from master).
This is despite the -target x86_64-linux-gnu flag given to the zig translate-c invocation in gen_sdl.sh. So is that being ignored, or overruled in some strange way?

@rohlem
Copy link
Contributor Author

rohlem commented Aug 12, 2021

Looking into it, it seems like the empty stubs/endian.h file overriding the compiler-provided target-specific file is probably the cause of this.

An alternative would be to remove the stub files, and add -lc to translate-c. The downside is that the generated file grows to 22k lines, with all the standard C symbols.
That seems the more sane default to me, but I assume you'll have your reasons to choose this manual patching method instead.

@rohlem rohlem changed the title sdl.zig wrapper is incorrectly big-endian translated sdl.zig file is incorrectly big-endian Aug 12, 2021
@ikskuh
Copy link
Owner

ikskuh commented Aug 12, 2021

Thanks for info!

Yeah, i have very good reasons to do this, and i know of the shortcomings of this method. My goal is to ultimativley not depend on SDL headers anymore and just use the (hand-translated) file with the correct semantics instead.

This allows us to have nicer types, correct usage of enums, and only the SDL2 API in there. If you are using the -l method, you cannot cross-compile anymore and require the SDL file to be generated for each platform.

@ikskuh ikskuh added the bug Something isn't working label Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants