NewModule compiles a new `Module` from the `wasm` provided with the given configuration in `engine`.
(engine *Engine, wasm []byte)
| 11 | // NewModule compiles a new `Module` from the `wasm` provided with the given configuration |
| 12 | // in `engine`. |
| 13 | func NewModule(engine *Engine, wasm []byte) (*Module, error) { |
| 14 | // We can't create the `wasm_byte_vec_t` here and pass it in because |
| 15 | // that runs into the error of "passed a pointer to a pointer" because |
| 16 | // the vec itself is passed by pointer and it contains a pointer to |
| 17 | // `wasm`. To work around this we insert some C shims above and call |
| 18 | // them. |
| 19 | var wasmPtr *C.uint8_t |
| 20 | if len(wasm) > 0 { |
| 21 | wasmPtr = (*C.uint8_t)(unsafe.Pointer(&wasm[0])) |
| 22 | } |
| 23 | var ptr *C.wasmtime_module_t |
| 24 | err := C.wasmtime_module_new(engine.ptr(), wasmPtr, C.size_t(len(wasm)), &ptr) |
| 25 | runtime.KeepAlive(engine) |
| 26 | runtime.KeepAlive(wasm) |
| 27 | |
| 28 | if err != nil { |
| 29 | return nil, mkError(err) |
| 30 | } |
| 31 | |
| 32 | return mkModule(ptr), nil |
| 33 | } |
| 34 | |
| 35 | // ModuleValidate validates whether `wasm` would be a valid wasm module according to the |
| 36 | // configuration in `store` |
searching dependent graphs…