Skip to content

Commit 0c9491d

Browse files
committed
Remove nullptr comments and fix relative path for libraries
Signed-off-by: Shreyas Atre <[email protected]>
1 parent bd8d0e9 commit 0c9491d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/Interpreter/Paths.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ namespace platform {
107107
}
108108

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

115-
void DLClose(void* Lib, std::string& Err /* = nullptr*/) {
115+
void DLClose(void* Lib, std::string& Err) {
116116
auto dl = llvm::sys::DynamicLibrary(Lib);
117117
llvm::sys::DynamicLibrary::closeLibrary(dl);
118118
if (Err.empty()) {
@@ -121,19 +121,20 @@ namespace platform {
121121
}
122122
#else
123123
static void DLErr(std::string& Err) {
124-
if (Err.empty())
125-
return;
126124
if (const char* DyLibError = ::dlerror())
127125
Err = std::string(DyLibError);
128126
}
129127

130-
void* DLOpen(const std::string& Path, std::string& Err /* = nullptr */) {
128+
void* DLOpen(const std::string& Path, std::string& Err) {
131129
void* Lib = ::dlopen(Path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
132-
DLErr(Err);
130+
if (Lib == nullptr) {
131+
DLErr(Err);
132+
return nullptr;
133+
}
133134
return Lib;
134135
}
135136

136-
void DLClose(void* Lib, std::string& Err /* = nullptr*/) {
137+
void DLClose(void* Lib, std::string& Err) {
137138
::dlclose(Lib);
138139
DLErr(Err);
139140
}

unittests/CppInterOp/DynamicLibraryManagerTest.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ TEST(UtilsPlatform, DLTest) {
6161
std::string err = "";
6262
#if defined(__APPLE__)
6363
auto dlopen_handle = Cpp::utils::platform::DLOpen(
64-
"./unittests/CppInterOp/libTestSharedLib.dylib", err);
64+
"./libTestSharedLib.dylib", err);
6565
#elif defined(_WIN32)
6666
auto dlopen_handle = Cpp::utils::platform::DLOpen(
67-
"./unittests/CppInterOp/libTestSharedLib.dll", err);
67+
"./libTestSharedLib.dll", err);
6868
#else
6969
auto dlopen_handle = Cpp::utils::platform::DLOpen(
70-
"./unittests/CppInterOp/libTestSharedLib.so", err);
70+
"./libTestSharedLib.so", err);
7171
#endif
72-
(void)dlopen_handle;
72+
EXPECT_TRUE(dlopen_handle);
73+
EXPECT_TRUE(err.empty());
74+
Cpp::utils::platform::DLOpen("missing", err);
75+
EXPECT_TRUE(err.find("no such file") != std::string::npos);
7376
}

0 commit comments

Comments
 (0)