diff --git a/crates/mun_runtime_capi/ffi b/crates/mun_runtime_capi/ffi index 6b183bc36..dc1d3ef3f 160000 --- a/crates/mun_runtime_capi/ffi +++ b/crates/mun_runtime_capi/ffi @@ -1 +1 @@ -Subproject commit 6b183bc3615d6cf56b18538f171bf975b7d2eb0c +Subproject commit dc1d3ef3fa135b7461e4ef871b3abb5e15b1d3e2 diff --git a/crates/mun_runtime_capi/src/lib.rs b/crates/mun_runtime_capi/src/lib.rs index 7a6f6d09c..a0a78e5f2 100644 --- a/crates/mun_runtime_capi/src/lib.rs +++ b/crates/mun_runtime_capi/src/lib.rs @@ -190,3 +190,49 @@ pub unsafe extern "C" fn mun_runtime_update( *updated = runtime.update(); ErrorHandle::default() } + +/// Retrieves the [`StructInfo`] corresponding to `type_info`, if the type is a struct. If +/// successful, `struct_info` is set, otherwise a non-zero error handle is returned. +/// +/// If a non-zero error handle is returned, it must be manually destructed using +/// [`mun_error_destroy`]. +/// +/// # Safety +/// +/// This function receives raw pointers as parameters. If any of the arguments is a null pointer, +/// an error will be returned. Passing pointers to invalid data, will lead to undefined behavior. +#[no_mangle] +pub unsafe extern "C" fn mun_type_info_as_struct( + type_info: *const TypeInfo, + struct_info: *mut StructInfo, +) -> ErrorHandle { + let type_info = match type_info.as_ref() { + Some(info) => info, + None => { + return HUB.errors.register(Box::new(err_msg( + "Invalid argument: `type_info` is null pointer", + ))) + } + }; + + let struct_info = match struct_info.as_mut() { + Some(info) => info, + None => { + return HUB.errors.register(Box::new(err_msg( + "Invalid argument: `struct_info` is null pointer", + ))) + } + }; + + match type_info.as_struct() { + Some(info) => *struct_info = info.clone(), + None => { + return HUB.errors.register(Box::new(err_msg(format!( + "Provided type `{}` is not a struct.", + type_info.name() + )))) + } + } + + ErrorHandle::default() +}