-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Description
When using the import and export function, I encountered a problem where the structure is used as a parameter for the export function. However, when this function is imported into another wasm and used, the final output result is incorrect
utils.h
#ifndef UTILS_H
#define UTILS_H
#define WASM_EXPORT(name) __attribute__((export_name(name)))
#define WASM_IMPORT(mod, name) __attribute__((import_module(mod), import_name(name)))
struct MyObject {
int val1 = 5;
int val2 = 5;
int val3 = 5;
void resetAll() {
val1 = 5;
val2 = 5;
val3 = 5;
}
};
#endif
share.cpp (define export function)
#include "../inc/utils.h"
#include <stdint.h>
MyObject obj;
WASM_IMPORT("env", "print") extern void print(int num);
WASM_EXPORT("set_obj") void set_obj(MyObject val) {
obj = val;
}
main.cpp (import functions which is exported by share.cpp)
#include "../inc/utils.h"
#include <stdint.h>
WASM_IMPORT("env", "print") extern void print(int num);
WASM_IMPORT("share_ctx", "set_obj") extern void set_obj(MyObject obj);
WASM_EXPORT("main_set_obj") void main_set_obj() {
MyObject obj;
obj.val1 = 1;
obj.val2 = 2;
obj.val3 = 3;
set_obj(obj);
}Can I pass the MyObject value and set it through the import 'set_obj' function ? the result is that all value is 0, which is not expected
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels