-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmem.h
33 lines (22 loc) · 1.17 KB
/
mem.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
#ifndef BEAN_MEM_H
#define BEAN_MEM_H
#include "common.h"
#include "bstate.h"
typedef struct bean_State bean_State;
#define beanM_limitN(n, t) \
((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : cast_uint((MAX_SIZET/sizeof(t))))
#define beanM_reallocvchar(B, ptr, oldsize, newsize, t) \
(cast(t *, beanM_realloc_(B, ptr, cast_sizet(oldsize) * sizeof(t), \
cast_sizet(newsize) * sizeof(t))))
#define beanM_mallocvchar(B, size, t) (cast(t *, malloc(sizeof(t) * size)))
#define beanM_growvector(B, v, nelems, size, t, limit, e) \
((v) = cast(t *, beanM_grow_(B, v, nelems, &(size), sizeof(t), beanM_limitN(limit, t), e)))
#define beanM_malloc_(B, type) \
(type *) beanM_realloc_(B, NULL, 0, sizeof(type))
#define beanM_array_malloc_(B, type, count) \
(type *) beanM_realloc_(B, NULL, 0, sizeof(type) * count)
#define beanM_array_dealloc_(B, arrayPtr, count) \
beanM_realloc_(B, NULL, sizeof(arrayPtr[0]) * count, 0)
void * beanM_realloc_(bean_State * B, void *ptr, size_t oldSize, size_t newSize);
void * beanM_grow_(bean_State * B, void * block, int n, int *psize, int size_elems, int limit, const char * what);
#endif