use SDL stdlib where possible

This commit is contained in:
2024-09-25 19:42:34 -03:00
parent ccad21ab90
commit 0fe1023667
9 changed files with 37 additions and 39 deletions

View File

@ -5,17 +5,23 @@
#include <physfsrwops.h>
#define STB_DS_IMPLEMENTATION
#define STBDS_ASSERT SDL_assert
#define STBDS_REALLOC(context,ptr,size) ((void)(context), SDL_realloc(ptr, size))
#define STBDS_FREE(context,ptr) ((void)(context), SDL_free(ptr))
#include <stb_ds.h>
#define STB_RECT_PACK_IMPLEMENTATION
#define STBRP_SORT SDL_qsort
#define STBRP_ASSERT SDL_assert
#include <stb_rect_pack.h>
#define STB_TRUETYPE_IMPLEMENTATION
#define STBTT_malloc(x,u) ((void)(u), SDL_malloc(x))
#define STBTT_free(x,u) ((void)(u), SDL_free(x))
#define STBTT_assert(x) SDL_assert(x)
#define STBTT_strlen(x) SDL_strlen(x)
#define STBTT_memcpy SDL_memcpy
#define STBTT_memset SDL_memset
#include <stb_truetype.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdnoreturn.h>
#include <string.h>
void cry_impl(const char *file, const int line, const char *title, const char *text) {
@ -57,7 +63,7 @@ void log_warn(const char *restrict format, ...) {
}
noreturn static void alloc_failure_death(void) {
_Noreturn static void alloc_failure_death(void) {
log_critical("Allocation failure. Aborting NOW.");
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"MEMORY ALLOCATION FAILURE.",
@ -70,7 +76,7 @@ noreturn static void alloc_failure_death(void) {
}
noreturn void die_abruptly(void) {
_Noreturn void die_abruptly(void) {
/* a zombie window will linger if we don't at least try to quit SDL */
SDL_Quit();
abort();
@ -78,7 +84,7 @@ noreturn void die_abruptly(void) {
void *cmalloc(size_t size) {
void *ptr = malloc(size);
void *ptr = SDL_malloc(size);
if (ptr == NULL)
alloc_failure_death();
return ptr;
@ -86,7 +92,7 @@ void *cmalloc(size_t size) {
void *crealloc(void *ptr, size_t size) {
void *out = realloc(ptr, size);
void *out = SDL_realloc(ptr, size);
if (out == NULL)
alloc_failure_death();
return out;
@ -94,7 +100,7 @@ void *crealloc(void *ptr, size_t size) {
void *ccalloc(size_t num, size_t size) {
void *ptr = calloc(num, size);
void *ptr = SDL_calloc(num, size);
if (ptr == NULL)
alloc_failure_death();
return ptr;
@ -161,13 +167,13 @@ char *file_to_str(const char *path) {
bool strends(const char *str, const char *suffix) {
size_t str_length = strlen(str);
size_t suffix_length = strlen(suffix);
size_t str_length = SDL_strlen(str);
size_t suffix_length = SDL_strlen(suffix);
if (suffix_length > str_length)
return false;
return memcmp((str + str_length) - suffix_length, suffix, suffix_length) == 0;
return SDL_memcmp((str + str_length) - suffix_length, suffix, suffix_length) == 0;
}