From 5861b264eea832231e730dbbbe03a082aab3bcf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dexter=20Castor=20D=C3=B6pping?= Date: Sat, 14 Nov 2020 16:55:50 +0100 Subject: [PATCH 1/2] Fix extension loaded multiple times in Linux The code checks whether or not the library has already been loaded by looking at the path() of every loaded dlops object. For Linux ".so" is appended before loading the library, but this is not appended when checking whether it's loaded. This causes the library to get added to the dlops list multiple times. This patch fixes the issue by introducing a new variable that has the required platform dependent suffix and uses that for the comparisons and loading. The `name` variable stays unchanged so that the logging messages uses the extension name as it appears in sqf. --- src/operators/ops_generic.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/operators/ops_generic.cpp b/src/operators/ops_generic.cpp index e6aae0fc..ab7bba26 100644 --- a/src/operators/ops_generic.cpp +++ b/src/operators/ops_generic.cpp @@ -1369,19 +1369,23 @@ namespace std::shared_ptr helpermethod_callextension_loadlibrary(runtime& runtime, std::string name) { + std::string dlname = name; + + #ifndef _WIN32 // Append .so for Linux + dlname += ".so"; + #endif + static char buffer[CALLEXTVERSIONBUFFSIZE + 1] = { 0 }; for (auto it : runtime.storage()) { - if (it->path() == name) + if (it->path() == dlname) { return it; } } -#ifdef _WIN32 - auto dl = std::make_shared(name); -#else - auto dl = std::make_shared(name + ".so"); -#endif + + auto dl = std::make_shared(dlname); + runtime.storage().push_back(dl); void* sym = nullptr; if (dl->try_resolve("RVExtensionVersion", &sym)) From 04cc519a24d42419811c7147817ca2607b8dd590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dexter=20Castor=20D=C3=B6pping?= Date: Sat, 14 Nov 2020 17:16:44 +0100 Subject: [PATCH 2/2] Load extensions with _x64 suffix when compiled for 64 bits --- src/operators/ops_generic.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operators/ops_generic.cpp b/src/operators/ops_generic.cpp index ab7bba26..957a9e0f 100644 --- a/src/operators/ops_generic.cpp +++ b/src/operators/ops_generic.cpp @@ -1371,6 +1371,10 @@ namespace { std::string dlname = name; + #ifdef ENVIRONMENT64 + dlname += "_x64"; + #endif + #ifndef _WIN32 // Append .so for Linux dlname += ".so"; #endif