sheredom / utf8.h

📚 single header utf8 string functions for C and C++
The Unlicense
1.69k stars 123 forks source link

Way of removing malloc completely #99

Closed DeanoC closed 2 years ago

DeanoC commented 2 years ago

At the moment, we can pass alloc_func_ptr into functions that need to allocate memory but the malloc path is still live and for bare metal platforms that don't have an actual malloc in the c lib is won't compile, would be nice if a define could remove the malloc call completely... Happy to fail if no malloc, I'll always be passing alloc_func_ptr.

For now I've just defined it out like so

if UTF8_NO_STD_MALLOC

//No malloc, you must pass in alloc_func_ptr assert(false);

else

n = (utf8_int8_t *)malloc(bytes);

endif

sheredom commented 2 years ago

That's seems reasonable, I'll add that!

sheredom commented 2 years ago

@DeanoC sorry for taking so long - I've had my head up my arse! I decided to not rely on assert.h, and just return NULL if you try use the malloc path with UTF8_NO_STD_MALLOC defined. Fixed in #104!