Skip to content

Commit 6240e56

Browse files
committed
capi: Add rich error reporting to fizzy_instantiate
1 parent ce9d0a5 commit 6240e56

File tree

4 files changed

+78
-39
lines changed

4 files changed

+78
-39
lines changed

bindings/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl Module {
110110
std::ptr::null(),
111111
std::ptr::null(),
112112
0,
113+
std::ptr::null_mut(),
113114
)
114115
};
115116
// Forget Module (and avoid calling drop) because it has been consumed by instantiate (even if it failed).

include/fizzy/fizzy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ bool fizzy_module_has_start_function(const FizzyModule* module);
398398
/// @param imported_globals Pointer to the imported globals array. Can be NULL iff
399399
/// @p imported_globals_size equals 0.
400400
/// @param imported_globals_size Size of the imported global array. Can be zero.
401+
/// @param error Pointer to store detailed error information at. Can be NULL
402+
/// if error information is not required.
401403
/// @return non-NULL pointer to instance in case of success,
402404
/// NULL otherwise.
403405
///
@@ -415,7 +417,7 @@ bool fizzy_module_has_start_function(const FizzyModule* module);
415417
FizzyInstance* fizzy_instantiate(const FizzyModule* module,
416418
const FizzyExternalFunction* imported_functions, size_t imported_functions_size,
417419
const FizzyExternalTable* imported_table, const FizzyExternalMemory* imported_memory,
418-
const FizzyExternalGlobal* imported_globals, size_t imported_globals_size);
420+
const FizzyExternalGlobal* imported_globals, size_t imported_globals_size, FizzyError* error);
419421

420422
/// Instantiate a module resolving imported functions.
421423
///

lib/fizzy/capi.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ bool fizzy_module_has_start_function(const FizzyModule* module)
602602
FizzyInstance* fizzy_instantiate(const FizzyModule* module,
603603
const FizzyExternalFunction* imported_functions, size_t imported_functions_size,
604604
const FizzyExternalTable* imported_table, const FizzyExternalMemory* imported_memory,
605-
const FizzyExternalGlobal* imported_globals, size_t imported_globals_size)
605+
const FizzyExternalGlobal* imported_globals, size_t imported_globals_size, FizzyError* error)
606606
{
607607
try
608608
{
@@ -614,10 +614,12 @@ FizzyInstance* fizzy_instantiate(const FizzyModule* module,
614614
auto instance = fizzy::instantiate(std::unique_ptr<const fizzy::Module>(unwrap(module)),
615615
std::move(functions), std::move(table), std::move(memory), std::move(globals));
616616

617+
set_success(error);
617618
return wrap(instance.release());
618619
}
619620
catch (...)
620621
{
622+
set_error_from_current_exception(error);
621623
return nullptr;
622624
}
623625
}

0 commit comments

Comments
 (0)