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_xobject.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_xobject.c')
-rw-r--r-- | pdf/pdf_xobject.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index 25503374..ceec02d0 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -1,18 +1,16 @@ #include "fitz.h" #include "mupdf.h" -fz_error -pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) +pdf_xobject * +pdf_load_xobject(pdf_xref *xref, fz_obj *dict) { - fz_error error; pdf_xobject *form; fz_obj *obj; fz_context *ctx = xref->ctx; - if ((*formp = pdf_find_item(ctx, xref->store, (pdf_store_drop_fn *)pdf_drop_xobject, dict))) + if ((form = pdf_find_item(ctx, xref->store, (pdf_store_drop_fn *)pdf_drop_xobject, dict))) { - pdf_keep_xobject(*formp); - return fz_okay; + return pdf_keep_xobject(form); } form = fz_malloc(ctx, sizeof(pdf_xobject)); @@ -52,9 +50,8 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) obj = fz_dict_gets(attrs, "CS"); if (obj) { - error = pdf_load_colorspace(&form->colorspace, xref, obj); - if (error) - fz_error_handle(error, "cannot load xobject colorspace"); + form->colorspace = pdf_load_colorspace(xref, obj); + fz_throw(ctx, "cannot load xobject colorspace"); } } @@ -62,16 +59,18 @@ pdf_load_xobject(pdf_xobject **formp, pdf_xref *xref, fz_obj *dict) if (form->resources) fz_keep_obj(form->resources); - error = pdf_load_stream(&form->contents, xref, fz_to_num(dict), fz_to_gen(dict)); - if (error) + fz_try(ctx) + { + form->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_xobject, dict); pdf_drop_xobject(ctx, form); - return fz_error_note(error, "cannot load xobject content stream (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); + fz_throw(ctx, "cannot load xobject content stream (%d %d R)", fz_to_num(dict), fz_to_gen(dict)); } - *formp = form; - return fz_okay; + return form; } pdf_xobject * |