OSDN Git Service

l10n: Updated Bulgarian translation of git (2296t,0f,0u)
[git-core/git.git] / alloc.c
diff --git a/alloc.c b/alloc.c
index d7c3605..12afadf 100644 (file)
--- a/alloc.c
+++ b/alloc.c
 
 #define BLOCKING 1024
 
-#define DEFINE_ALLOCATOR(name, type)                           \
-static struct alloc_state name##_state;                                \
-void *alloc_##name##_node(void)                                        \
-{                                                              \
-       return alloc_node(&name##_state, sizeof(type));         \
-}
-
 union any_object {
        struct object object;
        struct blob blob;
@@ -55,18 +48,51 @@ static inline void *alloc_node(struct alloc_state *s, size_t node_size)
        return ret;
 }
 
-DEFINE_ALLOCATOR(blob, struct blob)
-DEFINE_ALLOCATOR(tree, struct tree)
-DEFINE_ALLOCATOR(tag, struct tag)
-DEFINE_ALLOCATOR(object, union any_object)
+static struct alloc_state blob_state;
+void *alloc_blob_node(void)
+{
+       struct blob *b = alloc_node(&blob_state, sizeof(struct blob));
+       b->object.type = OBJ_BLOB;
+       return b;
+}
+
+static struct alloc_state tree_state;
+void *alloc_tree_node(void)
+{
+       struct tree *t = alloc_node(&tree_state, sizeof(struct tree));
+       t->object.type = OBJ_TREE;
+       return t;
+}
+
+static struct alloc_state tag_state;
+void *alloc_tag_node(void)
+{
+       struct tag *t = alloc_node(&tag_state, sizeof(struct tag));
+       t->object.type = OBJ_TAG;
+       return t;
+}
+
+static struct alloc_state object_state;
+void *alloc_object_node(void)
+{
+       struct object *obj = alloc_node(&object_state, sizeof(union any_object));
+       obj->type = OBJ_NONE;
+       return obj;
+}
 
 static struct alloc_state commit_state;
 
+unsigned int alloc_commit_index(void)
+{
+       static unsigned int count;
+       return count++;
+}
+
 void *alloc_commit_node(void)
 {
-       static int commit_count;
        struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
-       c->index = commit_count++;
+       c->object.type = OBJ_COMMIT;
+       c->index = alloc_commit_index();
        return c;
 }