From 98692f02ee679bdd5ac5316d5b384ff33ddb3980 Mon Sep 17 00:00:00 2001 From: Ashton Meuser Date: Thu, 12 Sep 2024 13:16:33 -0700 Subject: [PATCH] Backport GODOT_WASM_EXTERNREF --- src/defs.h | 1 + src/wasm.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/defs.h b/src/defs.h index 5d5ac6e..e7e6fb5 100644 --- a/src/defs.h +++ b/src/defs.h @@ -53,5 +53,6 @@ Useful for minimizing changes to implementation files between targets e.g. GDExt #define TIME_MONOTONIC OS::get_singleton()->get_ticks_usec() * 1000 #define NULL_VARIANT Variant() #define PAGE_SIZE 65536 +#define GODOT_WASM_EXTERNREF 128 // Different enums in Wasmer & Wasmtime (see https://github.com/wasmerio/wasmer/issues/5082) #endif diff --git a/src/wasm.cpp b/src/wasm.cpp index 77f18b6..b67eb02 100644 --- a/src/wasm.cpp +++ b/src/wasm.cpp @@ -55,7 +55,7 @@ namespace godot { inline wasm_val_t error_value(const char* message) { PRINT_ERROR(message); wasm_val_t value; - value.kind = WASM_ANYREF; + value.kind = GODOT_WASM_EXTERNREF; value.of.ref = NULL; return value; } @@ -121,12 +121,12 @@ namespace godot { if ((size_t)array.size() != results->size) return ERR_PARAMETER_RANGE_ERROR; for (uint16_t i = 0; i < results->size; i++) { results->data[i] = encode_variant(array[i], context->results[i]); - if (results->data[i].kind == WASM_ANYREF) return ERR_INVALID_DATA; + if (results->data[i].kind == GODOT_WASM_EXTERNREF) return ERR_INVALID_DATA; } return OK; } else if (results->size == 1) { results->data[0] = encode_variant(variant, context->results[0]); - return results->data[0].kind == WASM_ANYREF ? ERR_INVALID_DATA : OK; + return results->data[0].kind == GODOT_WASM_EXTERNREF ? ERR_INVALID_DATA : OK; } else return ERR_INVALID_DATA; } @@ -449,7 +449,7 @@ namespace godot { for (uint16_t i = 0; i < args.size(); i++) { Variant variant = args[i]; wasm_val_t value = encode_variant(variant, context.params[i]); - FAIL_IF(value.kind == WASM_ANYREF, "Invalid argument type", NULL_VARIANT); + FAIL_IF(value.kind == GODOT_WASM_EXTERNREF, "Invalid argument type", NULL_VARIANT); args_vec.push_back(value); } wasm_val_vec_t f_args = { args_vec.size(), args_vec.data() };