diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
commit | d208be26537db558edb70236ae517cea31b7ebab (patch) | |
tree | 57da95b97e354a53bd4517a42010e90968f007d9 /pdf/pdf_pattern.c | |
parent | ba46cad4b09bb957085900a203206c8fa5868cd4 (diff) | |
download | mupdf-d208be26537db558edb70236ae517cea31b7ebab.tar.xz |
Move to exception handling rather than error passing throughout.
This frees us from passing errors back everywhere, and hence enables us
to pass results back as return values.
Rather than having to explicitly check for errors everywhere and bubble
them, we now allow exception handling to do the work for us; the
downside to this is that we no longer emit as much debugging information
as we did before (though this could be put back in). For now, the
debugging information we have lost has been retained in comments
with 'RJW:' at the start.
This code needs fuller testing, but is being committed as a work in
progress.
Diffstat (limited to 'pdf/pdf_pattern.c')
-rw-r--r-- | pdf/pdf_pattern.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c index c50f93ae..194d9650 100644 --- a/pdf/pdf_pattern.c +++ b/pdf/pdf_pattern.c @@ -1,18 +1,16 @@ #include "fitz.h" #include "mupdf.h" -fz_error -pdf_load_pattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict) +pdf_pattern * +pdf_load_pattern(pdf_xref *xref, fz_obj *dict) { - fz_error error; pdf_pattern *pat; fz_obj *obj; fz_context *ctx = xref->ctx; - if ((*patp = pdf_find_item(ctx, xref->store, (pdf_store_drop_fn *)pdf_drop_pattern, dict))) + if ((pat = pdf_find_item(ctx, xref->store, (pdf_store_drop_fn *)pdf_drop_pattern, dict))) { - pdf_keep_pattern(*patp); - return fz_okay; + return pdf_keep_pattern(pat); } pat = fz_malloc(ctx, sizeof(pdf_pattern)); @@ -40,16 +38,17 @@ pdf_load_pattern(pdf_pattern **patp, pdf_xref *xref, fz_obj *dict) if (pat->resources) fz_keep_obj(pat->resources); - error = pdf_load_stream(&pat->contents, xref, fz_to_num(dict), fz_to_gen(dict)); - if (error) + fz_try(ctx) + { + pat->contents = pdf_load_stream(xref, fz_to_num(dict), fz_to_gen(dict)); + } + fz_catch(ctx) { pdf_remove_item(ctx, xref->store, (pdf_store_drop_fn *)pdf_drop_pattern, dict); pdf_drop_pattern(ctx, pat); - return fz_error_note(error, "cannot load pattern stream (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); + fz_throw(ctx, "cannot load pattern stream (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); } - - *patp = pat; - return fz_okay; + return pat; } pdf_pattern * |