Skip to content

Commit 0a8e426

Browse files
committed
Solve bug of metacall_inspect called after the destroy of node loader has been issued. The destroy method of the node loader should be executed before any destruction of the loader structure itself.
1 parent d4bc051 commit 0a8e426

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

source/loader/source/loader_impl.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ void loader_impl_destroy_handle(loader_handle_impl handle_impl)
487487

488488
if (handle_impl->impl->init == 0)
489489
{
490+
log_write("metacall", LOG_LEVEL_DEBUG, "Destroying handle %s", handle_impl->name);
491+
490492
if (loader_impl_function_hook_call(handle_impl->ctx, func_fini_name) != 0)
491493
{
492494
log_write("metacall", LOG_LEVEL_ERROR, "Error when calling destructor from handle impl: %p (%s)", (void *)handle_impl, func_fini_name);
@@ -1111,12 +1113,6 @@ void loader_impl_destroy(loader_impl impl)
11111113
{
11121114
log_write("metacall", LOG_LEVEL_DEBUG, "Destroy loader implementation %s", impl->tag);
11131115

1114-
set_iterate(impl->handle_impl_map, &loader_impl_destroy_handle_map_cb_iterate, NULL);
1115-
1116-
set_iterate(impl->type_info_map, &loader_impl_destroy_type_map_cb_iterate, NULL);
1117-
1118-
set_destroy(impl->type_info_map);
1119-
11201116
if (impl->init == 0)
11211117
{
11221118
loader_impl_interface interface_impl = loader_impl_symbol(impl);
@@ -1129,12 +1125,18 @@ void loader_impl_destroy(loader_impl impl)
11291125
impl->init = 1;
11301126
}
11311127

1128+
set_iterate(impl->handle_impl_map, &loader_impl_destroy_handle_map_cb_iterate, NULL);
1129+
1130+
set_destroy(impl->handle_impl_map);
1131+
1132+
set_iterate(impl->type_info_map, &loader_impl_destroy_type_map_cb_iterate, NULL);
1133+
1134+
set_destroy(impl->type_info_map);
1135+
11321136
set_iterate(impl->exec_path_map, &loader_impl_destroy_exec_path_map_cb_iterate, NULL);
11331137

11341138
set_destroy(impl->exec_path_map);
11351139

1136-
set_destroy(impl->handle_impl_map);
1137-
11381140
context_destroy(impl->ctx);
11391141

11401142
loader_impl_dynlink_destroy(impl);

source/tests/metacall_node_python_async_after_destroy_test/source/metacall_node_python_async_after_destroy_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ TEST_F(metacall_node_python_async_after_destroy_test, DefaultConstructor)
4242
{
4343
static const char buffer[] =
4444
/* NodeJS */
45-
"const { metacall, metacall_load_from_memory } = require('" METACALL_NODE_PORT_PATH "');\n"
45+
"const { metacall, metacall_load_from_memory, metacall_inspect } = require('" METACALL_NODE_PORT_PATH "');\n"
4646
"metacall_load_from_memory('py', `"
4747
/* Python */
4848
"def sum(a, b):\n"
4949
" return a + b\n"
5050
"`);\n"
5151
"function log(x) { console.log(x); return x; }\n"
5252
"setTimeout(() => { log(metacall('sum', 3, 4)) === 7 || process.exit(1) }, 2000);\n"
53-
"setTimeout(() => { log(metacall('sum', 3, 4)) === 7 || process.exit(1) }, 4000);\n"
53+
"setTimeout(() => { log(metacall_inspect()) || process.exit(1) }, 4000);\n"
5454
"setTimeout(() => { log(metacall('sum', 3, 4)) === 7 || process.exit(1) }, 6000);\n";
5555

5656
ASSERT_EQ((int)0, (int)metacall_load_from_memory("node", buffer, sizeof(buffer), NULL));

0 commit comments

Comments
 (0)