Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ jobs:
run: make wasm
- name: Run C++ tests
run: make cc
# TODO: C memory management seems to have broken entirely for yet unknown reasons
#- name: Run C tests
# run: make c
- name: Run C tests
run: make c
23 changes: 14 additions & 9 deletions example/hostref.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,42 @@ void check(own wasm_ref_t* actual, const wasm_ref_t* expected) {


int main(int argc, const char* argv[]) {
int rc = 0;

// Initialize.
printf("Initializing...\n");
wasm_engine_t* engine = wasm_engine_new();
wasm_store_t* store = wasm_store_new(engine);

// Load binary.
printf("Loading binary...\n");
wasm_byte_vec_t binary = WASM_EMPTY_VEC;
FILE* file = fopen("hostref.wasm", "rb");
if (!file) {
printf("> Error loading module!\n");
return 1;
rc = 1; goto cleanup;
}
fseek(file, 0L, SEEK_END);
size_t file_size = ftell(file);
fseek(file, 0L, SEEK_SET);
wasm_byte_vec_t binary;
wasm_byte_vec_new_uninitialized(&binary, file_size);
if (fread(binary.data, file_size, 1, file) != 1) {
printf("> Error loading module!\n");
return 1;
fclose(file);
rc = 1; goto cleanup;
}
fclose(file);

// Compile.
printf("Compiling module...\n");
own wasm_module_t* module = wasm_module_new(store, &binary);
wasm_byte_vec_delete(&binary);
binary = (wasm_byte_vec_t)WASM_EMPTY_VEC;
if (!module) {
printf("> Error compiling module!\n");
return 1;
rc = 1; goto cleanup;
}

wasm_byte_vec_delete(&binary);

// Create external callback function.
printf("Creating callback...\n");
own wasm_functype_t* callback_type = wasm_functype_new_1_1(
Expand All @@ -173,7 +176,7 @@ int main(int argc, const char* argv[]) {
wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
printf("> Error instantiating module!\n");
return 1;
rc = 1; goto cleanup;
}

wasm_func_delete(callback_func);
Expand Down Expand Up @@ -259,12 +262,14 @@ int main(int argc, const char* argv[]) {

wasm_extern_vec_delete(&exports);

cleanup:
// Shut down.
printf("Shutting down...\n");
wasm_byte_vec_delete(&binary);
wasm_store_delete(store);
wasm_engine_delete(engine);

// All done.
printf("Done.\n");
return 0;
if (!rc) printf("Done.\n");
return rc;
}
Binary file modified example/hostref.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion example/hostref.wat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(import "" "f" (func $fun (param externref) (result externref)))

(global $glob (export "global") (mut externref) (ref.null))
(global $glob (export "global") (mut externref) (ref.null extern))
(table $tab (export "table") 10 externref)

(func (export "global.set") (param $r externref)
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct borrowed_vec {
struct wasm_##name##_t : Name {}; \
\
void wasm_##name##_delete(wasm_##name##_t* x) { \
delete x; \
if (x) destroyer{}(static_cast<Name*>(x)); \
} \
\
extern "C++" inline auto hide_##name(Name* x) -> wasm_##name##_t* { \
Expand Down
1 change: 1 addition & 0 deletions src/wasm-v8-lowlevel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace wasm {

void flags_init() {
v8::internal::v8_flags.expose_gc = true;
v8::internal::v8_flags.experimental_wasm_typed_funcref = true;
}


Expand Down
Loading