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 <shreyasatre16@gmail.com>
  • Loading branch information
SAtacker committed Feb 3, 2024
1 parent bd8d0e9 commit 0c9491d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
15 changes: 8 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,20 @@ 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 0c9491d

Please sign in to comment.