Skip to content
Permalink
Browse files

Better PATH handling in module storage.

  • Loading branch information
egorpugin committed Mar 23, 2020
1 parent 6122e2d commit 1190abe5071061c2a987014cb6930802cbe94142
Showing with 20 additions and 5 deletions.
  1. +20 −5 src/sw/core/module_storage.cpp
@@ -44,15 +44,22 @@ const ModuleStorage::DynamicLibrary &ModuleStorage::get(const path &dll, const F

#ifdef _WIN32
// set dll deps
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS);
std::vector<void *> cookies;
for (const path &p : PATH)
cookies.push_back(AddDllDirectory(p.wstring().c_str()));
if (!PATH.empty())
{
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS);
for (const path &p : PATH)
cookies.push_back(AddDllDirectory(p.wstring().c_str()));
}
SCOPE_EXIT
{
// restore
for (auto c : cookies)
RemoveDllDirectory(c);
if (!cookies.empty())
{
for (auto c : cookies)
RemoveDllDirectory(c);
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
}
};
#endif

@@ -67,6 +74,14 @@ const ModuleStorage::DynamicLibrary &ModuleStorage::get(const path &dll, const F

return *modules.emplace(dll, std::move(module)).first->second;
}
catch (std::system_error &e)
{
err += ": "s + e.what() + " Error code = " + std::to_string(e.code().value()) + ".";
err += " Will rebuild on the next run.";
if (!do_not_remove_bad_module)
fs::remove(dll);
throw SW_RUNTIME_ERROR(err);
}
catch (std::exception &e)
{
err += ": "s + e.what();

0 comments on commit 1190abe

Please sign in to comment.
You can’t perform that action at this time.