summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_context.c1
-rw-r--r--fitz/base_error.c27
-rw-r--r--fitz/base_hash.c2
-rw-r--r--fitz/base_memory.c14
-rw-r--r--fitz/base_xml.c2
-rw-r--r--fitz/crypt_pkcs7.c2
-rw-r--r--fitz/dev_null.c22
-rw-r--r--fitz/filt_basic.c37
-rw-r--r--fitz/filt_dctd.c3
-rw-r--r--fitz/filt_faxd.c18
-rw-r--r--fitz/filt_flate.c4
-rw-r--r--fitz/filt_jbig2d.c2
-rw-r--r--fitz/image_jpeg.c4
-rw-r--r--fitz/image_jpx.c18
-rw-r--r--fitz/image_png.c48
-rw-r--r--fitz/image_tiff.c34
-rw-r--r--fitz/res_bitmap.c2
-rw-r--r--fitz/res_colorspace.c2
-rw-r--r--fitz/res_font.c15
-rw-r--r--fitz/res_image.c9
-rw-r--r--fitz/res_pcl.c28
-rw-r--r--fitz/res_pixmap.c16
-rw-r--r--fitz/res_pwg.c6
-rw-r--r--fitz/res_shade.c4
-rw-r--r--fitz/stm_open.c8
-rw-r--r--fitz/stm_read.c4
26 files changed, 177 insertions, 155 deletions
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, &params))
{
- 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;