-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C API: expose wasmtime_linker_get_one_by_name() #1897
C API: expose wasmtime_linker_get_one_by_name() #1897
Conversation
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:c-api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! To confirm, have you tried out using this API in your application? We don't have a ton of tests for the C API right now and we mostly rely on external testing for it.
abae679
to
0d5df22
Compare
Hi there! Yes, I have been using this in my embedding and its been working fine, and returning the Extern as expected. However, there has been something bugging me, and I am not sure if it is related or not. I am observing I've been using this new API like so: // static_memory_maximum_size = 0 for testing
wasm_name_t mod_name, func_name;
wasm_extern_t *func_extern;
wasm_func_t *func;
/* ... */
error = wasmtime_linker_get_one_by_name(linker, &mod_name, &func_name, &func_extern);
if (error) {
/* ... */
}
func = wasm_extern_as_func(func_extern); // this function is a nop
error = wasmtime_func_call(func, NULL, 0, NULL, 0, &trap);
wasm_extern_delete(func_extern);
if (error || trap) {
/* ... */
} In a gdb session, I observe 1152Kb being allocated here and never freed. This amount of memory sounded a lot like the default wasm stack to me, but even when I update the stack size in my Engine's config, I still see the same 1152Kb allocations. When I remove the Am I missing something here? I'm not sure if this is caused by a mistake in my use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh dear that does sound bad!
Could this perhaps be the instance-per-function-call logic of Linker
? Is the function that you're calling attached to a wasi command which means that we'll spin up one instance per function call, and then the instances aren't destroyed until the Store
is dropped?
It does make it hard to use indeed! I found out what the issue is, although I cannot explain quite why without digging into the Linker. Said Linker does not have WASI defined, and the function was declared in a module as such: #[no_mangle]
pub fn _start() {
// nop
} Turns out that changing the name from |
One more somewhat related question on memory management via the C API: should I expect Valgrind seems to have a lot of complaints about me calling these, below is an excerpt of the Valgrind output when calling the above 3 functions on my single Linker/Store/Engine during my application's exit:
|
I've opened #1913 to track the leak issues you were encountering. Otherwise for API usage you'll want to And finally, this looks good otherwise, so I'm going to go ahead and merge! Feel free to ping me on Zulip if you've still got memory issues though |
@alexcrichton I was writing something here to clarify that I read your comment at #1902 (comment) which answered my above question. Anyway, thank you for detailing it once again! Thanks for the merge too. |
* C API: expose wasmtime_linker_get_one_by_name() * C API: remove unnecessary 'unsafe' qualifiers * C API: avoid unnecessary mutable borrows of the Linker
I'd like to use the new Linker to manage my modules from C, is this a supported use-case for the Linker?