This commit is contained in:
jeka committed 2026-03-06 15:56:41 +03:00
1 parent 066a9aa89e
commit 7c29349de9
2 files changed
+261

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
/**
* Memory management layer
* Provides wrappers for malloc/realloc/calloc/free with error handling
*/
#ifndef MEM_H
#define MEM_H
#include <stddef.h>
#include <stdint.h>
#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