summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/context.h26
-rw-r--r--source/fitz/context.c4
-rw-r--r--source/fitz/error.c13
3 files changed, 24 insertions, 19 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h
index 7f5e15c8..c2b08898 100644
--- a/include/mupdf/fitz/context.h
+++ b/include/mupdf/fitz/context.h
@@ -10,6 +10,7 @@
typedef struct fz_alloc_context_s fz_alloc_context;
typedef struct fz_error_context_s fz_error_context;
+typedef struct fz_error_stack_slot_s fz_error_stack_slot;
typedef struct fz_id_context_s fz_id_context;
typedef struct fz_warn_context_s fz_warn_context;
typedef struct fz_font_context_s fz_font_context;
@@ -30,13 +31,16 @@ struct fz_alloc_context_s
void (*free)(void *, void *);
};
+struct fz_error_stack_slot_s
+{
+ int code;
+ fz_jmp_buf buffer;
+};
+
struct fz_error_context_s
{
- int top;
- struct {
- int code;
- fz_jmp_buf buffer;
- } stack[256];
+ fz_error_stack_slot *top;
+ fz_error_stack_slot stack[256];
int errcode;
char message[256];
};
@@ -50,24 +54,24 @@ void fz_var_imp(void *);
*/
#define fz_try(ctx) \
- {{{ fz_push_try(ctx); \
- if (fz_setjmp(ctx->error->stack[ctx->error->top].buffer) == 0)\
+ {{{ \
+ if (fz_setjmp(fz_push_try(ctx)->buffer) == 0)\
{ do {
#define fz_always(ctx) \
} while (0); \
} \
- if (ctx->error->stack[ctx->error->top].code < 3) \
+ if (ctx->error->top->code < 3) \
{ \
- ctx->error->stack[ctx->error->top].code++; \
+ ctx->error->top->code++; \
do { \
#define fz_catch(ctx) \
} while(0); \
} }}} \
- if (ctx->error->stack[ctx->error->top--].code > 1)
+ if ((ctx->error->top--)->code > 1)
-void fz_push_try(fz_context *ctx);
+fz_error_stack_slot *fz_push_try(fz_context *ctx);
FZ_NORETURN void fz_throw(fz_context *ctx, int errcode, const char *, ...) __printflike(3, 4);
FZ_NORETURN void fz_rethrow(fz_context *ctx);
FZ_NORETURN void fz_rethrow_message(fz_context *ctx, const char *fmt, ...) __printflike(2, 3);
diff --git a/source/fitz/context.c b/source/fitz/context.c
index 5d3373c2..52c225e9 100644
--- a/source/fitz/context.c
+++ b/source/fitz/context.c
@@ -100,7 +100,7 @@ fz_drop_context(fz_context *ctx)
if (ctx->error)
{
- assert(ctx->error->top == -1);
+ assert(ctx->error->top == ctx->error->stack - 1);
fz_free(ctx, ctx->error);
}
@@ -129,7 +129,7 @@ new_context_phase1(const fz_alloc_context *alloc, const fz_locks_context *locks)
ctx->error = Memento_label(fz_malloc_no_throw(ctx, sizeof(fz_error_context)), "fz_error_context");
if (!ctx->error)
goto cleanup;
- ctx->error->top = -1;
+ ctx->error->top = ctx->error->stack - 1;
ctx->error->errcode = FZ_ERROR_NONE;
ctx->error->message[0] = 0;
diff --git a/source/fitz/error.c b/source/fitz/error.c
index a34e5b79..724fd078 100644
--- a/source/fitz/error.c
+++ b/source/fitz/error.c
@@ -82,10 +82,10 @@ void fz_warn(fz_context *ctx, const char *fmt, ...)
FZ_NORETURN static void throw(fz_context *ctx)
{
- if (ctx->error->top >= 0)
+ if (ctx->error->top >= ctx->error->stack)
{
- ctx->error->stack[ctx->error->top].code += 2;
- fz_longjmp(ctx->error->stack[ctx->error->top].buffer, ctx->error->stack[ctx->error->top].code);
+ ctx->error->top->code += 2;
+ fz_longjmp(ctx->error->top->buffer, 1);
}
else
{
@@ -100,15 +100,16 @@ FZ_NORETURN static void throw(fz_context *ctx)
}
}
-void fz_push_try(fz_context *ctx)
+fz_error_stack_slot *fz_push_try(fz_context *ctx)
{
/* If we would overflow the exception stack, throw an exception instead
* of entering the try block. */
- if (ctx->error->top + 1 >= nelem(ctx->error->stack))
+ if (ctx->error->top + 1 >= ctx->error->stack + nelem(ctx->error->stack))
fz_throw(ctx, FZ_ERROR_GENERIC, "exception stack overflow!");
ctx->error->top++;
- ctx->error->stack[ctx->error->top].code = 0;
+ ctx->error->top->code = 0;
+ return ctx->error->top;
}
int fz_caught(fz_context *ctx)