diff options
68 files changed, 574 insertions, 495 deletions
diff --git a/apps/jstest_main.c b/apps/jstest_main.c index f01eabfc..2003ad55 100644 --- a/apps/jstest_main.c +++ b/apps/jstest_main.c @@ -326,7 +326,7 @@ main(int argc, char *argv[]) scriptname = argv[fz_optind++]; script = fopen(scriptname, "rb"); if (script == NULL) - fz_throw(ctx, "cannot open script: %s", scriptname); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open script: %s", scriptname); do { diff --git a/apps/mudraw.c b/apps/mudraw.c index 366cdb8a..57bd4be2 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -271,7 +271,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) } fz_catch(ctx) { - fz_throw(ctx, "cannot load page %d in file '%s'", pagenum, filename); + fz_rethrow_message(ctx, "cannot load page %d in file '%s'", pagenum, filename); } if (mujstest_file) @@ -396,7 +396,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) { fz_drop_display_list(ctx, list); fz_free_page(doc, page); - fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename); + fz_rethrow_message(ctx, "cannot draw page %d in file '%s'", pagenum, filename); } } @@ -485,7 +485,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) sprintf(buf, output, pagenum); file = fopen(buf, "wb"); if (file == NULL) - fz_throw(ctx, "cannot open file '%s': %s", buf, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", buf, strerror(errno)); out = fz_new_output_with_file(ctx, file); fz_bound_page(doc, page, &bounds); @@ -983,13 +983,13 @@ int main(int argc, char **argv) } fz_catch(ctx) { - fz_throw(ctx, "cannot open document: %s", filename); + fz_rethrow_message(ctx, "cannot open document: %s", filename); } if (fz_needs_password(doc)) { if (!fz_authenticate_password(doc, password)) - fz_throw(ctx, "cannot authenticate password: %s", filename); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); if (mujstest_file) fprintf(mujstest_file, "PASSWORD %s\n", password); } diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 7371ea0c..e76c6c7c 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -178,7 +178,7 @@ void pdfapp_open(pdfapp_t *app, char *filename, int reload) { password = winpassword(app, filename); if (!password) - fz_throw(ctx, "Needs a password"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Needs a password"); okay = fz_authenticate_password(app->doc, password); if (!okay) pdfapp_warn(app, "Invalid password."); diff --git a/apps/pdfclean.c b/apps/pdfclean.c index 3c1e810e..c437b819 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -212,7 +212,7 @@ int pdfclean_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); /* Only retain the specified subset of the pages */ if (subset) diff --git a/apps/pdfextract.c b/apps/pdfextract.c index 78a61f14..6e8e4aec 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -120,7 +120,7 @@ static void savefont(pdf_obj *dict, int num) obj = pdf_dict_gets(obj, "Subtype"); if (obj && !pdf_is_name(obj)) - fz_throw(ctx, "Invalid font descriptor subtype"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Invalid font descriptor subtype"); subtype = pdf_to_name(obj); if (!strcmp(subtype, "Type1C")) @@ -130,7 +130,7 @@ static void savefont(pdf_obj *dict, int num) else if (!strcmp(subtype, "OpenType")) ext = "otf"; else - fz_throw(ctx, "Unhandled font type '%s'", subtype); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unhandled font type '%s'", subtype); } if (!stream) @@ -146,15 +146,15 @@ static void savefont(pdf_obj *dict, int num) f = fopen(name, "wb"); if (!f) - fz_throw(ctx, "Error creating font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error creating font file"); len = fz_buffer_storage(ctx, buf, &data); n = fwrite(data, 1, len, f); if (n < len) - fz_throw(ctx, "Error writing font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error writing font file"); if (fclose(f) < 0) - fz_throw(ctx, "Error closing font file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Error closing font file"); fz_drop_buffer(ctx, buf); } @@ -164,7 +164,7 @@ static void showobject(int num) pdf_obj *obj; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); obj = pdf_load_object(doc, num, 0); @@ -207,7 +207,7 @@ int pdfextract_main(int argc, char **argv) doc = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(doc)) if (!pdf_authenticate_password(doc, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); if (fz_optind == argc) { diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c index fa21431e..79743892 100644 --- a/apps/pdfinfo.c +++ b/apps/pdfinfo.c @@ -576,7 +576,7 @@ gatherresourceinfo(int page, pdf_obj *rsrc, int show) pageref = xref->page_refs[page-1]; if (!pageobj) - fz_throw(ctx, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); font = pdf_dict_gets(rsrc, "Font"); if (show & FONTS && font) @@ -644,7 +644,7 @@ gatherpageinfo(int page, int show) pageref = xref->page_refs[page-1]; if (!pageobj) - fz_throw(ctx, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); gatherdimensions(page, pageref, pageobj); @@ -1008,7 +1008,7 @@ int pdfinfo_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, filename); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", filename); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); pagecount = pdf_count_pages(xref); showglobalinfo(); diff --git a/apps/pdfposter.c b/apps/pdfposter.c index 050a497f..ed3a4bda 100644 --- a/apps/pdfposter.c +++ b/apps/pdfposter.c @@ -170,7 +170,7 @@ int pdfposter_main(int argc, char **argv) xref = pdf_open_document_no_run(ctx, infile); if (pdf_needs_password(xref)) if (!pdf_authenticate_password(xref, password)) - fz_throw(ctx, "cannot authenticate password: %s", infile); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", infile); /* Only retain the specified subset of the pages */ decimatepages(xref); diff --git a/apps/pdfshow.c b/apps/pdfshow.c index 586a2fc6..78e3fd08 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -22,7 +22,7 @@ static void usage(void) static void showtrailer(void) { if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); printf("trailer\n"); pdf_fprint_obj(stdout, pdf_trailer(doc), 0); printf("\n"); @@ -33,10 +33,10 @@ static void showencrypt(void) pdf_obj *encrypt; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); encrypt = pdf_dict_gets(pdf_trailer(doc), "Encrypt"); if (!encrypt) - fz_throw(ctx, "document not encrypted"); + fz_throw(ctx, FZ_ERROR_GENERIC, "document not encrypted"); printf("encryption dictionary\n"); pdf_fprint_obj(stdout, pdf_resolve_indirect(encrypt), 0); printf("\n"); @@ -45,7 +45,7 @@ static void showencrypt(void) static void showxref(void) { if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); pdf_print_xref(doc); printf("\n"); } @@ -57,7 +57,7 @@ static void showpagetree(void) int i; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); count = pdf_count_pages(doc); for (i = 0; i < count; i++) @@ -123,7 +123,7 @@ static void showobject(int num, int gen) pdf_obj *obj; if (!doc) - fz_throw(ctx, "no file specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no file specified"); obj = pdf_load_object(doc, num, gen); diff --git a/cbz/mucbz.c b/cbz/mucbz.c index c61304d2..bbc8a5fe 100644 --- a/cbz/mucbz.c +++ b/cbz/mucbz.c @@ -85,7 +85,7 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) sig = getlong(doc->file); if (sig != ZIP_LOCAL_FILE_SIG) - fz_throw(ctx, "wrong zip local file signature (0x%x)", sig); + fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip local file signature (0x%x)", sig); (void) getshort(doc->file); /* version */ (void) getshort(doc->file); /* general */ @@ -135,15 +135,15 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) { code = inflateInit2(&stream, -15); if (code != Z_OK) - fz_throw(ctx, "zlib inflateInit2 error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateInit2 error: %s", stream.msg); code = inflate(&stream, Z_FINISH); if (code != Z_STREAM_END) { inflateEnd(&stream); - fz_throw(ctx, "zlib inflate error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflate error: %s", stream.msg); } code = inflateEnd(&stream); if (code != Z_OK) - fz_throw(ctx, "zlib inflateEnd error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateEnd error: %s", stream.msg); } fz_always(ctx) { @@ -159,7 +159,7 @@ cbz_read_zip_entry(cbz_document *doc, int offset, int *sizep) return udata; } - fz_throw(ctx, "unknown zip method: %d", method); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown zip method: %d", method); return NULL; /* not reached */ } @@ -184,7 +184,7 @@ cbz_read_zip_dir_imp(cbz_document *doc, int startoffset) sig = getlong(file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) - fz_throw(ctx, "wrong zip end of central directory signature (0x%x)", sig); + fz_throw(ctx, FZ_ERROR_GENERIC, "wrong zip end of central directory signature (0x%x)", sig); (void) getshort(file); /* this disk */ (void) getshort(file); /* start disk */ @@ -204,7 +204,7 @@ cbz_read_zip_dir_imp(cbz_document *doc, int startoffset) sig = getlong(doc->file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) - fz_throw(doc->ctx, "wrong zip central directory signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip central directory signature (0x%x)", sig); (void) getshort(file); /* version made by */ (void) getshort(file); /* version to extract */ @@ -271,7 +271,7 @@ cbz_read_zip_dir(cbz_document *doc) back += sizeof buf - 4; } - fz_throw(doc->ctx, "cannot find end of central directory"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find end of central directory"); } cbz_document * @@ -309,13 +309,18 @@ cbz_open_document(fz_context *ctx, const char *filename) file = fz_open_file(ctx, filename); if (!file) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - fz_try(ctx) { + fz_try(ctx) + { doc = cbz_open_document_with_stream(ctx, file); - } fz_always(ctx) { + } + fz_always(ctx) + { fz_close(file); - } fz_catch(ctx) { + } + fz_catch(ctx) + { fz_rethrow(ctx); } diff --git a/draw/draw_edge.c b/draw/draw_edge.c index 41647b0e..5f2f45d3 100644 --- a/draw/draw_edge.c +++ b/draw/draw_edge.c @@ -702,7 +702,7 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, const fz_irect *clip, { fz_free(ctx, alphas); fz_free(ctx, deltas); - fz_throw(ctx, "scan conversion failed (malloc failure)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "scan conversion failed (malloc failure)"); } memset(deltas, 0, (xmax - xmin + 1) * sizeof(int)); gel->alen = 0; diff --git a/fitz/base_context.c b/fitz/base_context.c index bf61e27d..231d9104 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -93,6 +93,7 @@ new_context_phase1(fz_alloc_context *alloc, fz_locks_context *locks) if (!ctx->error) goto cleanup; ctx->error->top = -1; + ctx->error->errcode = 0; ctx->error->message[0] = 0; ctx->warn = fz_malloc_no_throw(ctx, sizeof(fz_warn_context)); diff --git a/fitz/base_error.c b/fitz/base_error.c index 31d285fe..f16dd4d0 100644 --- a/fitz/base_error.c +++ b/fitz/base_error.c @@ -89,6 +89,7 @@ int fz_push_try(fz_error_context *ex) { assert(ex); ex->top++; + ex->errcode = FZ_ERROR_NONE; /* Normal case, get out of here quick */ if (ex->top < nelem(ex->stack)-1) return 1; /* We exit here, and the setjmp sets the code to 0 */ @@ -104,16 +105,24 @@ int fz_push_try(fz_error_context *ex) return 0; } -const char *fz_caught(fz_context *ctx) +int fz_caught(fz_context *ctx) +{ + assert(ctx); + assert(ctx->error); + return ctx->error->errcode; +} + +const char *fz_caught_message(fz_context *ctx) { assert(ctx); assert(ctx->error); return ctx->error->message; } -void fz_throw(fz_context *ctx, const char *fmt, ...) +void fz_throw(fz_context *ctx, int code, const char *fmt, ...) { va_list args; + ctx->error->errcode = code; va_start(args, fmt); vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args); va_end(args); @@ -129,3 +138,17 @@ void fz_rethrow(fz_context *ctx) { throw(ctx->error); } + +void fz_rethrow_message(fz_context *ctx, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args); + va_end(args); + + fz_flush_warnings(ctx); + fprintf(stderr, "error: %s\n", ctx->error->message); + LOGE("error: %s\n", ctx->error->message); + + throw(ctx->error); +} diff --git a/fitz/base_hash.c b/fitz/base_hash.c index e6ed019b..624cc305 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -177,7 +177,7 @@ fz_resize_hash(fz_context *ctx, fz_hash_table *table, int newsize) } } if (newents == NULL) - fz_throw(ctx, "hash table resize failed; out of memory (%d entries)", newsize); + fz_throw(ctx, FZ_ERROR_GENERIC, "hash table resize failed; out of memory (%d entries)", newsize); table->ents = newents; memset(table->ents, 0, sizeof(fz_hash_entry) * newsize); table->size = newsize; diff --git a/fitz/base_memory.c b/fitz/base_memory.c index dc1d0df0..f9e7b4f6 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -56,7 +56,7 @@ fz_malloc(fz_context *ctx, unsigned int size) p = do_scavenging_malloc(ctx, size); if (!p) - fz_throw(ctx, "malloc of %d bytes failed", size); + fz_throw(ctx, FZ_ERROR_GENERIC, "malloc of %d bytes failed", size); return p; } @@ -75,11 +75,11 @@ fz_malloc_array(fz_context *ctx, unsigned int count, unsigned int size) return 0; if (count > UINT_MAX / size) - fz_throw(ctx, "malloc of array (%d x %d bytes) failed (integer overflow)", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "malloc of array (%d x %d bytes) failed (integer overflow)", count, size); p = do_scavenging_malloc(ctx, count * size); if (!p) - fz_throw(ctx, "malloc of array (%d x %d bytes) failed", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "malloc of array (%d x %d bytes) failed", count, size); return p; } @@ -108,13 +108,13 @@ fz_calloc(fz_context *ctx, unsigned int count, unsigned int size) if (count > UINT_MAX / size) { - fz_throw(ctx, "calloc (%d x %d bytes) failed (integer overflow)", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "calloc (%d x %d bytes) failed (integer overflow)", count, size); } p = do_scavenging_malloc(ctx, count * size); if (!p) { - fz_throw(ctx, "calloc (%d x %d bytes) failed", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "calloc (%d x %d bytes) failed", count, size); } memset(p, 0, count*size); return p; @@ -154,11 +154,11 @@ fz_resize_array(fz_context *ctx, void *p, unsigned int count, unsigned int size) } if (count > UINT_MAX / size) - fz_throw(ctx, "resize array (%d x %d bytes) failed (integer overflow)", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "resize array (%d x %d bytes) failed (integer overflow)", count, size); np = do_scavenging_realloc(ctx, p, count * size); if (!np) - fz_throw(ctx, "resize array (%d x %d bytes) failed", count, size); + fz_throw(ctx, FZ_ERROR_GENERIC, "resize array (%d x %d bytes) failed", count, size); return np; } diff --git a/fitz/base_xml.c b/fitz/base_xml.c index f2cf04bb..8c97562c 100644 --- a/fitz/base_xml.c +++ b/fitz/base_xml.c @@ -443,7 +443,7 @@ fz_parse_xml(fz_context *ctx, unsigned char *s, int n) { error = xml_parse_document_imp(&parser, p); if (error) - fz_throw(ctx, "%s", error); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", error); } fz_always(ctx) { diff --git a/fitz/crypt_pkcs7.c b/fitz/crypt_pkcs7.c index 47f272a7..1bc50b6e 100644 --- a/fitz/crypt_pkcs7.c +++ b/fitz/crypt_pkcs7.c @@ -379,7 +379,7 @@ int pdf_check_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, fz_catch(ctx) { res = 0; - strncpy(ebuf, ctx->error->message, ebufsize); + strncpy(ebuf, fz_caught_message(ctx), ebufsize); } if (ebufsize > 0) diff --git a/fitz/dev_null.c b/fitz/dev_null.c index bf548d7f..175b00db 100644 --- a/fitz/dev_null.c +++ b/fitz/dev_null.c @@ -87,7 +87,7 @@ fz_clip_path(fz_device *dev, fz_path *path, const fz_rect *rect, int even_odd, c fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -111,7 +111,7 @@ fz_clip_stroke_path(fz_device *dev, fz_path *path, const fz_rect *rect, fz_strok fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -158,7 +158,7 @@ fz_clip_text(fz_device *dev, fz_text *text, const fz_matrix *ctm, int accumulate if (accumulate == 2) fz_rethrow(ctx); dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -182,7 +182,7 @@ fz_clip_stroke_text(fz_device *dev, fz_text *text, fz_stroke_state *stroke, cons fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -203,7 +203,7 @@ fz_pop_clip(fz_device *dev) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, "%s", dev->errmess); + fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->pop_clip) @@ -257,7 +257,7 @@ fz_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const f fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -281,7 +281,7 @@ fz_begin_mask(fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -317,7 +317,7 @@ fz_begin_group(fz_device *dev, const fz_rect *area, int isolated, int knockout, fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } } @@ -329,7 +329,7 @@ fz_end_group(fz_device *dev) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, "%s", dev->errmess); + fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->end_group) @@ -367,7 +367,7 @@ fz_begin_tile_id(fz_device *dev, const fz_rect *area, const fz_rect *view, float fz_catch(ctx) { dev->error_depth = 1; - strcpy(dev->errmess, fz_caught(ctx)); + strcpy(dev->errmess, fz_caught_message(ctx)); /* Error swallowed */ } return ret; @@ -380,7 +380,7 @@ fz_end_tile(fz_device *dev) { dev->error_depth--; if (dev->error_depth == 0) - fz_throw(dev->ctx, "%s", dev->errmess); + fz_throw(dev->ctx, FZ_ERROR_GENERIC, "%s", dev->errmess); return; } if (dev->end_tile) diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c index dcebd912..3968d193 100644 --- a/fitz/filt_basic.c +++ b/fitz/filt_basic.c @@ -134,19 +134,12 @@ fz_open_concat(fz_context *ctx, int len, int pad) { struct concat_filter *state; - fz_try(ctx) - { - state = fz_calloc(ctx, 1, sizeof(struct concat_filter) + (len-1)*sizeof(fz_stream *)); - state->max = len; - state->count = 0; - state->current = 0; - state->pad = pad; - state->ws = 0; /* We never send padding byte at the start */ - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } + state = fz_calloc(ctx, 1, sizeof(struct concat_filter) + (len-1)*sizeof(fz_stream *)); + state->max = len; + state->count = 0; + state->current = 0; + state->pad = pad; + state->ws = 0; /* We never send padding byte at the start */ return fz_new_stream(ctx, state, read_concat, close_concat); } @@ -157,7 +150,7 @@ fz_concat_push(fz_stream *concat, fz_stream *chain) struct concat_filter *state = (struct concat_filter *)concat->state; if (state->count == state->max) - fz_throw(concat->ctx, "Concat filter size exceeded"); + fz_throw(concat->ctx, FZ_ERROR_GENERIC, "Concat filter size exceeded"); state->chain[state->count++] = chain; } @@ -238,7 +231,7 @@ read_ahxd(fz_stream *stm, unsigned char *buf, int len) } else if (!iswhite(c)) { - fz_throw(stm->ctx, "bad data in ahxd: '%c'", c); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "bad data in ahxd: '%c'", c); } } @@ -384,7 +377,7 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len) else if (!iswhite(c)) { - fz_throw(stm->ctx, "bad data in a85d: '%c'", c); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "bad data in a85d: '%c'", c); } while (state->rp < state->wp && p < ep) @@ -461,7 +454,7 @@ read_rld(fz_stream *stm, unsigned char *buf, int len) state->n = 257 - state->run; state->c = fz_read_byte(state->chain); if (state->c < 0) - fz_throw(stm->ctx, "premature end of data in run length decode"); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); } } @@ -471,7 +464,7 @@ read_rld(fz_stream *stm, unsigned char *buf, int len) { int c = fz_read_byte(state->chain); if (c < 0) - fz_throw(stm->ctx, "premature end of data in run length decode"); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end of data in run length decode"); *p++ = c; state->n--; } @@ -598,7 +591,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len) { int c = fz_read_byte(state->chain); if (c < 0) - fz_throw(stm->ctx, "premature end in aes filter"); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "premature end in aes filter"); state->iv[state->ivcount++] = c; } @@ -611,7 +604,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len) if (n == 0) return p - buf; else if (n < 16) - fz_throw(stm->ctx, "partial block in aes filter"); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "partial block in aes filter"); aes_crypt_cbc(&state->aes, AES_DECRYPT, 16, state->iv, state->bp, state->bp); state->rp = state->bp; @@ -622,7 +615,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len) { int pad = state->bp[15]; if (pad < 1 || pad > 16) - fz_throw(stm->ctx, "aes padding out of range: %d", pad); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "aes padding out of range: %d", pad); state->wp -= pad; } @@ -654,7 +647,7 @@ fz_open_aesd(fz_stream *chain, unsigned char *key, unsigned keylen) state = fz_malloc_struct(ctx, fz_aesd); state->chain = chain; if (aes_setkey_dec(&state->aes, key, keylen * 8)) - fz_throw(ctx, "AES key init failed (keylen=%d)", keylen * 8); + fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", keylen * 8); state->ivcount = 0; state->rp = state->bp; state->wp = state->bp; diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c index 0a50dfa3..1a55e584 100644 --- a/fitz/filt_dctd.c +++ b/fitz/filt_dctd.c @@ -53,6 +53,7 @@ static boolean fill_input_buffer(j_decompress_ptr cinfo) } fz_catch(ctx) { + /* FIXME: TRYLATER */ return 0; } src->next_input_byte = chain->rp; @@ -96,7 +97,7 @@ read_dctd(fz_stream *stm, unsigned char *buf, int len) { if (cinfo->src) state->chain->rp = state->chain->wp - cinfo->src->bytes_in_buffer; - fz_throw(stm->ctx, "jpeg error: %s", state->msg); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "jpeg error: %s", state->msg); } if (!state->init) diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c index fab66f1a..8ac98f42 100644 --- a/fitz/filt_faxd.c +++ b/fitz/filt_faxd.c @@ -401,13 +401,13 @@ dec1d(fz_context *ctx, fz_faxd *fax) code = get_code(fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); if (code < 0) - fz_throw(ctx, "negative code in 1d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative code in 1d faxd"); if (fax->a + code > fax->columns) - fz_throw(ctx, "overflow in 1d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overflow in 1d faxd"); if (fax->c) setbits(fax->dst, fax->a, fax->a + code); @@ -440,13 +440,13 @@ dec2d(fz_context *ctx, fz_faxd *fax) code = get_code(fax, cf_white_decode, cfd_white_initial_bits); if (code == UNCOMPRESSED) - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); if (code < 0) - fz_throw(ctx, "negative code in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative code in 2d faxd"); if (fax->a + code > fax->columns) - fz_throw(ctx, "overflow in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overflow in 2d faxd"); if (fax->c) setbits(fax->dst, fax->a, fax->a + code); @@ -539,13 +539,13 @@ dec2d(fz_context *ctx, fz_faxd *fax) break; case UNCOMPRESSED: - fz_throw(ctx, "uncompressed data in faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "uncompressed data in faxd"); case ERROR: - fz_throw(ctx, "invalid code in 2d faxd"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid code in 2d faxd"); default: - fz_throw(ctx, "invalid code in 2d faxd (%d)", code); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid code in 2d faxd (%d)", code); } } diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c index ee7a83f9..73451d59 100644 --- a/fitz/filt_flate.c +++ b/fitz/filt_flate.c @@ -59,7 +59,7 @@ read_flated(fz_stream *stm, unsigned char *outbuf, int outlen) } else if (code != Z_OK) { - fz_throw(stm->ctx, "zlib error: %s", zp->msg); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "zlib error: %s", zp->msg); } } @@ -103,7 +103,7 @@ fz_open_flated(fz_stream *chain) code = inflateInit(&state->z); if (code != Z_OK) - fz_throw(ctx, "zlib error: inflateInit: %s", state->z.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: inflateInit: %s", state->z.msg); } fz_catch(ctx) { diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c index 3cb0bcef..12eb8c3b 100644 --- a/fitz/filt_jbig2d.c +++ b/fitz/filt_jbig2d.c @@ -50,7 +50,7 @@ read_jbig2d(fz_stream *stm, unsigned char *buf, int len) state->page = jbig2_page_out(state->ctx); if (!state->page) - fz_throw(stm->ctx, "jbig2_page_out failed"); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "jbig2_page_out failed"); } s = state->page->data; diff --git a/fitz/image_jpeg.c b/fitz/image_jpeg.c index faca16ef..b968c0cf 100644 --- a/fitz/image_jpeg.c +++ b/fitz/image_jpeg.c @@ -8,7 +8,7 @@ static void error_exit(j_common_ptr cinfo) fz_context *ctx = (fz_context *)cinfo->client_data; cinfo->err->format_message(cinfo, msg); - fz_throw(ctx, "jpeg error: %s", msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "jpeg error: %s", msg); } static void init_source(j_decompress_ptr cinfo) @@ -76,7 +76,7 @@ fz_load_jpeg_info(fz_context *ctx, unsigned char *rbuf, int rlen, int *xp, int * else if (cinfo.num_components == 4) *cspacep = fz_device_cmyk(ctx); else - fz_throw(ctx, "bad number of components in jpeg: %d", cinfo.num_components); + fz_throw(ctx, FZ_ERROR_GENERIC, "bad number of components in jpeg: %d", cinfo.num_components); *xp = cinfo.image_width; *yp = cinfo.image_height; diff --git a/fitz/image_jpx.c b/fitz/image_jpx.c index 43a4d2ef..cd41277d 100644 --- a/fitz/image_jpx.c +++ b/fitz/image_jpx.c @@ -88,7 +88,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs stream_block sb; if (size < 2) - fz_throw(ctx, "not enough data to determine image format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not enough data to determine image format"); /* Check for SOC marker -- if found we have a bare J2K stream */ if (data[0] == 0xFF && data[1] == 0x4F) @@ -106,7 +106,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs opj_set_error_handler(codec, fz_opj_error_callback, ctx); if (!opj_setup_decoder(codec, ¶ms)) { - fz_throw(ctx, "j2k decode failed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "j2k decode failed"); } stream = opj_stream_default_create(OPJ_TRUE); @@ -125,7 +125,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs { opj_stream_destroy(stream); opj_destroy_codec(codec); - fz_throw(ctx, "Failed to read JPX header"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read JPX header"); } if (!opj_decode(codec, stream, jpx)) @@ -133,7 +133,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs opj_stream_destroy(stream); opj_destroy_codec(codec); opj_image_destroy(jpx); - fz_throw(ctx, "Failed to decode JPX image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to decode JPX image"); } opj_stream_destroy(stream); @@ -141,24 +141,24 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs /* jpx should never be NULL here, but check anyway */ if (!jpx) - fz_throw(ctx, "opj_decode failed"); + fz_throw(ctx, FZ_ERROR_GENERIC, "opj_decode failed"); for (k = 1; k < (int)jpx->numcomps; k++) { if (jpx->comps[k].w != jpx->comps[0].w) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different width"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different width"); } if (jpx->comps[k].h != jpx->comps[0].h) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different height"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different height"); } if (jpx->comps[k].prec != jpx->comps[0].prec) { opj_image_destroy(jpx); - fz_throw(ctx, "image components have different precision"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image components have different precision"); } } @@ -205,7 +205,7 @@ fz_load_jpx(fz_context *ctx, unsigned char *data, int size, fz_colorspace *defcs fz_catch(ctx) { opj_image_destroy(jpx); - fz_throw(ctx, "out of memory"); + fz_rethrow_message(ctx, "out of memory loading jpx"); } p = img->samples; diff --git a/fitz/image_png.c b/fitz/image_png.c index 1f48e298..ad22e128 100644 --- a/fitz/image_png.c +++ b/fitz/image_png.c @@ -224,7 +224,7 @@ png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) int color, compression, filter; if (size != 13) - fz_throw(info->ctx, "IHDR chunk is the wrong size"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "IHDR chunk is the wrong size"); info->width = getuint(p + 0); info->height = getuint(p + 4); @@ -236,21 +236,21 @@ png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) info->interlace = p[12]; if (info->width <= 0) - fz_throw(info->ctx, "image width must be > 0"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "image width must be > 0"); if (info->height <= 0) - fz_throw(info->ctx, "image height must be > 0"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "image height must be > 0"); if (info->depth != 1 && info->depth != 2 && info->depth != 4 && info->depth != 8 && info->depth != 16) - fz_throw(info->ctx, "image bit depth must be one of 1, 2, 4, 8, 16"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "image bit depth must be one of 1, 2, 4, 8, 16"); if (color == 2 && info->depth < 8) - fz_throw(info->ctx, "illegal bit depth for truecolor"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor"); if (color == 3 && info->depth > 8) - fz_throw(info->ctx, "illegal bit depth for indexed"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for indexed"); if (color == 4 && info->depth < 8) - fz_throw(info->ctx, "illegal bit depth for grayscale with alpha"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for grayscale with alpha"); if (color == 6 && info->depth < 8) - fz_throw(info->ctx, "illegal bit depth for truecolor with alpha"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "illegal bit depth for truecolor with alpha"); info->indexed = 0; if (color == 0) /* gray */ @@ -267,14 +267,14 @@ png_read_ihdr(struct info *info, unsigned char *p, unsigned int size) info->n = 1; } else - fz_throw(info->ctx, "unknown color type"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown color type"); if (compression != 0) - fz_throw(info->ctx, "unknown compression method"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown compression method"); if (filter != 0) - fz_throw(info->ctx, "unknown filter method"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "unknown filter method"); if (info->interlace != 0 && info->interlace != 1) - fz_throw(info->ctx, "interlace method not supported"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "interlace method not supported"); } static void @@ -328,7 +328,7 @@ png_read_trns(struct info *info, unsigned char *p, unsigned int size) else { if (size != info->n * 2) - fz_throw(info->ctx, "tRNS chunk is the wrong size"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "tRNS chunk is the wrong size"); for (i = 0; i < info->n; i++) info->trns[i] = (p[i * 2] << 8 | p[i * 2 + 1]) & ((1 << info->depth) - 1); } @@ -344,12 +344,12 @@ png_read_idat(struct info *info, unsigned char *p, unsigned int size, z_stream * code = inflate(stm, Z_SYNC_FLUSH); if (code != Z_OK && code != Z_STREAM_END) - fz_throw(info->ctx, "zlib error: %s", stm->msg); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm->msg); if (stm->avail_in != 0) { if (stm->avail_out == 0) - fz_throw(info->ctx, "ran out of output before input"); - fz_throw(info->ctx, "inflate did not consume buffer (%d remaining)", stm->avail_in); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "ran out of output before input"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "inflate did not consume buffer (%d remaining)", stm->avail_in); } } @@ -357,7 +357,7 @@ static void png_read_phys(struct info *info, unsigned char *p, unsigned int size) { if (size != 9) - fz_throw(info->ctx, "pHYs chunk is the wrong size"); + fz_throw(info->ctx, FZ_ERROR_GENERIC, "pHYs chunk is the wrong size"); if (p[8] == 1) { info->xres = getuint(p) * 254 / 10000; @@ -381,7 +381,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in /* Read signature */ if (total < 8 + 12 || memcmp(p, png_signature, 8)) - fz_throw(ctx, "not a png image (wrong signature)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not a png image (wrong signature)"); p += 8; total -= 8; @@ -390,12 +390,12 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in size = getuint(p); if (total < 12 || size > total - 12) - fz_throw(ctx, "premature end of data in png image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in png image"); if (!memcmp(p + 4, "IHDR", 4)) png_read_ihdr(info, p + 8, size); else - fz_throw(ctx, "png file must start with IHDR chunk"); + fz_throw(ctx, FZ_ERROR_GENERIC, "png file must start with IHDR chunk"); p += size + 12; total -= size + 12; @@ -425,7 +425,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in if (code != Z_OK) { fz_free(ctx, info->samples); - fz_throw(ctx, "zlib error: %s", stm.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm.msg); } fz_try(ctx) @@ -436,7 +436,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in size = getuint(p); if (total < 12 || size > total - 12) - fz_throw(ctx, "premature end of data in png image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "premature end of data in png image"); if (!memcmp(p + 4, "PLTE", 4)) png_read_plte(info, p + 8, size); @@ -464,7 +464,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, unsigned in if (code != Z_OK) { fz_free(ctx, info->samples); - fz_throw(ctx, "zlib error: %s", stm.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib error: %s", stm.msg); } /* Apply prediction filter and deinterlacing */ @@ -558,7 +558,7 @@ fz_load_png(fz_context *ctx, unsigned char *p, int total) fz_catch(ctx) { fz_free(png.ctx, png.samples); - fz_throw(ctx, "out of memory"); + fz_rethrow_message(ctx, "out of memory loading png"); } image->xres = png.xres; diff --git a/fitz/image_tiff.c b/fitz/image_tiff.c index 6a650bff..5806bc00 100644 --- a/fitz/image_tiff.c +++ b/fitz/image_tiff.c @@ -279,13 +279,13 @@ fz_expand_tiff_colormap(struct tiff *tiff) /* image can be with or without extrasamples: comps is 1 or 2 */ if (tiff->samplesperpixel != 1 && tiff->samplesperpixel != 2) - fz_throw(tiff->ctx, "invalid number of samples for RGBPal"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid number of samples for RGBPal"); if (tiff->bitspersample != 4 && tiff->bitspersample != 8) - fz_throw(tiff->ctx, "invalid number of bits for RGBPal"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid number of bits for RGBPal"); if (tiff->colormaplen < (unsigned)maxval * 3) - fz_throw(tiff->ctx, "insufficient colormap data"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "insufficient colormap data"); stride = tiff->imagewidth * (tiff->samplesperpixel + 2); @@ -344,14 +344,14 @@ fz_decode_tiff_strips(struct tiff *tiff) unsigned i; if (!tiff->rowsperstrip || !tiff->stripoffsets || !tiff->stripbytecounts) - fz_throw(tiff->ctx, "no image data in tiff; maybe it is tiled"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "no image data in tiff; maybe it is tiled"); if (tiff->stripoffsetslen < (tiff->imagelength - 1) / tiff->rowsperstrip + 1 || tiff->stripbytecountslen < (tiff->imagelength - 1) / tiff->rowsperstrip + 1) - fz_throw(tiff->ctx, "insufficient strip offset data"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "insufficient strip offset data"); if (tiff->planar != 1) - fz_throw(tiff->ctx, "image data is not in chunky format"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "image data is not in chunky format"); tiff->stride = (tiff->imagewidth * tiff->samplesperpixel * tiff->bitspersample + 7) / 8; @@ -377,7 +377,7 @@ fz_decode_tiff_strips(struct tiff *tiff) tiff->colorspace = fz_device_rgb(tiff->ctx); break; default: - fz_throw(tiff->ctx, "unknown photometric: %d", tiff->photometric); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "unknown photometric: %d", tiff->photometric); } switch (tiff->resolutionunit) @@ -418,7 +418,7 @@ fz_decode_tiff_strips(struct tiff *tiff) wlen = tiff->samples + (unsigned int)(tiff->stride * tiff->imagelength) - wp; if (rp + rlen > tiff->ep) - fz_throw(tiff->ctx, "strip extends beyond the end of the file"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "strip extends beyond the end of the file"); /* the bits are in un-natural order */ if (tiff->fillorder == 2) @@ -446,7 +446,7 @@ fz_decode_tiff_strips(struct tiff *tiff) fz_decode_tiff_lzw(tiff, stm, wp, wlen); break; case 6: - fz_throw(tiff->ctx, "deprecated JPEG in TIFF compression not supported"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "deprecated JPEG in TIFF compression not supported"); break; case 7: fz_decode_tiff_jpeg(tiff, stm, wp, wlen); @@ -458,7 +458,7 @@ fz_decode_tiff_strips(struct tiff *tiff) fz_decode_tiff_packbits(tiff, stm, wp, wlen); break; default: - fz_throw(tiff->ctx, "unknown TIFF compression: %d", tiff->compression); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "unknown TIFF compression: %d", tiff->compression); } /* scramble the bits back into original order */ @@ -687,7 +687,7 @@ fz_read_tiff_tag(struct tiff *tiff, unsigned offset) case TileLength: case TileOffsets: case TileByteCounts: - fz_throw(tiff->ctx, "tiled tiffs not supported"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "tiled tiffs not supported"); default: /* printf("unknown tag: %d t=%d n=%d\n", tag, type, count); */ @@ -742,12 +742,12 @@ fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, in tiff->order = TII; tiff->order = readshort(tiff); if (tiff->order != TII && tiff->order != TMM) - fz_throw(tiff->ctx, "not a TIFF file, wrong magic marker"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong magic marker"); /* check version */ version = readshort(tiff); if (version != 42) - fz_throw(tiff->ctx, "not a TIFF file, wrong version marker"); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "not a TIFF file, wrong version marker"); /* get offset of IFD */ offset = readlong(tiff); @@ -759,12 +759,12 @@ fz_decode_tiff_header(fz_context *ctx, struct tiff *tiff, unsigned char *buf, in tiff->rp = tiff->bp + offset; if (tiff->rp < tiff->bp || tiff->rp > tiff->ep) - fz_throw(tiff->ctx, "invalid IFD offset %u", offset); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "invalid IFD offset %u", offset); count = readshort(tiff); if (count * 12 > (unsigned)(tiff->ep - tiff->rp)) - fz_throw(tiff->ctx, "overlarge IFD entry count %u", count); + fz_throw(tiff->ctx, FZ_ERROR_GENERIC, "overlarge IFD entry count %u", count); offset += 2; for (i = 0; i < count; i++) @@ -830,7 +830,7 @@ fz_load_tiff(fz_context *ctx, unsigned char *buf, int len) } fz_catch(ctx) { - fz_throw(ctx, "out of memory"); + fz_rethrow_message(ctx, "out of memory loading tiff"); } return image; @@ -862,6 +862,6 @@ fz_load_tiff_info(fz_context *ctx, unsigned char *buf, int len, int *wp, int *hp } fz_catch(ctx) { - fz_throw(ctx, "out of memory"); + fz_rethrow_message(ctx, "out of memory loading tiff"); } } diff --git a/fitz/res_bitmap.c b/fitz/res_bitmap.c index ecdca8e5..6357f7d7 100644 --- a/fitz/res_bitmap.c +++ b/fitz/res_bitmap.c @@ -58,7 +58,7 @@ fz_write_pbm(fz_context *ctx, fz_bitmap *bitmap, char *filename) fp = fopen(filename, "wb"); if (!fp) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); assert(bitmap->n == 1); diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index e1533218..07da5a95 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -1231,7 +1231,7 @@ fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsign fz_catch(ctx) { fz_free(ctx, idx); - fz_throw(ctx, "failed to create indexed colorspace"); + fz_rethrow_message(ctx, "failed to create indexed colorspace"); } return cs; } diff --git a/fitz/res_font.c b/fitz/res_font.c index aa3ace9b..e8613f84 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -237,7 +237,7 @@ fz_keep_freetype(fz_context *ctx) { char *mess = ft_error_string(fterr); fz_unlock(ctx, FZ_LOCK_FREETYPE); - fz_throw(ctx, "cannot init freetype: %s", mess); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot init freetype: %s", mess); } FT_Library_Version(fct->ftlib, &maj, &min, &pat); @@ -247,7 +247,7 @@ fz_keep_freetype(fz_context *ctx) if (fterr) fz_warn(ctx, "freetype finalizing: %s", ft_error_string(fterr)); fz_unlock(ctx, FZ_LOCK_FREETYPE); - fz_throw(ctx, "freetype version too old: %d.%d.%d", maj, min, pat); + fz_throw(ctx, FZ_ERROR_GENERIC, "freetype version too old: %d.%d.%d", maj, min, pat); } fct->ftlib_refs++; @@ -286,7 +286,7 @@ fz_new_font_from_file(fz_context *ctx, char *name, char *path, int index, int us if (fterr) { fz_drop_freetype(ctx); - fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); + fz_throw(ctx, FZ_ERROR_GENERIC, "freetype: cannot load font: %s", ft_error_string(fterr)); } if (!name) @@ -318,7 +318,7 @@ fz_new_font_from_memory(fz_context *ctx, char *name, unsigned char *data, int le if (fterr) { fz_drop_freetype(ctx); - fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); + fz_throw(ctx, FZ_ERROR_GENERIC, "freetype: cannot load font: %s", ft_error_string(fterr)); } if (!name) @@ -834,16 +834,17 @@ fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *tr FT_Outline_Decompose(&face->glyph->outline, &outline_funcs, &cc); fz_closepath(ctx, cc.path); } + fz_always(ctx) + { + fz_unlock(ctx, FZ_LOCK_FREETYPE); + } fz_catch(ctx) { fz_warn(ctx, "freetype cannot decompose outline"); fz_free(ctx, cc.path); - fz_unlock(ctx, FZ_LOCK_FREETYPE); return NULL; } - fz_unlock(ctx, FZ_LOCK_FREETYPE); - return cc.path; } diff --git a/fitz/res_image.c b/fitz/res_image.c index 542ff40a..73b4bc28 100644 --- a/fitz/res_image.c +++ b/fitz/res_image.c @@ -142,7 +142,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in len = fz_read(stm, samples, h * stride); if (len < 0) { - fz_throw(ctx, "cannot read image data"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read image data"); } /* Make sure we read the EOF marker (for inline images only) */ @@ -157,6 +157,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in } fz_catch(ctx) { + /* FIXME: TryLater? */ fz_warn(ctx, "ignoring error at end of image"); } } @@ -456,7 +457,7 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) fz_try(ctx) { if (len < 8) - fz_throw(ctx, "unknown image file format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format"); bc = fz_malloc_struct(ctx, fz_compressed_buffer); bc->buffer = fz_keep_buffer(ctx, buffer); @@ -473,14 +474,14 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) fz_load_png_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); } else if (memcmp(buf, "II", 2) == 0 && buf[2] == 0xBC) - fz_throw(ctx, "JPEG-XR codec is not available"); + fz_throw(ctx, FZ_ERROR_GENERIC, "JPEG-XR codec is not available"); else if (memcmp(buf, "MM", 2) == 0 || memcmp(buf, "II", 2) == 0) { bc->params.type = FZ_IMAGE_TIFF; fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); } else - fz_throw(ctx, "unknown image file format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format"); } fz_catch(ctx) { diff --git a/fitz/res_pcl.c b/fitz/res_pcl.c index d5b351d4..eae5dad2 100644 --- a/fitz/res_pcl.c +++ b/fitz/res_pcl.c @@ -178,7 +178,7 @@ void fz_pcl_preset(fz_context *ctx, fz_pcl_options *opts, const char *preset) else if (!strcmp(preset, "oce9050")) copy_opts(opts, &fz_pcl_options_oce9050); else - fz_throw(ctx, "Unknown preset '%s'", preset); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unknown preset '%s'", preset); } void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, int val) @@ -203,7 +203,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in opts->features = (opts->features & ~PCL_ANY_SPACING) | PCL5_SPACING; break; default: - fz_throw(ctx, "Unsupported PCL spacing %d (0-3 only)", val); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unsupported PCL spacing %d (0-3 only)", val); } } else if (!strcmp(option, "mode2")) @@ -213,7 +213,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_MODE_2_COMPRESSION; else - fz_throw(ctx, "Expected 0 or 1 for mode2 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for mode2 value"); } else if (!strcmp(option, "mode3")) { @@ -222,7 +222,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_MODE_3_COMPRESSION; else - fz_throw(ctx, "Expected 0 or 1 for mode3 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for mode3 value"); } else if (!strcmp(option, "eog_reset")) { @@ -231,7 +231,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_END_GRAPHICS_DOES_RESET; else - fz_throw(ctx, "Expected 0 or 1 for eog_reset value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for eog_reset value"); } else if (!strcmp(option, "has_duplex")) { @@ -240,7 +240,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_HAS_DUPLEX; else - fz_throw(ctx, "Expected 0 or 1 for has_duplex value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_duplex value"); } else if (!strcmp(option, "has_papersize")) { @@ -249,7 +249,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_CAN_SET_PAPER_SIZE; else - fz_throw(ctx, "Expected 0 or 1 for has_papersize value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_papersize value"); } else if (!strcmp(option, "has_copies")) { @@ -258,7 +258,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= PCL_CAN_PRINT_COPIES; else - fz_throw(ctx, "Expected 0 or 1 for has_papersize value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for has_papersize value"); } else if (!strcmp(option, "is_ljet4pjl")) { @@ -267,7 +267,7 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= HACK__IS_A_LJET4PJL; else - fz_throw(ctx, "Expected 0 or 1 for is_ljet4pjl value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for is_ljet4pjl value"); } else if (!strcmp(option, "is_oce9050")) { @@ -276,10 +276,10 @@ void fz_pcl_option(fz_context *ctx, fz_pcl_options *opts, const char *option, in else if (val == 1) opts->features |= HACK__IS_A_OCE9050; else - fz_throw(ctx, "Expected 0 or 1 for is_oce9050 value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Expected 0 or 1 for is_oce9050 value"); } else - fz_throw(ctx, "Unknown pcl option '%s'", option); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unknown pcl option '%s'", option); } static void @@ -409,7 +409,7 @@ fz_output_pcl(fz_output *out, const fz_pixmap *pixmap, fz_pcl_options *pcl) ctx = out->ctx; if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as pcl"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pcl"); pcl_header(out, pcl, 1, pixmap->xres); @@ -804,7 +804,7 @@ fz_write_pcl(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, fz_ fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); @@ -834,7 +834,7 @@ fz_write_pcl_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 4288d379..1d3d536f 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -30,7 +30,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h fz_pixmap *pix; if (w < 0 || h < 0) - fz_throw(ctx, "Illegal dimensions for pixmap %d %d", w, h); + fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal dimensions for pixmap %d %d", w, h); pix = fz_malloc_struct(ctx, fz_pixmap); FZ_INIT_STORABLE(pix, 1, fz_free_pixmap_imp); @@ -60,7 +60,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h fz_try(ctx) { if (pix->w + pix->n - 1 > INT_MAX / pix->n) - fz_throw(ctx, "overly wide image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "overly wide image"); pix->samples = fz_malloc_array(ctx, pix->h, pix->w * pix->n); } fz_catch(ctx) @@ -439,11 +439,11 @@ fz_write_pnm(fz_context *ctx, fz_pixmap *pixmap, char *filename) int len; if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as pnm"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pnm"); fp = fopen(filename, "wb"); if (!fp) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); if (pixmap->n == 1 || pixmap->n == 2) fprintf(fp, "P5\n"); @@ -498,7 +498,7 @@ fz_write_pam(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) fp = fopen(filename, "wb"); if (!fp) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fprintf(fp, "P7\n"); fprintf(fp, "WIDTH %d\n", pixmap->w); @@ -565,7 +565,7 @@ fz_write_png(fz_context *ctx, fz_pixmap *pixmap, char *filename, int savealpha) if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); @@ -609,7 +609,7 @@ fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha) fz_var(cdata); if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as png"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as png"); sn = pixmap->n; dn = pixmap->n; @@ -662,7 +662,7 @@ fz_output_png(fz_output *out, const fz_pixmap *pixmap, int savealpha) { fz_free(ctx, udata); fz_free(ctx, cdata); - fz_throw(ctx, "cannot compress image data"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot compress image data"); } big32(head+0, pixmap->w); diff --git a/fitz/res_pwg.c b/fitz/res_pwg.c index e9d1b626..fe1fcd2e 100644 --- a/fitz/res_pwg.c +++ b/fitz/res_pwg.c @@ -92,7 +92,7 @@ fz_output_pwg_page(fz_output *out, const fz_pixmap *pixmap, const fz_pwg_options ctx = out->ctx; if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4) - fz_throw(ctx, "pixmap must be grayscale or rgb to write as pwg"); + fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale or rgb to write as pwg"); sn = pixmap->n; dn = pixmap->n; @@ -262,7 +262,7 @@ fz_write_pwg(fz_context *ctx, fz_pixmap *pixmap, char *filename, int append, con fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); @@ -294,7 +294,7 @@ fz_write_pwg_bitmap(fz_context *ctx, fz_bitmap *bitmap, char *filename, int appe fp = fopen(filename, append ? "ab" : "wb"); if (!fp) { - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); } fz_var(out); diff --git a/fitz/res_shade.c b/fitz/res_shade.c index 676f375c..b13dc215 100644 --- a/fitz/res_shade.c +++ b/fitz/res_shade.c @@ -914,7 +914,7 @@ fz_process_mesh(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, else if (shade->type == FZ_MESH_TYPE7) fz_process_mesh_type7(ctx, shade, ctm, &painter); else - fz_throw(ctx, "Unexpected mesh type %d\n", shade->type); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unexpected mesh type %d\n", shade->type); } static fz_rect * @@ -1006,7 +1006,7 @@ fz_bound_mesh(fz_context *ctx, fz_shade *shade, fz_rect *bbox) shade->type == FZ_MESH_TYPE7) fz_bound_mesh_type4567(ctx, shade, bbox); else - fz_throw(ctx, "Unexpected mesh type %d\n", shade->type); + fz_throw(ctx, FZ_ERROR_GENERIC, "Unexpected mesh type %d\n", shade->type); return bbox; } diff --git a/fitz/stm_open.c b/fitz/stm_open.c index d82acf0a..9e4dc8d4 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -67,7 +67,7 @@ static int read_file(fz_stream *stm, unsigned char *buf, int len) { int n = read(*(int*)stm->state, buf, len); if (n < 0) - fz_throw(stm->ctx, "read error: %s", strerror(errno)); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "read error: %s", strerror(errno)); return n; } @@ -75,7 +75,7 @@ static void seek_file(fz_stream *stm, int offset, int whence) { int n = lseek(*(int*)stm->state, offset, whence); if (n < 0) - fz_throw(stm->ctx, "cannot lseek: %s", strerror(errno)); + fz_throw(stm->ctx, FZ_ERROR_GENERIC, "cannot lseek: %s", strerror(errno)); stm->pos = n; stm->rp = stm->bp; stm->wp = stm->bp; @@ -131,7 +131,7 @@ fz_open_file(fz_context *ctx, const char *name) int fd = open(name, O_BINARY | O_RDONLY, 0); #endif if (fd == -1) - fz_throw(ctx, "cannot open %s", name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open %s", name); return fz_open_fd(ctx, fd); } @@ -141,7 +141,7 @@ fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) - fz_throw(ctx, "cannot open file %ls", name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file %ls", name); return fz_open_fd(ctx, fd); } #endif diff --git a/fitz/stm_read.c b/fitz/stm_read.c index 3ffb918f..ee3d1cad 100644 --- a/fitz/stm_read.c +++ b/fitz/stm_read.c @@ -84,6 +84,7 @@ fz_fill_buffer(fz_stream *stm) } fz_catch(stm->ctx) { + /* FIXME: TryLater */ fz_warn(stm->ctx, "read error; treating as end of file"); stm->error = 1; } @@ -121,7 +122,7 @@ fz_read_best(fz_stream *stm, int initial, int *truncated) if (buf->len >= MIN_BOMB && buf->len / 200 > initial) { - fz_throw(ctx, "compression bomb detected"); + fz_throw(ctx, FZ_ERROR_GENERIC, "compression bomb detected"); } n = fz_read(stm, buf->data + buf->len, buf->cap - buf->len); @@ -133,6 +134,7 @@ fz_read_best(fz_stream *stm, int initial, int *truncated) } fz_catch(ctx) { + /* FIXME: TryLater */ if (truncated) { *truncated = 1; diff --git a/image/muimage.c b/image/muimage.c index 890457ab..ed3280b2 100644 --- a/image/muimage.c +++ b/image/muimage.c @@ -54,13 +54,18 @@ image_open_document(fz_context *ctx, const char *filename) file = fz_open_file(ctx, filename); if (!file) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - fz_try(ctx) { + fz_try(ctx) + { doc = image_open_document_with_stream(ctx, file); - } fz_always(ctx) { + } + fz_always(ctx) + { fz_close(file); - } fz_catch(ctx) { + } + fz_catch(ctx) + { fz_rethrow(ctx); } diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 5f36370a..5f5df366 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -34,6 +34,7 @@ struct fz_error_context_s int code; fz_jmp_buf buffer; } stack[256]; + int errcode; char message[256]; }; @@ -64,10 +65,19 @@ void fz_var_imp(void *); if (ctx->error->stack[ctx->error->top--].code > 1) int fz_push_try(fz_error_context *ex); -void fz_throw(fz_context *, const char *, ...) __printflike(2, 3) FZ_NORETURN; +void fz_throw(fz_context *, int errcode, const char *, ...) __printflike(3, 4) FZ_NORETURN; void fz_rethrow(fz_context *) FZ_NORETURN; +void fz_rethrow_message(fz_context *, const char *, ...) __printflike(2, 3) FZ_NORETURN; void fz_warn(fz_context *ctx, const char *fmt, ...) __printflike(2, 3); -const char *fz_caught(fz_context *ctx); +const char *fz_caught_message(fz_context *ctx); +int fz_caught(fz_context *ctx); + +enum +{ + FZ_ERROR_NONE = 0, + FZ_ERROR_GENERIC = 1, + FZ_ERROR_COUNT +}; /* fz_flush_warnings: Flush any repeated warnings. diff --git a/pdf/pdf_annot.c b/pdf/pdf_annot.c index 208d93e7..c50bbba2 100644 --- a/pdf/pdf_annot.c +++ b/pdf/pdf_annot.c @@ -327,6 +327,7 @@ pdf_load_link_annots(pdf_document *xref, pdf_obj *annots, const fz_matrix *page_ } fz_catch(xref->ctx) { + /* FIXME: TryLater */ link = NULL; } @@ -502,6 +503,7 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page) } fz_catch(ctx) { + /* FIXME: TryLater */ ap = NULL; is_dict = 0; } @@ -564,6 +566,7 @@ pdf_load_annots(pdf_document *xref, pdf_obj *annots, pdf_page *page) { pdf_free_annot(ctx, annot); fz_warn(ctx, "ignoring broken annotation"); + /* FIXME: TryLater */ } } @@ -618,6 +621,7 @@ pdf_update_annot(pdf_document *xref, pdf_annot *annot) fz_catch(ctx) { fz_warn(ctx, "ignoring broken annotation"); + /* FIXME: TryLater */ } } } diff --git a/pdf/pdf_cmap_load.c b/pdf/pdf_cmap_load.c index 340f914b..5fcae15d 100644 --- a/pdf/pdf_cmap_load.c +++ b/pdf/pdf_cmap_load.c @@ -31,7 +31,7 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj) fz_var(cmap); if (pdf_obj_marked(stmobj)) - fz_throw(ctx, "Recursion in embedded cmap"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in embedded cmap"); if ((cmap = pdf_find_item(ctx, pdf_free_cmap_imp, stmobj))) { @@ -77,16 +77,16 @@ pdf_load_embedded_cmap(pdf_document *xref, pdf_obj *stmobj) if (cmap) pdf_drop_cmap(ctx, cmap); if (phase < 1) - fz_throw(ctx, "cannot open cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); + fz_rethrow_message(ctx, "cannot open cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); else if (phase < 2) - fz_throw(ctx, "cannot parse cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); + fz_rethrow_message(ctx, "cannot parse cmap stream (%d %d R)", pdf_to_num(stmobj), pdf_to_gen(stmobj)); else if (phase < 3) - fz_throw(ctx, "cannot load system usecmap '%s'", pdf_to_name(obj)); + fz_rethrow_message(ctx, "cannot load system usecmap '%s'", pdf_to_name(obj)); else { if (phase == 3) pdf_obj_unmark(obj); - fz_throw(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_rethrow_message(ctx, "cannot load embedded usecmap (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } } @@ -127,13 +127,13 @@ pdf_load_system_cmap(fz_context *ctx, char *cmap_name) cmap = pdf_load_builtin_cmap(ctx, cmap_name); if (!cmap) - fz_throw(ctx, "no builtin cmap file: %s", cmap_name); + fz_throw(ctx, FZ_ERROR_GENERIC, "no builtin cmap file: %s", cmap_name); if (cmap->usecmap_name[0] && !cmap->usecmap) { usecmap = pdf_load_builtin_cmap(ctx, cmap->usecmap_name); if (!usecmap) - fz_throw(ctx, "nu builtin cmap file: %s", cmap->usecmap_name); + fz_throw(ctx, FZ_ERROR_GENERIC, "nu builtin cmap file: %s", cmap->usecmap_name); pdf_set_usecmap(ctx, cmap, usecmap); } diff --git a/pdf/pdf_cmap_parse.c b/pdf/pdf_cmap_parse.c index 85b89939..361c512f 100644 --- a/pdf/pdf_cmap_parse.c +++ b/pdf/pdf_cmap_parse.c @@ -67,7 +67,7 @@ pdf_parse_codespace_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_ else break; } - fz_throw(ctx, "expected string or endcodespacerange"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcodespacerange"); } static void @@ -84,19 +84,19 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf return; else if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string or endcidrange"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcidrange"); lo = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex(file, buf); if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string"); hi = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected integer"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected integer"); dst = buf->i; @@ -118,13 +118,13 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf return; else if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string or endcidchar"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endcidchar"); src = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected integer"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected integer"); dst = buf->i; @@ -148,7 +148,7 @@ pdf_parse_bf_range_array(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_l /* Note: does not handle [ /Name /Name ... ] */ else if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string or ]"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or ]"); if (buf->len / 2) { @@ -177,13 +177,13 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf return; else if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string or endbfrange"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endbfrange"); lo = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex(file, buf); if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string"); hi = pdf_code_from_string(buf->scratch, buf->len); if (lo < 0 || lo > 65535 || hi < 0 || hi > 65535 || lo > hi) @@ -229,7 +229,7 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf else { - fz_throw(ctx, "expected string or array or endbfrange"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or array or endbfrange"); } } } @@ -250,14 +250,14 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf * return; else if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string or endbfchar"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string or endbfchar"); src = pdf_code_from_string(buf->scratch, buf->len); tok = pdf_lex(file, buf); /* Note: does not handle /dstName */ if (tok != PDF_TOK_STRING) - fz_throw(ctx, "expected string"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected string"); if (buf->len / 2) { @@ -337,7 +337,7 @@ pdf_load_cmap(fz_context *ctx, fz_stream *file) fz_catch(ctx) { pdf_drop_cmap(ctx, cmap); - fz_throw(ctx, "syntaxerror in cmap"); + fz_rethrow_message(ctx, "syntaxerror in cmap"); } return cmap; diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c index fc1ff541..84b3e847 100644 --- a/pdf/pdf_colorspace.c +++ b/pdf/pdf_colorspace.c @@ -16,7 +16,7 @@ load_icc_based(pdf_document *xref, pdf_obj *dict) case 4: return fz_device_cmyk(xref->ctx); } - fz_throw(xref->ctx, "syntaxerror: ICCBased must have 1, 3 or 4 components"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: ICCBased must have 1, 3 or 4 components"); return NULL; /* Stupid MSVC */ } @@ -111,7 +111,7 @@ load_separation(pdf_document *xref, pdf_obj *array) n = 1; if (n > FZ_MAX_COLORS) - fz_throw(ctx, "too many components in colorspace"); + fz_throw(ctx, FZ_ERROR_GENERIC, "too many components in colorspace"); base = pdf_load_colorspace(xref, baseobj); @@ -188,12 +188,12 @@ load_indexed(pdf_document *xref, pdf_obj *array) } fz_catch(ctx) { - fz_throw(ctx, "cannot open colorspace lookup table (%d 0 R)", pdf_to_num(lookupobj)); + fz_rethrow_message(ctx, "cannot open colorspace lookup table (%d 0 R)", pdf_to_num(lookupobj)); } } else { - fz_throw(ctx, "cannot parse colorspace lookup table"); + fz_rethrow_message(ctx, "cannot parse colorspace lookup table"); } cs = fz_new_indexed_colorspace(ctx, base, high, lookup); @@ -216,7 +216,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) fz_context *ctx = xref->ctx; if (pdf_obj_marked(obj)) - fz_throw(ctx, "Recursion in colorspace definition"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in colorspace definition"); if (pdf_is_name(obj)) { @@ -236,7 +236,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) else if (!strcmp(str, "DeviceCMYK")) return fz_device_cmyk(ctx); else - fz_throw(ctx, "unknown colorspace: %s", pdf_to_name(obj)); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown colorspace: %s", pdf_to_name(obj)); } else if (pdf_is_array(obj)) @@ -300,7 +300,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) cs = pdf_load_colorspace(xref, pobj); } else - fz_throw(ctx, "syntaxerror: unknown colorspace %s", str); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown colorspace %s", str); } fz_always(ctx) { @@ -315,7 +315,7 @@ pdf_load_colorspace_imp(pdf_document *xref, pdf_obj *obj) } } - fz_throw(xref->ctx, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: could not parse color space (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); return NULL; /* Stupid MSVC */ } diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 9ffce0e1..5128473c 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -60,12 +60,12 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (!pdf_is_name(obj)) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "unspecified encryption handler"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unspecified encryption handler"); } if (strcmp(pdf_to_name(obj), "Standard") != 0) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "unknown encryption handler: '%s'", pdf_to_name(obj)); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown encryption handler: '%s'", pdf_to_name(obj)); } crypt->v = 0; @@ -75,7 +75,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "unknown encryption version"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown encryption version"); } /* Standard security handler (PDF 1.7 table 3.19) */ @@ -96,7 +96,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) else { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "encryption dictionary missing version and revision value"); + fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing version and revision value"); } obj = pdf_dict_gets(dict, "O"); @@ -108,7 +108,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) else { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "encryption dictionary missing owner password"); + fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing owner password"); } obj = pdf_dict_gets(dict, "U"); @@ -125,7 +125,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) else { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "encryption dictionary missing user password"); + fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing user password"); } obj = pdf_dict_gets(dict, "P"); @@ -143,7 +143,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "encryption dictionary missing owner encryption key"); + fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing owner encryption key"); } memcpy(crypt->oe, pdf_to_str_buf(obj), 32); @@ -151,7 +151,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (!pdf_is_string(obj) || pdf_to_str_len(obj) != 32) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "encryption dictionary missing user encryption key"); + fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing user encryption key"); } memcpy(crypt->ue, pdf_to_str_buf(obj), 32); } @@ -188,12 +188,12 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (crypt->length % 8 != 0) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "invalid encryption key length"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid encryption key length"); } if (crypt->length < 0 || crypt->length > 256) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "invalid encryption key length"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid encryption key length"); } } @@ -240,7 +240,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) fz_catch(ctx) { pdf_free_crypt(ctx, crypt); - fz_throw(ctx, "cannot parse string crypt filter (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_rethrow_message(ctx, "cannot parse string crypt filter (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } /* in crypt revision 4, the crypt filter determines the key length */ @@ -272,7 +272,7 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, int is_stdcf = (!is_identity && (strcmp(name, "StdCF") == 0)); if (!is_identity && !is_stdcf) - fz_throw(ctx, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf)); + fz_throw(ctx, FZ_ERROR_GENERIC, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf)); cf->method = PDF_CRYPT_NONE; cf->length = crypt->length; @@ -285,7 +285,7 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, dict = pdf_dict_gets(crypt->cf, name); if (!pdf_is_dict(dict)) - fz_throw(ctx, "cannot parse crypt filter (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse crypt filter (%d %d R)", pdf_to_num(crypt->cf), pdf_to_gen(crypt->cf)); obj = pdf_dict_gets(dict, "CFM"); if (pdf_is_name(obj)) @@ -311,13 +311,13 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, cf->length = cf->length * 8; if ((cf->length % 8) != 0) - fz_throw(ctx, "invalid key length: %d", cf->length); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length); if ((crypt->r == 1 || crypt->r == 2 || crypt->r == 4) && (cf->length < 0 || cf->length > 128)) - fz_throw(ctx, "invalid key length: %d", cf->length); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length); if ((crypt->r == 5 || crypt->r == 6) && cf->length != 256) - fz_throw(ctx, "invalid key length: %d", cf->length); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key length: %d", cf->length); } /* @@ -439,7 +439,7 @@ pdf_compute_encryption_key_r5(fz_context *ctx, pdf_crypt *crypt, unsigned char * /* clear password buffer and use it as iv */ memset(buffer + 32, 0, sizeof(buffer) - 32); if (aes_setkey_dec(&aes, buffer, crypt->length)) - fz_throw(ctx, "AES key init failed (keylen=%d)", crypt->length); + fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", crypt->length); aes_crypt_cbc(&aes, AES_DECRYPT, 32, buffer + 32, ownerkey ? crypt->oe : crypt->ue, crypt->key); } @@ -484,7 +484,7 @@ pdf_compute_hardened_hash_r6(fz_context *ctx, unsigned char *password, int pwlen /* Step 3: encrypt data using data block as key and iv */ if (aes_setkey_enc(&aes, block, 128)) - fz_throw(ctx, "AES key init failed (keylen=%d)", 128); + fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", 128); aes_crypt_cbc(&aes, AES_ENCRYPT, data_len * 64, block + 16, data, data); /* Step 4: determine SHA-2 hash size for this round */ @@ -535,7 +535,7 @@ pdf_compute_encryption_key_r6(fz_context *ctx, pdf_crypt *crypt, unsigned char * memset(iv, 0, sizeof(iv)); if (aes_setkey_dec(&aes, hash, 256)) - fz_throw(ctx, "AES key init failed (keylen=256)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=256)"); aes_crypt_cbc(&aes, AES_DECRYPT, 32, iv, ownerkey ? crypt->oe : crypt->ue, crypt->key); } @@ -901,7 +901,7 @@ pdf_crypt_obj_imp(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, unsigned char fz_aes aes; memcpy(iv, s, 16); if (aes_setkey_dec(&aes, key, keylen * 8)) - fz_throw(ctx, "AES key init failed (keylen=%d)", keylen * 8); + fz_throw(ctx, FZ_ERROR_GENERIC, "AES key init failed (keylen=%d)", keylen * 8); aes_crypt_cbc(&aes, AES_DECRYPT, n - 16, iv, s + 16, s); /* delete space used for iv and padding bytes at end */ if (s[n - 17] < 1 || s[n - 17] > 16) diff --git a/pdf/pdf_device.c b/pdf/pdf_device.c index ecd3cd3f..602a778f 100644 --- a/pdf/pdf_device.c +++ b/pdf/pdf_device.c @@ -813,6 +813,7 @@ pdf_dev_new_form(pdf_obj **form_ref, pdf_device *pdev, const fz_rect *bbox, int } fz_catch(ctx) { + pdf_drop_obj(form); fz_rethrow(ctx); } diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c index 65589c94..1c2beb7b 100644 --- a/pdf/pdf_font.c +++ b/pdf/pdf_font.c @@ -182,7 +182,7 @@ pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname) data = pdf_lookup_builtin_font(fontname, &len); if (!data) - fz_throw(ctx, "cannot find builtin font: '%s'", fontname); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); @@ -198,7 +198,7 @@ pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontnam data = pdf_lookup_substitute_font(mono, serif, bold, italic, &len); if (!data) - fz_throw(ctx, "cannot find substitute font"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find substitute font"); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); @@ -215,7 +215,7 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fon data = pdf_lookup_substitute_cjk_font(ros, serif, &len); if (!data) - fz_throw(ctx, "cannot find builtin CJK font"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin CJK font"); /* a glyph bbox cache is too big for droid sans fallback (51k glyphs!) */ fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 0); @@ -282,7 +282,7 @@ pdf_load_embedded_font(pdf_document *xref, pdf_font_desc *fontdesc, char *fontna } fz_catch(ctx) { - fz_throw(ctx, "cannot load font stream (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); + fz_rethrow_message(ctx, "cannot load font stream (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); } fz_try(ctx) @@ -292,7 +292,7 @@ pdf_load_embedded_font(pdf_document *xref, pdf_font_desc *fontdesc, char *fontna fz_catch(ctx) { fz_drop_buffer(ctx, buf); - fz_throw(ctx, "cannot load embedded font (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); + fz_rethrow_message(ctx, "cannot load embedded font (%d %d R)", pdf_to_num(stmref), pdf_to_gen(stmref)); } fontdesc->size += buf->len; @@ -688,6 +688,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict) } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "cannot load ToUnicode CMap"); } @@ -738,7 +739,7 @@ pdf_load_simple_font(pdf_document *xref, pdf_obj *dict) if (fontdesc && etable != fontdesc->cid_to_gid) fz_free(ctx, etable); pdf_drop_font(ctx, fontdesc); - fz_throw(ctx, "cannot load simple font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load simple font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; } @@ -777,7 +778,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ cidinfo = pdf_dict_gets(dict, "CIDSystemInfo"); if (!cidinfo) - fz_throw(ctx, "cid font is missing info"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cid font is missing info"); obj = pdf_dict_gets(cidinfo, "Registry"); tmplen = fz_mini(sizeof tmpstr - 1, pdf_to_str_len(obj)); @@ -800,7 +801,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ descriptor = pdf_dict_gets(dict, "FontDescriptor"); if (!descriptor) - fz_throw(ctx, "syntaxerror: missing font descriptor"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing font descriptor"); pdf_load_font_descriptor(fontdesc, xref, descriptor, collection, basefont, 1); face = fontdesc->font->ft_face; @@ -823,7 +824,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ } else { - fz_throw(ctx, "syntaxerror: font missing encoding"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: font missing encoding"); } fontdesc->size += pdf_cmap_size(ctx, fontdesc->encoding); @@ -857,7 +858,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ fterr = FT_Select_Charmap(face, ft_encoding_unicode); if (fterr) { - fz_throw(ctx, "fonterror: no unicode cmap when emulating CID font: %s", ft_error_string(fterr)); + fz_throw(ctx, FZ_ERROR_GENERIC, "fonterror: no unicode cmap when emulating CID font: %s", ft_error_string(fterr)); } if (!strcmp(collection, "Adobe-CNS1")) @@ -982,7 +983,7 @@ load_cid_font(pdf_document *xref, pdf_obj *dict, pdf_obj *encoding, pdf_obj *to_ fz_catch(ctx) { pdf_drop_font(ctx, fontdesc); - fz_throw(ctx, "cannot load cid font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load cid font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; @@ -999,7 +1000,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict) dfonts = pdf_dict_gets(dict, "DescendantFonts"); if (!dfonts) - fz_throw(xref->ctx, "cid font is missing descendant fonts"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cid font is missing descendant fonts"); dfont = pdf_array_get(dfonts, 0); @@ -1012,7 +1013,7 @@ pdf_load_type0_font(pdf_document *xref, pdf_obj *dict) else if (pdf_is_name(subtype) && !strcmp(pdf_to_name(subtype), "CIDFontType2")) return load_cid_font(xref, dfont, encoding, to_unicode); else - fz_throw(xref->ctx, "syntaxerror: unknown cid font type"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type"); return NULL; /* Stupid MSVC */ } @@ -1056,6 +1057,7 @@ pdf_load_font_descriptor(pdf_font_desc *fontdesc, pdf_document *xref, pdf_obj *d } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "ignored error when loading embedded font; attempting to load system font"); if (origname != fontname && !iscidfont) pdf_load_builtin_font(ctx, fontdesc, fontname); diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 9b58c07b..6e1d26ce 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -305,7 +305,7 @@ static void get_font_info(pdf_document *doc, pdf_obj *dr, char *da, font_info *f parse_da(ctx, da, &font_rec->da_rec); if (font_rec->da_rec.font_name == NULL) - fz_throw(ctx, "No font name in default appearance"); + fz_throw(ctx, FZ_ERROR_GENERIC, "No font name in default appearance"); font_rec->font = pdf_load_font(doc, dr, pdf_dict_gets(pdf_dict_gets(dr, "Font"), font_rec->da_rec.font_name), 0); } @@ -2602,7 +2602,7 @@ void pdf_field_set_text_color(pdf_document *doc, pdf_obj *field, pdf_obj *col) } fz_catch(ctx) { - fz_warn(ctx, "%s", ctx->error->message); + fz_warn(ctx, "%s", fz_caught_message(ctx)); } } diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index 368c1415..4771fbfd 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -707,7 +707,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) switch (tok) { case PDF_TOK_EOF: - fz_throw(ctx, "truncated calculator function"); + fz_throw(ctx, FZ_ERROR_GENERIC, "truncated calculator function"); case PDF_TOK_INT: resize_code(ctx, func, *codeptr); @@ -761,12 +761,12 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) } if (tok != PDF_TOK_KEYWORD) - fz_throw(ctx, "missing keyword in 'if-else' context"); + fz_throw(ctx, FZ_ERROR_GENERIC, "missing keyword in 'if-else' context"); if (!strcmp(buf->scratch, "if")) { if (elseptr >= 0) - fz_throw(ctx, "too many branches for 'if'"); + fz_throw(ctx, FZ_ERROR_GENERIC, "too many branches for 'if'"); func->u.p.code[opptr].type = PS_OPERATOR; func->u.p.code[opptr].u.op = PS_OP_IF; func->u.p.code[opptr+2].type = PS_BLOCK; @@ -777,7 +777,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) else if (!strcmp(buf->scratch, "ifelse")) { if (elseptr < 0) - fz_throw(ctx, "not enough branches for 'ifelse'"); + fz_throw(ctx, FZ_ERROR_GENERIC, "not enough branches for 'ifelse'"); func->u.p.code[opptr].type = PS_OPERATOR; func->u.p.code[opptr].u.op = PS_OP_IFELSE; func->u.p.code[opptr+1].type = PS_BLOCK; @@ -789,7 +789,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) } else { - fz_throw(ctx, "unknown keyword in 'if-else' context: '%s'", buf->scratch); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown keyword in 'if-else' context: '%s'", buf->scratch); } break; @@ -816,7 +816,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) a = b = mid; } if (cmp != 0) - fz_throw(ctx, "unknown operator: '%s'", buf->scratch); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown operator: '%s'", buf->scratch); resize_code(ctx, func, *codeptr); func->u.p.code[*codeptr].type = PS_OPERATOR; @@ -825,7 +825,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr, pdf_lexbuf *buf) break; default: - fz_throw(ctx, "calculator function syntax error"); + fz_throw(ctx, FZ_ERROR_GENERIC, "calculator function syntax error"); } } } @@ -852,7 +852,7 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int tok = pdf_lex(stream, &buf); if (tok != PDF_TOK_OPEN_BRACE) { - fz_throw(ctx, "stream is not a calculator function"); + fz_throw(ctx, FZ_ERROR_GENERIC, "stream is not a calculator function"); } func->u.p.code = NULL; @@ -868,7 +868,7 @@ load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int } fz_catch(ctx) { - fz_throw(ctx, "cannot parse calculator function (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot parse calculator function (%d %d R)", num, gen); } func->base.size += func->u.p.cap * sizeof(psobj); @@ -918,7 +918,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, obj = pdf_dict_gets(dict, "Size"); if (pdf_array_len(obj) < func->base.m) - fz_throw(ctx, "too few sample function dimension sizes"); + fz_throw(ctx, FZ_ERROR_GENERIC, "too few sample function dimension sizes"); if (pdf_array_len(obj) > func->base.m) fz_warn(ctx, "too many sample function dimension sizes"); for (i = 0; i < func->base.m; i++) @@ -977,7 +977,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, samplecount *= func->u.sa.size[i]; if (samplecount > MAX_SAMPLE_FUNCTION_SIZE) - fz_throw(ctx, "sample function too large"); + fz_throw(ctx, FZ_ERROR_GENERIC, "sample function too large"); func->u.sa.samples = fz_malloc_array(ctx, samplecount, sizeof(float)); func->base.size += samplecount * sizeof(float); @@ -993,7 +993,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, if (fz_is_eof_bits(stream)) { fz_close(stream); - fz_throw(ctx, "truncated sample function stream"); + fz_throw(ctx, FZ_ERROR_GENERIC, "truncated sample function stream"); } switch (bps) @@ -1023,7 +1023,7 @@ load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, break; default: fz_close(stream); - fz_throw(ctx, "sample stream bit depth %d unsupported", bps); + fz_throw(ctx, FZ_ERROR_GENERIC, "sample stream bit depth %d unsupported", bps); } func->u.sa.samples[i] = s; @@ -1227,7 +1227,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) obj = pdf_dict_gets(dict, "Functions"); if (!pdf_is_array(obj)) - fz_throw(ctx, "stitching function has no input functions"); + fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no input functions"); fz_try(ctx) { @@ -1264,10 +1264,10 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) obj = pdf_dict_gets(dict, "Bounds"); if (!pdf_is_array(obj)) - fz_throw(ctx, "stitching function has no bounds"); + fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no bounds"); { if (pdf_array_len(obj) < k - 1) - fz_throw(ctx, "too few subfunction boundaries"); + fz_throw(ctx, FZ_ERROR_GENERIC, "too few subfunction boundaries"); if (pdf_array_len(obj) > k) fz_warn(ctx, "too many subfunction boundaries"); @@ -1276,7 +1276,7 @@ load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict) num = pdf_array_get(obj, i); func->u.st.bounds[i] = pdf_to_real(num); if (i && func->u.st.bounds[i - 1] > func->u.st.bounds[i]) - fz_throw(ctx, "subfunction %d boundary out of range", i); + fz_throw(ctx, FZ_ERROR_GENERIC, "subfunction %d boundary out of range", i); } if (k > 1 && (func->domain[0][0] > func->u.st.bounds[0] || @@ -1624,7 +1624,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) int i; if (pdf_obj_marked(dict)) - fz_throw(ctx, "Recursion in function definition"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Recursion in function definition"); if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict))) { @@ -1696,7 +1696,7 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) default: fz_free(ctx, func); - fz_throw(ctx, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } pdf_store_item(ctx, dict, func, func->base.size); @@ -1705,13 +1705,13 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) { int type = func->type; fz_drop_function(ctx, (fz_function *)func); - fz_throw(ctx, "cannot load %s function (%d %d R)", - type == SAMPLE ? "sampled" : - type == EXPONENTIAL ? "exponential" : - type == STITCHING ? "stitching" : - type == POSTSCRIPT ? "calculator" : - "unknown", - pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load %s function (%d %d R)", + type == SAMPLE ? "sampled" : + type == EXPONENTIAL ? "exponential" : + type == STITCHING ? "stitching" : + type == POSTSCRIPT ? "calculator" : + "unknown", + pdf_to_num(dict), pdf_to_gen(dict)); } return (fz_function *)func; diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index a75e6a73..719841d5 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -37,7 +37,7 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c { fz_pixmap *mask_pixmap; if (image->n != 2) - fz_throw(ctx, "soft mask must be grayscale"); + fz_throw(ctx, FZ_ERROR_GENERIC, "soft mask must be grayscale"); mask_pixmap = fz_alpha_from_gray(ctx, image->tile, 1); fz_drop_pixmap(ctx, image->tile); image->tile = mask_pixmap; @@ -61,17 +61,17 @@ pdf_load_image_imp(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict, fz_stream *c bpc = 1; if (w <= 0) - fz_throw(ctx, "image width is zero (or less)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image width is zero (or less)"); if (h <= 0) - fz_throw(ctx, "image height is zero (or less)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image height is zero (or less)"); if (bpc <= 0) - fz_throw(ctx, "image depth is zero (or less)"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image depth is zero (or less)"); if (bpc > 16) - fz_throw(ctx, "image depth is too large: %d", bpc); + fz_throw(ctx, FZ_ERROR_GENERIC, "image depth is too large: %d", bpc); if (w > (1 << 16)) - fz_throw(ctx, "image is too wide"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image is too wide"); if (h > (1 << 16)) - fz_throw(ctx, "image is too high"); + fz_throw(ctx, FZ_ERROR_GENERIC, "image is too high"); obj = pdf_dict_getsa(dict, "ColorSpace", "CS"); if (obj && !imagemask && !forcemask) diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index ab883021..43a6d466 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -372,6 +372,7 @@ begin_softmask(pdf_csi * csi, softmask_save *save) } fz_catch(ctx) { + /* FIXME: TryLater */ /* FIXME: Ignore error - nasty, but if we throw from * here the clip stack would be messed up. */ if (csi->cookie) @@ -1187,6 +1188,7 @@ pdf_grestore(pdf_csi *csi) } fz_catch(ctx) { + /* FIXME: TryLater */ /* Silently swallow the problem */ } clip_depth--; @@ -1472,7 +1474,7 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, pdf_gstate *pat_gstate, const f } fz_catch(ctx) { - fz_throw(ctx, "cannot render pattern tile"); + fz_rethrow_message(ctx, "cannot render pattern tile"); } } } @@ -1619,11 +1621,11 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) gstate->font = pdf_load_font(csi->xref, rdb, font, csi->nested_depth); if (!gstate->font) - fz_throw(ctx, "cannot find font in store"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font in store"); gstate->size = pdf_to_real(pdf_array_get(val, 1)); } else - fz_throw(ctx, "malformed /Font dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "malformed /Font dictionary"); } else if (!strcmp(s, "LC")) @@ -1666,7 +1668,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) gstate->stroke_state->dash_phase = pdf_to_real(pdf_array_get(val, 1)); } else - fz_throw(ctx, "malformed /D"); + fz_throw(ctx, FZ_ERROR_GENERIC, "malformed /D"); } else if (!strcmp(s, "CA")) @@ -1697,7 +1699,7 @@ pdf_run_extgstate(pdf_csi *csi, pdf_obj *rdb, pdf_obj *extgstate) group = pdf_dict_gets(val, "G"); if (!group) - fz_throw(ctx, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load softmask xobject (%d %d R)", pdf_to_num(val), pdf_to_gen(val)); xobj = pdf_load_xobject(csi->xref, group); colorspace = xobj->colorspace; @@ -1825,7 +1827,7 @@ static void pdf_run_BI(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) ch = fz_read_byte(file); ch = fz_read_byte(file); if (ch != 'I') - fz_throw(ctx, "syntax error after inline image"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error after inline image"); } static void pdf_run_B(pdf_csi *csi) @@ -1883,10 +1885,10 @@ static void pdf_run_cs_imp(pdf_csi *csi, pdf_obj *rdb, int what) { dict = pdf_dict_gets(rdb, "ColorSpace"); if (!dict) - fz_throw(ctx, "cannot find ColorSpace dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ColorSpace dictionary"); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find colorspace resource '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find colorspace resource '%s'", csi->name); colorspace = pdf_load_colorspace(csi->xref, obj); } @@ -1923,15 +1925,15 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) dict = pdf_dict_gets(rdb, "XObject"); if (!dict) - fz_throw(ctx, "cannot find XObject dictionary when looking for: '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find XObject dictionary when looking for: '%s'", csi->name); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find xobject resource: '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find xobject resource: '%s'", csi->name); subtype = pdf_dict_gets(obj, "Subtype"); if (!pdf_is_name(subtype)) - fz_throw(ctx, "no XObject subtype specified"); + fz_throw(ctx, FZ_ERROR_GENERIC, "no XObject subtype specified"); if (pdf_is_hidden_ocg(pdf_dict_gets(obj, "OC"), csi, rdb)) return; @@ -1959,7 +1961,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) } fz_catch(ctx) { - fz_throw(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_rethrow_message(ctx, "cannot draw xobject (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } } @@ -1991,7 +1993,7 @@ static void pdf_run_Do(pdf_csi *csi, pdf_obj *rdb) else { - fz_throw(ctx, "unknown XObject subtype: '%s'", pdf_to_name(subtype)); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown XObject subtype: '%s'", pdf_to_name(subtype)); } } @@ -2086,7 +2088,7 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m switch (kind) { case PDF_MAT_NONE: - fz_throw(ctx, "cannot set color in mask objects"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot set color in mask objects"); case PDF_MAT_COLOR: pdf_set_color(csi, what, csi->stack); @@ -2095,11 +2097,11 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m case PDF_MAT_PATTERN: dict = pdf_dict_gets(rdb, "Pattern"); if (!dict) - fz_throw(ctx, "cannot find Pattern dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Pattern dictionary"); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find pattern resource '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find pattern resource '%s'", csi->name); patterntype = pdf_dict_gets(obj, "PatternType"); @@ -2119,12 +2121,12 @@ static void pdf_run_SC_imp(pdf_csi *csi, pdf_obj *rdb, int what, pdf_material *m } else { - fz_throw(ctx, "unknown pattern type: %d", pdf_to_int(patterntype)); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown pattern type: %d", pdf_to_int(patterntype)); } break; case PDF_MAT_SHADE: - fz_throw(ctx, "cannot set color in shade objects"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot set color in shade objects"); } mat->gstate_num = csi->gparent; } @@ -2183,11 +2185,11 @@ static void pdf_run_Tf(pdf_csi *csi, pdf_obj *rdb) dict = pdf_dict_gets(rdb, "Font"); if (!dict) - fz_throw(ctx, "cannot find Font dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Font dictionary"); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find font resource: '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find font resource: '%s'", csi->name); gstate->font = pdf_load_font(csi->xref, rdb, obj, csi->nested_depth); } @@ -2365,11 +2367,11 @@ static void pdf_run_gs(pdf_csi *csi, pdf_obj *rdb) dict = pdf_dict_gets(rdb, "ExtGState"); if (!dict) - fz_throw(ctx, "cannot find ExtGState dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ExtGState dictionary"); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find extgstate resource '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find extgstate resource '%s'", csi->name); pdf_run_extgstate(csi, rdb, obj); } @@ -2466,11 +2468,11 @@ static void pdf_run_sh(pdf_csi *csi, pdf_obj *rdb) dict = pdf_dict_gets(rdb, "Shading"); if (!dict) - fz_throw(ctx, "cannot find shading dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find shading dictionary"); obj = pdf_dict_gets(dict, csi->name); if (!obj) - fz_throw(ctx, "cannot find shading resource: '%s'", csi->name); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find shading resource: '%s'", csi->name); if ((csi->dev->hints & FZ_IGNORE_SHADE) == 0) { @@ -2593,7 +2595,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot draw xobject/image"); + fz_rethrow_message(ctx, "cannot draw xobject/image"); } break; case C('E','M','C'): pdf_run_EMC(csi); break; @@ -2623,7 +2625,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot set font"); + fz_rethrow_message(ctx, "cannot set font"); } break; case B('T','j'): pdf_run_Tj(csi); break; @@ -2652,7 +2654,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot set graphics state"); + fz_rethrow_message(ctx, "cannot set graphics state"); } break; case A('h'): pdf_run_h(csi); break; @@ -2676,7 +2678,7 @@ pdf_run_keyword(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, char *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot draw shading"); + fz_rethrow_message(ctx, "cannot draw shading"); } break; case A('v'): pdf_run_v(csi); break; @@ -2758,12 +2760,12 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) if (!strcmp(buf->scratch, "Tw") || !strcmp(buf->scratch, "Tc")) fz_warn(ctx, "ignoring keyword '%s' inside array", buf->scratch); else - fz_throw(ctx, "syntax error in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in array"); } else if (tok == PDF_TOK_EOF) break; else - fz_throw(ctx, "syntax error in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in array"); } else switch (tok) @@ -2808,7 +2810,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) csi->top ++; } else - fz_throw(ctx, "stack overflow"); + fz_throw(ctx, FZ_ERROR_GENERIC, "stack overflow"); break; case PDF_TOK_REAL: @@ -2817,7 +2819,7 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) csi->top ++; } else - fz_throw(ctx, "stack overflow"); + fz_throw(ctx, FZ_ERROR_GENERIC, "stack overflow"); break; case PDF_TOK_STRING: @@ -2846,13 +2848,14 @@ pdf_run_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file, pdf_lexbuf *buf) break; default: - fz_throw(ctx, "syntax error in content stream"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in content stream"); } } while (tok != PDF_TOK_EOF); } fz_catch(ctx) { + /* FIXME: TryLater */ /* Swallow the error */ if (csi->cookie) csi->cookie->errors++; @@ -2898,6 +2901,7 @@ pdf_run_contents_stream(pdf_csi *csi, pdf_obj *rdb, fz_stream *file) } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "Content stream parsing error - rendering truncated"); } while (csi->gtop > csi->gbot) @@ -2986,7 +2990,7 @@ static void pdf_run_page_contents_with_usage(pdf_document *xref, pdf_page *page, } fz_catch(ctx) { - fz_throw(ctx, "cannot parse page content stream"); + fz_rethrow_message(ctx, "cannot parse page content stream"); } if (page->transparency) @@ -3034,7 +3038,7 @@ static void pdf_run_annot_with_usage(pdf_document *xref, pdf_page *page, pdf_ann while (csi->gtop > 0) pdf_grestore(csi); pdf_free_csi(csi); - fz_throw(ctx, "cannot parse annotation appearance stream"); + fz_rethrow_message(ctx, "cannot parse annotation appearance stream"); } } pdf_free_csi(csi); @@ -3093,7 +3097,7 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de fz_try(ctx) { if (nested_depth > 10) - fz_throw(ctx, "Too many nestings of Type3 glyphs"); + fz_throw(ctx, FZ_ERROR_GENERIC, "Too many nestings of Type3 glyphs"); pdf_run_contents_buffer(csi, resources, contents); } fz_always(ctx) @@ -3102,6 +3106,6 @@ pdf_run_glyph(pdf_document *xref, pdf_obj *resources, fz_buffer *contents, fz_de } fz_catch(ctx) { - fz_throw(ctx, "cannot parse glyph content stream"); + fz_rethrow_message(ctx, "cannot parse glyph content stream"); } } diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index e0bdc755..4a2313f1 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -493,7 +493,8 @@ static pdf_jsimp_obj *doc_getField(void *jsctx, void *obj, int argc, pdf_jsimp_o } fz_catch(ctx) { - fz_warn(ctx, "doc_getField failed: %s", ctx->error->message); + /* FIXME: TryLater ? */ + fz_warn(ctx, "doc_getField failed: %s", fz_caught_message(ctx)); dict = NULL; } @@ -591,7 +592,7 @@ static pdf_jsimp_obj *doc_resetForm(void *jsctx, void *obj, int argc, pdf_jsimp_ } fz_catch(ctx) { - fz_warn(ctx, "doc_resetForm failed: %s", ctx->error->message); + fz_warn(ctx, "doc_resetForm failed: %s", fz_caught_message(ctx)); } return NULL; @@ -832,7 +833,8 @@ void pdf_js_load_document_level(pdf_js *js) } fz_catch(ctx) { - fz_warn(ctx, "Warning: %s", ctx->error->message); + /* FIXME: TryLater ? */ + fz_warn(ctx, "Warning: %s", fz_caught_message(ctx)); } } } diff --git a/pdf/pdf_jsimp_cpp.c b/pdf/pdf_jsimp_cpp.c index 10fd835b..59cc4dd9 100644 --- a/pdf/pdf_jsimp_cpp.c +++ b/pdf/pdf_jsimp_cpp.c @@ -10,7 +10,7 @@ pdf_jsimp *pdf_new_jsimp(fz_context *ctx, void *jsctx) pdf_jsimp *jsi = NULL; const char *err = pdf_new_jsimp_cpp(ctx, jsctx, &jsi); if (err != NULL) - fz_throw(ctx, "%s", err); + fz_throw(ctx, FZ_ERROR_GENERIC, "%s", err); return jsi; } @@ -31,7 +31,7 @@ pdf_jsimp_type *pdf_jsimp_new_type(pdf_jsimp *imp, pdf_jsimp_dtr *dtr) pdf_jsimp_type *type = NULL; const char *err = pdf_jsimp_new_type_cpp(imp, dtr, &type); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return type; } @@ -47,21 +47,21 @@ void pdf_jsimp_addmethod(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_j { const char *err = pdf_jsimp_addmethod_cpp(imp, type, name, meth); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); } void pdf_jsimp_addproperty(pdf_jsimp *imp, pdf_jsimp_type *type, char *name, pdf_jsimp_getter *get, pdf_jsimp_setter *set) { const char *err = pdf_jsimp_addproperty_cpp(imp, type, name, get, set); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); } void pdf_jsimp_set_global_type(pdf_jsimp *imp, pdf_jsimp_type *type) { const char *err = pdf_jsimp_set_global_type_cpp(imp, type); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); } pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *natobj) @@ -69,7 +69,7 @@ pdf_jsimp_obj *pdf_jsimp_new_obj(pdf_jsimp *imp, pdf_jsimp_type *type, void *nat pdf_jsimp_obj *obj = NULL; const char *err = pdf_jsimp_new_obj_cpp(imp, type, natobj, &obj); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return obj; } @@ -86,7 +86,7 @@ int pdf_jsimp_to_type(pdf_jsimp *imp, pdf_jsimp_obj *obj) int type = 0; const char *err = pdf_jsimp_to_type_cpp(imp, obj, &type); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return type; } @@ -96,7 +96,7 @@ pdf_jsimp_obj *pdf_jsimp_from_string(pdf_jsimp *imp, char *str) pdf_jsimp_obj *obj = NULL; const char *err = pdf_jsimp_from_string_cpp(imp, str, &obj); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return obj; } @@ -106,7 +106,7 @@ char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj) char *str = NULL; const char *err = pdf_jsimp_to_string_cpp(imp, obj, &str); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return str; } @@ -116,7 +116,7 @@ pdf_jsimp_obj *pdf_jsimp_from_number(pdf_jsimp *imp, double num) pdf_jsimp_obj *obj = NULL; const char *err = pdf_jsimp_from_number_cpp(imp, num, &obj); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return obj; } @@ -126,7 +126,7 @@ double pdf_jsimp_to_number(pdf_jsimp *imp, pdf_jsimp_obj *obj) double num; const char *err = pdf_jsimp_to_number_cpp(imp, obj, &num); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return num; } @@ -136,7 +136,7 @@ int pdf_jsimp_array_len(pdf_jsimp *imp, pdf_jsimp_obj *obj) int len = 0; const char *err = pdf_jsimp_array_len_cpp(imp, obj, &len); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return len; } @@ -146,7 +146,7 @@ pdf_jsimp_obj *pdf_jsimp_array_item(pdf_jsimp *imp, pdf_jsimp_obj *obj, int i) pdf_jsimp_obj *item = NULL; const char *err = pdf_jsimp_array_item_cpp(imp, obj, i, &item); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return item; } @@ -156,7 +156,7 @@ pdf_jsimp_obj *pdf_jsimp_property(pdf_jsimp *imp, pdf_jsimp_obj *obj, char *prop pdf_jsimp_obj *pobj = NULL; const char *err = pdf_jsimp_property_cpp(imp, obj, prop, &pobj); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); return pobj; } @@ -165,14 +165,14 @@ void pdf_jsimp_execute(pdf_jsimp *imp, char *code) { const char *err = pdf_jsimp_execute_cpp(imp, code); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); } void pdf_jsimp_execute_count(pdf_jsimp *imp, char *code, int count) { const char *err = pdf_jsimp_execute_count_cpp(imp, code, count); if (err != NULL) - fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err); + fz_throw(pdf_jsimp_ctx_cpp(imp), FZ_ERROR_GENERIC, "%s", err); } pdf_jsimp_obj *pdf_jsimp_call_method(pdf_jsimp *imp, pdf_jsimp_method *meth, void *jsctx, void *obj, int argc, pdf_jsimp_obj *args[]) { @@ -186,7 +186,7 @@ pdf_jsimp_obj *pdf_jsimp_call_method(pdf_jsimp *imp, pdf_jsimp_method *meth, voi fz_catch(ctx) { res = NULL; - fz_warn(ctx, "%s", ctx->error->message); + fz_warn(ctx, "%s", fz_caught_message(ctx)); } return res; @@ -204,7 +204,7 @@ pdf_jsimp_obj *pdf_jsimp_call_getter(pdf_jsimp *imp, pdf_jsimp_getter *get, void fz_catch(ctx) { res = NULL; - fz_warn(ctx, "%s", ctx->error->message); + fz_warn(ctx, "%s", fz_caught_message(ctx)); } return res; @@ -220,6 +220,6 @@ void pdf_jsimp_call_setter(pdf_jsimp *imp, pdf_jsimp_setter *set, void *jsctx, v } fz_catch(ctx) { - fz_warn(ctx, "%s", ctx->error->message); + fz_warn(ctx, "%s", fz_caught_message(ctx)); } } diff --git a/pdf/pdf_object.c b/pdf/pdf_object.c index c07f4bef..8e5cf419 100644 --- a/pdf/pdf_object.c +++ b/pdf/pdf_object.c @@ -867,7 +867,7 @@ pdf_dict_getp(pdf_obj *obj, const char *keys) char *k, *e; if (strlen(keys)+1 > 256) - fz_throw(obj->ctx, "buffer overflow in pdf_dict_getp"); + fz_throw(obj->ctx, FZ_ERROR_GENERIC, "buffer overflow in pdf_dict_getp"); strcpy(buf, keys); @@ -1021,7 +1021,7 @@ pdf_dict_putp(pdf_obj *obj, const char *keys, pdf_obj *val) pdf_obj *cobj = NULL; if (strlen(keys)+1 > 256) - fz_throw(obj->ctx, "buffer overflow in pdf_dict_getp"); + fz_throw(obj->ctx, FZ_ERROR_GENERIC, "buffer overflow in pdf_dict_getp"); strcpy(buf, keys); @@ -1227,6 +1227,7 @@ pdf_obj *pdf_new_obj_from_str(fz_context *ctx, const char *src) } fz_catch(ctx) { + /* FIXME: TryLater */ return NULL; } diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index df75ff51..8a12b67b 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -161,9 +161,9 @@ pdf_load_page_tree(pdf_document *xref) count = pdf_dict_gets(pages, "Count"); if (!pdf_is_dict(pages)) - fz_throw(ctx, "missing page tree"); + fz_throw(ctx, FZ_ERROR_GENERIC, "missing page tree"); if (!pdf_is_int(count) || pdf_to_int(count) < 0) - fz_throw(ctx, "missing page count"); + fz_throw(ctx, FZ_ERROR_GENERIC, "missing page count"); xref->page_cap = pdf_to_int(count); xref->page_len = 0; @@ -343,7 +343,7 @@ pdf_load_page(pdf_document *xref, int number) pdf_load_page_tree(xref); if (number < 0 || number >= xref->page_len) - fz_throw(ctx, "cannot find page %d", number + 1); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find page %d", number + 1); pageobj = xref->page_objs[number]; pageref = xref->page_refs[number]; @@ -440,7 +440,7 @@ pdf_load_page(pdf_document *xref, int number) fz_catch(ctx) { pdf_free_page(xref, page); - fz_throw(ctx, "cannot load page %d contents (%d 0 R)", number + 1, pdf_to_num(pageref)); + fz_rethrow_message(ctx, "cannot load page %d contents (%d 0 R)", number + 1, pdf_to_num(pageref)); } return page; diff --git a/pdf/pdf_parse.c b/pdf/pdf_parse.c index b50e1094..18ab3113 100644 --- a/pdf/pdf_parse.c +++ b/pdf/pdf_parse.c @@ -292,7 +292,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) case PDF_TOK_R: if (n != 2) - fz_throw(ctx, "cannot parse indirect reference in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse indirect reference in array"); obj = pdf_new_indirect(ctx, a, b, xref); pdf_array_push(ary, obj); pdf_drop_obj(obj); @@ -352,7 +352,7 @@ pdf_parse_array(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; default: - fz_throw(ctx, "cannot parse token in array"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse token in array"); } } end: @@ -362,7 +362,7 @@ end: { pdf_drop_obj(obj); pdf_drop_obj(ary); - fz_throw(ctx, "cannot parse array"); + fz_rethrow_message(ctx, "cannot parse array"); } return op; } @@ -396,7 +396,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; if (tok != PDF_TOK_NAME) - fz_throw(ctx, "invalid key in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid key in dict"); key = pdf_new_name(ctx, buf->scratch); @@ -444,10 +444,10 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) break; } } - fz_throw(ctx, "invalid indirect reference in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid indirect reference in dict"); default: - fz_throw(ctx, "unknown token in dict"); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in dict"); } pdf_dict_put(dict, key, val); @@ -462,7 +462,7 @@ pdf_parse_dict(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) pdf_drop_obj(dict); pdf_drop_obj(key); pdf_drop_obj(val); - fz_throw(ctx, "cannot parse dict"); + fz_rethrow_message(ctx, "cannot parse dict"); } return dict; } @@ -488,7 +488,7 @@ pdf_parse_stm_obj(pdf_document *xref, fz_stream *file, pdf_lexbuf *buf) case PDF_TOK_FALSE: return pdf_new_bool(ctx, 0); break; case PDF_TOK_NULL: return pdf_new_null(ctx); break; case PDF_TOK_INT: return pdf_new_int(ctx, buf->i); break; - default: fz_throw(ctx, "unknown token in object stream"); + default: fz_throw(ctx, FZ_ERROR_GENERIC, "unknown token in object stream"); } return NULL; /* Stupid MSVC */ } @@ -508,17 +508,17 @@ pdf_parse_ind_obj(pdf_document *xref, tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected object number"); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected object number"); num = buf->i; tok = pdf_lex(file, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "expected generation number (%d ? obj)", num); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected generation number (%d ? obj)", num); gen = buf->i; tok = pdf_lex(file, buf); if (tok != PDF_TOK_OBJ) - fz_throw(ctx, "expected 'obj' keyword (%d %d ?)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'obj' keyword (%d %d ?)", num, gen); tok = pdf_lex(file, buf); @@ -558,14 +558,14 @@ pdf_parse_ind_obj(pdf_document *xref, break; } } - fz_throw(ctx, "expected 'R' keyword (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "expected 'R' keyword (%d %d R)", num, gen); case PDF_TOK_ENDOBJ: obj = pdf_new_null(ctx); goto skip; default: - fz_throw(ctx, "syntax error in object (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntax error in object (%d %d R)", num, gen); } fz_try(ctx) @@ -575,7 +575,7 @@ pdf_parse_ind_obj(pdf_document *xref, fz_catch(ctx) { pdf_drop_obj(obj); - fz_throw(ctx, "cannot parse indirect object (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot parse indirect object (%d %d R)", num, gen); } skip: diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c index 15d0b942..622705b2 100644 --- a/pdf/pdf_pattern.c +++ b/pdf/pdf_pattern.c @@ -77,7 +77,7 @@ pdf_load_pattern(pdf_document *xref, pdf_obj *dict) { pdf_remove_item(ctx, pdf_free_pattern_imp, dict); pdf_drop_pattern(ctx, pat); - fz_throw(ctx, "cannot load pattern stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load pattern stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return pat; } diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index e482ec3a..421696a2 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -44,9 +44,10 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf } fz_catch(ctx) { + /* FIXME: TryLater */ /* Don't let a broken object at EOF overwrite a good one */ if (file->eof) - fz_throw(ctx, "broken object at EOF ignored"); + fz_rethrow_message(ctx, "broken object at EOF ignored"); /* Silently swallow the error */ dict = pdf_new_dict(ctx, 2); } @@ -84,7 +85,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf { *tmpofs = fz_tell(file); if (*tmpofs < 0) - fz_throw(ctx, "cannot tell in file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(file, buf); } @@ -99,7 +100,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf *stmofsp = fz_tell(file); if (*stmofsp < 0) - fz_throw(ctx, "cannot seek in file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file"); if (stm_len > 0) { @@ -110,6 +111,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "cannot find endstream token, falling back to scanning"); } if (tok == PDF_TOK_ENDSTREAM) @@ -119,7 +121,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf n = fz_read(file, (unsigned char *) buf->scratch, 9); if (n < 0) - fz_throw(ctx, "cannot read from file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read from file"); while (memcmp(buf->scratch, "endstream", 9) != 0) { @@ -135,7 +137,7 @@ pdf_repair_obj(fz_stream *file, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf atobjend: *tmpofs = fz_tell(file); if (*tmpofs < 0) - fz_throw(ctx, "cannot tell in file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(file, buf); if (tok != PDF_TOK_ENDOBJ) fz_warn(ctx, "object missing 'endobj' token"); @@ -144,7 +146,7 @@ atobjend: /* Read another token as we always return the next one */ *tmpofs = fz_tell(file); if (*tmpofs < 0) - fz_throw(ctx, "cannot tell in file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(file, buf); } } @@ -181,7 +183,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen) tok = pdf_lex(stm, &buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen); n = buf.i; if (n < 0) @@ -205,7 +207,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen) tok = pdf_lex(stm, &buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen); } } fz_always(ctx) @@ -215,7 +217,7 @@ pdf_repair_obj_stm(pdf_document *xref, int num, int gen) } fz_catch(ctx) { - fz_throw(ctx, "cannot load object stream object (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot load object stream object (%d %d R)", num, gen); } } @@ -266,7 +268,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) /* look for '%PDF' version marker within first kilobyte of file */ n = fz_read(xref->file, (unsigned char *)buf->scratch, fz_mini(buf->size, 1024)); if (n < 0) - fz_throw(ctx, "cannot read from file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot read from file"); fz_seek(xref->file, 0, 0); for (i = 0; i < n - 4; i++) @@ -289,7 +291,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) { tmpofs = fz_tell(xref->file); if (tmpofs < 0) - fz_throw(ctx, "cannot tell in file"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); fz_try(ctx) { @@ -297,6 +299,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "ignoring the rest of the file"); break; } @@ -322,6 +325,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) } fz_catch(ctx) { + /* FIXME: TryLater */ /* If we haven't seen a root yet, there is nothing * we can do, but give up. Otherwise, we'll make * do. */ @@ -372,6 +376,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) } fz_catch(ctx) { + /* FIXME: TryLater */ /* If we haven't seen a root yet, there is nothing * we can do, but give up. Otherwise, we'll make * do. */ @@ -577,6 +582,6 @@ pdf_repair_obj_stms(pdf_document *xref) pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i); if (entry->type == 'o' && pdf_get_populating_xref_entry(xref, entry->ofs)->type != 'n') - fz_throw(xref->ctx, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid reference to non-object-stream: %d (%d 0 R)", entry->ofs, i); } } diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index 04c50b03..41ddcc1a 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -346,7 +346,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf obj = pdf_dict_gets(dict, "ColorSpace"); if (!obj) - fz_throw(ctx, "shading colorspace is missing"); + fz_throw(ctx, FZ_ERROR_GENERIC, "shading colorspace is missing"); shade->colorspace = pdf_load_colorspace(xref, obj); obj = pdf_dict_gets(dict, "Background"); @@ -374,7 +374,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf func[0] = pdf_load_function(xref, obj, in, out); if (!func[0]) - fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } else if (pdf_is_array(obj)) { @@ -382,12 +382,12 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf if (funcs != 1 && funcs != shade->colorspace->n) { funcs = 0; - fz_throw(ctx, "incorrect number of shading functions"); + fz_throw(ctx, FZ_ERROR_GENERIC, "incorrect number of shading functions"); } if (funcs > FZ_MAX_COLORS) { funcs = 0; - fz_throw(ctx, "too many shading functions"); + fz_throw(ctx, FZ_ERROR_GENERIC, "too many shading functions"); } if (type == 1) @@ -400,13 +400,13 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf { func[i] = pdf_load_function(xref, pdf_array_get(obj, i), in, out); if (!func[i]) - fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } } else if (type < 4) { /* Functions are compulsory for types 1,2,3 */ - fz_throw(ctx, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load shading function (%d %d R)", pdf_to_num(obj), pdf_to_gen(obj)); } shade->type = type; @@ -420,7 +420,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf case 6: pdf_load_type6_shade(shade, xref, dict, funcs, func); break; case 7: pdf_load_type7_shade(shade, xref, dict, funcs, func); break; default: - fz_throw(ctx, "unknown shading type: %d", type); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown shading type: %d", type); } } fz_always(ctx) @@ -433,7 +433,7 @@ pdf_load_shading_dict(pdf_document *xref, pdf_obj *dict, const fz_matrix *transf { fz_drop_shade(ctx, shade); - fz_throw(ctx, "cannot load shading type %d (%d %d R)", type, pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load shading type %d (%d %d R)", type, pdf_to_num(dict), pdf_to_gen(dict)); } return shade; } @@ -481,7 +481,7 @@ pdf_load_shading(pdf_document *xref, pdf_obj *dict) obj = pdf_dict_gets(dict, "Shading"); if (!obj) - fz_throw(ctx, "syntaxerror: missing shading dictionary"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing shading dictionary"); shade = pdf_load_shading_dict(xref, obj, &mat); } diff --git a/pdf/pdf_stream.c b/pdf/pdf_stream.c index 7c1f4a6c..7e74b666 100644 --- a/pdf/pdf_stream.c +++ b/pdf/pdf_stream.c @@ -329,14 +329,14 @@ pdf_open_raw_renumbered_stream(pdf_document *xref, int num, int gen, int orig_nu pdf_xref_entry *x; if (num < 0 || num >= pdf_xref_len(xref)) - fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen); x = pdf_get_xref_entry(xref, num); pdf_cache_object(xref, num, gen); if (x->stm_ofs == 0) - fz_throw(xref->ctx, "object is not a stream"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream"); return pdf_open_raw_filter(xref->file, xref, x->obj, num, orig_num, orig_gen, x->stm_ofs); } @@ -347,14 +347,14 @@ pdf_open_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or pdf_xref_entry *x; if (num < 0 || num >= pdf_xref_len(xref)) - fz_throw(xref->ctx, "object id out of range (%d %d R)", num, gen); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object id out of range (%d %d R)", num, gen); x = pdf_get_xref_entry(xref, num); pdf_cache_object(xref, num, gen); if (x->stm_ofs == 0 && x->stm_buf == NULL) - fz_throw(xref->ctx, "object is not a stream"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream"); return pdf_open_filter(xref->file, xref, x->obj, orig_num, orig_gen, x->stm_ofs, params); } @@ -374,7 +374,7 @@ fz_stream * pdf_open_stream_with_offset(pdf_document *xref, int num, int gen, pdf_obj *dict, int stm_ofs) { if (stm_ofs == 0) - fz_throw(xref->ctx, "object is not a stream"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "object is not a stream"); return pdf_open_filter(xref->file, xref, dict, num, gen, stm_ofs, NULL); } @@ -477,7 +477,7 @@ pdf_load_image_stream(pdf_document *xref, int num, int gen, int orig_num, int or } fz_catch(ctx) { - fz_throw(ctx, "cannot read raw stream (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot read raw stream (%d %d R)", num, gen); } return buf; @@ -536,6 +536,7 @@ pdf_open_object_array(pdf_document *xref, pdf_obj *list) } fz_catch(ctx) { + /* FIXME: TryLater */ fz_warn(ctx, "cannot load content stream part %d/%d", i + 1, n); continue; } diff --git a/pdf/pdf_type3.c b/pdf/pdf_type3.c index bb952ff7..d85d9f11 100644 --- a/pdf/pdf_type3.c +++ b/pdf/pdf_type3.c @@ -60,7 +60,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) encoding = pdf_dict_gets(dict, "Encoding"); if (!encoding) { - fz_throw(ctx, "syntaxerror: Type3 font missing Encoding"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Encoding"); } if (pdf_is_name(encoding)) @@ -108,7 +108,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) widths = pdf_dict_gets(dict, "Widths"); if (!widths) { - fz_throw(ctx, "syntaxerror: Type3 font missing Widths"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Widths"); } for (i = first; i <= last; i++) @@ -140,7 +140,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) charprocs = pdf_dict_gets(dict, "CharProcs"); if (!charprocs) { - fz_throw(ctx, "syntaxerror: Type3 font missing CharProcs"); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing CharProcs"); } for (i = 0; i < 256; i++) @@ -161,7 +161,7 @@ pdf_load_type3_font(pdf_document *xref, pdf_obj *rdb, pdf_obj *dict) { if (fontdesc) pdf_drop_font(ctx, fontdesc); - fz_throw(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load type3 font (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } return fontdesc; } @@ -184,6 +184,7 @@ void pdf_load_type3_glyphs(pdf_document *xref, pdf_font_desc *fontdesc, int nest } fz_catch(ctx) { - fz_warn(ctx, "Type3 glyph load failed: %s", fz_caught(ctx)); + /* FIXME: TryLater */ + fz_warn(ctx, "Type3 glyph load failed: %s", fz_caught_message(ctx)); } } diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c index 9ca4607e..a423edef 100644 --- a/pdf/pdf_write.c +++ b/pdf/pdf_write.c @@ -531,6 +531,7 @@ static pdf_obj *sweepref(pdf_document *xref, pdf_write_options *opts, pdf_obj *o } fz_catch(ctx) { + /* FIXME: TryLater */ /* Leave broken */ } @@ -1642,12 +1643,13 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in } fz_catch(ctx) { + /* FIXME: TryLater ? */ if (opts->continue_on_error) { fprintf(opts->out, "%d %d obj\nnull\nendobj\n", num, gen); if (opts->errors) (*opts->errors)++; - fz_warn(ctx, "%s", fz_caught(ctx)); + fz_warn(ctx, "%s", fz_caught_message(ctx)); return; } else @@ -1723,12 +1725,13 @@ static void writeobject(pdf_document *xref, pdf_write_options *opts, int num, in } fz_catch(ctx) { + /* FIXME: TryLater ? */ if (opts->continue_on_error) { fprintf(opts->out, "%d %d obj\nnull\nendobj\n", num, gen); if (opts->errors) (*opts->errors)++; - fz_warn(ctx, "%s", fz_caught(ctx)); + fz_warn(ctx, "%s", fz_caught_message(ctx)); } else { @@ -2229,7 +2232,7 @@ void pdf_write_document(pdf_document *xref, char *filename, fz_write_options *fz opts.out = fopen(filename, "wb"); if (!opts.out) - fz_throw(ctx, "cannot open output file '%s'", filename); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open output file '%s'", filename); fz_try(ctx) { diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c index a47ea687..61fc876a 100644 --- a/pdf/pdf_xobject.c +++ b/pdf/pdf_xobject.c @@ -88,7 +88,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict) { form->colorspace = pdf_load_colorspace(xref, obj); if (!form->colorspace) - fz_throw(ctx, "cannot load xobject colorspace"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load xobject colorspace"); } } @@ -102,7 +102,7 @@ pdf_load_xobject(pdf_document *xref, pdf_obj *dict) { pdf_remove_item(ctx, pdf_free_xobject_imp, dict); pdf_drop_xobject(ctx, form); - fz_throw(ctx, "cannot load xobject content stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); + fz_rethrow_message(ctx, "cannot load xobject content stream (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict)); } form->me = pdf_keep_obj(dict); @@ -217,7 +217,7 @@ pdf_new_xobject(pdf_document *xref, const fz_rect *bbox, const fz_matrix *mat) pdf_drop_obj(dict); pdf_drop_obj(idict); pdf_drop_xobject(ctx, form); - fz_throw(ctx, "failed to create xobject)"); + fz_rethrow_message(ctx, "failed to create xobject)"); } return idict; diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c index 9b3d6653..9224d515 100644 --- a/pdf/pdf_xref.c +++ b/pdf/pdf_xref.c @@ -205,7 +205,7 @@ pdf_load_version(pdf_document *xref) fz_seek(xref->file, 0, SEEK_SET); fz_read_line(xref->file, buf, sizeof buf); if (memcmp(buf, "%PDF-", 5) != 0) - fz_throw(xref->ctx, "cannot recognize version marker"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot recognize version marker"); xref->version = atoi(buf + 5) * 10 + atoi(buf + 7); } @@ -226,7 +226,7 @@ pdf_read_start_xref(pdf_document *xref) n = fz_read(xref->file, buf, sizeof buf); if (n < 0) - fz_throw(xref->ctx, "cannot read from file"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot read from file"); for (i = n - 9; i >= 0; i--) { @@ -242,7 +242,7 @@ pdf_read_start_xref(pdf_document *xref) } } - fz_throw(xref->ctx, "cannot find startxref"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find startxref"); } /* @@ -265,7 +265,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf) fz_read_line(xref->file, buf->scratch, buf->size); if (strncmp(buf->scratch, "xref", 4) != 0) - fz_throw(xref->ctx, "cannot find xref marker"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find xref marker"); while (1) { @@ -277,7 +277,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf) s = buf->scratch; fz_strsep(&s, " "); /* ignore ofs */ if (!s) - fz_throw(xref->ctx, "invalid range marker in xref"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "invalid range marker in xref"); len = fz_atoi(fz_strsep(&s, " ")); /* broken pdfs where the section is not on a separate line */ @@ -286,7 +286,7 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf) t = fz_tell(xref->file); if (t < 0) - fz_throw(xref->ctx, "cannot tell in file"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot tell in file"); fz_seek(xref->file, t + 20 * len, SEEK_SET); } @@ -296,23 +296,23 @@ pdf_xref_size_from_old_trailer(pdf_document *xref, pdf_lexbuf *buf) pdf_obj *trailer; tok = pdf_lex(xref->file, buf); if (tok != PDF_TOK_TRAILER) - fz_throw(xref->ctx, "expected trailer marker"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer marker"); tok = pdf_lex(xref->file, buf); if (tok != PDF_TOK_OPEN_DICT) - fz_throw(xref->ctx, "expected trailer dictionary"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary"); trailer = pdf_parse_dict(xref, xref->file, buf); size = pdf_to_int(pdf_dict_gets(trailer, "Size")); if (!size) - fz_throw(xref->ctx, "trailer missing Size entry"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "trailer missing Size entry"); pdf_drop_obj(trailer); } fz_catch(xref->ctx) { - fz_throw(xref->ctx, "cannot parse trailer"); + fz_rethrow_message(xref->ctx, "cannot parse trailer"); } fz_seek(xref->file, ofs, SEEK_SET); @@ -345,7 +345,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf) fz_read_line(xref->file, buf->scratch, buf->size); if (strncmp(buf->scratch, "xref", 4) != 0) - fz_throw(xref->ctx, "cannot find xref marker"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot find xref marker"); while (1) { @@ -366,7 +366,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf) } if (ofs < 0) - fz_throw(xref->ctx, "out of range object num in xref: %d", ofs); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", ofs); /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) @@ -381,7 +381,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf) pdf_xref_entry *entry = pdf_get_populating_xref_entry(xref, i); n = fz_read(xref->file, (unsigned char *) buf->scratch, 20); if (n < 0) - fz_throw(xref->ctx, "cannot read xref table"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "cannot read xref table"); if (!entry->type) { s = buf->scratch; @@ -394,7 +394,7 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf) entry->gen = atoi(s + 11); entry->type = s[17]; if (s[17] != 'f' && s[17] != 'n' && s[17] != 'o') - fz_throw(xref->ctx, "unexpected xref type: %#x (%d %d R)", s[17], i, entry->gen); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "unexpected xref type: %#x (%d %d R)", s[17], i, entry->gen); } } } @@ -403,17 +403,17 @@ pdf_read_old_xref(pdf_document *xref, pdf_lexbuf *buf) { tok = pdf_lex(xref->file, buf); if (tok != PDF_TOK_TRAILER) - fz_throw(xref->ctx, "expected trailer marker"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer marker"); tok = pdf_lex(xref->file, buf); if (tok != PDF_TOK_OPEN_DICT) - fz_throw(xref->ctx, "expected trailer dictionary"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "expected trailer dictionary"); trailer = pdf_parse_dict(xref, xref->file, buf); } fz_catch(xref->ctx) { - fz_throw(xref->ctx, "cannot parse trailer"); + fz_rethrow_message(xref->ctx, "cannot parse trailer"); } return trailer; } @@ -424,9 +424,9 @@ pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, in int i, n; if (i0 < 0 || i1 < 0) - fz_throw(xref->ctx, "negative xref stream entry index"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); if (i0 + i1 > pdf_xref_len(xref)) - fz_throw(xref->ctx, "xref stream has too many entries"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); for (i = i0; i < i0 + i1; i++) { @@ -436,7 +436,7 @@ pdf_read_new_xref_section(pdf_document *xref, fz_stream *stm, int i0, int i1, in int c = 0; if (fz_is_eof(stm)) - fz_throw(xref->ctx, "truncated xref stream"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "truncated xref stream"); for (n = 0; n < w0; n++) a = (a << 8) + fz_read_byte(stm); @@ -486,25 +486,25 @@ pdf_read_new_xref(pdf_document *xref, pdf_lexbuf *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot parse compressed xref stream object"); + fz_rethrow_message(ctx, "cannot parse compressed xref stream object"); } fz_try(ctx) { obj = pdf_dict_gets(trailer, "Size"); if (!obj) - fz_throw(ctx, "xref stream missing Size entry (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing Size entry (%d %d R)", num, gen); size = pdf_to_int(obj); /* Access xref entry to assure table size */ (void)pdf_get_populating_xref_entry(xref, size-1); if (num < 0 || num >= pdf_xref_len(xref)) - fz_throw(ctx, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(xref) - 1); + fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d %d R) out of range (0..%d)", num, gen, pdf_xref_len(xref) - 1); obj = pdf_dict_gets(trailer, "W"); if (!obj) - fz_throw(ctx, "xref stream missing W entry (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing W entry (%d %d R)", num, gen); w0 = pdf_to_int(pdf_array_get(obj, 0)); w1 = pdf_to_int(pdf_array_get(obj, 1)); w2 = pdf_to_int(pdf_array_get(obj, 2)); @@ -573,11 +573,11 @@ pdf_read_xref(pdf_document *xref, int ofs, pdf_lexbuf *buf) else if (c >= '0' && c <= '9') trailer = pdf_read_new_xref(xref, buf); else - fz_throw(ctx, "cannot recognize xref format"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize xref format"); } fz_catch(ctx) { - fz_throw(ctx, "cannot read xref (ofs=%d)", ofs); + fz_rethrow_message(ctx, "cannot read xref (ofs=%d)", ofs); } return trailer; } @@ -631,7 +631,7 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset if (xrefstmofs) { if (xrefstmofs < 0) - fz_throw(ctx, "negative xref stream offset"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset"); /* Read the XRefStm stream, but throw away the resulting trailer. We do not @@ -643,15 +643,16 @@ read_xref_section(pdf_document *xref, int ofs, pdf_lexbuf *buf, ofs_list *offset prevofs = pdf_to_int(pdf_dict_gets(trailer, "Prev")); if (prevofs < 0) - fz_throw(ctx, "negative xref stream offset for previous xref stream"); - + fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset for previous xref stream"); + } + fz_always(ctx) + { pdf_drop_obj(trailer); trailer = NULL; } fz_catch(ctx) { - pdf_drop_obj(trailer); - fz_throw(ctx, "cannot read xref at offset %d", ofs); + fz_rethrow_message(ctx, "cannot read xref at offset %d", ofs); } return prevofs; @@ -705,7 +706,7 @@ pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf) /* broken pdfs where first object is not free */ if (pdf_get_xref_entry(xref, 0)->type != 'f') - fz_throw(ctx, "first object in xref is not free"); + fz_throw(ctx, FZ_ERROR_GENERIC, "first object in xref is not free"); /* broken pdfs where object offsets are out of range */ xref_len = pdf_xref_len(xref); @@ -719,11 +720,11 @@ pdf_load_xref(pdf_document *xref, pdf_lexbuf *buf) if (entry->ofs == 0) entry->type = 'f'; else if (entry->ofs <= 0 || entry->ofs >= xref->file_size) - fz_throw(ctx, "object offset out of range: %d (%d 0 R)", entry->ofs, i); + fz_throw(ctx, FZ_ERROR_GENERIC, "object offset out of range: %d (%d 0 R)", entry->ofs, i); } if (entry->type == 'o') if (entry->ofs <= 0 || entry->ofs >= xref_len || pdf_get_xref_entry(xref, entry->ofs)->type != 'n') - fz_throw(ctx, "invalid reference to an objstm that does not exist: %d (%d 0 R)", entry->ofs, i); + fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", entry->ofs, i); } } @@ -741,19 +742,19 @@ pdf_ocg_set_config(pdf_document *xref, int config) if (config == 0) return; else - fz_throw(xref->ctx, "Unknown OCG config (None known!)"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Unknown OCG config (None known!)"); } if (config == 0) { cobj = pdf_dict_gets(obj, "D"); if (!cobj) - fz_throw(xref->ctx, "No default OCG config"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "No default OCG config"); } else { cobj = pdf_array_get(pdf_dict_gets(obj, "Configs"), config); if (!cobj) - fz_throw(xref->ctx, "Illegal OCG config"); + fz_throw(xref->ctx, FZ_ERROR_GENERIC, "Illegal OCG config"); } pdf_drop_obj(desc->intent); @@ -910,6 +911,7 @@ pdf_init_document(pdf_document *xref) } fz_catch(ctx) { + /* FIXME: TryLater ? */ pdf_free_xref_sections(xref); fz_warn(xref->ctx, "trying to repair broken xref"); repaired = 1; @@ -950,6 +952,7 @@ pdf_init_document(pdf_document *xref) } fz_catch(ctx) { + /* FIXME: TryLater ? */ fz_warn(ctx, "ignoring broken object (%d 0 R)", i); continue; } @@ -989,7 +992,7 @@ pdf_init_document(pdf_document *xref) pdf_drop_obj(dict); pdf_drop_obj(nobj); pdf_close_document(xref); - fz_throw(ctx, "cannot open document"); + fz_rethrow_message(ctx, "cannot open document"); } fz_try(ctx) @@ -998,6 +1001,7 @@ pdf_init_document(pdf_document *xref) } fz_catch(ctx) { + /* FIXME: TryLater ? */ fz_warn(ctx, "Ignoring Broken Optional Content"); } } @@ -1096,9 +1100,9 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf) first = pdf_to_int(pdf_dict_gets(objstm, "First")); if (count < 0) - fz_throw(ctx, "negative number of objects in object stream"); + fz_throw(ctx, FZ_ERROR_GENERIC, "negative number of objects in object stream"); if (first < 0) - fz_throw(ctx, "first object in object stream resides outside stream"); + fz_throw(ctx, FZ_ERROR_GENERIC, "first object in object stream resides outside stream"); numbuf = fz_calloc(ctx, count, sizeof(int)); ofsbuf = fz_calloc(ctx, count, sizeof(int)); @@ -1108,12 +1112,12 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf) { tok = pdf_lex(stm, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen); numbuf[i] = buf->i; tok = pdf_lex(stm, buf); if (tok != PDF_TOK_INT) - fz_throw(ctx, "corrupt object stream (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d %d R)", num, gen); ofsbuf[i] = buf->i; } @@ -1130,7 +1134,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf) if (numbuf[i] < 1 || numbuf[i] >= xref_len) { pdf_drop_obj(obj); - fz_throw(ctx, "object id (%d 0 R) out of range (0..%d)", numbuf[i], xref_len - 1); + fz_throw(ctx, FZ_ERROR_GENERIC, "object id (%d 0 R) out of range (0..%d)", numbuf[i], xref_len - 1); } entry = pdf_get_xref_entry(xref, numbuf[i]); @@ -1165,7 +1169,7 @@ pdf_load_obj_stm(pdf_document *xref, int num, int gen, pdf_lexbuf *buf) } fz_catch(ctx) { - fz_throw(ctx, "cannot open object stream (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot open object stream (%d %d R)", num, gen); } } @@ -1181,7 +1185,7 @@ pdf_cache_object(pdf_document *xref, int num, int gen) fz_context *ctx = xref->ctx; if (num < 0 || num >= pdf_xref_len(xref)) - fz_throw(ctx, "object out of range (%d %d R); xref size %d", num, gen, pdf_xref_len(xref)); + fz_throw(ctx, FZ_ERROR_GENERIC, "object out of range (%d %d R); xref size %d", num, gen, pdf_xref_len(xref)); x = pdf_get_xref_entry(xref, num); @@ -1204,14 +1208,14 @@ pdf_cache_object(pdf_document *xref, int num, int gen) } fz_catch(ctx) { - fz_throw(ctx, "cannot parse object (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot parse object (%d %d R)", num, gen); } if (rnum != num) { pdf_drop_obj(x->obj); x->obj = NULL; - fz_throw(ctx, "found object (%d %d R) instead of (%d %d R)", rnum, rgen, num, gen); + fz_rethrow_message(ctx, "found object (%d %d R) instead of (%d %d R)", rnum, rgen, num, gen); } if (xref->crypt) @@ -1227,15 +1231,15 @@ pdf_cache_object(pdf_document *xref, int num, int gen) } fz_catch(ctx) { - fz_throw(ctx, "cannot load object stream containing object (%d %d R)", num, gen); + fz_rethrow_message(ctx, "cannot load object stream containing object (%d %d R)", num, gen); } if (!x->obj) - fz_throw(ctx, "object (%d %d R) was not found in its object stream", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "object (%d %d R) was not found in its object stream", num, gen); } } else { - fz_throw(ctx, "cannot find object in xref (%d %d R)", num, gen); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find object in xref (%d %d R)", num, gen); } } @@ -1251,7 +1255,7 @@ pdf_load_object(pdf_document *xref, int num, int gen) } fz_catch(ctx) { - fz_throw(ctx, "cannot load object (%d %d R) into cache", num, gen); + fz_rethrow_message(ctx, "cannot load object (%d %d R) into cache", num, gen); } entry = pdf_get_xref_entry(xref, num); @@ -1290,6 +1294,7 @@ pdf_resolve_indirect(pdf_obj *ref) } fz_catch(ctx) { + /* FIXME: TryLater ? */ fz_warn(ctx, "cannot load object (%d %d R) into cache", num, gen); return NULL; } @@ -1536,7 +1541,7 @@ pdf_open_document_no_run(fz_context *ctx, const char *filename) } fz_catch(ctx) { - fz_throw(ctx, "cannot load document '%s'", filename); + fz_rethrow_message(ctx, "cannot load document '%s'", filename); } return doc; } diff --git a/xps/xps_doc.c b/xps/xps_doc.c index 0bee4931..9953cb37 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -400,7 +400,7 @@ xps_read_page_list(xps_document *doc) xps_read_and_process_metadata_part(doc, "/_rels/.rels", NULL); if (!doc->start_part) - fz_throw(doc->ctx, "cannot find fixed document sequence start part"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find fixed document sequence start part"); xps_read_and_process_metadata_part(doc, doc->start_part, NULL); @@ -414,6 +414,7 @@ xps_read_page_list(xps_document *doc) } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ fz_warn(doc->ctx, "cannot process FixedDocument rels part"); } xps_read_and_process_metadata_part(doc, fixdoc->name, fixdoc); @@ -446,10 +447,11 @@ xps_load_fixed_page(xps_document *doc, xps_page *page) } fz_catch(ctx) { + /* FIXME: TryLater ? */ root = NULL; } if (!root) - fz_throw(doc->ctx, "FixedPage missing root element"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "FixedPage missing root element"); if (!strcmp(fz_xml_tag(root), "mc:AlternateContent")) { @@ -457,7 +459,7 @@ xps_load_fixed_page(xps_document *doc, xps_page *page) if (!node) { fz_free_xml(doc->ctx, root); - fz_throw(doc->ctx, "FixedPage missing alternate root element"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "FixedPage missing alternate root element"); } fz_detach_xml(node); fz_free_xml(doc->ctx, root); @@ -467,21 +469,21 @@ xps_load_fixed_page(xps_document *doc, xps_page *page) if (strcmp(fz_xml_tag(root), "FixedPage")) { fz_free_xml(doc->ctx, root); - fz_throw(doc->ctx, "expected FixedPage element"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "expected FixedPage element"); } width_att = fz_xml_att(root, "Width"); if (!width_att) { fz_free_xml(doc->ctx, root); - fz_throw(doc->ctx, "FixedPage missing required attribute: Width"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "FixedPage missing required attribute: Width"); } height_att = fz_xml_att(root, "Height"); if (!height_att) { fz_free_xml(doc->ctx, root); - fz_throw(doc->ctx, "FixedPage missing required attribute: Height"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "FixedPage missing required attribute: Height"); } page->width = atoi(width_att); @@ -507,7 +509,7 @@ xps_load_page(xps_document *doc, int number) n ++; } - fz_throw(doc->ctx, "cannot find page %d", number + 1); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find page %d", number + 1); return NULL; } diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index dd4487d4..72f37ca1 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -510,6 +510,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm, } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ fz_warn(doc->ctx, "cannot find font resource part '%s'", partname); return; } @@ -526,6 +527,7 @@ xps_parse_glyphs(xps_document *doc, const fz_matrix *ctm, } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ fz_warn(doc->ctx, "cannot load font resource '%s'", partname); xps_free_part(doc, part); return; diff --git a/xps/xps_image.c b/xps/xps_image.c index c00c96ae..eb0d876f 100644 --- a/xps/xps_image.c +++ b/xps/xps_image.c @@ -38,7 +38,7 @@ xps_find_image_brush_source_part(xps_document *doc, char *base_uri, fz_xml *root image_source_att = fz_xml_att(root, "ImageSource"); if (!image_source_att) - fz_throw(doc->ctx, "cannot find image source attribute"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find image source attribute"); /* "{ColorConvertedBitmap /Resources/Image.tiff /Resources/Profile.icc}" */ if (strstr(image_source_att, "{ColorConvertedBitmap") == image_source_att) @@ -69,7 +69,7 @@ xps_find_image_brush_source_part(xps_document *doc, char *base_uri, fz_xml *root } if (!image_name) - fz_throw(doc->ctx, "cannot find image source"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find image source"); if (image_part) { @@ -102,6 +102,7 @@ xps_parse_image_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *ar } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ fz_warn(doc->ctx, "cannot find image source"); return; } @@ -116,6 +117,7 @@ xps_parse_image_brush(xps_document *doc, const fz_matrix *ctm, const fz_rect *ar } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ fz_warn(doc->ctx, "cannot decode image resource"); return; } diff --git a/xps/xps_outline.c b/xps/xps_outline.c index bb5eccb0..b87460a4 100644 --- a/xps/xps_outline.c +++ b/xps/xps_outline.c @@ -131,6 +131,7 @@ xps_load_outline(xps_document *doc) } fz_catch(doc->ctx) { + /* FIXME: TryLater ? */ outline = NULL; } if (!outline) diff --git a/xps/xps_resource.c b/xps/xps_resource.c index 658129c9..5c927e1d 100644 --- a/xps/xps_resource.c +++ b/xps/xps_resource.c @@ -75,6 +75,7 @@ xps_parse_remote_resource_dictionary(xps_document *doc, char *base_uri, char *so } fz_catch(ctx) { + /* FIXME: TryLater ? */ xml = NULL; } @@ -84,7 +85,7 @@ xps_parse_remote_resource_dictionary(xps_document *doc, char *base_uri, char *so if (strcmp(fz_xml_tag(xml), "ResourceDictionary")) { fz_free_xml(doc->ctx, xml); - fz_throw(doc->ctx, "expected ResourceDictionary element"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "expected ResourceDictionary element"); } fz_strlcpy(part_uri, part_name, sizeof part_uri); diff --git a/xps/xps_zip.c b/xps/xps_zip.c index 0bda1341..70b643af 100644 --- a/xps/xps_zip.c +++ b/xps/xps_zip.c @@ -113,7 +113,7 @@ xps_read_zip_entry(xps_document *doc, xps_entry *ent, unsigned char *outbuf) sig = getlong(doc->file); if (sig != ZIP_LOCAL_FILE_SIG) { - fz_throw(doc->ctx, "wrong zip local file signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip local file signature (0x%x)", sig); } (void) getshort(doc->file); /* version */ @@ -152,27 +152,27 @@ xps_read_zip_entry(xps_document *doc, xps_entry *ent, unsigned char *outbuf) if (code != Z_OK) { fz_free(ctx, inbuf); - fz_throw(ctx, "zlib inflateInit2 error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateInit2 error: %s", stream.msg); } code = inflate(&stream, Z_FINISH); if (code != Z_STREAM_END) { inflateEnd(&stream); fz_free(ctx, inbuf); - fz_throw(ctx, "zlib inflate error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflate error: %s", stream.msg); } code = inflateEnd(&stream); if (code != Z_OK) { fz_free(ctx, inbuf); - fz_throw(ctx, "zlib inflateEnd error: %s", stream.msg); + fz_throw(ctx, FZ_ERROR_GENERIC, "zlib inflateEnd error: %s", stream.msg); } fz_free(ctx, inbuf); } else { - fz_throw(ctx, "unknown compression method (%d)", method); + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown compression method (%d)", method); } } @@ -192,7 +192,7 @@ xps_read_zip_dir(xps_document *doc, int start_offset) sig = getlong(doc->file); if (sig != ZIP_END_OF_CENTRAL_DIRECTORY_SIG) - fz_throw(doc->ctx, "wrong zip end of central directory signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip end of central directory signature (0x%x)", sig); (void) getshort(doc->file); /* this disk */ (void) getshort(doc->file); /* start disk */ @@ -208,18 +208,18 @@ xps_read_zip_dir(xps_document *doc, int start_offset) sig = getlong(doc->file); if (sig != ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR_SIG) - fz_throw(doc->ctx, "wrong zip64 end of central directory locator signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip64 end of central directory locator signature (0x%x)", sig); (void) getlong(doc->file); /* start disk */ offset = getlong64(doc->file); /* offset to end of central directory record */ if (offset < 0) - fz_throw(doc->ctx, "zip64 files larger than 2 GB aren't supported"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "zip64 files larger than 2 GB aren't supported"); fz_seek(doc->file, offset, 0); sig = getlong(doc->file); if (sig != ZIP64_END_OF_CENTRAL_DIRECTORY_SIG) - fz_throw(doc->ctx, "wrong zip64 end of central directory signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip64 end of central directory signature (0x%x)", sig); (void) getlong64(doc->file); /* size of record */ (void) getshort(doc->file); /* version made by */ @@ -232,7 +232,7 @@ xps_read_zip_dir(xps_document *doc, int start_offset) offset = getlong64(doc->file); /* offset to central directory */ if (count < 0 || offset < 0) - fz_throw(doc->ctx, "zip64 files larger than 2 GB aren't supported"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "zip64 files larger than 2 GB aren't supported"); } doc->zip_table = fz_malloc_array(doc->ctx, count, sizeof(xps_entry)); @@ -245,7 +245,7 @@ xps_read_zip_dir(xps_document *doc, int start_offset) { sig = getlong(doc->file); if (sig != ZIP_CENTRAL_DIRECTORY_SIG) - fz_throw(doc->ctx, "wrong zip central directory signature (0x%x)", sig); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "wrong zip central directory signature (0x%x)", sig); (void) getshort(doc->file); /* version made by */ (void) getshort(doc->file); /* version to extract */ @@ -283,7 +283,7 @@ xps_read_zip_dir(xps_document *doc, int start_offset) metasize -= 4 + size; } if (doc->zip_table[i].usize < 0 || doc->zip_table[i].csize < 0 || doc->zip_table[i].offset < 0) - fz_throw(doc->ctx, "zip64 files larger than 2 GB aren't supported"); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "zip64 files larger than 2 GB aren't supported"); fz_seek(doc->file, commentsize, 1); } @@ -321,7 +321,7 @@ xps_find_and_read_zip_dir(xps_document *doc) back += sizeof buf - 4; } - fz_throw(ctx, "cannot find end of central directory"); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find end of central directory"); } /* @@ -377,7 +377,7 @@ xps_read_zip_part(xps_document *doc, char *partname) size += ent->usize; } if (!seen_last) - fz_throw(doc->ctx, "cannot find all pieces for part '%s'", partname); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find all pieces for part '%s'", partname); /* Inflate the pieces */ if (count) @@ -405,7 +405,7 @@ xps_read_zip_part(xps_document *doc, char *partname) return part; } - fz_throw(doc->ctx, "cannot find part '%s'", partname); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find part '%s'", partname); return NULL; } @@ -475,7 +475,7 @@ xps_read_dir_part(xps_document *doc, char *name) fclose(file); } if (!seen_last) - fz_throw(doc->ctx, "cannot find all pieces for part '%s'", name); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find all pieces for part '%s'", name); /* Inflate the pieces */ if (count) @@ -492,7 +492,7 @@ xps_read_dir_part(xps_document *doc, char *name) if (!file) { xps_free_part(doc, part); - fz_throw(doc->ctx, "cannot open file '%s'", buf); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot open file '%s'", buf); } n = fread(part->data + offset, 1, size - offset, file); offset += n; @@ -501,7 +501,7 @@ xps_read_dir_part(xps_document *doc, char *name) return part; } - fz_throw(doc->ctx, "cannot find part '%s'", name); + fz_throw(doc->ctx, FZ_ERROR_GENERIC, "cannot find part '%s'", name); return NULL; } @@ -619,7 +619,7 @@ xps_open_document(fz_context *ctx, const char *filename) file = fz_open_file(ctx, filename); if (!file) - fz_throw(ctx, "cannot open file '%s': %s", filename, strerror(errno)); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) { @@ -631,7 +631,7 @@ xps_open_document(fz_context *ctx, const char *filename) } fz_catch(ctx) { - fz_throw(ctx, "cannot load document '%s'", filename); + fz_rethrow_message(ctx, "cannot load document '%s'", filename); } return doc; } |