From 8507263af7233bb5ab4cc1a8e0ca452e3be81542 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Oct 2012 22:43:21 +0100 Subject: [PATCH 1/2] lib/util: Make "struct bitmap" abstract --- lib/util/bitmap.c | 5 +++++ lib/util/bitmap.h | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/util/bitmap.c b/lib/util/bitmap.c index 7defd77..1ae2aaa 100644 --- a/lib/util/bitmap.c +++ b/lib/util/bitmap.c @@ -20,6 +20,11 @@ #include "includes.h" #include "lib/util/bitmap.h" +struct bitmap { + uint32_t *b; + unsigned int n; +}; + /* these functions provide a simple way to allocate integers from a pool without repetition */ diff --git a/lib/util/bitmap.h b/lib/util/bitmap.h index cf7aa1b..6d75929 100644 --- a/lib/util/bitmap.h +++ b/lib/util/bitmap.h @@ -19,10 +19,7 @@ /* The following definitions come from lib/bitmap.c */ -struct bitmap { - uint32_t *b; - unsigned int n; -}; +struct bitmap; struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n); int bitmap_copy(struct bitmap * const dst, const struct bitmap * const src); -- 1.7.9.5 From 798fdd52dc0bbb33dfee3e5adf0accea3a27aa70 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Oct 2012 23:15:09 +0100 Subject: [PATCH 2/2] lib/util: Simplify bitmap.c a bit This avoids the double-talloc for bitmaps --- lib/util/bitmap.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/util/bitmap.c b/lib/util/bitmap.c index 1ae2aaa..77de55a 100644 --- a/lib/util/bitmap.c +++ b/lib/util/bitmap.c @@ -21,8 +21,8 @@ #include "lib/util/bitmap.h" struct bitmap { - uint32_t *b; unsigned int n; + uint32_t b[1]; /* We allocate more */ }; /* these functions provide a simple way to allocate integers from a @@ -35,16 +35,15 @@ struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n) { struct bitmap *bm; - bm = talloc(mem_ctx, struct bitmap); + bm = (struct bitmap *)talloc_zero_size( + mem_ctx, + offsetof(struct bitmap, b) + sizeof(uint32_t)*((n+31)/32)); if (!bm) return NULL; + talloc_set_name_const(bm, "struct bitmap"); + bm->n = n; - bm->b = talloc_zero_array(bm, uint32_t, (n+31)/32); - if (!bm->b) { - TALLOC_FREE(bm); - return NULL; - } return bm; } -- 1.7.9.5