From 04108f759e1445c4b9158dc22aca27a79cbad238 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 9 Dec 2015 17:49:48 +0000 Subject: Android: Try and minimise warnings in JNI code. Push the pointer->long and long->pointer casting through 2 static inline functions. --- platform/android/jni/mupdf.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'platform') diff --git a/platform/android/jni/mupdf.c b/platform/android/jni/mupdf.c index 1afd5c65..e7a64b34 100644 --- a/platform/android/jni/mupdf.c +++ b/platform/android/jni/mupdf.c @@ -112,6 +112,19 @@ struct globals_s static jfieldID global_fid; static jfieldID buffer_fid; +// Do our best to avoid casting warnings. +#define CAST(type, var) (type)pointer_cast(var) + +static inline void *pointer_cast(jlong l) +{ + return (void *)(intptr_t)l; +} + +static inline jlong jlong_cast(void *p) +{ + return (jlong)(intptr_t)p; +} + static void drop_changed_rects(fz_context *ctx, rect_node **nodePtr) { rect_node *node = *nodePtr; @@ -252,7 +265,7 @@ static void alerts_fin(globals *glo) // Should only be called from the single background AsyncTask thread static globals *get_globals(JNIEnv *env, jobject thiz) { - globals *glo = (globals *)(intptr_t)((*env)->GetLongField(env, thiz, global_fid)); + globals *glo = CAST(globals *, (*env)->GetLongField(env, thiz, global_fid)); if (glo != NULL) { glo->env = env; @@ -349,7 +362,7 @@ JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename) (*env)->ReleaseStringUTFChars(env, jfilename, filename); - return (jlong)(intptr_t)glo; + return jlong_cast(glo); } typedef struct buffer_state_s @@ -503,7 +516,7 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic) (*env)->ReleaseStringUTFChars(env, jmagic, magic); - return (jlong)(intptr_t)glo; + return jlong_cast(glo); } JNIEXPORT int JNICALL -- cgit v1.2.3