Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
8.86k stars 535 forks source link

Add `const` qualifiers to `nk_allocator` in more places. #642

Closed SnootierMoon closed 1 month ago

SnootierMoon commented 1 month ago

The nk_allocator struct consists of 3 fields, userdata (application-specified ptr), alloc (allocate function), and free (deallocate function). None of these are modified once provided by the library user as far as I can tell, so it should be safe to make this struct const in all API parameters.

Since stb-truetype uses a void* for allocation data, a cast is necessary. But, since the nk_stbtt_malloc/nk_stbtt_free implementations don't modify the nk_allocator (as the potentially mutable allocator is stored indirectly in nk_allocator.userdata), this should be fine as well.