Skip to content

Commit

Permalink
adapt to newer wamr version
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Aug 25, 2024
1 parent 317ab27 commit fec5e49
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/cpp/helper-types/wit-host.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ typedef uint8_t *guest_address;
typedef size_t guest_size;
extern "C" void *cabi_realloc(void *ptr, size_t old_size, size_t align,
size_t new_size);
#define INVALID_GUEST_ADDRESS nullptr
#elif defined(WIT_WASI64)
typedef uint64_t guest_address;
typedef uint64_t guest_size;
#define INVALID_GUEST_ADDRESS 0
#else
typedef uint32_t guest_address;
typedef uint32_t guest_size;
#define INVALID_GUEST_ADDRESS 0
#endif
} // namespace wit

Expand Down Expand Up @@ -76,7 +79,7 @@ class string {
static string from_view(wasm_exec_env_t exec_env, std::string_view v) {
void *addr = nullptr;
wasm_function_inst_t wasm_func = wasm_runtime_lookup_function(
wasm_runtime_get_module_inst(exec_env), "cabi_realloc", "(*$ii)*");
wasm_runtime_get_module_inst(exec_env), "cabi_realloc"/*, "(*$ii)*"*/);

wasm_val_t wasm_results[1] = {WASM_INIT_VAL};
wasm_val_t wasm_args[4] = {
Expand Down Expand Up @@ -190,7 +193,7 @@ class ResourceExportBase : public ResourceTable<guest_address> {
int32_t index;

public:
ResourceExportBase() : rep(nullptr), index(-1) {}
ResourceExportBase() : rep(INVALID_GUEST_ADDRESS), index(-1) {}
ResourceExportBase(int32_t i) : rep(*lookup_resource(i)), index(i) {}
ResourceExportBase(ResourceExportBase &&b) : rep(b.rep), index(b.index) {
b.rep = 0;
Expand All @@ -204,7 +207,7 @@ class ResourceExportBase : public ResourceTable<guest_address> {
b.rep = 0;
}
~ResourceExportBase() {
if (index >= 0 && rep != nullptr) {
if (index >= 0 && rep != INVALID_GUEST_ADDRESS) {
remove_resource(index);
}
}
Expand Down

0 comments on commit fec5e49

Please sign in to comment.