@@ -46,7 +46,7 @@ namespace gz
46
46
// / \return If a library exists at the given path, get a point to its dl
47
47
// / handle. If the library does not exist, get a nullptr.
48
48
public: std::shared_ptr<void > LoadLib (
49
- const std::string &_pathToLibrary);
49
+ const std::string &_pathToLibrary, bool _noDelete );
50
50
51
51
// / \brief Using a dl handle produced by LoadLib, extract the
52
52
// / Info from the loaded library.
@@ -139,12 +139,18 @@ namespace gz
139
139
// ///////////////////////////////////////////////
140
140
std::unordered_set<std::string> Loader::LoadLib (
141
141
const std::string &_pathToLibrary)
142
+ {
143
+ return this ->LoadLib (_pathToLibrary, false );
144
+ }
145
+ // ///////////////////////////////////////////////
146
+ std::unordered_set<std::string> Loader::LoadLib (
147
+ const std::string &_pathToLibrary, bool _noDelete)
142
148
{
143
149
std::unordered_set<std::string> newPlugins;
144
150
145
151
// Attempt to load the library at this path
146
152
const std::shared_ptr<void > &dlHandle =
147
- this ->dataPtr ->LoadLib (_pathToLibrary);
153
+ this ->dataPtr ->LoadLib (_pathToLibrary, _noDelete );
148
154
149
155
// Quit early and return an empty set of plugin names if we did not
150
156
// actually get a valid dlHandle.
@@ -420,7 +426,7 @@ namespace gz
420
426
421
427
// ///////////////////////////////////////////////
422
428
std::shared_ptr<void > Loader::Implementation::LoadLib (
423
- const std::string &_full_path)
429
+ const std::string &_full_path, bool _noDelete )
424
430
{
425
431
std::shared_ptr<void > dlHandlePtr;
426
432
@@ -431,7 +437,14 @@ namespace gz
431
437
432
438
// NOTE: We open using RTLD_LOCAL instead of RTLD_GLOBAL to prevent the
433
439
// symbols of different libraries from writing over each other.
434
- void *dlHandle = dlopen (_full_path.c_str (), RTLD_LAZY | RTLD_LOCAL);
440
+ #ifdef _WIN32
441
+ // RTLD_NODELETE is not defined in dlfcn-32.
442
+ (void ) _noDelete;
443
+ int dlopenMode = RTLD_LAZY | RTLD_LOCAL;
444
+ #else
445
+ int dlopenMode = RTLD_LAZY | RTLD_LOCAL | (_noDelete ? RTLD_NODELETE : 0 );
446
+ #endif
447
+ void *dlHandle = dlopen (_full_path.c_str (), dlopenMode);
435
448
436
449
const char *loadError = dlerror ();
437
450
if (nullptr == dlHandle || nullptr != loadError)
0 commit comments