Skip to content

Commit b80dfc1

Browse files
committed
Review of PR #294
1 parent fe109a5 commit b80dfc1

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

source/loaders/ext_loader/source/ext_loader_impl.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
#include <string>
3939
#include <vector>
4040

41-
typedef struct loader_impl_ext_type
42-
{
43-
std::set<std::filesystem::path> paths;
44-
45-
} * loader_impl_ext;
46-
4741
typedef struct loader_impl_ext_handle_lib_type
4842
{
4943
std::string name;
@@ -52,6 +46,13 @@ typedef struct loader_impl_ext_handle_lib_type
5246

5347
} * loader_impl_ext_handle_lib;
5448

49+
typedef struct loader_impl_ext_type
50+
{
51+
std::set<std::filesystem::path> paths;
52+
std::map<std::string, loader_impl_ext_handle_lib_type> destroy_list;
53+
54+
} * loader_impl_ext;
55+
5556
typedef struct loader_impl_ext_handle_type
5657
{
5758
std::vector<loader_impl_ext_handle_lib_type> extensions;
@@ -64,8 +65,6 @@ union loader_impl_function_cast
6465
int (*fn)(void *, void *);
6566
};
6667

67-
static std::map<std::string, loader_impl_ext_handle_lib_type> destroy_list;
68-
6968
dynlink ext_loader_impl_load_from_file_dynlink(loader_impl_ext ext_impl, const loader_path path);
7069
int ext_loader_impl_load_from_file_handle(loader_impl_ext ext_impl, loader_impl_ext_handle ext_handle, const loader_path path);
7170
static void ext_loader_impl_destroy_handle(loader_impl_ext_handle ext_handle);
@@ -146,12 +145,12 @@ dynlink ext_loader_impl_load_from_file_dynlink(loader_impl_ext ext_impl, const l
146145

147146
int ext_loader_impl_load_from_file_handle(loader_impl_ext ext_impl, loader_impl_ext_handle ext_handle, const loader_path path)
148147
{
149-
auto iterator = destroy_list.find(path);
150-
if (iterator != destroy_list.end())
148+
auto iterator = ext_impl->destroy_list.find(path);
149+
if (iterator != ext_impl->destroy_list.end())
151150
{
152151
log_write("metacall", LOG_LEVEL_DEBUG, "Unloading handle: %s <%p>", iterator->second.name.c_str(), iterator->second.handle);
153152
dynlink_unload(iterator->second.handle);
154-
destroy_list.erase(path);
153+
ext_impl->destroy_list.erase(path);
155154
}
156155

157156
dynlink lib = ext_loader_impl_load_from_file_dynlink(ext_impl, path);
@@ -261,16 +260,21 @@ void ext_loader_impl_destroy_handle(loader_impl_ext_handle ext_handle)
261260

262261
int ext_loader_impl_clear(loader_impl impl, loader_handle handle)
263262
{
264-
loader_impl_ext_handle ext_handle = static_cast<loader_impl_ext_handle>(handle);
263+
loader_impl_ext ext_impl = static_cast<loader_impl_ext>(loader_impl_get(impl));
265264

266-
(void)impl;
265+
if (ext_impl == NULL)
266+
{
267+
return 1;
268+
}
269+
270+
loader_impl_ext_handle ext_handle = static_cast<loader_impl_ext_handle>(handle);
267271

268272
if (ext_handle != NULL)
269273
{
270274
for (size_t i = 0; i < ext_handle->extensions.size(); i++)
271275
{
272276
log_write("metacall", LOG_LEVEL_DEBUG, "Storing handle: %s <%p> in destroy list", ext_handle->extensions[i].name.c_str(), ext_handle->extensions[i].handle);
273-
destroy_list[ext_handle->extensions[i].name] = ext_handle->extensions[i];
277+
ext_impl->destroy_list[ext_handle->extensions[i].name] = ext_handle->extensions[i];
274278
ext_handle->extensions.erase(ext_handle->extensions.begin() + i);
275279
}
276280

@@ -310,17 +314,18 @@ int ext_loader_impl_destroy(loader_impl impl)
310314
/* Destroy children loaders */
311315
loader_unload_children(impl);
312316

313-
delete ext_impl;
314-
315317
/* Destroy all handles */
316-
if (!destroy_list.empty())
318+
if (!ext_impl->destroy_list.empty())
317319
{
318-
for (auto iterator : destroy_list)
320+
for (auto iterator : ext_impl->destroy_list)
319321
{
320322
log_write("metacall", LOG_LEVEL_DEBUG, "Unloading handle: %s <%p>", iterator.second.name.c_str(), iterator.second.handle);
321323
dynlink_unload(iterator.second.handle);
322324
}
323325
}
326+
327+
delete ext_impl;
328+
324329
return 0;
325330
}
326331

source/tests/metacall_ext_test/source/metacall_ext_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ TEST_F(metacall_ext_test, DefaultConstructor)
4848
EXPECT_EQ((long)metacall_value_to_long(ret), (long)7);
4949

5050
metacall_value_destroy(ret);
51+
5152
/* Print inspect information */
5253
{
5354
size_t size = 0;

0 commit comments

Comments
 (0)