summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-09-11 19:29:42 -0500
committerRobin Watts <robin.watts@artifex.com>2011-09-14 17:44:13 +0100
commit89ae81f651bfa112b8e07317eb6983beaf7cb212 (patch)
tree3f99dad1253b795629e66d45b915c1d72043242b /fitz
parentcefb81f1886685580a40b17b5e495a8a8a1ebeaf (diff)
downloadmupdf-89ae81f651bfa112b8e07317eb6983beaf7cb212.tar.xz
Initial import of exception handling code
Import exception handling code from WSS, modified to fit into the fitz world. With this code we have 'real' fz_try/fz_catch/fz_rethrow functions, handling a fz_except type. We therefore rename the existing fz_throw/ fz_catch/fz_rethrow to be fz_error_make/fz_error_handle/fz_error_note. We don't actually use fz_try/fz_catch/fz_rethrow yet...
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_error.c12
-rw-r--r--fitz/base_hash.c2
-rw-r--r--fitz/base_object.c2
-rw-r--r--fitz/except.c49
-rw-r--r--fitz/except.h46
-rw-r--r--fitz/exceptxxx.h36
-rw-r--r--fitz/filt_basic.c22
-rw-r--r--fitz/filt_dctd.c2
-rw-r--r--fitz/filt_faxd.c22
-rw-r--r--fitz/filt_flate.c2
-rw-r--r--fitz/filt_jbig2d.c4
-rw-r--r--fitz/filt_jpxd.c12
-rw-r--r--fitz/filt_predict.c2
-rw-r--r--fitz/fitz.h47
-rw-r--r--fitz/res_bitmap.c2
-rw-r--r--fitz/res_font.c16
-rw-r--r--fitz/res_pixmap.c12
-rw-r--r--fitz/stm_open.c2
-rw-r--r--fitz/stm_read.c10
19 files changed, 223 insertions, 79 deletions
diff --git a/fitz/base_error.c b/fitz/base_error.c
index a0efa290..1610d033 100644
--- a/fitz/base_error.c
+++ b/fitz/base_error.c
@@ -66,7 +66,7 @@ fz_get_error_line(int n)
}
fz_error
-fz_throw_imp(const char *file, int line, const char *func, char *fmt, ...)
+fz_error_make_imp(const char *file, int line, const char *func, char *fmt, ...)
{
va_list ap;
char one[LINE_LEN], two[LINE_LEN];
@@ -84,7 +84,7 @@ fz_throw_imp(const char *file, int line, const char *func, char *fmt, ...)
}
fz_error
-fz_rethrow_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
+fz_error_note_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
char one[LINE_LEN], two[LINE_LEN];
@@ -100,7 +100,7 @@ fz_rethrow_imp(const char *file, int line, const char *func, fz_error cause, cha
}
void
-fz_catch_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
+fz_error_handle_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...)
{
va_list ap;
char one[LINE_LEN], two[LINE_LEN];
@@ -114,7 +114,7 @@ fz_catch_imp(const char *file, int line, const char *func, fz_error cause, char
}
fz_error
-fz_throw_impx(char *fmt, ...)
+fz_error_make_impx(char *fmt, ...)
{
va_list ap;
char buf[LINE_LEN];
@@ -131,7 +131,7 @@ fz_throw_impx(char *fmt, ...)
}
fz_error
-fz_rethrow_impx(fz_error cause, char *fmt, ...)
+fz_error_note_impx(fz_error cause, char *fmt, ...)
{
va_list ap;
char buf[LINE_LEN];
@@ -146,7 +146,7 @@ fz_rethrow_impx(fz_error cause, char *fmt, ...)
}
void
-fz_catch_impx(fz_error cause, char *fmt, ...)
+fz_error_handle_impx(fz_error cause, char *fmt, ...)
{
va_list ap;
char buf[LINE_LEN];
diff --git a/fitz/base_hash.c b/fitz/base_hash.c
index fcfc1f61..b7caf173 100644
--- a/fitz/base_hash.c
+++ b/fitz/base_hash.c
@@ -100,7 +100,7 @@ fz_resize_hash(fz_hash_table *table, int newsize)
if (newsize < oldload * 8 / 10)
{
- fz_throw("assert: resize hash too small");
+ fz_error_make("assert: resize hash too small");
return;
}
diff --git a/fitz/base_object.c b/fitz/base_object.c
index 5c20767a..4a23e5ab 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -537,7 +537,7 @@ fz_copy_dict(fz_obj *obj)
int i;
if (fz_is_indirect(obj) || !fz_is_dict(obj))
- fz_throw("assert: not a dict (%s)", fz_objkindstr(obj));
+ fz_error_make("assert: not a dict (%s)", fz_objkindstr(obj));
new = fz_new_dict(fz_dict_len(obj));
for (i = 0; i < fz_dict_len(obj); i++)
diff --git a/fitz/except.c b/fitz/except.c
new file mode 100644
index 00000000..348b950e
--- /dev/null
+++ b/fitz/except.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include "except.h"
+
+static void do_throw(fz_except_context *ex)
+{
+ if(ex->depth >= 0)
+ longjmp(ex->stack[ex->depth].buffer, 1);
+ else {
+ printf("Uncaught exception: %s\n", ex->except.mess);
+ exit(EXIT_FAILURE); /* Bale through normal channels */
+ }
+}
+
+void fz_throw(fz_context *ctx, char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsprintf(ctx->except->except.mess, fmt, args);
+ va_end(args);
+ do_throw(ctx->except);
+}
+
+fz_except *fz_caught(fz_context *ctx)
+{
+ return &ctx->except->except;
+}
+
+void fz_rethrow(fz_context *ctx)
+{
+ do_throw(ctx->except);
+}
+
+void fz_except_xxx_push(fz_except_context *ex)
+{
+ if(ex->depth+1 >= MAXDEPTH) {
+ fprintf(stderr, "Exception stack overflow!\n");
+ exit(EXIT_FAILURE); /* Bale through normal channels */
+ }
+ ex->depth++;
+}
+
+void fz_var_xxx(void *e)
+{
+ /* Do nothing */
+}
diff --git a/fitz/except.h b/fitz/except.h
new file mode 100644
index 00000000..a964b94e
--- /dev/null
+++ b/fitz/except.h
@@ -0,0 +1,46 @@
+#ifndef EXCEPT_H
+#define EXCEPT_H
+
+#include "fitz.h"
+
+typedef struct fz_except {
+ char mess[256];
+} fz_except;
+
+#include "exceptxxx.h"
+/*
+ Macros for fz_try and fz_catch are defined in exceptxxx.h,
+ but their definitions are best ignored. Just use them as follows:
+
+ fz_var(..);
+ fz_var(..);
+
+ fz_try(ctx)
+ {
+ .
+ .
+ .
+ }
+ fz_catch(ctx)
+ {
+ .
+ .
+ .
+ }
+
+ and don't return from within the try clause.
+*/
+
+void fz_throw(fz_context *, char *, ...);
+
+fz_except *fz_caught(fz_context *);
+
+void fz_rethrow(fz_context *);
+
+#define fz_var(A) fz_var_xxx((void *)&(A))
+
+void fz_var_xxx(void *x);
+
+void fz_except_init(fz_context *);
+
+#endif /* EXCEPT */
diff --git a/fitz/exceptxxx.h b/fitz/exceptxxx.h
new file mode 100644
index 00000000..185f73f6
--- /dev/null
+++ b/fitz/exceptxxx.h
@@ -0,0 +1,36 @@
+#ifndef EXCEPTXXX_H
+#define EXCEPTXXX_H
+
+#include <setjmp.h>
+
+#define fz_try(ctx) \
+if(fz_except_xxx_push(ctx->except), \
+ !setjmp(ctx->except.stack[ctx->except.depth].buffer)) \
+{
+
+#define fz_catch(ctx) \
+ ctx->except.stack[ctx->except.depth].failed = 0;\
+}\
+else\
+{\
+ ctx->except.stack[ctx->except.depth].failed = 1;\
+}\
+if(ex->stack[ex->depth--].failed)
+
+typedef struct fz_except_xxx_stack
+{
+ int failed;
+ jmp_buf buffer;
+} fz_except_xxx_stack;
+
+#define MAXDEPTH (20)
+
+struct fz_except_context {
+ fz_except_xxx_stack stack[MAXDEPTH];
+ int depth;
+ fz_except except;
+};
+
+void fz_except_xxx_push(fz_except_context *);
+
+#endif /* EXCEPTXXX */
diff --git a/fitz/filt_basic.c b/fitz/filt_basic.c
index feb13076..15c42137 100644
--- a/fitz/filt_basic.c
+++ b/fitz/filt_basic.c
@@ -23,7 +23,7 @@ read_null(fz_stream *stm, unsigned char *buf, int len)
int amount = MIN(len, state->remain);
int n = fz_read(state->chain, buf, amount);
if (n < 0)
- return fz_rethrow(n, "read error in null filter");
+ return fz_error_note(n, "read error in null filter");
state->remain -= n;
return n;
}
@@ -124,7 +124,7 @@ read_ahxd(fz_stream *stm, unsigned char *buf, int len)
}
else if (!iswhite(c))
{
- return fz_throw("bad data in ahxd: '%c'", c);
+ return fz_error_make("bad data in ahxd: '%c'", c);
}
}
@@ -228,7 +228,7 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len)
case 0:
break;
case 1:
- return fz_throw("partial final byte in a85d");
+ return fz_error_make("partial final byte in a85d");
case 2:
word = word * (85 * 85 * 85) + 0xffffff;
state->bp[0] = word >> 24;
@@ -256,7 +256,7 @@ read_a85d(fz_stream *stm, unsigned char *buf, int len)
else if (!iswhite(c))
{
- return fz_throw("bad data in a85d: '%c'", c);
+ return fz_error_make("bad data in a85d: '%c'", c);
}
while (state->rp < state->wp && p < ep)
@@ -322,7 +322,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)
- return fz_throw("premature end of data in run length decode");
+ return fz_error_make("premature end of data in run length decode");
}
}
@@ -332,7 +332,7 @@ read_rld(fz_stream *stm, unsigned char *buf, int len)
{
int c = fz_read_byte(state->chain);
if (c < 0)
- return fz_throw("premature end of data in run length decode");
+ return fz_error_make("premature end of data in run length decode");
*p++ = c;
state->n--;
}
@@ -391,7 +391,7 @@ read_arc4(fz_stream *stm, unsigned char *buf, int len)
n = fz_read(state->chain, buf, len);
if (n < 0)
- return fz_rethrow(n, "read error in arc4 filter");
+ return fz_error_note(n, "read error in arc4 filter");
fz_arc4_encrypt(&state->arc4, buf, buf, n);
@@ -443,7 +443,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
{
int c = fz_read_byte(state->chain);
if (c < 0)
- return fz_throw("premature end in aes filter");
+ return fz_error_make("premature end in aes filter");
state->iv[state->ivcount++] = c;
}
@@ -454,11 +454,11 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
{
int n = fz_read(state->chain, state->bp, 16);
if (n < 0)
- return fz_rethrow(n, "read error in aes filter");
+ return fz_error_note(n, "read error in aes filter");
else if (n == 0)
return p - buf;
else if (n < 16)
- return fz_throw("partial block in aes filter");
+ return fz_error_make("partial block in aes filter");
aes_crypt_cbc(&state->aes, AES_DECRYPT, 16, state->iv, state->bp, state->bp);
state->rp = state->bp;
@@ -469,7 +469,7 @@ read_aesd(fz_stream *stm, unsigned char *buf, int len)
{
int pad = state->bp[15];
if (pad < 1 || pad > 16)
- return fz_throw("aes padding out of range: %d", pad);
+ return fz_error_make("aes padding out of range: %d", pad);
state->wp -= pad;
}
diff --git a/fitz/filt_dctd.c b/fitz/filt_dctd.c
index 0e24b794..372efe9e 100644
--- a/fitz/filt_dctd.c
+++ b/fitz/filt_dctd.c
@@ -86,7 +86,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;
- return fz_throw("jpeg error: %s", state->msg);
+ return fz_error_make("jpeg error: %s", state->msg);
}
if (!state->init)
diff --git a/fitz/filt_faxd.c b/fitz/filt_faxd.c
index dcf56cf3..d36c8c76 100644
--- a/fitz/filt_faxd.c
+++ b/fitz/filt_faxd.c
@@ -345,13 +345,13 @@ dec1d(fz_faxd *fax)
code = get_code(fax, cf_white_decode, cfd_white_initial_bits);
if (code == UNCOMPRESSED)
- return fz_throw("uncompressed data in faxd");
+ return fz_error_make("uncompressed data in faxd");
if (code < 0)
- return fz_throw("negative code in 1d faxd");
+ return fz_error_make("negative code in 1d faxd");
if (fax->a + code > fax->columns)
- return fz_throw("overflow in 1d faxd");
+ return fz_error_make("overflow in 1d faxd");
if (fax->c)
setbits(fax->dst, fax->a, fax->a + code);
@@ -386,13 +386,13 @@ dec2d(fz_faxd *fax)
code = get_code(fax, cf_white_decode, cfd_white_initial_bits);
if (code == UNCOMPRESSED)
- return fz_throw("uncompressed data in faxd");
+ return fz_error_make("uncompressed data in faxd");
if (code < 0)
- return fz_throw("negative code in 2d faxd");
+ return fz_error_make("negative code in 2d faxd");
if (fax->a + code > fax->columns)
- return fz_throw("overflow in 2d faxd");
+ return fz_error_make("overflow in 2d faxd");
if (fax->c)
setbits(fax->dst, fax->a, fax->a + code);
@@ -485,13 +485,13 @@ dec2d(fz_faxd *fax)
break;
case UNCOMPRESSED:
- return fz_throw("uncompressed data in faxd");
+ return fz_error_make("uncompressed data in faxd");
case ERROR:
- return fz_throw("invalid code in 2d faxd");
+ return fz_error_make("invalid code in 2d faxd");
default:
- return fz_throw("invalid code in 2d faxd (%d)", code);
+ return fz_error_make("invalid code in 2d faxd (%d)", code);
}
return 0;
@@ -560,14 +560,14 @@ loop:
fax->eolc = 0;
error = dec1d(fax);
if (error)
- return fz_rethrow(error, "cannot decode 1d code");
+ return fz_error_note(error, "cannot decode 1d code");
}
else if (fax->dim == 2)
{
fax->eolc = 0;
error = dec2d(fax);
if (error)
- return fz_rethrow(error, "cannot decode 2d code");
+ return fz_error_note(error, "cannot decode 2d code");
}
/* no eol check after makeup codes nor in the middle of an H code */
diff --git a/fitz/filt_flate.c b/fitz/filt_flate.c
index e7d4c9f7..4d4caf37 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)
{
- return fz_throw("zlib error: %s", zp->msg);
+ return fz_error_make("zlib error: %s", zp->msg);
}
}
diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c
index 4dbe542c..ad335045 100644
--- a/fitz/filt_jbig2d.c
+++ b/fitz/filt_jbig2d.c
@@ -57,7 +57,7 @@ read_jbig2d(fz_stream *stm, unsigned char *buf, int len)
{
n = fz_read(state->chain, tmp, sizeof tmp);
if (n < 0)
- return fz_rethrow(n, "read error in jbig2 filter");
+ return fz_error_note(n, "read error in jbig2 filter");
if (n == 0)
break;
jbig2_data_in(state->ctx, tmp, n);
@@ -67,7 +67,7 @@ read_jbig2d(fz_stream *stm, unsigned char *buf, int len)
state->page = jbig2_page_out(state->ctx);
if (!state->page)
- return fz_throw("jbig2_page_out failed");
+ return fz_error_make("jbig2_page_out failed");
}
s = state->page->data;
diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c
index 765aad29..d646cabc 100644
--- a/fitz/filt_jpxd.c
+++ b/fitz/filt_jpxd.c
@@ -34,7 +34,7 @@ fz_load_jpx_image(fz_pixmap **imgp, unsigned char *data, int size, fz_colorspace
int x, y, k, v;
if (size < 2)
- return fz_throw("not enough data to determine image format");
+ return fz_error_make("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)
@@ -61,16 +61,16 @@ fz_load_jpx_image(fz_pixmap **imgp, unsigned char *data, int size, fz_colorspace
opj_destroy_decompress(info);
if (!jpx)
- return fz_throw("opj_decode failed");
+ return fz_error_make("opj_decode failed");
for (k = 1; k < jpx->numcomps; k++)
{
if (jpx->comps[k].w != jpx->comps[0].w)
- return fz_throw("image components have different width");
+ return fz_error_make("image components have different width");
if (jpx->comps[k].h != jpx->comps[0].h)
- return fz_throw("image components have different height");
+ return fz_error_make("image components have different height");
if (jpx->comps[k].prec != jpx->comps[0].prec)
- return fz_throw("image components have different precision");
+ return fz_error_make("image components have different precision");
}
n = jpx->numcomps;
@@ -112,7 +112,7 @@ fz_load_jpx_image(fz_pixmap **imgp, unsigned char *data, int size, fz_colorspace
if (!img)
{
opj_image_destroy(jpx);
- return fz_throw("out of memory");
+ return fz_error_make("out of memory");
}
p = img->samples;
diff --git a/fitz/filt_predict.c b/fitz/filt_predict.c
index 94f2718a..17cfe905 100644
--- a/fitz/filt_predict.c
+++ b/fitz/filt_predict.c
@@ -154,7 +154,7 @@ read_predict(fz_stream *stm, unsigned char *buf, int len)
{
n = fz_read(state->chain, state->in, state->stride + ispng);
if (n < 0)
- return fz_rethrow(n, "read error in prediction filter");
+ return fz_error_note(n, "read error in prediction filter");
if (n == 0)
return p - buf;
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 30b037e8..afc92436 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -68,33 +68,33 @@ int gettimeofday(struct timeval *tv, struct timezone *tz);
#if __STDC_VERSION__ == 199901L /* C99 */
-#define fz_throw(...) fz_throw_imp(__FILE__, __LINE__, __func__, __VA_ARGS__)
-#define fz_rethrow(cause, ...) fz_rethrow_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
+#define fz_error_make(...) fz_error_make_imp(__FILE__, __LINE__, __func__, __VA_ARGS__)
+#define fz_error_note(cause, ...) fz_error_note_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
#define fz_catch(cause, ...) fz_catch_imp(__FILE__, __LINE__, __func__, cause, __VA_ARGS__)
#elif _MSC_VER >= 1500 /* MSVC 9 or newer */
#define inline __inline
#define restrict __restrict
-#define fz_throw(...) fz_throw_imp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
-#define fz_rethrow(cause, ...) fz_rethrow_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
-#define fz_catch(cause, ...) fz_catch_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
+#define fz_error_make(...) fz_error_make_imp(__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
+#define fz_error_note(cause, ...) fz_error_note_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
+#define fz_catch(cause, ...) fz_error_handle_imp(__FILE__, __LINE__, __FUNCTION__, cause, __VA_ARGS__)
#elif __GNUC__ >= 3 /* GCC 3 or newer */
#define inline __inline
#define restrict __restrict
-#define fz_throw(fmt...) fz_throw_imp(__FILE__, __LINE__, __FUNCTION__, fmt)
-#define fz_rethrow(cause, fmt...) fz_rethrow_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
-#define fz_catch(cause, fmt...) fz_catch_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
+#define fz_error_make(fmt...) fz_error_make_imp(__FILE__, __LINE__, __FUNCTION__, fmt)
+#define fz_error_note(cause, fmt...) fz_error_note_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
+#define fz_error_handle(cause, fmt...) fz_error_handle_imp(__FILE__, __LINE__, __FUNCTION__, cause, fmt)
#else /* Unknown or ancient */
#define inline
#define restrict
-#define fz_throw fz_throw_impx
-#define fz_rethrow fz_rethrow_impx
-#define fz_catch fz_catch_impx
+#define fz_error_make fz_error_make_impx
+#define fz_error_note fz_error_note_impx
+#define fz_error_handle fz_catch_impx
#endif
@@ -122,13 +122,13 @@ typedef int fz_error;
void fz_warn(char *fmt, ...) __printflike(1, 2);
void fz_flush_warnings(void);
-fz_error fz_throw_imp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
-fz_error fz_rethrow_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-void fz_catch_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
+fz_error fz_error_make_imp(const char *file, int line, const char *func, char *fmt, ...) __printflike(4, 5);
+fz_error fz_error_note_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
+void fz_error_handle_imp(const char *file, int line, const char *func, fz_error cause, char *fmt, ...) __printflike(5, 6);
-fz_error fz_throw_impx(char *fmt, ...) __printflike(1, 2);
-fz_error fz_rethrow_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
-void fz_catch_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
+fz_error fz_error_make_impx(char *fmt, ...) __printflike(1, 2);
+fz_error fz_error_note_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
+void fz_error_handle_impx(fz_error cause, char *fmt, ...) __printflike(2, 3);
/* extract the last error stack trace */
int fz_get_error_count(void);
@@ -1119,4 +1119,17 @@ enum
FZ_BLEND_KNOCKOUT = 32
};
+/* Fitz context */
+
+typedef struct fz_except_context fz_except_context;
+typedef struct fz_alloc_context fz_alloc_context;
+
+typedef struct fz_context
+{
+ fz_except_context *except;
+ fz_alloc_context *alloc;
+}
+fz_context;
+
+
#endif
diff --git a/fitz/res_bitmap.c b/fitz/res_bitmap.c
index 0b852af2..a50d0952 100644
--- a/fitz/res_bitmap.c
+++ b/fitz/res_bitmap.c
@@ -55,7 +55,7 @@ fz_write_pbm(fz_bitmap *bitmap, char *filename)
fp = fopen(filename, "wb");
if (!fp)
- return fz_throw("cannot open file '%s': %s", filename, strerror(errno));
+ return fz_error_make("cannot open file '%s': %s", filename, strerror(errno));
assert(bitmap->n == 1);
diff --git a/fitz/res_font.c b/fitz/res_font.c
index ffee1d46..c78b5995 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -150,7 +150,7 @@ fz_init_freetype(void)
fterr = FT_Init_FreeType(&fz_ftlib);
if (fterr)
- return fz_throw("cannot init freetype: %s", ft_error_string(fterr));
+ return fz_error_make("cannot init freetype: %s", ft_error_string(fterr));
FT_Library_Version(fz_ftlib, &maj, &min, &pat);
if (maj == 2 && min == 1 && pat < 7)
@@ -158,7 +158,7 @@ fz_init_freetype(void)
fterr = FT_Done_FreeType(fz_ftlib);
if (fterr)
fz_warn("freetype finalizing: %s", ft_error_string(fterr));
- return fz_throw("freetype version too old: %d.%d.%d", maj, min, pat);
+ return fz_error_make("freetype version too old: %d.%d.%d", maj, min, pat);
}
fz_ftlib_refs++;
@@ -189,11 +189,11 @@ fz_new_font_from_file(fz_font **fontp, char *path, int index)
error = fz_init_freetype();
if (error)
- return fz_rethrow(error, "cannot init freetype library");
+ return fz_error_note(error, "cannot init freetype library");
fterr = FT_New_Face(fz_ftlib, path, index, &face);
if (fterr)
- return fz_throw("freetype: cannot load font: %s", ft_error_string(fterr));
+ return fz_error_make("freetype: cannot load font: %s", ft_error_string(fterr));
font = fz_new_font(face->family_name);
font->ft_face = face;
@@ -216,11 +216,11 @@ fz_new_font_from_memory(fz_font **fontp, unsigned char *data, int len, int index
error = fz_init_freetype();
if (error)
- return fz_rethrow(error, "cannot init freetype library");
+ return fz_error_note(error, "cannot init freetype library");
fterr = FT_New_Memory_Face(fz_ftlib, data, len, index, &face);
if (fterr)
- return fz_throw("freetype: cannot load font: %s", ft_error_string(fterr));
+ return fz_error_make("freetype: cannot load font: %s", ft_error_string(fterr));
font = fz_new_font(face->family_name);
font->ft_face = face;
@@ -534,7 +534,7 @@ fz_render_t3_glyph(fz_font *font, int gid, fz_matrix trm, fz_colorspace *model)
dev = fz_new_bbox_device(&bbox);
error = font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
if (error)
- fz_catch(error, "cannot draw type3 glyph");
+ fz_error_handle(error, "cannot draw type3 glyph");
if (dev->flags & FZ_CHARPROC_MASK)
{
@@ -567,7 +567,7 @@ fz_render_t3_glyph(fz_font *font, int gid, fz_matrix trm, fz_colorspace *model)
dev = fz_new_draw_device_type3(cache, glyph);
error = font->t3run(font->t3xref, font->t3resources, contents, dev, ctm);
if (error)
- fz_catch(error, "cannot draw type3 glyph");
+ fz_error_handle(error, "cannot draw type3 glyph");
fz_free_device(dev);
fz_free_glyph_cache(cache);
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index 83f46526..dccc62e3 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -301,11 +301,11 @@ fz_write_pnm(fz_pixmap *pixmap, char *filename)
int len;
if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4)
- return fz_throw("pixmap must be grayscale or rgb to write as pnm");
+ return fz_error_make("pixmap must be grayscale or rgb to write as pnm");
fp = fopen(filename, "wb");
if (!fp)
- return fz_throw("cannot open file '%s': %s", filename, strerror(errno));
+ return fz_error_make("cannot open file '%s': %s", filename, strerror(errno));
if (pixmap->n == 1 || pixmap->n == 2)
fprintf(fp, "P5\n");
@@ -361,7 +361,7 @@ fz_write_pam(fz_pixmap *pixmap, char *filename, int savealpha)
fp = fopen(filename, "wb");
if (!fp)
- return fz_throw("cannot open file '%s': %s", filename, strerror(errno));
+ return fz_error_make("cannot open file '%s': %s", filename, strerror(errno));
fprintf(fp, "P7\n");
fprintf(fp, "WIDTH %d\n", pixmap->w);
@@ -443,7 +443,7 @@ fz_write_png(fz_pixmap *pixmap, char *filename, int savealpha)
int err;
if (pixmap->n != 1 && pixmap->n != 2 && pixmap->n != 4)
- return fz_throw("pixmap must be grayscale or rgb to write as png");
+ return fz_error_make("pixmap must be grayscale or rgb to write as png");
sn = pixmap->n;
dn = pixmap->n;
@@ -488,7 +488,7 @@ fz_write_png(fz_pixmap *pixmap, char *filename, int savealpha)
{
fz_free(udata);
fz_free(cdata);
- return fz_throw("cannot compress image data");
+ return fz_error_make("cannot compress image data");
}
fp = fopen(filename, "wb");
@@ -496,7 +496,7 @@ fz_write_png(fz_pixmap *pixmap, char *filename, int savealpha)
{
fz_free(udata);
fz_free(cdata);
- return fz_throw("cannot open file '%s': %s", filename, strerror(errno));
+ return fz_error_make("cannot open file '%s': %s", filename, strerror(errno));
}
big32(head+0, pixmap->w);
diff --git a/fitz/stm_open.c b/fitz/stm_open.c
index 74346f73..81eb819e 100644
--- a/fitz/stm_open.c
+++ b/fitz/stm_open.c
@@ -55,7 +55,7 @@ static int read_file(fz_stream *stm, unsigned char *buf, int len)
{
int n = read(*(int*)stm->state, buf, len);
if (n < 0)
- return fz_throw("read error: %s", strerror(errno));
+ return fz_error_make("read error: %s", strerror(errno));
return n;
}
diff --git a/fitz/stm_read.c b/fitz/stm_read.c
index 59f06433..89811333 100644
--- a/fitz/stm_read.c
+++ b/fitz/stm_read.c
@@ -23,7 +23,7 @@ fz_read(fz_stream *stm, unsigned char *buf, int len)
if (n < 0)
{
stm->error = 1;
- return fz_rethrow(n, "read error");
+ return fz_error_note(n, "read error");
}
else if (n == 0)
{
@@ -50,7 +50,7 @@ fz_read(fz_stream *stm, unsigned char *buf, int len)
if (n < 0)
{
stm->error = 1;
- return fz_rethrow(n, "read error");
+ return fz_error_note(n, "read error");
}
else if (n == 0)
{
@@ -80,7 +80,7 @@ fz_fill_buffer(fz_stream *stm)
if (n < 0)
{
stm->error = 1;
- fz_catch(n, "read error; treating as end of file");
+ fz_error_handle(n, "read error; treating as end of file");
}
else if (n == 0)
{
@@ -113,14 +113,14 @@ fz_read_all(fz_buffer **bufp, fz_stream *stm, int initial)
if (buf->len / 200 > initial)
{
fz_drop_buffer(buf);
- return fz_throw("compression bomb detected");
+ return fz_error_make("compression bomb detected");
}
n = fz_read(stm, buf->data + buf->len, buf->cap - buf->len);
if (n < 0)
{
fz_drop_buffer(buf);
- return fz_rethrow(n, "read error");
+ return fz_error_note(n, "read error");
}
if (n == 0)
break;