Bug 1485833 - Use a backwards compatible way of handling NDK changes in jni.h. r=jchen

When building with the NDK clang, which is the easiest way of building locally,
NDK r17 doesn't work for ARM builds because of a broken clang, and while the
NDK r18-beta fixes that problem, for some people it causes a different set of
issues.
Since NDK r15c doesn't have the ndk-version.h headers, switch to a different
way of bridging the differences that allows people to continue building with
r15c locally.

Differential Revision: https://phabricator.services.mozilla.com/D4471

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan Henning 2018-08-28 20:05:36 +00:00
parent c9cfb100eb
commit 07d61a0e0f
2 changed files with 13 additions and 10 deletions

View File

@ -1,7 +1,6 @@
#ifndef mozilla_jni_Types_h__
#define mozilla_jni_Types_h__
#include <android/ndk-version.h>
#include <jni.h>
#include "mozilla/jni/Refs.h"
@ -54,16 +53,20 @@ template<class Cls> struct TypeAdapter<LocalRef<Cls>> {
#define MOZ_JNICALL_ABI
#endif
#if __NDK_MAJOR__ >= 18
#define JVALUE_PTR const jvalue*
#else
#define JVALUE_PTR jvalue*
#endif
// NDK r18 made jvalue* method parameters const. We detect the change directly
// instead of using ndk-version.h in order to remain compatible with r15 for
// now, which doesn't include those headers.
class CallArgs {
static const jvalue* test(void (JNIEnv::*)(jobject, jmethodID, const jvalue*));
static jvalue* test(void (JNIEnv::*)(jobject, jmethodID, jvalue*));
public:
using JValueType = decltype(test(&JNIEnv::CallVoidMethodA));
};
template<class Cls> constexpr jobject
(JNIEnv::*TypeAdapter<LocalRef<Cls>>::Call)(jobject, jmethodID, JVALUE_PTR) MOZ_JNICALL_ABI;
(JNIEnv::*TypeAdapter<LocalRef<Cls>>::Call)(jobject, jmethodID, CallArgs::JValueType) MOZ_JNICALL_ABI;
template<class Cls> constexpr jobject
(JNIEnv::*TypeAdapter<LocalRef<Cls>>::StaticCall)(jclass, jmethodID, JVALUE_PTR) MOZ_JNICALL_ABI;
(JNIEnv::*TypeAdapter<LocalRef<Cls>>::StaticCall)(jclass, jmethodID, CallArgs::JValueType) MOZ_JNICALL_ABI;
template<class Cls> constexpr jobject
(JNIEnv::*TypeAdapter<LocalRef<Cls>>::Get)(jobject, jfieldID);
template<class Cls> constexpr jobject

View File

@ -19,9 +19,9 @@ namespace detail {
#define DEFINE_PRIMITIVE_TYPE_ADAPTER(NativeType, JNIType, JNIName, ABIName) \
\
constexpr JNIType (JNIEnv::*TypeAdapter<NativeType>::Call) \
(jobject, jmethodID, JVALUE_PTR) MOZ_JNICALL_ABI; \
(jobject, jmethodID, CallArgs::JValueType) MOZ_JNICALL_ABI; \
constexpr JNIType (JNIEnv::*TypeAdapter<NativeType>::StaticCall) \
(jclass, jmethodID, JVALUE_PTR) MOZ_JNICALL_ABI; \
(jclass, jmethodID, CallArgs::JValueType) MOZ_JNICALL_ABI; \
constexpr JNIType (JNIEnv::*TypeAdapter<NativeType>::Get) \
(jobject, jfieldID) ABIName; \
constexpr JNIType (JNIEnv::*TypeAdapter<NativeType>::StaticGet) \