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

Why does the wasmtime import function need to be declared in advance? #146

Closed
rayowang opened this issue Sep 4, 2022 · 4 comments
Closed

Comments

@rayowang
Copy link

rayowang commented Sep 4, 2022

No description provided.

@alexcrichton
Copy link
Member

Sorry I'm not 100% sure what you're asking here, can you clarify with some code and ask about a particular API?

@rayowang
Copy link
Author

rayowang commented Sep 8, 2022

Sorry I'm not 100% sure what you're asking here, can you clarify with some code and ask about a particular API?

Like the following code, if it is without any import declarations, it will report an error, and more often, how many functions are imported is often unknown in advance.

截屏2022-09-08 13 34 17

=== RUN TestNewInstanceButNoImport
--- FAIL: TestNewInstanceButNoImport (0.00s)
panic: expected 0 imports, found 1 [recovered]
panic: expected 0 imports, found 1

goroutine 35 [running]:
testing.tRunner.func1.2({0x4137460, 0xc00011e340})
/usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
/usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1212 +0x218
panic({0x4137460, 0xc00011e340})
/usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
github.com/bytecodealliance/wasmtime-go.TestNewInstanceButNoImport(0x0)
/Users/wangzhilong23/JD/go/src/wasmtime-go/instance_test.go:169 +0xf4
testing.tRunner(0xc0001051e0, 0x415ff30)
/usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
/usr/local/Cellar/go/1.17.2/libexec/src/testing/testing.go:1306 +0x35a

@alexcrichton
Copy link
Member

This is the contract of the NewInstance API where the imports must line up exactly with the imports reported by the module. You can learn the imports before instantiation through the Module type. I'd recommend using the Linker type, however, for instantiation since the NewInstance API is intended to be a low-level control.

@rayowang
Copy link
Author

rayowang commented Sep 8, 2022

This is the contract of the NewInstance API where the imports must line up exactly with the imports reported by the module. You can learn the imports before instantiation through the Module type. I'd recommend using the Linker type, however, for instantiation since the NewInstance API is intended to be a low-level control.

OK, I got it, thanks

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

No branches or pull requests

2 participants