Commit 3d2d485a authored by Mygod's avatar Mygod

Refine ndk-build

Fix #2077.
parent 94f04ae3
......@@ -327,7 +327,7 @@ LOCAL_SRC_FILES:= jni-helper.cpp
LOCAL_LDLIBS := -ldl -llog
LOCAL_STATIC_LIBRARIES := cpufeatures libancillary
LOCAL_STATIC_LIBRARIES := libancillary
include $(BUILD_SHARED_LIBRARY)
......@@ -477,7 +477,3 @@ libpcre_src_files := \
LOCAL_SRC_FILES := $(addprefix pcre/, $(libpcre_src_files)) $(LOCAL_PATH)/patch/pcre/pcre_chartables.c
include $(BUILD_STATIC_LIBRARY)
# Import cpufeatures
$(call import-module,android/cpufeatures)
APP_ABI := armeabi-v7a arm64-v8a x86
APP_PLATFORM := android-21
APP_STL := c++_static
NDK_TOOLCHAIN_VERSION := clang
......@@ -13,7 +13,7 @@ using namespace std;
// Based on: https://android.googlesource.com/platform/libcore/+/564c7e8/luni/src/main/native/libcore_io_Linux.cpp#256
static void throwException(JNIEnv* env, jclass exceptionClass, jmethodID ctor2, const char* functionName, int error) {
jstring detailMessage = env->NewStringUTF(functionName);
if (detailMessage == NULL) {
if (detailMessage == nullptr) {
// Not really much we can do here. We're probably dead in the water,
// but let's try to stumble on...
env->ExceptionClear();
......@@ -24,7 +24,7 @@ static void throwException(JNIEnv* env, jclass exceptionClass, jmethodID ctor2,
static void throwErrnoException(JNIEnv* env, const char* functionName) {
int error = errno;
static jclass ErrnoException = static_cast<jclass>(env->NewGlobalRef(
static auto ErrnoException = static_cast<jclass>(env->NewGlobalRef(
env->FindClass("android/system/ErrnoException")));
static jmethodID ctor2 = env->GetMethodID(ErrnoException, "<init>", "(Ljava/lang/String;I)V");
throwException(env, ErrnoException, ctor2, functionName, error);
......@@ -33,10 +33,10 @@ static void throwErrnoException(JNIEnv* env, const char* functionName) {
#pragma clang diagnostic ignored "-Wunused-parameter"
extern "C" {
JNIEXPORT void JNICALL
Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) {
Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jclass type, jint tun_fd, jstring path) {
int fd;
struct sockaddr_un addr;
const char *sock_str = env->GetStringUTFChars(path, 0);
const char *sock_str = env->GetStringUTFChars(path, nullptr);
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
throwErrnoException(env, "socket");
......@@ -58,12 +58,11 @@ quit:
close(fd);
quit2:
env->ReleaseStringUTFChars(path, sock_str);
return;
}
JNIEXPORT jbyteArray JNICALL
Java_com_github_shadowsocks_JniHelper_parseNumericAddress(JNIEnv *env, jobject thiz, jstring str) {
const char *src = env->GetStringUTFChars(str, 0);
Java_com_github_shadowsocks_JniHelper_parseNumericAddress(JNIEnv *env, jclass type, jstring str) {
const char *src = env->GetStringUTFChars(str, nullptr);
jbyte dst[max(sizeof(in_addr), sizeof(in6_addr))];
jbyteArray arr = nullptr;
if (inet_pton(AF_INET, src, dst) == 1) {
......@@ -81,7 +80,6 @@ Java_com_github_shadowsocks_JniHelper_parseNumericAddress(JNIEnv *env, jobject t
/*
* This is called by the VM when the shared library is first loaded.
*/
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
return JNI_VERSION_1_6;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment