Memory allocation: moved to alloc.[ch]

This commit is contained in:
2024-07-10 07:49:44 +02:00
parent 3100504fa2
commit 5401e83db8
7 changed files with 80 additions and 37 deletions

View File

@@ -14,34 +14,5 @@
#ifndef _UTIL_H
#define _UTIL_H
#include <stdio.h>
#include <stdlib.h>
#include "chessdefs.h"
#undef safe_malloc
#undef safe_free
/* force BUG_ON, to get a program abort for failed malloc/free
*/
#pragma push_macro("BUG_ON")
#undef BUG_ON
#define BUG_ON
#include <bug.h>
#define safe_malloc(size) ({ \
void *_ret = malloc(size); \
bug_on(_ret == NULL); \
_ret; \
})
#define safe_free(ptr) do { \
bug_on(ptr == NULL); \
free(ptr); \
} while (0)
/* restore BUG_ON
*/
#pragma pop_macro("BUG_ON")
#endif /* UTIL_H */