Skip to content

Commit

Permalink
Remove nullptr comments and fix relative path for libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Atre <[email protected]>
  • Loading branch information
SAtacker committed Feb 3, 2024
1 parent bd8d0e9 commit 39b920e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 9 additions & 7 deletions lib/Interpreter/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ namespace platform {
}

#if defined(_WIN32)
void* DLOpen(const std::string& Path, std::string& Err /* = nullptr */) {
void* DLOpen(const std::string& Path, std::string& Err) {
auto lib = llvm::sys::DynamicLibrary::getLibrary(Path.c_str(), &Err);
return lib.getOSSpecificHandle();
}

void DLClose(void* Lib, std::string& Err /* = nullptr*/) {
void DLClose(void* Lib, std::string& Err) {
auto dl = llvm::sys::DynamicLibrary(Lib);
llvm::sys::DynamicLibrary::closeLibrary(dl);
if (Err.empty()) {
Expand All @@ -121,19 +121,21 @@ namespace platform {
}
#else
static void DLErr(std::string& Err) {
if (Err.empty())
return;
if (const char* DyLibError = ::dlerror())
Err = std::string(DyLibError);
}

void* DLOpen(const std::string& Path, std::string& Err /* = nullptr */) {
void* DLOpen(const std::string& Path, std::string& Err) {
void* Lib = ::dlopen(Path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
DLErr(Err);
if (Lib == nullptr)
{
DLErr(Err);
return nullptr;
}
return Lib;
}

void DLClose(void* Lib, std::string& Err /* = nullptr*/) {
void DLClose(void* Lib, std::string& Err) {
::dlclose(Lib);
DLErr(Err);
}
Expand Down
11 changes: 7 additions & 4 deletions unittests/CppInterOp/DynamicLibraryManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ TEST(UtilsPlatform, DLTest) {
std::string err = "";
#if defined(__APPLE__)
auto dlopen_handle = Cpp::utils::platform::DLOpen(
"./unittests/CppInterOp/libTestSharedLib.dylib", err);
"./libTestSharedLib.dylib", err);
#elif defined(_WIN32)
auto dlopen_handle = Cpp::utils::platform::DLOpen(
"./unittests/CppInterOp/libTestSharedLib.dll", err);
"./libTestSharedLib.dll", err);
#else
auto dlopen_handle = Cpp::utils::platform::DLOpen(
"./unittests/CppInterOp/libTestSharedLib.so", err);
"./libTestSharedLib.so", err);
#endif
(void)dlopen_handle;
EXPECT_TRUE(dlopen_handle);
EXPECT_TRUE(err.empty());
Cpp::utils::platform::DLOpen("missing", err);
EXPECT_TRUE(err.find("no such file") != std::string::npos);
}

0 comments on commit 39b920e

Please sign in to comment.