/** * Memory management layer * Provides wrappers for malloc/realloc/calloc/free with error handling */ #ifndef MEM_H #define MEM_H #include #include #ifdef __cplusplus extern "C" { #endif #define XSTR(s) STR(s) #define STR(s) #s #define LOCATION __FILE__ ":" XSTR(__LINE__) void u_check(void* ptr, const char* text, const char* location); #define u_malloc(size) u_malloc_impl(size, LOCATION) #define u_calloc(nmemb, size) u_calloc_impl(nmemb, size, LOCATION) #define u_realloc(ptr, size) u_realloc_impl(ptr, size, LOCATION) #define u_free(ptr) u_free_impl(ptr, LOCATION) #define u_strdup(s) u_strdup_impl(s, LOCATION) void* u_malloc_impl(uint32_t size, const char* location); void* u_calloc_impl(uint32_t nmemb, uint32_t size, const char* location); void* u_realloc_impl(void* ptr, uint32_t size, const char* location); void u_free_impl(void* ptr, const char* location); char* u_strdup_impl(const char* s, const char* location); void u_report_unfreed_blocks(void); #ifdef __cplusplus } #endif #endif // MEM_H