File tree 2 files changed +15
-11
lines changed
2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -107,12 +107,12 @@ namespace platform {
107
107
}
108
108
109
109
#if defined(_WIN32)
110
- void * DLOpen (const std::string& Path, std::string& Err /* = nullptr */ ) {
110
+ void * DLOpen (const std::string& Path, std::string& Err) {
111
111
auto lib = llvm::sys::DynamicLibrary::getLibrary (Path.c_str (), &Err);
112
112
return lib.getOSSpecificHandle ();
113
113
}
114
114
115
- void DLClose (void * Lib, std::string& Err /* = nullptr */ ) {
115
+ void DLClose (void * Lib, std::string& Err) {
116
116
auto dl = llvm::sys::DynamicLibrary (Lib);
117
117
llvm::sys::DynamicLibrary::closeLibrary (dl);
118
118
if (Err.empty ()) {
@@ -121,19 +121,20 @@ namespace platform {
121
121
}
122
122
#else
123
123
static void DLErr (std::string& Err) {
124
- if (Err.empty ())
125
- return ;
126
124
if (const char * DyLibError = ::dlerror ())
127
125
Err = std::string (DyLibError);
128
126
}
129
127
130
- void * DLOpen (const std::string& Path, std::string& Err /* = nullptr */ ) {
128
+ void * DLOpen (const std::string& Path, std::string& Err) {
131
129
void * Lib = ::dlopen (Path.c_str (), RTLD_LAZY | RTLD_GLOBAL);
132
- DLErr (Err);
130
+ if (Lib == nullptr ) {
131
+ DLErr (Err);
132
+ return nullptr ;
133
+ }
133
134
return Lib;
134
135
}
135
136
136
- void DLClose (void * Lib, std::string& Err /* = nullptr */ ) {
137
+ void DLClose (void * Lib, std::string& Err) {
137
138
::dlclose (Lib);
138
139
DLErr (Err);
139
140
}
Original file line number Diff line number Diff line change @@ -61,13 +61,16 @@ TEST(UtilsPlatform, DLTest) {
61
61
std::string err = " " ;
62
62
#if defined(__APPLE__)
63
63
auto dlopen_handle = Cpp::utils::platform::DLOpen (
64
- " ./unittests/CppInterOp/ libTestSharedLib.dylib" , err);
64
+ " ./libTestSharedLib.dylib" , err);
65
65
#elif defined(_WIN32)
66
66
auto dlopen_handle = Cpp::utils::platform::DLOpen (
67
- " ./unittests/CppInterOp/ libTestSharedLib.dll" , err);
67
+ " ./libTestSharedLib.dll" , err);
68
68
#else
69
69
auto dlopen_handle = Cpp::utils::platform::DLOpen (
70
- " ./unittests/CppInterOp/ libTestSharedLib.so" , err);
70
+ " ./libTestSharedLib.so" , err);
71
71
#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);
73
76
}
You can’t perform that action at this time.
0 commit comments