aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/CMakeLists.txt6
-rw-r--r--src/core/GpgFrontendCore.cpp4
-rw-r--r--src/core/function/SecureMemoryAllocator.cpp20
-rw-r--r--src/core/function/gpg/GpgKeyOpera.cpp4
-rw-r--r--src/core/thread/Task.cpp5
-rw-r--r--src/test/core/GpgCoreTestKeygen.cpp9
-rw-r--r--third_party/CMakeLists.txt15
7 files changed, 46 insertions, 17 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index cc207217..ee95b061 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -44,7 +44,9 @@ add_library(gpgfrontend_core SHARED ${CORE_SOURCE})
set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendCoreExport.h")
generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}")
-target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
+if(NOT APPLE)
+ target_link_libraries(gpgfrontend_core PUBLIC mimalloc)
+endif()
# link third-party libraries
target_link_libraries(gpgfrontend_core PUBLIC config++)
@@ -72,7 +74,7 @@ else ()
endif ()
# link gnupg libraries
-target_link_libraries(gpgfrontend_core PRIVATE gpgme assuan gpg-error)
+target_link_libraries(gpgfrontend_core PUBLIC gpgme assuan gpg-error)
# link openssl
target_link_libraries(gpgfrontend_core PUBLIC OpenSSL::SSL OpenSSL::Crypto)
# link boost libraries
diff --git a/src/core/GpgFrontendCore.cpp b/src/core/GpgFrontendCore.cpp
index 5021b37d..2508f4e7 100644
--- a/src/core/GpgFrontendCore.cpp
+++ b/src/core/GpgFrontendCore.cpp
@@ -28,5 +28,7 @@
#include "core/GpgFrontendCore.h"
+#ifndef MACOS
// mimalloc
-#include <mimalloc-new-delete.h> \ No newline at end of file
+#include <mimalloc-new-delete.h>
+#endif
diff --git a/src/core/function/SecureMemoryAllocator.cpp b/src/core/function/SecureMemoryAllocator.cpp
index 2c584753..02efcbe0 100644
--- a/src/core/function/SecureMemoryAllocator.cpp
+++ b/src/core/function/SecureMemoryAllocator.cpp
@@ -28,19 +28,31 @@
#include "SecureMemoryAllocator.h"
+#ifndef MACOS
#include <mimalloc.h>
+#endif
namespace GpgFrontend {
auto SecureMemoryAllocator::Allocate(std::size_t size) -> void* {
+#ifndef MACOS
auto* addr = mi_malloc(size);
+#else
+ auto* addr = malloc(size);
+#endif
+
SPDLOG_TRACE("secure memory allocator trys to alloc memory, address: {}",
static_cast<void*>(addr));
return addr;
}
auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
+#ifndef MACOS
auto* addr = mi_realloc(ptr, size);
+#else
+ auto* addr = realloc(ptr, size);
+#endif
+
SPDLOG_TRACE(
"secure memory allocator trys to realloc memory, "
"old address: {}, new address: {}",
@@ -48,6 +60,12 @@ auto SecureMemoryAllocator::Reallocate(void* ptr, std::size_t size) -> void* {
return addr;
}
-void SecureMemoryAllocator::Deallocate(void* p) { mi_free(p); }
+void SecureMemoryAllocator::Deallocate(void* p) {
+#ifndef MACOS
+ mi_free(p);
+#else
+ free(p);
+#endif
+}
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp
index a89badc6..3ea9b365 100644
--- a/src/core/function/gpg/GpgKeyOpera.cpp
+++ b/src/core/function/gpg/GpgKeyOpera.cpp
@@ -199,9 +199,7 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params,
GpgGenKeyResult result;
if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
- auto temp_result =
- NewResult(gpgme_op_genkey_result(ctx.DefaultContext()));
- std::swap(temp_result, result);
+ result = NewResult(gpgme_op_genkey_result(ctx.DefaultContext()));
}
data_object->Swap({result});
diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp
index a5d718ee..3b27e52f 100644
--- a/src/core/thread/Task.cpp
+++ b/src/core/thread/Task.cpp
@@ -177,8 +177,9 @@ class Task::Impl {
SPDLOG_TRACE("task runnable {} finished, rtn: {}", GetFullID(), rtn);
// set return value
this->SetRTN(rtn);
-
+#ifdef RELEASE
try {
+#endif
if (callback_) {
SPDLOG_TRACE("task {} has a callback function", GetFullID());
if (callback_thread_ == QThread::currentThread()) {
@@ -236,6 +237,7 @@ class Task::Impl {
GetFullID());
emit parent_->SignalTaskEnd();
}
+#ifdef RELEASE
} catch (std::exception &e) {
SPDLOG_ERROR("exception was caught at task callback: {}", e.what());
SPDLOG_ERROR(
@@ -255,6 +257,7 @@ class Task::Impl {
GetFullID());
emit parent_->SignalTaskEnd();
}
+#endif
}
};
diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp
index aab400cb..f78f88dd 100644
--- a/src/test/core/GpgCoreTestKeygen.cpp
+++ b/src/test/core/GpgCoreTestKeygen.cpp
@@ -41,7 +41,7 @@ namespace GpgFrontend::Test {
TEST_F(GpgCoreTest, GenerateKeyTest) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
- keygen_info->SetName("foo");
+ keygen_info->SetName("foo_0");
keygen_info->SetEmail("[email protected]");
keygen_info->SetComment("");
keygen_info->SetKeyLength(1024);
@@ -57,6 +57,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest) {
const DataObjectPtr& data_object) {
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(data_object->GetObjectSize(), 1);
auto result = ExtractParams<GpgGenKeyResult>(data_object, 0);
auto* fpr = result->fpr;
auto key =
@@ -79,7 +80,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest) {
TEST_F(GpgCoreTest, GenerateKeyTest_1) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
- keygen_info->SetName("foo");
+ keygen_info->SetName("foo_1");
keygen_info->SetEmail("[email protected]");
keygen_info->SetComment("hello gpgfrontend");
keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[0]);
@@ -119,7 +120,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest_1) {
TEST_F(GpgCoreTest, GenerateKeyTest_4) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
- keygen_info->SetName("foo");
+ keygen_info->SetName("foo_2");
keygen_info->SetEmail("[email protected]");
keygen_info->SetComment("");
keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[1]);
@@ -156,7 +157,7 @@ TEST_F(GpgCoreTest, GenerateKeyTest_4) {
TEST_F(GpgCoreTest, GenerateKeyTest_5) {
auto keygen_info = SecureCreateSharedObject<GenKeyInfo>();
- keygen_info->SetName("foo");
+ keygen_info->SetName("foo_3");
keygen_info->SetEmail("[email protected]");
keygen_info->SetComment("");
keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[2]);
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 79cd322b..b0ddc488 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -30,12 +30,17 @@ set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(json EXCLUDE_FROM_ALL)
add_subdirectory(spdlog EXCLUDE_FROM_ALL)
-set(MI_SECURE ON)
-if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
- # set(MI_TRACK_VALGRIND ON)
- set(MI_TRACK_ASAN ON)
+# not working at macOS
+if(NOT APPLE)
+ set(MI_SECURE ON)
+ if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+ # set(MI_TRACK_VALGRIND ON)
+ set(MI_TRACK_ASAN ON)
+ endif()
+ add_subdirectory(mimalloc EXCLUDE_FROM_ALL)
endif()
-add_subdirectory(mimalloc EXCLUDE_FROM_ALL)
+
+
set(INSTALL_GTEST OFF)
add_subdirectory(googletest EXCLUDE_FROM_ALL) \ No newline at end of file