summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Reinhardt <simon.reinhardt@stud.uni-regensburg.de>2016-05-07 22:20:51 +0200
committerRobin Watts <robin.watts@artifex.com>2016-05-12 12:18:19 +0100
commitc99afdde9b0032daa5b64107bd063180ffc3ad3b (patch)
tree8585e0b0fa4e0484515dfdac0740f26788412f40
parentea2b0bffaf8e5a8fbbe85a5dcfde2f95d29d5282 (diff)
downloadmupdf-c99afdde9b0032daa5b64107bd063180ffc3ad3b.tar.xz
Add variadic versions of fz_throw and fz_warn.
-rw-r--r--include/mupdf/fitz/context.h2
-rw-r--r--source/fitz/error.c29
2 files changed, 22 insertions, 9 deletions
diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h
index 2908f6b0..6153e6e1 100644
--- a/include/mupdf/fitz/context.h
+++ b/include/mupdf/fitz/context.h
@@ -74,8 +74,10 @@ void fz_var_imp(void *);
if ((ctx->error->top--)->code > 1)
int fz_push_try(fz_context *ctx);
+FZ_NORETURN void fz_vthrow(fz_context *ctx, int errcode, const char *, va_list ap);
FZ_NORETURN void fz_throw(fz_context *ctx, int errcode, const char *, ...) __printflike(3, 4);
FZ_NORETURN void fz_rethrow(fz_context *ctx);
+void fz_vwarn(fz_context *ctx, const char *fmt, va_list ap);
void fz_warn(fz_context *ctx, const char *fmt, ...) __printflike(2, 3);
const char *fz_caught_message(fz_context *ctx);
int fz_caught(fz_context *ctx);
diff --git a/source/fitz/error.c b/source/fitz/error.c
index 6330b4ec..b72e3d9a 100644
--- a/source/fitz/error.c
+++ b/source/fitz/error.c
@@ -22,14 +22,11 @@ void fz_flush_warnings(fz_context *ctx)
ctx->warn->count = 0;
}
-void fz_warn(fz_context *ctx, const char *fmt, ...)
+void fz_vwarn(fz_context *ctx, const char *fmt, va_list ap)
{
- va_list ap;
char buf[sizeof ctx->warn->message];
- va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
- va_end(ap);
#ifdef USE_OUTPUT_DEBUG_STRING
OutputDebugStringA(buf);
OutputDebugStringA("\n");
@@ -49,6 +46,15 @@ void fz_warn(fz_context *ctx, const char *fmt, ...)
}
}
+void fz_warn(fz_context *ctx, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fz_vwarn(ctx, fmt, ap);
+ va_end(ap);
+}
+
+
/* Error context */
/* When we first setjmp, code is set to 0. Whenever we throw, we add 2 to
@@ -155,13 +161,10 @@ const char *fz_caught_message(fz_context *ctx)
return ctx->error->message;
}
-void fz_throw(fz_context *ctx, int code, const char *fmt, ...)
+void fz_vthrow(fz_context *ctx, int code, const char *fmt, va_list ap)
{
- va_list args;
ctx->error->errcode = code;
- va_start(args, fmt);
- vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, args);
- va_end(args);
+ vsnprintf(ctx->error->message, sizeof ctx->error->message, fmt, ap);
if (code != FZ_ERROR_ABORT)
{
@@ -178,6 +181,14 @@ void fz_throw(fz_context *ctx, int code, const char *fmt, ...)
throw(ctx);
}
+void fz_throw(fz_context *ctx, int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fz_vthrow(ctx, code, fmt, ap);
+ va_end(ap);
+}
+
void fz_rethrow(fz_context *ctx)
{
assert(ctx && ctx->error && ctx->error->errcode >= FZ_ERROR_NONE);