diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-11-10 14:12:48 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-11-10 14:38:13 +0100 |
commit | 97c9056b6af80e8b6703031a0ae45fe6dc0e2766 (patch) | |
tree | 841630b0f63af9510bb16b33bdbc7077e55a7ff6 | |
parent | 268f28925f0d18d1289ac39c1c05d94c70914d9f (diff) | |
download | mupdf-97c9056b6af80e8b6703031a0ae45fe6dc0e2766.tar.xz |
Remove fz_android_fprintf.
Use android logging for throw/warn like we do with OutputDebugString
on windows.
-rw-r--r-- | include/mupdf/fitz/system.h | 10 | ||||
-rw-r--r-- | source/fitz/error.c | 92 |
2 files changed, 19 insertions, 83 deletions
diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h index c7cd3713..05527710 100644 --- a/include/mupdf/fitz/system.h +++ b/include/mupdf/fitz/system.h @@ -137,16 +137,6 @@ void fz_free_argv(int argc, char **argv); #define S_ISDIR(mode) ((mode) & S_IFDIR) #endif -#ifdef __ANDROID__ -int fz_android_fprintf(void *file, const char *fmt, ...); -#ifndef NDEBUG -/* Capture fprintf for stdout/stderr to the android logging - * stream. Only do this in debug builds as this implies a - * delay */ -#define fprintf fz_android_fprintf -#endif -#endif - /* inline is standard in C++. For some compilers we can enable it within C too. */ #ifndef __cplusplus diff --git a/source/fitz/error.c b/source/fitz/error.c index 0f371bc6..fe1045dd 100644 --- a/source/fitz/error.c +++ b/source/fitz/error.c @@ -13,6 +13,11 @@ #endif #endif +#ifdef __ANDROID__ +#define USE_ANDROID_LOG +#include <android/log.h> +#endif + /* Warning context */ void fz_var_imp(void *var) @@ -40,6 +45,9 @@ void fz_vwarn(fz_context *ctx, const char *fmt, va_list ap) OutputDebugStringA(buf); OutputDebugStringA("\n"); #endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_WARN, "libmupdf", "%s", buf); +#endif if (!strcmp(buf, ctx->warn->message)) { @@ -102,12 +110,15 @@ FZ_NORETURN static void throw(fz_context *ctx) } else { - fprintf(stderr, "uncaught exception: %s\n", ctx->error->message); + fprintf(stderr, "uncaught error: %s\n", ctx->error->message); #ifdef USE_OUTPUT_DEBUG_STRING - OutputDebugStringA("uncaught exception: "); + OutputDebugStringA("uncaught error: "); OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); #endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "(uncaught) %s", ctx->error->message); +#endif exit(EXIT_FAILURE); } } @@ -132,6 +143,9 @@ static int fz_fake_throw(fz_context *ctx, int code, const char *fmt, ...) OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); #endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "%s", ctx->error->message); +#endif } /* We need to arrive in the always/catch block as if throw @@ -182,6 +196,9 @@ FZ_NORETURN void fz_vthrow(fz_context *ctx, int code, const char *fmt, va_list a OutputDebugStringA(ctx->error->message); OutputDebugStringA("\n"); #endif +#ifdef USE_ANDROID_LOG + __android_log_print(ANDROID_LOG_ERROR, "libmupdf", "%s", ctx->error->message); +#endif } throw(ctx); @@ -207,74 +224,3 @@ void fz_rethrow_if(fz_context *ctx, int err) if (ctx->error->errcode == err) fz_rethrow(ctx); } - -/* Android specific code to take fprintf to LOG */ - -#ifdef __ANDROID__ -#include <unistd.h> -#include <android/log.h> - -#define LOG_TAG "libmupdf" - -static char android_log_buffer[4096]; -static int android_log_fill = 0; - -static char android_log_buffer2[4096]; - -int fz_android_fprintf(void *file, const char *fmt, ...) -{ - va_list args; - char *p, *q; - - /* Just in case someone has some magic fprintf redirection code working */ - va_start(args, fmt); - vfprintf(file, fmt, args); - va_end(args); - - if (file != stdout && file != stderr) - return 0; - - va_start(args, fmt); - vsnprintf(android_log_buffer2, sizeof(android_log_buffer2)-1, fmt, args); - va_end(args); - - /* Ensure we are always null terminated */ - android_log_buffer2[sizeof(android_log_buffer2)-1] = 0; - - p = android_log_buffer2; - q = p; - do - { - /* Find the end of the string, or the next \n */ - while (*p && *p != '\n') - p++; - - /* We need to output from q to p. Limit ourselves to what - * will fit in the existing buffer. */ - if (p - q >= sizeof(android_log_buffer)-1 - android_log_fill) - p = q + sizeof(android_log_buffer)-1 - android_log_fill; - - memcpy(&android_log_buffer[android_log_fill], q, p-q); - android_log_fill += p-q; - if (*p == '\n') - { - android_log_buffer[android_log_fill] = 0; - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", android_log_buffer); - usleep(1); /* Hack to avoid the logcat buffer losing data */ - android_log_fill = 0; - p++; /* Skip over the \n */ - } - else if (android_log_fill >= sizeof(android_log_buffer)-1) - { - android_log_buffer[sizeof(android_log_buffer2)-1] = 0; - __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s", android_log_buffer); - usleep(1); /* Hack to avoid the logcat buffer losing data */ - android_log_fill = 0; - } - q = p; - } - while (*p); - - return 0; -} -#endif |