30 lines
807 B
C
30 lines
807 B
C
|
|
#ifndef APFL_ALLOC_H
|
||
|
|
#define APFL_ALLOC_H
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
#define ALLOCATOR_CALL(a, oldptr, oldsize, newsize) \
|
||
|
|
((a).alloc((a).opaque, (oldptr), (oldsize), (newsize)))
|
||
|
|
|
||
|
|
#define ALLOC_BYTES(a, n) (((n) == 0) ? NULL : ALLOCATOR_CALL(a, NULL, 0, (n)))
|
||
|
|
#define REALLOC_BYTES(a, ptr, old, new) ALLOCATOR_CALL(a, ptr, old, new)
|
||
|
|
#define FREE_BYTES(a, ptr, n) ALLOCATOR_CALL(a, ptr, n, 0)
|
||
|
|
|
||
|
|
#define REALLOC_LIST(a, ptr, old, new) REALLOC_BYTES(a, ptr, sizeof(*ptr) * (old), sizeof(*ptr) * (new))
|
||
|
|
#define ALLOC_LIST(a, T, len) (T *)ALLOC_BYTES(a, sizeof(T) * (len))
|
||
|
|
#define FREE_LIST(a, ptr, len) FREE_BYTES(a, ptr, sizeof(*ptr) * (len))
|
||
|
|
|
||
|
|
#define ALLOC_OBJ(a, T) ALLOC_LIST(a, T, 1)
|
||
|
|
#define FREE_OBJ(a, ptr) FREE_LIST(a, ptr, 1)
|
||
|
|
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif
|