#ifndef UCX_ALLOCATOR_H
#define UCX_ALLOCATOR_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
void *(*malloc)(
void *data,
size_t n
);
void *(*realloc)(
void *data,
void *mem,
size_t n
)
__attribute__((__warn_unused_result__));
void *(*calloc)(
void *data,
size_t nelem,
size_t n
);
void (*free)(
void *data,
void *mem
)
__attribute__((__nonnull__));
} cx_allocator_class;
struct cx_allocator_s {
cx_allocator_class *cl;
void *data;
};
typedef struct cx_allocator_s CxAllocator;
extern CxAllocator *cxDefaultAllocator;
typedef void (*cx_destructor_func)(
void *memory) __attribute__((__nonnull__));
typedef void (*cx_destructor_func2)(
void *data,
void *memory
) __attribute__((__nonnull__(
2)));
int cx_reallocate(
void **mem,
size_t n
)
__attribute__((__nonnull__));
void *cxMalloc(
CxAllocator
const *allocator,
size_t n
)
__attribute__((__malloc__))
__attribute__((__alloc_size__(
2)));
void *cxRealloc(
CxAllocator
const *allocator,
void *mem,
size_t n
)
__attribute__((__warn_unused_result__))
__attribute__((__alloc_size__(
3)));
int cxReallocate(
CxAllocator
const *allocator,
void **mem,
size_t n
)
__attribute__((__nonnull__));
void *cxCalloc(
CxAllocator
const *allocator,
size_t nelem,
size_t n
)
__attribute__((__malloc__))
__attribute__((__alloc_size__(
2,
3)));
void cxFree(
CxAllocator
const *allocator,
void *mem
)
__attribute__((__nonnull__));
#ifdef __cplusplus
}
#endif
#endif