Skip to content
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

Add function to retrieve function name from wasm_frame_t #3222

Merged
merged 15 commits into from
Oct 25, 2022
Merged

Conversation

fschutt
Copy link
Contributor

@fschutt fschutt commented Oct 10, 2022

Fixes #3166.

@fschutt fschutt marked this pull request as draft October 10, 2022 10:36
@fschutt fschutt marked this pull request as ready for review October 10, 2022 10:50
@fschutt fschutt requested a review from syrusakbary October 10, 2022 12:02
@fschutt
Copy link
Contributor Author

fschutt commented Oct 11, 2022

Should be done like https://docs.wasmtime.dev/c-api/trap_8h_source.html

@fschutt
Copy link
Contributor Author

fschutt commented Oct 18, 2022

@syrusakbary @Michael-F-Bryan review + merge?

@Michael-F-Bryan
Copy link
Contributor

It doesn't look like we provide a function which gives you a *const c_char from a *const wasm_name_t. Does that mean we expect the caller to cast a wasm_name_t to a *const char so they can read it?

Jumping around wasmtime's docs, it seems like wasm_name_t is just a typedef for wasm_byte_vec_t, which is pretty much the C version of an &str reference pointing into our wasm_frame_t.

I'm not sure whether frame.info.function_name() and frame.info.module_name() return borrowed &strs or owned Strings, but if they're borrowed it means we can drop the wasm_name_delete() destructor.

@fschutt
Copy link
Contributor Author

fschutt commented Oct 19, 2022

I'm not sure whether frame.info.function_name() and frame.info.module_name() return borrowed &strs or owned Strings, but if they're borrowed it means we can drop the wasm_name_delete() destructor.

It doesn't matter because we need to convert them to CString anyway (trailing 0). So we need to allocate.

Does that mean we expect the caller to cast a wasm_name_t to a *const char so they can read it?

No, it returns a wasm_name_t, which has to be deleted by the user because it allocates Rust memory (see above). So I wanted to make that clear in the API, so that we have wasm_frame_module_name and wasm_frame_function_name for creation of the wasm_name_t and wasm_name_delete for deletion. The API is not that hard.

Users can print printf("%s", wasm_name_t.name); just like normal.

lib/c-api/src/wasm_c_api/types/frame.rs Outdated Show resolved Hide resolved
lib/c-api/src/wasm_c_api/types/frame.rs Outdated Show resolved Hide resolved
@Michael-F-Bryan
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 25, 2022

Build succeeded:

  • Code lint

@bors bors bot merged commit dc8f108 into master Oct 25, 2022
@bors bors bot deleted the wasm-frame-t branch October 25, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to get function name from wasm_frame_t?
3 participants