From 0109da15d841263498f987ee23c7f20974bf3db1 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 6 Apr 2021 13:44:58 +0800 Subject: [PATCH] [core] Add missing NDEBUG --- core/build.gradle.kts | 12 ++++++++---- core/src/main/cpp/main/src/context.cpp | 10 +++++++--- core/src/main/cpp/main/src/context.h | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 8b4f0626..f8e62c13 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -158,11 +158,15 @@ android { ) cppFlags.addAll(flags) cFlags.addAll(flags) + val configFlags = arrayOf( + "-Oz", + "-DNDEBUG" + ).joinToString(" ") arguments.addAll(arrayOf( - "-DCMAKE_CXX_FLAGS_RELEASE=-Oz", - "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-Oz", - "-DCMAKE_C_FLAGS_RELEASE=-Oz", - "-DCMAKE_C_FLAGS_RELWITHDEBINFO=-Oz" + "-DCMAKE_CXX_FLAGS_RELEASE=$configFlags", + "-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=$configFlags", + "-DCMAKE_C_FLAGS_RELEASE=$configFlags", + "-DCMAKE_C_FLAGS_RELWITHDEBINFO=$configFlags" )) } } diff --git a/core/src/main/cpp/main/src/context.cpp b/core/src/main/cpp/main/src/context.cpp index 76437814..bff086d6 100644 --- a/core/src/main/cpp/main/src/context.cpp +++ b/core/src/main/cpp/main/src/context.cpp @@ -57,10 +57,14 @@ namespace lspd { } } - void Context::PreLoadDex(const std::string &dex_path) { + void Context::PreLoadDex(std::string_view dex_path) { if (LIKELY(!dex.empty())) return; - FILE *f = fopen(dex_path.c_str(), "rb"); + FILE *f = fopen(dex_path.data(), "rb"); + if (!f) { + LOGE("Fail to open dex from %s", dex_path.data()); + return; + } fseek(f, 0, SEEK_END); dex.resize(ftell(f)); rewind(f); @@ -70,7 +74,7 @@ namespace lspd { } fclose(f); - LOGI("Loaded %s with size %zu", dex_path.c_str(), dex.size()); + LOGI("Loaded %s with size %zu", dex_path.data(), dex.size()); } void Context::LoadDex(JNIEnv *env) { diff --git a/core/src/main/cpp/main/src/context.h b/core/src/main/cpp/main/src/context.h index 695ce540..dc14de94 100644 --- a/core/src/main/cpp/main/src/context.h +++ b/core/src/main/cpp/main/src/context.h @@ -57,7 +57,7 @@ namespace lspd { void OnNativeForkSystemServerPre(JNIEnv *env); - void PreLoadDex(const std::string &dex_paths); + void PreLoadDex(std::string_view dex_paths); private: inline static std::unique_ptr instance_ = std::make_unique();