Skip to content

Conversation

@bartbes
Copy link
Contributor

@bartbes bartbes commented Jul 26, 2025

I was trying to use the C api and could not figure out how to implement a finalizer that takes no arguments. Turns out, the c declaration simply did not match the rust implementation.

See the rust specification of finalizer here:

pub unsafe extern "C" fn wasmtime_component_linker_instance_add_func(
linker_instance: &mut wasmtime_component_linker_instance_t,
name: *const u8,
name_len: usize,
callback: wasmtime_component_func_callback_t,
data: *mut c_void,
finalizer: Option<extern "C" fn(*mut c_void)>,
) -> Option<Box<wasmtime_error_t>> {

extern "C" fn(*mut c_void)> of course matches void(*)(void*), not void(*)().

…add_func

The rust side of the function (crates/c-api/src/component/linker.rs:111)
specifies the type of the argument as `Option<extern "C" fn(*mut
c_void)>`.
@bartbes bartbes requested a review from a team as a code owner July 26, 2025 09:50
@bartbes bartbes requested review from alexcrichton and removed request for a team July 26, 2025 09:50
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Jul 26, 2025
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Jul 26, 2025
Merged via the queue into bytecodealliance:main with commit 726c793 Jul 26, 2025
45 checks passed
bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
…add_func (bytecodealliance#11327)

The rust side of the function (crates/c-api/src/component/linker.rs:111)
specifies the type of the argument as `Option<extern "C" fn(*mut
c_void)>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants