Merge commit 'origin/mc-4.6'
[free-mc.git] / mhl / memory.h
blobb00617700ce37336541aa50d1c1c0c5e8d791222
1 #ifndef __MHL_MEM
2 #define __MHL_MEM
4 #include <memory.h>
5 #include <stdlib.h>
7 /* allocate a chunk of stack memory, uninitialized */
8 #define mhl_mem_alloc_u(sz) (malloc(sz))
10 /* allocate a chunk of stack memory, zeroed */
11 #define mhl_mem_alloc_z(sz) (calloc(1,sz))
13 /* free a chunk of memory from stack, passing NULL does no harm */
14 static inline void mhl_mem_free(void* ptr)
16 if (ptr) free(ptr);
19 /* free an ptr and NULL it */
20 #define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0);
22 /* allocate a chunk on stack - automatically free'd on function exit */
23 #define mhl_stack_alloc(sz) (alloca(sz))
25 /* re-alloc memory chunk */
26 #define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz))
28 #endif