diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2012-08-04 19:35:39 +0200 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2012-08-06 13:59:30 +0200 |
commit | ffb37aaa386095d61846419c860eb46b587b6b1d (patch) | |
tree | 313e382bf77e57062bebd26bfc5ae1dc656eb11e | |
parent | d44c98001b404a18ccc9d219976b9f32c28922c3 (diff) | |
download | mupdf-ffb37aaa386095d61846419c860eb46b587b6b1d.tar.xz |
Make use of fz_always instead of repeating code for error and normal path
-rw-r--r-- | apps/mudraw.c | 8 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 40 | ||||
-rw-r--r-- | pdf/pdf_outline.c | 8 | ||||
-rw-r--r-- | pdf/pdf_page.c | 12 | ||||
-rw-r--r-- | xps/xps_image.c | 6 | ||||
-rw-r--r-- | xps/xps_outline.c | 12 | ||||
-rw-r--r-- | xps/xps_zip.c | 6 |
7 files changed, 57 insertions, 35 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index dcd7dafd..0f11a7a1 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -130,15 +130,17 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) dev = fz_new_list_device(ctx, list); fz_run_page(doc, page, dev, fz_identity, &cookie); } - fz_catch(ctx) + fz_always(ctx) { fz_free_device(dev); + dev = NULL; + } + fz_catch(ctx) + { fz_free_display_list(ctx, list); fz_free_page(doc, page); fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename); } - fz_free_device(dev); - dev = NULL; } if (showxml) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index d8b8b9bc..03e09587 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -539,12 +539,14 @@ pdf_show_path(pdf_csi *csi, int doclose, int dofill, int dostroke, int even_odd) if (dofill || dostroke) pdf_end_group(csi); } - fz_catch(ctx) + fz_always(ctx) { fz_free_path(ctx, path); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - fz_free_path(ctx, path); } /* @@ -658,13 +660,14 @@ pdf_flush_text(pdf_csi *csi) pdf_end_group(csi); } - fz_catch(ctx) + fz_always(ctx) { fz_free_text(ctx, text); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - - fz_free_text(ctx, text); } static void @@ -1311,17 +1314,17 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what) { pdf_run_contents_object(csi, pat->resources, pat->contents); } - fz_catch(ctx) + fz_always(ctx) { pdf_grestore(csi); while (oldtop < csi->gtop) pdf_grestore(csi); + } + fz_catch(ctx) + { csi->top_ctm = oldtopctm; fz_throw(ctx, "cannot render pattern tile"); } - pdf_grestore(csi); - while (oldtop < csi->gtop) - pdf_grestore(csi); } } } @@ -1786,13 +1789,14 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) { pdf_run_xobject(csi, xobj->resources, xobj, fz_identity); } - fz_catch(ctx) + fz_always(ctx) { pdf_drop_xobject(ctx, xobj); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } - - pdf_drop_xobject(ctx, xobj); } else if (!strcmp(pdf_to_name(subtype), "Image")) @@ -2317,12 +2321,14 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb) { pdf_show_shade(csi, shd); } - fz_catch(ctx) + fz_always(ctx) { fz_drop_shade(ctx, shd); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - fz_drop_shade(ctx, shd); } } @@ -2872,10 +2878,12 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de { pdf_run_contents_buffer(csi, resources, contents); } - fz_catch(ctx) + fz_always(ctx) { pdf_free_csi(csi); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot parse glyph content stream"); } - pdf_free_csi(csi); } diff --git a/pdf/pdf_outline.c b/pdf/pdf_outline.c index d4bea75a..8f93f5cb 100644 --- a/pdf/pdf_outline.c +++ b/pdf/pdf_outline.c @@ -43,16 +43,16 @@ pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict) dict = pdf_dict_gets(dict, "Next"); } } - fz_catch(ctx) + fz_always(ctx) { for (dict = odict; dict && pdf_dict_marked(dict); dict = pdf_dict_gets(dict, "Next")) pdf_dict_unmark(dict); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - for (dict = odict; dict && pdf_dict_marked(dict); dict = pdf_dict_gets(dict, "Next")) - pdf_dict_unmark(dict); - return first; } diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index 4aa0a893..0733da2f 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -19,12 +19,14 @@ put_marker_bool(fz_context *ctx, pdf_obj *rdb, char *marker, int val) { pdf_dict_puts(rdb, marker, tmp); } - fz_catch(ctx) + fz_always(ctx) { pdf_drop_obj(tmp); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - pdf_drop_obj(tmp); } typedef struct pdf_page_load_s pdf_page_load; @@ -270,12 +272,14 @@ found: useBM = 1; } } - fz_catch(ctx) + fz_always(ctx) { pdf_dict_unmark(rdb); + } + fz_catch(ctx) + { fz_rethrow(ctx); } - pdf_dict_unmark(rdb); put_marker_bool(ctx, rdb, ".useBM", useBM); return useBM; diff --git a/xps/xps_image.c b/xps/xps_image.c index 1f46a756..1a6a8573 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -160,13 +160,15 @@ xps_parse_image_brush(xps_document *doc, fz_matrix ctm, fz_rect area, { image = xps_load_image(doc->ctx, part->data, part->size); } + fz_always(doc->ctx) + { + xps_free_part(doc, part); + } fz_catch(doc->ctx) { fz_warn(doc->ctx, "cannot decode image resource"); - xps_free_part(doc, part); return; } - xps_free_part(doc, part); xps_parse_tiling_brush(doc, ctm, area, base_uri, dict, root, xps_paint_image_brush, image); diff --git a/xps/xps_outline.c b/xps/xps_outline.c index 0feb7b24..21dc0710 100644 --- a/xps/xps_outline.c +++ b/xps/xps_outline.c @@ -88,12 +88,14 @@ xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) { root = xml_parse_document(doc->ctx, part->data, part->size); } - fz_catch(doc->ctx) + fz_always(doc->ctx) { xps_free_part(doc, part); + } + fz_catch(doc->ctx) + { fz_rethrow(doc->ctx); } - xps_free_part(doc, part); if (!root) return NULL; @@ -101,12 +103,14 @@ xps_load_document_structure(xps_document *doc, xps_fixdoc *fixdoc) { outline = xps_parse_document_structure(doc, root); } - fz_catch(doc->ctx) + fz_always(doc->ctx) { xml_free_element(doc->ctx, root); + } + fz_catch(doc->ctx) + { fz_rethrow(doc->ctx); } - xml_free_element(doc->ctx, root); return outline; } diff --git a/xps/xps_zip.c b/xps/xps_zip.c index 17523f10..e7756f89 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -626,12 +626,14 @@ xps_open_document(fz_context *ctx, char *filename) { doc = xps_open_document_with_stream(file); } - fz_catch(ctx) + fz_always(ctx) { fz_close(file); + } + fz_catch(ctx) + { fz_throw(ctx, "cannot load document '%s'", filename); } - fz_close(file); return doc; } |