@@ -153,17 +153,17 @@ static std::string printValue(const wasm_val_t &value) {
153
153
}
154
154
}
155
155
156
- static std::string printValues (const wasm_val_t values[], size_t size ) {
157
- if (size == 0 ) {
156
+ static std::string printValues (const wasm_val_vec_t * values) {
157
+ if (values-> size == 0 ) {
158
158
return " " ;
159
159
}
160
160
161
161
std::string s;
162
- for (size_t i = 0 ; i < size; i++) {
162
+ for (size_t i = 0 ; i < values-> size ; i++) {
163
163
if (i) {
164
164
s.append (" , " );
165
165
}
166
- s.append (printValue (values[i]));
166
+ s.append (printValue (values-> data [i]));
167
167
}
168
168
return s;
169
169
}
@@ -209,7 +209,7 @@ bool Wamr::link(std::string_view debug_name) {
209
209
WasmImporttypeVec import_types;
210
210
wasm_module_imports (module_.get (), import_types.get ());
211
211
212
- std::vector<const wasm_extern_t *> imports;
212
+ std::vector<wasm_extern_t *> imports;
213
213
for (size_t i = 0 ; i < import_types.get ()->size ; i++) {
214
214
const wasm_name_t *module_name_ptr = wasm_importtype_module (import_types.get ()->data [i]);
215
215
const wasm_name_t *name_ptr = wasm_importtype_name (import_types.get ()->data [i]);
@@ -273,7 +273,8 @@ bool Wamr::link(std::string_view debug_name) {
273
273
return false ;
274
274
}
275
275
276
- instance_ = wasm_instance_new (store_.get (), module_.get (), imports.data (), nullptr );
276
+ wasm_extern_vec_t imports_vec = {imports.size (), imports.data ()};
277
+ instance_ = wasm_instance_new (store_.get (), module_.get (), &imports_vec, nullptr );
277
278
assert (instance_ != nullptr );
278
279
279
280
WasmExportTypeVec export_types;
@@ -403,14 +404,10 @@ template <> uint64_t convertValueTypeToArg<uint64_t>(wasm_val_t val) {
403
404
template <> double convertValueTypeToArg<double >(wasm_val_t val) { return val.of .f64 ; }
404
405
405
406
template <typename T, typename U, std::size_t ... I>
406
- constexpr T convertValTypesToArgsTupleImpl (const U &arr , std::index_sequence<I...>) {
407
+ constexpr T convertValTypesToArgsTuple (const U &vec , std::index_sequence<I...>) {
407
408
return std::make_tuple (
408
- convertValueTypeToArg<typename ConvertWordType<std::tuple_element_t <I, T>>::type>(arr[I])...);
409
- }
410
-
411
- template <typename T, typename U, typename Is = std::make_index_sequence<std::tuple_size<T>::value>>
412
- constexpr T convertValTypesToArgsTuple (const U &arr) {
413
- return convertValTypesToArgsTupleImpl<T>(arr, Is ());
409
+ convertValueTypeToArg<typename ConvertWordType<std::tuple_element_t <I, T>>::type>(
410
+ vec->data [I])...);
414
411
}
415
412
416
413
template <typename T, std::size_t ... I>
@@ -449,14 +446,15 @@ void Wamr::registerHostFunctionImpl(std::string_view module_name, std::string_vi
449
446
WasmFunctypePtr type = newWasmNewFuncType<std::tuple<Args...>>();
450
447
WasmFuncPtr func = wasm_func_new_with_env (
451
448
store_.get (), type.get (),
452
- [](void *data, const wasm_val_t params[], wasm_val_t results[] ) -> wasm_trap_t * {
449
+ [](void *data, const wasm_val_vec_t * params, wasm_val_vec_t * results) -> wasm_trap_t * {
453
450
auto func_data = reinterpret_cast <HostFuncData *>(data);
454
451
const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
455
452
if (log) {
456
453
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->name_ + " (" +
457
- printValues (params, sizeof ...(Args) ) + " )" );
454
+ printValues (params) + " )" );
458
455
}
459
- auto args = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
456
+ auto args = convertValTypesToArgsTuple<std::tuple<Args...>>(
457
+ params, std::make_index_sequence<sizeof ...(Args)>{});
460
458
auto fn = reinterpret_cast <void (*)(Args...)>(func_data->raw_func_ );
461
459
std::apply (fn, args);
462
460
if (log) {
@@ -481,17 +479,18 @@ void Wamr::registerHostFunctionImpl(std::string_view module_name, std::string_vi
481
479
WasmFunctypePtr type = newWasmNewFuncType<R, std::tuple<Args...>>();
482
480
WasmFuncPtr func = wasm_func_new_with_env (
483
481
store_.get (), type.get (),
484
- [](void *data, const wasm_val_t params[], wasm_val_t results[] ) -> wasm_trap_t * {
482
+ [](void *data, const wasm_val_vec_t * params, wasm_val_vec_t * results) -> wasm_trap_t * {
485
483
auto func_data = reinterpret_cast <HostFuncData *>(data);
486
484
const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
487
485
if (log) {
488
486
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->name_ + " (" +
489
- printValues (params, sizeof ...(Args) ) + " )" );
487
+ printValues (params) + " )" );
490
488
}
491
- auto args = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
489
+ auto args = convertValTypesToArgsTuple<std::tuple<Args...>>(
490
+ params, std::make_index_sequence<sizeof ...(Args)>{});
492
491
auto fn = reinterpret_cast <R (*)(Args...)>(func_data->raw_func_ );
493
492
R res = std::apply (fn, args);
494
- assignVal<R>(res, results[0 ]);
493
+ assignVal<R>(res, results-> data [0 ]);
495
494
if (log) {
496
495
func_data->vm_ ->integration ()->trace (" [vm<-host] " + func_data->name_ +
497
496
" return: " + std::to_string (res));
@@ -534,14 +533,16 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
534
533
}
535
534
536
535
*function = [func, function_name, this ](ContextBase *context, Args... args) -> void {
537
- wasm_val_t params[] = {makeVal (args)...};
536
+ wasm_val_t params_arr[] = {makeVal (args)...};
537
+ const wasm_val_vec_t params = WASM_ARRAY_VEC (params_arr);
538
+ wasm_val_vec_t results = WASM_EMPTY_VEC;
538
539
const bool log = cmpLogLevel (LogLevel::trace);
539
540
if (log) {
540
- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
541
- printValues (params, sizeof ...(Args)) + " )" );
541
+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" + printValues (¶ms) +
542
+ " )" );
542
543
}
543
544
SaveRestoreContext saved_context (context);
544
- WasmTrapPtr trap{wasm_func_call (func, params, nullptr )};
545
+ WasmTrapPtr trap{wasm_func_call (func, & params, &results )};
545
546
if (trap) {
546
547
WasmByteVec error_message;
547
548
wasm_trap_message (trap.get (), error_message.get ());
@@ -580,15 +581,17 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
580
581
}
581
582
582
583
*function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
583
- wasm_val_t params[] = {makeVal (args)...};
584
- wasm_val_t results[1 ];
584
+ wasm_val_t params_arr[] = {makeVal (args)...};
585
+ const wasm_val_vec_t params = WASM_ARRAY_VEC (params_arr);
586
+ wasm_val_t results_arr[1 ];
587
+ wasm_val_vec_t results = WASM_ARRAY_VEC (results_arr);
585
588
const bool log = cmpLogLevel (LogLevel::trace);
586
589
if (log) {
587
- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
588
- printValues (params, sizeof ...(Args)) + " )" );
590
+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" + printValues (¶ms) +
591
+ " )" );
589
592
}
590
593
SaveRestoreContext saved_context (context);
591
- WasmTrapPtr trap{wasm_func_call (func, params, results)};
594
+ WasmTrapPtr trap{wasm_func_call (func, & params, & results)};
592
595
if (trap) {
593
596
WasmByteVec error_message;
594
597
wasm_trap_message (trap.get (), error_message.get ());
@@ -597,7 +600,7 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
597
600
std::string (error_message.get ()->data , error_message.get ()->size ));
598
601
return R{};
599
602
}
600
- R ret = convertValueTypeToArg<R>(results[0 ]);
603
+ R ret = convertValueTypeToArg<R>(results. data [0 ]);
601
604
if (log) {
602
605
integration ()->trace (" [host<-vm] " + std::string (function_name) +
603
606
" return: " + std::to_string (ret));
0 commit comments