From 9021f53c5129cdeaa31e316e6155d993036eaca6 Mon Sep 17 00:00:00 2001 From: GongChangYan <1084015508@qq.com> Date: Mon, 22 Jan 2024 10:55:18 +0800 Subject: [PATCH] fix comments --- Options.cmake | 2 +- src/plugin/cpp_plugin.cpp | 7 +------ src/plugin/cpp_plugin.h | 33 ++++++++++++++++++++++++++++++++- test/test_cpp_procedure.cpp | 4 ++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Options.cmake b/Options.cmake index ebb69a7bec..b96a9d0e11 100644 --- a/Options.cmake +++ b/Options.cmake @@ -48,7 +48,7 @@ endif (ENABLE_SQL_IO) option(ENABLE_ASAN "Enable Address Sanitizer." OFF) if (ENABLE_ASAN) message("Address Sanitizer is enabled.") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_ASAN -fsanitize=address -fno-omit-frame-pointer -static-libasan") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -static-libasan") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -static-libasan ") else (ENABLE_ASAN) message("Address Sanitizer is disabled.") diff --git a/src/plugin/cpp_plugin.cpp b/src/plugin/cpp_plugin.cpp index 12af79be0f..cae06d6fdf 100644 --- a/src/plugin/cpp_plugin.cpp +++ b/src/plugin/cpp_plugin.cpp @@ -141,10 +141,5 @@ void CppPluginManagerImpl::LoadPlugin(const std::string& user, const std::string } void CppPluginManagerImpl::UnloadPlugin(const std::string& user, const std::string& name, - PluginInfoBase* pinfo) { -// using namespace lgraph::dll; -// PluginInfo* info = dynamic_cast(pinfo); -// if (!UnloadDynamicLibrary(info->lib_handle)) -// throw InternalError("Failed to unload library [{}].", name); -} + PluginInfoBase* pinfo) {} } // namespace lgraph diff --git a/src/plugin/cpp_plugin.h b/src/plugin/cpp_plugin.h index aa0d78c8cb..10a3cb0602 100644 --- a/src/plugin/cpp_plugin.h +++ b/src/plugin/cpp_plugin.h @@ -36,8 +36,31 @@ class CppPluginManagerImpl : public PluginManagerImplBase { lgraph_api::ProcessInTxn* func_txn = nullptr; lgraph_api::GetSignature* get_sig_spec = nullptr; }; - + /** + * Open the dynamic library and find the run-time address + * refers to of the symbol "Process". + * + * Opening multiple algorithm libraries at the same time will cause the problem + * of "cannot allocate memory in static TLS block". Use OpenDynamicLib to load the + * plugin each time before calling the plugin, and use CloseDynamicLib to unload + * the plugin after calling the plugin. + * + * @param [in] pinfo If non-null, the pinfo. + * @param [in,out] dinfo plugin handle. + * + * */ void OpenDynamicLib(const PluginInfoBase* pinfo, DynamicLibinfo &dinfo); + + /** + * Close the dynamic library. + * + * Opening multiple algorithm libraries at the same time will cause the problem + * of "cannot allocate memory in static TLS block". Use OpenDynamicLib to load the + * plugin each time before calling the plugin, and use CloseDynamicLib to unload + * the plugin after calling the plugin. + * + * @param [in,out] dinfo plugin handle. + * */ void CloseDynamicLib(DynamicLibinfo &dinfo); protected: @@ -64,6 +87,11 @@ class CppPluginManagerImpl : public PluginManagerImplBase { /** * Loads a plugin and sets contents in pinfo accordingly. * + * Opening multiple algorithm libraries at the same time will cause the problem + * of "cannot allocate memory in static TLS block". Call OpenDynamicLib to verify + * that there are no errors in the plugin file and then call CloseDynamicLib to + * uninstall the dynamic library. + * * @param name The name. * @param [in,out] pinfo If non-null, the pinfo. * @param [in,out] error The error. @@ -76,6 +104,9 @@ class CppPluginManagerImpl : public PluginManagerImplBase { /** * Unload plugin and set pinfo if necessary. * + * Does nothing because the dynamic library has already been unloaded + * in CloseDynamicLib. + * * @param [in,out] pinfo If non-null, the pinfo. * @param [in,out] error The error. * diff --git a/test/test_cpp_procedure.cpp b/test/test_cpp_procedure.cpp index a03d52c8b2..97e2271eca 100644 --- a/test/test_cpp_procedure.cpp +++ b/test/test_cpp_procedure.cpp @@ -452,7 +452,7 @@ TEST_F(TestCppPlugin, CppPlugin) { "#include ", (plugin::CodeType)6, "test", true, "v1")); } -#ifndef ENABLE_ASAN +#ifndef __SANITIZE_ADDRESS__ { UT_LOG() << "Testing load many plugins"; for (int i = 0; i < 32; i++) { @@ -468,7 +468,7 @@ TEST_F(TestCppPlugin, CppPlugin) { } pm.DeleteAllPlugins(lgraph::_detail::DEFAULT_ADMIN_NAME); } -#endif // ENABLE_ASAN +#endif // __SANITIZE_ADDRESS__ } #endif }