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 ability to get import and export information from wasm_export interface #3329

Closed
bnason-nf opened this issue Apr 17, 2024 · 2 comments · Fixed by #3330
Closed

Add ability to get import and export information from wasm_export interface #3329

bnason-nf opened this issue Apr 17, 2024 · 2 comments · Fixed by #3330

Comments

@bnason-nf
Copy link
Contributor

bnason-nf commented Apr 17, 2024

Feature

When using the wasm_export API, it currently doesn't seem possible to get information about the imports and exports of a module. When using the wasm_c_api API, that information is exposed. It would be nice to add support for this in wasm_export also.

Benefit

Using wasm_export is beneficial in some cases where the added functionality it provides is desired, but if it's not a superset of wasm_c_api then there are drawbacks to using either API.

There is a little more discussion in issue #1740.

Implementation

I have a working implementation, and will submit a pull request of that as a starting point for the desired implementation.

Alternatives

The only alternative I'm aware of is extremely ugly and unsafe:

    char errorString[128];
    wasm_module_t module = wasm_runtime_load(data, dataSize, errorString, sizeof(errorString));

    char moduleHack[64]; /* sizeof(wasm_module_ex_t) */
    memset(moduleHack, 0xff, sizeof(moduleHack)); /* fill with non-zero to make internal wasm_module_ex_t ref_count not be empty */
    *(wasm_module_t *)moduleHack = module;
    wasm_module_t *moduleEx = (wasm_module_t *)moduleHack;

    wasm_importtype_vec_t imports;
    memset(&imports, 0, sizeof(imports));
    wasm_module_imports(moduleEx, &imports);
bnason-nf added a commit to bnason-nf/wasm-micro-runtime that referenced this issue Apr 17, 2024
@bnason-nf
Copy link
Contributor Author

@lum1n0us as we discussed in #1740, I've created this issue and a corresponding pull request. I'm not sure if this matches what you'd like to see stylistically, but it's a pretty simple implementation and fully provides the functionality I'm looking for. I'm happy to make any adjustments you'd like to see.

@lum1n0us
Copy link
Collaborator

The only alternative I'm aware of is extremely ugly and unsafe:

👍 Can't agree more.

victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 1, 2024
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 2, 2024
)

Resolves bytecodealliance#3329.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
)

Resolves bytecodealliance#3329.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants