diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-01-20 16:02:34 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-02-17 16:31:42 +0100 |
commit | 76a09166ddbe5b741f54f0fd203f2135e5b532c3 (patch) | |
tree | e331ba98b1a69ae56ac461341a85624ff61f2d59 | |
parent | b9d11456411907e9add8d91b02d67842990c2952 (diff) | |
download | mupdf-76a09166ddbe5b741f54f0fd203f2135e5b532c3.tar.xz |
Reference count fz_document.
-rw-r--r-- | docs/example.c | 2 | ||||
-rw-r--r-- | docs/multi-threaded.c | 2 | ||||
-rw-r--r-- | include/mupdf/fitz/document.h | 8 | ||||
-rw-r--r-- | platform/android/jni/mupdf.c | 6 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocRef.m | 4 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 2 | ||||
-rw-r--r-- | source/cbz/mucbz.c | 1 | ||||
-rw-r--r-- | source/fitz/document.c | 11 | ||||
-rw-r--r-- | source/img/muimage.c | 1 | ||||
-rw-r--r-- | source/pdf/pdf-xref.c | 1 | ||||
-rw-r--r-- | source/tiff/mutiff.c | 1 | ||||
-rw-r--r-- | source/tools/mjsgen.c | 2 | ||||
-rw-r--r-- | source/tools/mudraw.c | 6 | ||||
-rw-r--r-- | source/xps/xps-zip.c | 1 |
14 files changed, 31 insertions, 17 deletions
diff --git a/docs/example.c b/docs/example.c index 19372d81..bf04c805 100644 --- a/docs/example.c +++ b/docs/example.c @@ -93,7 +93,7 @@ render(char *filename, int pagenumber, int zoom, int rotation) fz_drop_pixmap(ctx, pix); fz_free_page(doc, page); - fz_close_document(doc); + fz_drop_document(doc); fz_free_context(ctx); } diff --git a/docs/multi-threaded.c b/docs/multi-threaded.c index 2742fdf8..c5df1f4e 100644 --- a/docs/multi-threaded.c +++ b/docs/multi-threaded.c @@ -272,7 +272,7 @@ int main(int argc, char **argv) // Finally the document is closed and the main thread's // context is freed. - fz_close_document(doc); + fz_drop_document(doc); fz_free_context(ctx); return 0; diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index e140bc3f..cc078044 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -42,6 +42,7 @@ typedef void (fz_document_rebind_fn)(fz_document *doc, fz_context *ctx); struct fz_document_s { + int refs; fz_document_close_fn *close; fz_document_needs_password_fn *needs_password; fz_document_authenticate_password_fn *authenticate_password; @@ -113,14 +114,15 @@ fz_document *fz_open_document(fz_context *ctx, const char *filename); fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream); /* - fz_close_document: Close and free an open document. + fz_drop_document: Release an open document. The resource store in the context associated with fz_document - is emptied, and any allocations for the document are freed. + is emptied, and any allocations for the document are freed when + the last reference is dropped. Does not throw exceptions. */ -void fz_close_document(fz_document *doc); +void fz_drop_document(fz_document *doc); /* fz_needs_password: Check if a document is encrypted with a diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index 21c7bbb5..1b2b6e2f 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -330,7 +330,7 @@ JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename) fz_catch(ctx) { LOGE("Failed: %s", ctx->error->message); - fz_close_document(glo->doc); + fz_drop_document(glo->doc); glo->doc = NULL; fz_free_context(ctx); glo->ctx = NULL; @@ -484,7 +484,7 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic) fz_catch(ctx) { LOGE("Failed: %s", ctx->error->message); - fz_close_document(glo->doc); + fz_drop_document(glo->doc); glo->doc = NULL; fz_free_context(ctx); glo->ctx = NULL; @@ -1718,7 +1718,7 @@ static void close_doc(globals *glo) alerts_fin(glo); - fz_close_document(glo->doc); + fz_drop_document(glo->doc); glo->doc = NULL; } diff --git a/platform/ios/Classes/MuDocRef.m b/platform/ios/Classes/MuDocRef.m index bd2b87c0..44337dc0 100644 --- a/platform/ios/Classes/MuDocRef.m +++ b/platform/ios/Classes/MuDocRef.m @@ -33,7 +33,7 @@ if (self) { if (doc != NULL) - fz_close_document(doc); + fz_drop_document(doc); [self release]; self = nil; } @@ -46,7 +46,7 @@ { __block fz_document *block_doc = doc; dispatch_async(queue, ^{ - fz_close_document(block_doc); + fz_drop_document(block_doc); }); [super dealloc]; } diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index 4f05a496..7ce52e9e 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -401,7 +401,7 @@ void pdfapp_close(pdfapp_t *app) fz_free_page(app->doc, app->page); app->page = NULL; - fz_close_document(app->doc); + fz_drop_document(app->doc); app->doc = NULL; #ifdef HAVE_CURL diff --git a/source/cbz/mucbz.c b/source/cbz/mucbz.c index 9b548125..6951e798 100644 --- a/source/cbz/mucbz.c +++ b/source/cbz/mucbz.c @@ -263,6 +263,7 @@ cbz_rebind(cbz_document *doc, fz_context *ctx) static void cbz_init_document(cbz_document *doc) { + doc->super.refs = 1; doc->super.close = (fz_document_close_fn *)cbz_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)cbz_count_pages; doc->super.load_page = (fz_document_load_page_fn *)cbz_load_page; diff --git a/source/fitz/document.c b/source/fitz/document.c index ad2e84ba..64de1bc0 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -142,10 +142,17 @@ fz_open_document(fz_context *ctx, const char *filename) return NULL; } +fz_document * +fz_keep_document(fz_document *doc) +{ + ++doc->refs; + return doc; +} + void -fz_close_document(fz_document *doc) +fz_drop_document(fz_document *doc) { - if (doc && doc->close) + if (doc && --doc->refs == 0 && doc->close) doc->close(doc); } diff --git a/source/img/muimage.c b/source/img/muimage.c index 7e0f56ab..21fd6261 100644 --- a/source/img/muimage.c +++ b/source/img/muimage.c @@ -150,6 +150,7 @@ image_rebind(image_document *doc, fz_context *ctx) static void image_init_document(image_document *doc) { + doc->super.refs = 1; doc->super.close = (fz_document_close_fn *)image_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)image_count_pages; doc->super.load_page = (fz_document_load_page_fn *)image_load_page; diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index ec2ff8f5..172c13e6 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -2268,6 +2268,7 @@ pdf_new_document(fz_context *ctx, fz_stream *file) { pdf_document *doc = fz_malloc_struct(ctx, pdf_document); + doc->super.refs = 1; doc->super.close = (fz_document_close_fn *)pdf_close_document; doc->super.needs_password = (fz_document_needs_password_fn *)pdf_needs_password; doc->super.authenticate_password = (fz_document_authenticate_password_fn *)pdf_authenticate_password; diff --git a/source/tiff/mutiff.c b/source/tiff/mutiff.c index a48165bf..ae9a7a72 100644 --- a/source/tiff/mutiff.c +++ b/source/tiff/mutiff.c @@ -179,6 +179,7 @@ tiff_rebind(tiff_document *doc, fz_context *ctx) static void tiff_init_document(tiff_document *doc) { + doc->super.refs = 1; doc->super.close = (fz_document_close_fn *)tiff_close_document; doc->super.count_pages = (fz_document_count_pages_fn *)tiff_count_pages; doc->super.load_page = (fz_document_load_page_fn *)tiff_load_page; diff --git a/source/tools/mjsgen.c b/source/tools/mjsgen.c index 3e11fde3..1987e76d 100644 --- a/source/tools/mjsgen.c +++ b/source/tools/mjsgen.c @@ -278,7 +278,7 @@ int main(int argc, char **argv) processpages(ctx, doc); - fz_close_document(doc); + fz_drop_document(doc); } fz_catch(ctx) { diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 420ca1dc..734429da 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -1067,7 +1067,7 @@ int main(int argc, char **argv) if (showxml || showtext == TEXT_XML) fz_printf(out, "</document>\n"); - fz_close_document(doc); + fz_drop_document(doc); doc = NULL; } fz_catch(ctx) @@ -1075,7 +1075,7 @@ int main(int argc, char **argv) if (!ignore_errors) fz_rethrow(ctx); - fz_close_document(doc); + fz_drop_document(doc); doc = NULL; fz_warn(ctx, "ignoring error in '%s'", filename); } @@ -1083,7 +1083,7 @@ int main(int argc, char **argv) } fz_catch(ctx) { - fz_close_document(doc); + fz_drop_document(doc); fprintf(stderr, "error: cannot draw '%s'\n", filename); errored = 1; } diff --git a/source/xps/xps-zip.c b/source/xps/xps-zip.c index 8b96773f..1dbd103c 100644 --- a/source/xps/xps-zip.c +++ b/source/xps/xps-zip.c @@ -254,6 +254,7 @@ xps_rebind(xps_document *doc, fz_context *ctx) static void xps_init_document(xps_document *doc) { + doc->super.refs = 1; doc->super.close = (fz_document_close_fn *)xps_close_document; doc->super.load_outline = (fz_document_load_outline_fn *)xps_load_outline; doc->super.count_pages = (fz_document_count_pages_fn *)xps_count_pages; |