Add type and memset safe alloca wrapper.

This commit is contained in:
Pierre Habouzit 2008-06-23 16:31:40 +02:00
parent ef4eae17c4
commit df89ea2887
1 changed files with 5 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#include <alloca.h>
/** A list of possible position, not sex related */ /** A list of possible position, not sex related */
typedef enum typedef enum
@ -60,6 +61,10 @@ typedef struct
#define ssizeof(foo) (ssize_t)sizeof(foo) #define ssizeof(foo) (ssize_t)sizeof(foo)
#define countof(foo) (ssizeof(foo) / ssizeof(foo[0])) #define countof(foo) (ssizeof(foo) / ssizeof(foo[0]))
#define p_alloca(type, count) \
((type *)memset(alloca(sizeof(type) * (count)), \
0, sizeof(type) * (count)))
#define p_alloc_nr(x) (((x) + 16) * 3 / 2) #define p_alloc_nr(x) (((x) + 16) * 3 / 2)
#define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count))) #define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count)))
#define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count))) #define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count)))