SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Hide some SDL structure

Open 1bsyl opened this issue 2 years ago • 4 comments

Adding or removing fields to structure are always api breakage.

Should we try to expose less SDL structures, so that they don't prevent to break api.

  • doesn't make sense to hide SDL_rect, because all fields are used
  • doesn't make sense to expose SDL_render, because almost no fields are used.

Candidate are structures, with few used fields, that can be hidden, and we add get/set function for usage

1bsyl avatar Jan 16 '23 10:01 1bsyl

Sure, do you have a set of structures you'd like to hide?

slouken avatar Nov 08 '23 01:11 slouken

Tossing this into 3.0 ABI for further review, but it's possible that SDL_Properties mitigates this.

icculus avatar May 18 '24 21:05 icculus

I grepped the codebase for lines with "typedef" and "struct", which brings up 125 items.

Most of these are already good (including the previously-mentioned SDL_Renderer, which is already an opaque type).

The only ones I saw that I think are worth considering at all...

  • SDL_AtomicInt: maybe we just make this totally opaque, since its point is to prevent accessing the int value directly anyhow.
  • SDL_Surface: Probably the perfect example of what @1bsyl is thinking of here, right?
  • SDL_DisplayMode: has a driverdata field, which is a little awkward, maybe.
  • SDL_hid_device_info: I don't love that this is a linked list and has unsigned short values and wchar_t * fields, but I assume this is inherited from hidapi and we can't do much about this and most people don't need it anyhow.

The rest looks pretty good from here. A big pain point was SDL_RWops, but now it is opaque, and if we want to change the interface struct to add/remove/change function pointers, we'll just make a Version 2 struct and a new function to create an SDL_IOStream with the different interface, and paper over the Version 1 differences internally.

Anyhow, we can decide what to do with these (which might be nothing).

icculus avatar Jun 27 '24 04:06 icculus

SDL_AtomicInt: maybe we just make this totally opaque, since its point is to prevent accessing the int value directly anyhow.

(then again, you can't simply create these as static/global if we make these opaque, which is a very common way to use atomic ints.)

icculus avatar Jun 27 '24 04:06 icculus

I'm investigating trimming down SDL_Surface now, and opened a separate issue for SDL_DisplayMode in https://github.com/libsdl-org/SDL/issues/10198. SDL_AtomicInt we want to be static/global, and we won't touch SDL_hid_device_info, for source code compatibility with hidapi.

slouken avatar Jul 08 '24 16:07 slouken