[gs-commits] mupdf 1.16.1.85 Add fz_pool_size to return current alloca

[email protected] (Robin Watts) Fri, 4 Oct 2019 11:42:10 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
commit 0557726e74e5ba44b3bda5dabe5905cfb02b619d
Author: Robin Watts <[email protected]>
Date:   Tue Oct 1 18:49:26 2019 +0100

    Add fz_pool_size to return current allocation in a pool.

diff --git a/include/mupdf/fitz/pool.h b/include/mupdf/fitz/pool.h
index 8cc7540..5e15c95 100644
--- a/include/mupdf/fitz/pool.h
+++ b/include/mupdf/fitz/pool.h
@@ -9,6 +9,7 @@ typedef struct fz_pool_s fz_pool;
 fz_pool *fz_new_pool(fz_context *ctx);
 void *fz_pool_alloc(fz_context *ctx, fz_pool *pool, size_t size);
 char *fz_pool_strdup(fz_context *ctx, fz_pool *pool, const char *s);
+size_t fz_pool_size(fz_context *ctx, fz_pool *pool);
 void fz_drop_pool(fz_context *ctx, fz_pool *pool);
 
 #endif
diff --git a/source/fitz/pool.c b/source/fitz/pool.c
index 26ded2d..98c4886 100644
--- a/source/fitz/pool.c
+++ b/source/fitz/pool.c
@@ -10,6 +10,7 @@ typedef struct fz_pool_node_s fz_pool_node;
 
 struct fz_pool_s
 {
+	size_t size;
 	fz_pool_node *head, *tail;
 	char *pos, *end;
 };
@@ -50,6 +51,7 @@ static void *fz_pool_alloc_oversize(fz_context *ctx, fz_pool *pool, size_t size)
 	node = Memento_label(fz_calloc(ctx, offsetof(fz_pool_node, mem) + size, 1), "fz_pool_oversize");
 	node->next = pool->head;
 	pool->head = node;
+	pool->size += offsetof(fz_pool_node, mem) + size;
 
 	return node->mem;
 }
@@ -70,6 +72,7 @@ void *fz_pool_alloc(fz_context *ctx, fz_pool *pool, size_t size)
 		pool->tail = pool->tail->next = node;
 		pool->pos = node->mem;
 		pool->end = node->mem + POOL_SIZE;
+		pool->size += offsetof(fz_pool_node, mem) + POOL_SIZE;
 	}
 	ptr = pool->pos;
 	pool->pos += size;
@@ -84,6 +87,11 @@ char *fz_pool_strdup(fz_context *ctx, fz_pool *pool, const char *s)
 	return p;
 }
 
+size_t fz_pool_size(fz_context *ctx, fz_pool *pool)
+{
+	return pool ? pool->size : 0;
+}
+
 void fz_drop_pool(fz_context *ctx, fz_pool *pool)
 {
 	fz_pool_node *node;

http://git.ghostscript.com/?p=mupdf.git;a=commit;h=0557726e74e5ba44b3bda5dabe5905cfb02b619d

--
MuPDF library
Artifex Software, Inc.