onbsd/include/mem.h
2024-11-16 13:48:36 -06:00

21 lines
849 B
C

#ifndef MEM_INCLUDED
#define MEM_INCLUDED
#include "except.h"
#include <stddef.h>
extern const Exception out_of_memory; // OOM Exception
extern void *mem_alloc (size_t nbytes,const char *file, int line);
extern void *mem_calloc(size_t count, size_t nbytes,const char *file, int line);
extern void mem_free(void *ptr, const char *file, int line);
extern void *mem_realloc(void *ptr, size_t nbytes, const char *file, int line);
#define ALLOC(nbytes) mem_alloc((nbytes), __FILE__, __LINE__)
#define CALLOC(count, nbytes) mem_calloc((count), (nbytes), __FILE__, __LINE__)
#define NEW(p) ((p) = ALLOC((size_t)sizeof *(p)))
#define NEW0(p) ((p) = CALLOC(1, (size_t)sizeof *(p)))
#define FREE(ptr) ((void)(mem_free((ptr), __FILE__, __LINE__), (ptr) = 0))
#define REALLOC(ptr, nbytes) ((ptr) = mem_realloc((ptr), (nbytes), __FILE__, __LINE__))
#endif