-
Notifications
You must be signed in to change notification settings - Fork 153
/
mir-alloc.h
47 lines (37 loc) · 1.13 KB
/
mir-alloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* This file is a part of MIR project.
Copyright (C) 2018-2024 Vladimir Makarov <[email protected]>.
*/
#ifndef MIR_ALLOC_H
#define MIR_ALLOC_H
#include <assert.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct MIR_alloc {
void *(*malloc) (size_t, void *);
void *(*calloc) (size_t, size_t, void *);
void *(*realloc) (void *, size_t, size_t, void *);
void (*free) (void *, void *);
void *user_data;
} *MIR_alloc_t;
static inline void *MIR_malloc (MIR_alloc_t alloc, size_t size) {
assert (alloc != NULL);
return alloc->malloc (size, alloc->user_data);
}
static inline void *MIR_calloc (MIR_alloc_t alloc, size_t num, size_t size) {
assert (alloc != NULL);
return alloc->calloc (num, size, alloc->user_data);
}
static inline void *MIR_realloc (MIR_alloc_t alloc, void *ptr, size_t old_size, size_t new_size) {
assert (alloc != NULL);
return alloc->realloc (ptr, old_size, new_size, alloc->user_data);
}
static inline void MIR_free (MIR_alloc_t alloc, void *ptr) {
assert (alloc != NULL);
alloc->free (ptr, alloc->user_data);
}
#ifdef __cplusplus
}
#endif
#endif /* #ifndef MIR_ALLOC_H */