Skip to content

Commit d1bc419

Browse files
committed
Solve bugs in wasm loader and tests.
1 parent 23f3417 commit d1bc419

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

source/loaders/wasm_loader/source/wasm_loader_function.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static function_return function_wasm_interface_invoke(function func, function_im
161161

162162
if (args_size != signature_count(sig))
163163
{
164-
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Invalid number of arguments (%d expected, %d given)", args_size, signature_count(sig));
164+
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Invalid number of arguments (%d expected, %d given) in call to function %s", args_size, signature_count(sig), function_name(func));
165165
return NULL;
166166
}
167167

@@ -183,13 +183,13 @@ static function_return function_wasm_interface_invoke(function func, function_im
183183

184184
if (param_type_id != arg_type_id)
185185
{
186-
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Invalid type for argument %d (expected %d, was %d)", idx, param_type_id, arg_type_id);
186+
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Invalid type for argument %d (expected %s, was %s) in call to function %s", idx, type_id_name(param_type_id), type_id_name(arg_type_id), function_name(func));
187187
return NULL;
188188
}
189189

190190
if (reflect_to_wasm_type(args[idx], &wasm_args[idx]) != 0)
191191
{
192-
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Unsupported type for argument %d", idx);
192+
log_write("metacall", LOG_LEVEL_ERROR, "WebAssembly loader: Unsupported type for argument %d in call to function %s", idx, function_name(func));
193193
return NULL;
194194
}
195195
}

source/loaders/wasm_loader/source/wasm_loader_handle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int wasm_loader_handle_add_module(loader_impl_wasm_handle handle, const loader_n
7777
goto error_initialize_imports;
7878
}
7979

80-
strncpy(module.name, name, sizeof(module.name));
80+
strncpy(module.name, name, LOADER_NAME_SIZE - 1);
8181

8282
// There is no way to check whether `wasm_module_exports` or
8383
// `wasm_instance_new` fail, so just hope for the best.

source/scripts/python/wasm/source/wasm.py.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ def test():
1313

1414
# We can't import both functions.wasm and functions.wat here because their
1515
# definitions would collide.
16-
from functions.wasm import none_ret_none, i32_ret_none, i32_f32_i64_f64_ret_none, none_ret_i32, none_ret_i32_f32_i64_f64, i32_f32_i64_f64_ret_i32_f32_i64_f64, trap
16+
from functions.wasm import none_ret_none, i64_ret_none, i64_f64_i64_f64_ret_none, none_ret_i64, none_ret_i64_f64_i64_f64, i64_f64_i64_f64_ret_i64_f64_i64_f64, trap
1717

1818
assert none_ret_none() is None
19-
assert i32_ret_none(0) is None
20-
assert i32_f32_i64_f64_ret_none(0) is None
21-
assert none_ret_i32() == 1
22-
assert none_ret_i32_f32_i64_f64() == [1, 2, 3, 4]
23-
assert i32_f32_i64_f64_ret_i32_f32_i64_f64(0, 0, 0, 0) == [1, 2, 3, 4]
19+
assert i64_ret_none(0) is None
20+
assert i64_f64_i64_f64_ret_none(0) is None
21+
assert none_ret_i64() == 1
22+
assert none_ret_i64_f64_i64_f64() == [1, 2, 3, 4]
23+
assert i64_f64_i64_f64_ret_i64_f64_i64_f64(0, 0.0, 0, 0.0) == [1, 2, 3, 4]
2424
assert trap() is None
2525

2626
# We test an invalid load file attempt first to avoid polluting the global
238 Bytes
Binary file not shown.

source/scripts/wasm/tests/source/functions.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
22
(func (export "none_ret_none"))
3-
(func (export "i32_ret_none") (param i32))
3+
(func (export "i64_ret_none") (param i64))
44
(func (export "i32_f32_i64_f64_ret_none") (param i32) (param f32) (param i64) (param f64))
55
(func (export "none_ret_i32") (result i32)
66
i32.const 1)

source/tests/metacall_wasm_test/source/metacall_wasm_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ TEST_F(metacall_wasm_test, DiscoverFunctions)
120120
ASSERT_EQ(NULL, metacall_handle_function(handle, "does_not_exist"));
121121

122122
TestFunction(handle, "none_ret_none", {}, METACALL_INVALID);
123-
TestFunction(handle, "i32_ret_none", { METACALL_INT }, METACALL_INVALID);
123+
TestFunction(handle, "i64_ret_none", { METACALL_LONG }, METACALL_INVALID);
124124
TestFunction(handle, "i32_f32_i64_f64_ret_none", { METACALL_INT, METACALL_FLOAT, METACALL_LONG, METACALL_DOUBLE }, METACALL_INVALID);
125125
TestFunction(handle, "none_ret_i32", {}, METACALL_INT);
126126

@@ -137,10 +137,10 @@ TEST_F(metacall_wasm_test, CallFunctions)
137137
void *ret = metacall("none_ret_none");
138138
ASSERT_EQ(NULL, ret);
139139

140-
ret = metacall("i32_ret_none", 0);
140+
ret = metacall("i64_ret_none", 0L);
141141
ASSERT_EQ(NULL, ret);
142142

143-
ret = metacall("i32_f32_i64_f64_ret_none", 0, 0, 0, 0);
143+
ret = metacall("i32_f32_i64_f64_ret_none", 0, 0.0f, 0L, 0.0);
144144
ASSERT_EQ(NULL, ret);
145145

146146
ret = metacall("none_ret_i32");

0 commit comments

Comments
 (0)