gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
xalloc.h
Go to the documentation of this file.
1#ifndef __ALLOC
2#define __ALLOC
3#ifndef MEM_UNSECURE
4static void *xcheck(void *a) {
5 if (a) return a;
6 gw_err(_("Out of Memory\n"));
7 THREAD_RETURN(NULL);
8}
9#else
10#define xcheck(a) (a)
11#endif
12
13ANEW static inline void *xmalloc(const m_uint sz) {
14 void *a = malloc(sz);
15 return xcheck(a);
16}
17
18ANEW static inline void *xcalloc(const m_uint n, const m_uint sz) {
19 void *a = calloc(n, sz);
20 return xcheck(a);
21}
22
23ANEW static inline void *xrealloc(void *p, const m_uint sz) {
24 void *a = realloc(p, sz);
25 return xcheck(a);
26}
27
28#define xfree(a) free(a)
29#endif
#define _(String)
Definition defs.h:13
#define ANEW
Definition defs.h:22
#define gw_err(...)
similar to fprintf(stderr, fmt, ...)
Definition err_msg.h:11
uintptr_t m_uint
Definition gwcommon.h:11
#define THREAD_RETURN(arg)
static void * xcheck(void *a)
Definition xalloc.h:4
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18
static ANEW void * xmalloc(const m_uint sz)
Definition xalloc.h:13
static ANEW void * xrealloc(void *p, const m_uint sz)
Definition xalloc.h:23