summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-04-15 14:10:33 +0100
committerRobin Watts <robin.watts@artifex.com>2016-04-26 15:13:08 +0100
commit26f4d19a9a575eb44a6fac44c3a991beee8b589d (patch)
treeb9c9a8c42e794db77a3208dd99fce732beead280
parenta2fc54fe202624b7f82662eb9ca04c718d886718 (diff)
downloadmupdf-26f4d19a9a575eb44a6fac44c3a991beee8b589d.tar.xz
Improve fz_new_document
Use a macro to make fz_new_document nicer (akin to fz_malloc_struct).
-rw-r--r--include/mupdf/fitz/document.h4
-rw-r--r--source/cbz/mucbz.c2
-rw-r--r--source/cbz/muimg.c2
-rw-r--r--source/cbz/mutiff.c2
-rw-r--r--source/fitz/document.c2
-rw-r--r--source/gprf/gprf-doc.c2
-rw-r--r--source/html/epub-doc.c2
-rw-r--r--source/html/html-doc.c4
-rw-r--r--source/pdf/pdf-xref.c2
-rw-r--r--source/svg/svg-doc.c2
10 files changed, 13 insertions, 11 deletions
diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h
index b70f7a8a..c3d96280 100644
--- a/include/mupdf/fitz/document.h
+++ b/include/mupdf/fitz/document.h
@@ -147,7 +147,9 @@ fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz
/*
fz_new_document: Create and initialize a document struct.
*/
-void *fz_new_document(fz_context *ctx, int size);
+void *fz_new_document_of_size(fz_context *ctx, int size);
+
+#define fz_new_document(C,M) ((M*)Memento_label(fz_new_document_of_size(ctx, sizeof(M)), #M))
/*
fz_drop_document: Release an open document.
diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c
index af955a27..2cbe3a80 100644
--- a/source/cbz/mucbz.c
+++ b/source/cbz/mucbz.c
@@ -197,7 +197,7 @@ cbz_lookup_metadata(fz_context *ctx, cbz_document *doc, const char *key, char *b
static cbz_document *
cbz_open_document_with_stream(fz_context *ctx, fz_stream *file)
{
- cbz_document *doc = fz_new_document(ctx, sizeof *doc);
+ cbz_document *doc = fz_new_document(ctx, cbz_document);
doc->super.close = (fz_document_close_fn *)cbz_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)cbz_count_pages;
diff --git a/source/cbz/muimg.c b/source/cbz/muimg.c
index f200480e..41831cdf 100644
--- a/source/cbz/muimg.c
+++ b/source/cbz/muimg.c
@@ -92,7 +92,7 @@ img_lookup_metadata(fz_context *ctx, img_document *doc, const char *key, char *b
static img_document *
img_new_document(fz_context *ctx, fz_image *image)
{
- img_document *doc = fz_new_document(ctx, sizeof *doc);
+ img_document *doc = fz_new_document(ctx, img_document);
doc->super.close = (fz_document_close_fn *)img_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)img_count_pages;
diff --git a/source/cbz/mutiff.c b/source/cbz/mutiff.c
index 2dcf4e5b..57e90ea3 100644
--- a/source/cbz/mutiff.c
+++ b/source/cbz/mutiff.c
@@ -119,7 +119,7 @@ tiff_open_document_with_stream(fz_context *ctx, fz_stream *file)
{
tiff_document *doc;
- doc = fz_new_document(ctx, sizeof *doc);
+ doc = fz_new_document(ctx, tiff_document);
doc->super.close = (fz_document_close_fn *)tiff_close_document;
doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages;
diff --git a/source/fitz/document.c b/source/fitz/document.c
index 7041616b..6c2d9500 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -147,7 +147,7 @@ fz_open_document(fz_context *ctx, const char *filename)
}
void *
-fz_new_document(fz_context *ctx, int size)
+fz_new_document_of_size(fz_context *ctx, int size)
{
fz_document *doc = fz_calloc(ctx, 1, size);
doc->refs = 1;
diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c
index d09248b1..d56501ba 100644
--- a/source/gprf/gprf-doc.c
+++ b/source/gprf/gprf-doc.c
@@ -846,7 +846,7 @@ gprf_open_document_with_stream(fz_context *ctx, fz_stream *file)
{
gprf_document *doc;
- doc = Memento_label(fz_new_document(ctx, sizeof(gprf_document)), "gprf_document");
+ doc = fz_new_document(ctx, gprf_document);
doc->super.close = gprf_close_document;
doc->super.count_pages = gprf_count_pages;
doc->super.load_page = gprf_load_page;
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index e080e7f9..5f67e0d4 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -415,7 +415,7 @@ epub_init(fz_context *ctx, fz_archive *zip)
{
epub_document *doc;
- doc = fz_new_document(ctx, sizeof *doc);
+ doc = fz_new_document(ctx, epub_document);
doc->zip = zip;
doc->set = fz_new_html_font_set(ctx);
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index e5c3d91e..a7f48111 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -117,7 +117,7 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file)
html_document *doc;
fz_buffer *buf;
- doc = fz_new_document(ctx, sizeof *doc);
+ doc = fz_new_document(ctx, html_document);
doc->super.close = htdoc_close_document;
doc->super.layout = htdoc_layout;
@@ -144,7 +144,7 @@ htdoc_open_document(fz_context *ctx, const char *filename)
fz_dirname(dirname, filename, sizeof dirname);
- doc = fz_new_document(ctx, sizeof *doc);
+ doc = fz_new_document(ctx, html_document);
doc->super.close = htdoc_close_document;
doc->super.layout = htdoc_layout;
doc->super.count_pages = htdoc_count_pages;
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index e915b600..9f849e89 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -2329,7 +2329,7 @@ pdf_page_presentation(fz_context *ctx, pdf_page *page, float *duration)
static pdf_document *
pdf_new_document(fz_context *ctx, fz_stream *file)
{
- pdf_document *doc = fz_new_document(ctx, sizeof *doc);
+ pdf_document *doc = fz_new_document(ctx, pdf_document);
doc->super.close = (fz_document_close_fn *)pdf_close_document;
doc->super.needs_password = (fz_document_needs_password_fn *)pdf_needs_password;
diff --git a/source/svg/svg-doc.c b/source/svg/svg-doc.c
index d9df7a27..9b7aa670 100644
--- a/source/svg/svg-doc.c
+++ b/source/svg/svg-doc.c
@@ -91,7 +91,7 @@ svg_open_document_with_buffer(fz_context *ctx, fz_buffer *buf)
root = fz_parse_xml(ctx, buf->data, buf->len, 0);
- doc = Memento_label(fz_new_document(ctx, sizeof(svg_document)), "svg_document");
+ doc = fz_new_document(ctx, svg_document);
doc->super.close = svg_close_document;
doc->super.count_pages = svg_count_pages;
doc->super.load_page = svg_load_page;