diff options
-rw-r--r-- | draw/draw_blend.c | 2 | ||||
-rw-r--r-- | fitz/dev_trace.c | 1 | ||||
-rw-r--r-- | fitz/fitz.h | 382 | ||||
-rw-r--r-- | ios/document.c | 2 | ||||
-rw-r--r-- | pdf/pdf_crypt.c | 2 | ||||
-rw-r--r-- | xps/xps_glyphs.c | 1 |
6 files changed, 197 insertions, 193 deletions
diff --git a/draw/draw_blend.c b/draw/draw_blend.c index 1a6fcc13..e60c09c5 100644 --- a/draw/draw_blend.c +++ b/draw/draw_blend.c @@ -436,7 +436,7 @@ fz_blend_separable_nonisolated(byte * restrict bp, byte * restrict sp, int n, in * sc = (rc - bc)/ha + bc * Now, the result of the blend (rc) was stored in src, so * we actually want to calculate: - * sc = (sc-bc)/ha + bc + * sc = (sc-bc)/ha + bc */ invha = ha ? 255 * 256 / ha : 0; invra = ra ? 255 * 256 / ra : 0; diff --git a/fitz/dev_trace.c b/fitz/dev_trace.c index 62661a3d..73449ad1 100644 --- a/fitz/dev_trace.c +++ b/fitz/dev_trace.c @@ -242,7 +242,6 @@ fz_trace_begin_mask(fz_device *dev, fz_rect bbox, int luminosity, fz_colorspace printf("<mask bbox=\"%g %g %g %g\" s=\"%s\" ", bbox.x0, bbox.y0, bbox.x1, bbox.y1, luminosity ? "luminosity" : "alpha"); -// fz_trace_color(colorspace, color, 1); printf(">\n"); } diff --git a/fitz/fitz.h b/fitz/fitz.h index 889ba5e2..9d6eb368 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -137,133 +137,137 @@ struct fz_error_context_s void fz_var_imp(void *); #define fz_var(var) fz_var_imp((void *)&(var)) -/* MuPDF uses an set of exception handling macros to simplify error return - * and cleanup. Conceptually, they work a lot like C++'s try/catch system, - * but do not require any special compiler support. - * - * The basic formulation is as follows: - * - * fz_try(ctx) - * { - * // Try to perform a task. Never 'return', 'goto' or 'longjmp' out - * // of here. 'break' may be used to safely exit (just) the try block - * // scope. - * } - * fz_always(ctx) - * { - * // Any code here is always executed, regardless of whether an - * // exception was thrown within the try or not. Never 'return', 'goto' - * // or longjmp out from here. 'break' may be used to safely exit (just) - * // the always block scope. - * } - * fz_catch(ctx) - * { - * // This code is called (after any always block) only if something - * // within the fz_try block (including any functions it called) threw - * // an exception. The code here is expected to handle the exception - * // (maybe record/report the error, cleanup any stray state etc) and - * // can then either exit the block, or pass on the exception to a - * // higher level (enclosing) fz_try block (using fz_throw, or - * // fz_rethrow). - * } - * - * The fz_always block is optional, and can safely be omitted. - * - * The macro based nature of this system has 3 main limitations: - * - * 1) Never return from within try (or 'goto' or longjmp out of it). - * This upsets the internal housekeeping of the macros and will cause - * problems later on. The code will detect such things happening, but - * by then it is too late to give a helpful error report as to where the - * original infraction occurred. - * - * 2) The fz_try(ctx) { ... } fz_always(ctx) { ... } fz_catch(ctx) { ... } - * is not one atomic C statement. That is to say, if you do: - * - * if (condition) - * fz_try(ctx) { ... } - * fz_catch(ctx) { ... } - * - * then you will not get what you want. Use the following instead: - * - * if (condition) { - * fz_try(ctx) { ... } - * fz_catch(ctx) { ... } - * } - * - * 3) The macros are implemented using setjmp and longjmp, and so the standard - * C restrictions on the use of those functions apply to fz_try/fz_catch - * too. In particular, any "truly local" variable that is set between the - * start of fz_try and something in fz_try throwing an exception may become - * undefined as part of the process of throwing that exception. - * - * As a way of mitigating this problem, we provide an fz_var() macro that - * tells the compiler to ensure that that variable is not unset by the - * act of throwing the exception. - * - * A model piece of code using these macros then might be: - * - * house build_house(plans *p) - * { - * material m = NULL; - * walls w = NULL; - * roof r = NULL; - * house h = NULL; - * tiles t = make_tiles(); - * - * fz_var(w); - * fz_var(r); - * fz_var(h); - * - * fz_try(ctx) - * { - * fz_try(ctx) - * { - * m = make_bricks(); - * } - * fz_catch(ctx) - * { - * // No bricks available, make do with straw? - * m = make_straw(); - * } - * w = make_walls(m, p); - * r = make_roof(m, t); - * h = combine(w, r); // Note, NOT: return combine(w,r); - * } - * fz_always(ctx) - * { - * drop_walls(w); - * drop_roof(r); - * drop_material(m); - * drop_tiles(t); - * } - * fz_catch(ctx) - * { - * fz_throw(ctx, "build_house failed"); - * } - * return h; - * } - * - * Things to note about this: - * - * a) If make_tiles throws an exception, this will immediately be handled - * by some higher level exception handler. If it succeeds, t will be - * set before fz_try starts, so there is no need to fz_var(t); - * - * b) We try first off to make some bricks as our building material. If - * this fails, we fall back to straw. If this fails, we'll end up in - * the fz_catch, and the process will fail neatly. - * - * c) We assume in this code that combine takes new reference to both the - * walls and the roof it uses, and therefore that w and r need to be - * cleaned up in all cases. - * - * d) We assume the standard C convention that it is safe to destroy - * NULL things. - */ +/* + +MuPDF uses a set of exception handling macros to simplify error return +and cleanup. Conceptually, they work a lot like C++'s try/catch system, +but do not require any special compiler support. + +The basic formulation is as follows: + + fz_try(ctx) + { + // Try to perform a task. Never 'return', 'goto' or 'longjmp' out + // of here. 'break' may be used to safely exit (just) the try block + // scope. + } + fz_always(ctx) + { + // Any code here is always executed, regardless of whether an + // exception was thrown within the try or not. Never 'return', 'goto' + // or longjmp out from here. 'break' may be used to safely exit (just) + // the always block scope. + } + fz_catch(ctx) + { + // This code is called (after any always block) only if something + // within the fz_try block (including any functions it called) threw + // an exception. The code here is expected to handle the exception + // (maybe record/report the error, cleanup any stray state etc) and + // can then either exit the block, or pass on the exception to a + // higher level (enclosing) fz_try block (using fz_throw, or + // fz_rethrow). + } + +The fz_always block is optional, and can safely be omitted. + +The macro based nature of this system has 3 main limitations: + +1) Never return from within try (or 'goto' or longjmp out of it). + This upsets the internal housekeeping of the macros and will cause + problems later on. The code will detect such things happening, but + by then it is too late to give a helpful error report as to where the + original infraction occurred. + +2) The fz_try(ctx) { ... } fz_always(ctx) { ... } fz_catch(ctx) { ... } + is not one atomic C statement. That is to say, if you do: + + if (condition) + fz_try(ctx) { ... } + fz_catch(ctx) { ... } + + then you will not get what you want. Use the following instead: + + if (condition) { + fz_try(ctx) { ... } + fz_catch(ctx) { ... } + } + +3) The macros are implemented using setjmp and longjmp, and so the standard + C restrictions on the use of those functions apply to fz_try/fz_catch + too. In particular, any "truly local" variable that is set between the + start of fz_try and something in fz_try throwing an exception may become + undefined as part of the process of throwing that exception. + +As a way of mitigating this problem, we provide an fz_var() macro that +tells the compiler to ensure that that variable is not unset by the +act of throwing the exception. + +A model piece of code using these macros then might be: + + house build_house(plans *p) + { + material m = NULL; + walls w = NULL; + roof r = NULL; + house h = NULL; + tiles t = make_tiles(); + + fz_var(w); + fz_var(r); + fz_var(h); + + fz_try(ctx) + { + fz_try(ctx) + { + m = make_bricks(); + } + fz_catch(ctx) + { + // No bricks available, make do with straw? + m = make_straw(); + } + w = make_walls(m, p); + r = make_roof(m, t); + h = combine(w, r); // Note, NOT: return combine(w,r); + } + fz_always(ctx) + { + drop_walls(w); + drop_roof(r); + drop_material(m); + drop_tiles(t); + } + fz_catch(ctx) + { + fz_throw(ctx, "build_house failed"); + } + return h; + } + +Things to note about this: + +a) If make_tiles throws an exception, this will immediately be handled + by some higher level exception handler. If it succeeds, t will be + set before fz_try starts, so there is no need to fz_var(t); + +b) We try first off to make some bricks as our building material. If + this fails, we fall back to straw. If this fails, we'll end up in + the fz_catch, and the process will fail neatly. + +c) We assume in this code that combine takes new reference to both the + walls and the roof it uses, and therefore that w and r need to be + cleaned up in all cases. + +d) We assume the standard C convention that it is safe to destroy + NULL things. + +*/ /* Exception macro definitions. Just treat these as a black box - pay no * attention to the man behind the curtain. */ + #define fz_try(ctx) \ if (fz_push_try(ctx->error), \ (ctx->error->stack[ctx->error->top].code = setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ @@ -280,63 +284,65 @@ void fz_var_imp(void *); if (ctx->error->stack[ctx->error->top--].code) /* - * We also include a couple of other formulations of the macros, with - * different strengths and weaknesses. These will be removed shortly, but - * I want them in git for at least 1 revision so I have a record of them. - * - * A formulation of try/always/catch that lifts limitation 2 above, but - * has problems when try/catch are nested in the same function; the inner - * nestings need to use fz_always_(ctx, label) and fz_catch_(ctx, label) - * instead. This was held as too high a price to pay to drop limitation 2. - * - * #define fz_try(ctx) \ - * if (fz_push_try(ctx->error), \ - * (ctx->error->stack[ctx->error->top].code = setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ - * { do { - * - * #define fz_always_(ctx, label) \ - * } while (0); \ - * goto ALWAYS_LABEL_ ## label ; \ - * } \ - * else if (ctx->error->stack[ctx->error->top].code) \ - * { ALWAYS_LABEL_ ## label : \ - * do { - * - * #define fz_catch_(ctx, label) \ - * } while(0); \ - * if (ctx->error->stack[ctx->error->top--].code) \ - * goto CATCH_LABEL_ ## label; \ - * } \ - * else if (ctx->error->top--, 1) \ - * CATCH_LABEL ## label: - * - * #define fz_always(ctx) fz_always_(ctx, TOP) - * #define fz_catch(ctx) fz_catch_(ctx, TOP) - * - * Another alternative formulation, that again removes limitation 2, but at - * the cost of an always block always costing us 1 extra longjmp per - * execution. Again this was felt to be too high a cost to use. - * - * #define fz_try(ctx) \ - * if (fz_push_try(ctx->error), \ - * (ctx->error->stack[ctx->error->top].code = setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ - * { do { - * - * #define fz_always(ctx) \ - * } while (0); \ - * longjmp(ctx->error->stack[ctx->error->top].buffer, 3); \ - * } \ - * else if (ctx->error->stack[ctx->error->top].code & 1) \ - * { do { - * - * #define fz_catch(ctx) \ - * } while(0); \ - * if (ctx->error->stack[ctx->error->top].code == 1) \ - * longjmp(ctx->error->stack[ctx->error->top].buffer, 2); \ - * ctx->error->top--;\ - * } \ - * else if (ctx->error->top--, 1) - */ + +We also include a couple of other formulations of the macros, with +different strengths and weaknesses. These will be removed shortly, but +I want them in git for at least 1 revision so I have a record of them. + +A formulation of try/always/catch that lifts limitation 2 above, but +has problems when try/catch are nested in the same function; the inner +nestings need to use fz_always_(ctx, label) and fz_catch_(ctx, label) +instead. This was held as too high a price to pay to drop limitation 2. + +#define fz_try(ctx) \ + if (fz_push_try(ctx->error), \ + (ctx->error->stack[ctx->error->top].code = setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ + { do { + +#define fz_always_(ctx, label) \ + } while (0); \ + goto ALWAYS_LABEL_ ## label ; \ + } \ + else if (ctx->error->stack[ctx->error->top].code) \ + { ALWAYS_LABEL_ ## label : \ + do { + +#define fz_catch_(ctx, label) \ + } while(0); \ + if (ctx->error->stack[ctx->error->top--].code) \ + goto CATCH_LABEL_ ## label; \ + } \ + else if (ctx->error->top--, 1) \ + CATCH_LABEL ## label: + +#define fz_always(ctx) fz_always_(ctx, TOP) +#define fz_catch(ctx) fz_catch_(ctx, TOP) + +Another alternative formulation, that again removes limitation 2, but at +the cost of an always block always costing us 1 extra longjmp per +execution. Again this was felt to be too high a cost to use. + +#define fz_try(ctx) \ + if (fz_push_try(ctx->error), \ + (ctx->error->stack[ctx->error->top].code = setjmp(ctx->error->stack[ctx->error->top].buffer)) == 0) \ + { do { + +#define fz_always(ctx) \ + } while (0); \ + longjmp(ctx->error->stack[ctx->error->top].buffer, 3); \ + } \ + else if (ctx->error->stack[ctx->error->top].code & 1) \ + { do { + +#define fz_catch(ctx) \ + } while(0); \ + if (ctx->error->stack[ctx->error->top].code == 1) \ + longjmp(ctx->error->stack[ctx->error->top].buffer, 2); \ + ctx->error->top--;\ + } \ + else if (ctx->error->top--, 1) + +*/ void fz_push_try(fz_error_context *ex); void fz_throw(fz_context *, char *, ...) __printflike(2, 3); @@ -1459,13 +1465,13 @@ typedef enum fz_link_kind_e } fz_link_kind; enum { - fz_link_flag_l_valid = 1, /* lt.x is valid */ - fz_link_flag_t_valid = 2, /* lt.y is valid */ - fz_link_flag_r_valid = 4, /* rb.x is valid */ - fz_link_flag_b_valid = 8, /* rb.y is valid */ - fz_link_flag_fit_h = 16, /* Fit horizontally */ - fz_link_flag_fit_v = 32, /* Fit vertically */ - fz_link_flag_r_is_zoom = 64 /* rb.x is actually a zoom figure */ + fz_link_flag_l_valid = 1, /* lt.x is valid */ + fz_link_flag_t_valid = 2, /* lt.y is valid */ + fz_link_flag_r_valid = 4, /* rb.x is valid */ + fz_link_flag_b_valid = 8, /* rb.y is valid */ + fz_link_flag_fit_h = 16, /* Fit horizontally */ + fz_link_flag_fit_v = 32, /* Fit vertically */ + fz_link_flag_r_is_zoom = 64 /* rb.x is actually a zoom figure */ }; struct fz_link_dest_s diff --git a/ios/document.c b/ios/document.c index cb392c12..066f5209 100644 --- a/ios/document.c +++ b/ios/document.c @@ -3,7 +3,7 @@ #include "xps/muxps.h" #include "document.h" -#include <ctype.h> // for tolower() +#include <ctype.h> /* for tolower() */ struct document * open_document(fz_context *ctx, char *filename) diff --git a/pdf/pdf_crypt.c b/pdf/pdf_crypt.c index 4e8dc5e5..c272562e 100644 --- a/pdf/pdf_crypt.c +++ b/pdf/pdf_crypt.c @@ -419,7 +419,7 @@ pdf_compute_encryption_key_r5(pdf_crypt *crypt, unsigned char *password, int pwl fz_sha256_update(&sha256, buffer, pwlen + 8); fz_sha256_final(&sha256, buffer); - // clear password buffer and use it as iv + /* clear password buffer and use it as iv */ memset(buffer + 32, 0, sizeof(buffer) - 32); aes_setkey_dec(&aes, buffer, crypt->length); aes_crypt_cbc(&aes, AES_DECRYPT, 32, buffer + 32, ownerkey ? crypt->oe : crypt->ue, crypt->key); diff --git a/xps/xps_glyphs.c b/xps/xps_glyphs.c index 8b88c4d0..bbc49af1 100644 --- a/xps/xps_glyphs.c +++ b/xps/xps_glyphs.c @@ -139,7 +139,6 @@ xps_select_best_font_encoding(xps_document *doc, fz_font *font) { 3, 3 }, /* Prc */ { 3, 2 }, /* ShiftJis */ { 3, 0 }, /* Symbol */ - // { 0, * }, -- Unicode (deprecated) { 1, 0 }, { -1, -1 }, }; |