5
5
6
6
namespace bs
7
7
{
8
- static bool operator <(const NPtr<DynLib>& lhs, const String& rhs)
8
+
9
+ namespace
10
+ {
11
+ static void dynlib_delete (DynLib* lib)
12
+ {
13
+ lib->unload ();
14
+ bs_delete (lib);
15
+ }
16
+ } // namespace ()
17
+
18
+ static bool operator <(const UPtr<DynLib>& lhs, const String& rhs)
9
19
{
10
20
return lhs->getName () < rhs;
11
21
}
12
22
13
- static bool operator <(const String& lhs, const NPtr <DynLib>& rhs)
23
+ static bool operator <(const String& lhs, const UPtr <DynLib>& rhs)
14
24
{
15
25
return lhs < rhs->getName ();
16
26
}
17
- static bool operator <(const NPtr<DynLib>& lhs, const NPtr<DynLib>& rhs)
27
+
28
+ static bool operator <(const UPtr<DynLib>& lhs, const UPtr<DynLib>& rhs)
18
29
{
19
30
return lhs->getName () < rhs->getName ();
20
31
}
@@ -28,48 +39,38 @@ namespace bs
28
39
const String::size_type length = filename.length ();
29
40
const String extension = String (" ." ) + DynLib::EXTENSION;
30
41
const String::size_type extLength = extension.length ();
31
- if (length <= extLength || filename.substr (length - extLength) != extension)
42
+ if (length <= extLength || filename.substr (length - extLength) != extension)
32
43
filename.append (extension);
33
44
34
45
if (DynLib::PREFIX != nullptr )
35
46
filename.insert (0 , DynLib::PREFIX);
36
47
37
48
const auto & iterFind = mLoadedLibraries .lower_bound (filename);
38
- if (iterFind != mLoadedLibraries .end () && (*iterFind)->getName () == filename)
49
+ if (iterFind != mLoadedLibraries .end () && (*iterFind)->getName () == filename)
39
50
{
40
51
return iterFind->get ();
41
52
}
42
53
else
43
54
{
44
55
DynLib* newLib = bs_new<DynLib>(std::move (filename));
45
- mLoadedLibraries .emplace_hint (iterFind, newLib);
56
+ mLoadedLibraries .emplace_hint (iterFind, newLib, &dynlib_delete );
46
57
return newLib;
47
58
}
48
59
}
49
60
50
61
void DynLibManager::unload (DynLib* lib)
51
62
{
52
63
const auto & iterFind = mLoadedLibraries .find (lib->getName ());
53
- if (iterFind != mLoadedLibraries .end ())
64
+ if (iterFind != mLoadedLibraries .end ())
54
65
{
55
66
mLoadedLibraries .erase (iterFind);
56
67
}
57
-
58
- lib->unload ();
59
- bs_delete (lib);
60
- }
61
-
62
- DynLibManager::~DynLibManager ()
63
- {
64
- // Unload & delete each resource in turn
65
- for (auto & entry : mLoadedLibraries )
68
+ else
66
69
{
67
- entry->unload ();
68
- bs_delete (entry.get ());
70
+ // Somehow a DynLib not owned by the manager...?
71
+ // Well, we should clean it up anyway...
72
+ dynlib_delete (lib);
69
73
}
70
-
71
- // Empty the list
72
- mLoadedLibraries .clear ();
73
74
}
74
75
75
76
DynLibManager& gDynLibManager ()
0 commit comments