talloc: add TC_POOL_SPACE_LEFT() macro
authorStefan Metzmacher <metze@samba.org>
Thu, 31 Mar 2011 14:51:40 +0000 (16:51 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 8 Apr 2011 07:28:10 +0000 (09:28 +0200)
metze

Signed-off-By: Andrew Tridgell <tridge@samba.org>
lib/talloc/talloc.c

index 867705fdf458cdd40b833cd759fe712624e059ff..8caa6837bbc2cd98d83b69ff0ed54a101ed25f7b 100644 (file)
@@ -333,6 +333,10 @@ _PUBLIC_ const char *talloc_parent_name(const void *ptr)
 
 #define TALLOC_POOL_HDR_SIZE 16
 
+#define TC_POOL_SPACE_LEFT(_pool_tc) \
+       PTR_DIFF(TC_HDR_SIZE + (_pool_tc)->size + (char *)(_pool_tc), \
+                (_pool_tc)->pool)
+
 static unsigned int *talloc_pool_objectcount(struct talloc_chunk *tc)
 {
        return (unsigned int *)((char *)tc + TC_HDR_SIZE);
@@ -365,8 +369,7 @@ static struct talloc_chunk *talloc_alloc_pool(struct talloc_chunk *parent,
                return NULL;
        }
 
-       space_left = ((char *)pool_ctx + TC_HDR_SIZE + pool_ctx->size)
-               - ((char *)pool_ctx->pool);
+       space_left = TC_POOL_SPACE_LEFT(pool_ctx);
 
        /*
         * Align size to 16 bytes