-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Avoid assuming that Go structs match C strucs #501
Comments
Hi @Keithcat1, thanks for the suggestion! Would you be submitting a PR that implements this change? Otherwise, I will have a look at it when I have more time in my hand. |
dusk125
pushed a commit
to dusk125/go-sdl2
that referenced
this issue
Aug 4, 2022
Start of addressing veandco#501, more work will be required. A note: this change makes PollEvent return a stack-copy of the Event structure, rather than a pointer; this should be fine as the events are small structures.
dusk125
pushed a commit
to dusk125/go-sdl2
that referenced
this issue
Aug 4, 2022
Start of addressing veandco#501, more work will be required. A note: this change makes PollEvent return a stack-copy of the Event structure, rather than a pointer; this should be fine as the events are small structures.
veeableful
pushed a commit
that referenced
this issue
Aug 6, 2022
* Updating functions to take the enum type * Remove c-wrapping of Events Start of addressing #501, more work will be required. A note: this change makes PollEvent return a stack-copy of the Event structure, rather than a pointer; this should be fine as the events are small structures. Co-authored-by: Allen Ray <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed that Go-SDL2 seems to deal with structs by defining Go structs that have the same field layout as SDL2 structs.
However, this is unsafe because if SDL2 updates and silently adds or changes struct fields, the C compiler will figure it out and throw errors if your code is now invalid, but Go could randomly cause undefined behavior (this happened for me in github.com/gen2brain/malgo and there is a PR from me to fix it in there somewhere).
This can be avoided by declaring Go structs that map more or less to the SDL2 structs and manually convert between C and Go representations. This also gives us the benefits of being able to use native Go types like string instead of char*, bool instead of int and func() instead of C function pointers which are harder to use anyway.
The text was updated successfully, but these errors were encountered: