Skip to content

Commit ae73aec

Browse files
bors[bot]jubianchi
andauthored
Merge #153
153: fix: Update wat2wasm since it changed in Wasmer r=jubianchi a=jubianchi Co-authored-by: jubianchi <[email protected]>
2 parents 2286364 + a17ac9d commit ae73aec

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

wasmer/packaged/include/wasmer_wasm.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <stdlib.h>
5656
#include "wasm.h"
5757

58+
#if defined(WASMER_COMPILER_ENABLED)
5859
/**
5960
* Kind of compilers that can be used by the engines.
6061
*
@@ -66,6 +67,7 @@ typedef enum {
6667
LLVM = 1,
6768
SINGLEPASS = 2,
6869
} wasmer_compiler_t;
70+
#endif
6971

7072
/**
7173
* Kind of engines that can be used by the store.
@@ -143,10 +145,18 @@ intptr_t wasi_env_read_stdout(wasi_env_t *env, char *buffer, uintptr_t buffer_le
143145
#endif
144146

145147
#if defined(WASMER_WASI_ENABLED)
148+
/**
149+
* This function is deprecated. You may safely remove all calls to it and everything
150+
* will continue to work.
151+
*/
146152
bool wasi_env_set_instance(wasi_env_t *env, const wasm_instance_t *instance);
147153
#endif
148154

149155
#if defined(WASMER_WASI_ENABLED)
156+
/**
157+
* This function is deprecated. You may safely remove all calls to it and everything
158+
* will continue to work.
159+
*/
150160
void wasi_env_set_memory(wasi_env_t *env, const wasm_memory_t *memory);
151161
#endif
152162

@@ -168,10 +178,12 @@ wasm_func_t *wasi_get_start_function(wasm_instance_t *instance);
168178
wasi_version_t wasi_get_wasi_version(const wasm_module_t *module);
169179
#endif
170180

181+
#if defined(WASMER_COMPILER_ENABLED)
171182
/**
172183
* Configure the compiler to use.
173184
*/
174185
void wasm_config_set_compiler(wasm_config_t *config, wasmer_compiler_t compiler);
186+
#endif
175187

176188
/**
177189
* Configure the engine to use.
@@ -180,7 +192,7 @@ void wasm_config_set_engine(wasm_config_t *config, wasmer_engine_t engine);
180192

181193
void wasm_module_name(const wasm_module_t *module, wasm_name_t *out);
182194

183-
bool wasm_module_set_name(wasm_module_t *module, const wasm_name_t *name);
195+
bool wasm_module_set_name(wasm_module_t *module, wasm_name_t *name);
184196

185197
/**
186198
* Gets the length in bytes of the last error if any.
@@ -228,8 +240,8 @@ int wasmer_last_error_message(char *buffer, int length);
228240
* Parses in-memory bytes as either the WAT format, or a binary Wasm
229241
* module. This is wasmer-specific.
230242
*
231-
* In case of failure, `wat2wasm` returns `NULL`.
243+
* In case of failure, `wat2wasm` sets the `out->data = NULL` and `out->size = 0`.
232244
*/
233-
wasm_byte_vec_t *wat2wasm(const wasm_byte_vec_t *wat);
245+
void wat2wasm(const wasm_byte_vec_t *wat, wasm_byte_vec_t *out);
234246

235247
#endif /* WASMER_WASM_H */
Binary file not shown.
880 KB
Binary file not shown.

wasmer/wat.go

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
package wasmer
22

33
// #include <wasmer_wasm.h>
4-
//
5-
// wasm_byte_vec_t *to_wat2wasm(uint8_t *wat_data, size_t wat_length) {
6-
// wasm_byte_vec_t wat;
7-
// wat.size = wat_length;
8-
// wat.data = (wasm_byte_t*) wat_data;
9-
//
10-
// return wat2wasm(&wat);
11-
// }
124
import "C"
135
import (
14-
"runtime"
156
"unsafe"
167
)
178

189
func Wat2Wasm(wat string) ([]byte, error) {
19-
watAsBytes := []byte(wat)
20-
var watPtr *C.uint8_t
10+
var watBytes C.wasm_byte_vec_t
2111
var watLength = len(wat)
12+
C.wasm_byte_vec_new(&watBytes, C.size_t(watLength), C.CString(wat))
2213

23-
if watLength > 0 {
24-
watPtr = (*C.uint8_t)(unsafe.Pointer(&watAsBytes[0]))
25-
}
26-
27-
var wasm *C.wasm_byte_vec_t = C.to_wat2wasm(watPtr, C.size_t(watLength))
28-
runtime.KeepAlive(wat)
14+
var wasm C.wasm_byte_vec_t
15+
C.wat2wasm(
16+
&watBytes,
17+
&wasm,
18+
)
19+
C.wasm_byte_vec_delete(&watBytes)
2920

30-
if wasm == nil {
21+
if wasm.data == nil {
3122
return nil, newErrorFromWasmer()
3223
}
3324

3425
wasmBytes := C.GoBytes(unsafe.Pointer(wasm.data), C.int(wasm.size))
35-
C.wasm_byte_vec_delete(wasm)
26+
C.wasm_byte_vec_delete(&wasm)
3627

3728
return wasmBytes, nil
3829
}

0 commit comments

Comments
 (0)