git-p4: Unset P4DIFF environment variable when using 'p4 -du diff'
[gitweb.git] / alloc.c
diff --git a/alloc.c b/alloc.c
index 460db192d5a7de4073eb89972871720dd1c8fe1e..216c23a6f854c614d38c743cd7687a37f304161b 100644 (file)
--- a/alloc.c
+++ b/alloc.c
 
 #define BLOCKING 1024
 
-#define DEFINE_ALLOCATOR(name)                                 \
+#define DEFINE_ALLOCATOR(name, type)                           \
 static unsigned int name##_allocs;                             \
-struct name *alloc_##name##_node(void)                         \
+void *alloc_##name##_node(void)                                        \
 {                                                              \
        static int nr;                                          \
-       static struct name *block;                              \
+       static type *block;                                     \
+       void *ret;                                              \
                                                                \
        if (!nr) {                                              \
                nr = BLOCKING;                                  \
-               block = xcalloc(BLOCKING, sizeof(struct name)); \
+               block = xmalloc(BLOCKING * sizeof(type));       \
        }                                                       \
        nr--;                                                   \
        name##_allocs++;                                        \
-       return block++;                                         \
+       ret = block++;                                          \
+       memset(ret, 0, sizeof(type));                           \
+       return ret;                                             \
 }
 
-DEFINE_ALLOCATOR(blob)
-DEFINE_ALLOCATOR(tree)
-DEFINE_ALLOCATOR(commit)
-DEFINE_ALLOCATOR(tag)
+union any_object {
+       struct object object;
+       struct blob blob;
+       struct tree tree;
+       struct commit commit;
+       struct tag tag;
+};
+
+DEFINE_ALLOCATOR(blob, struct blob)
+DEFINE_ALLOCATOR(tree, struct tree)
+DEFINE_ALLOCATOR(commit, struct commit)
+DEFINE_ALLOCATOR(tag, struct tag)
+DEFINE_ALLOCATOR(object, union any_object)
 
 #ifdef NO_C99_FORMAT
 #define SZ_FMT "%u"