Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Store globals #157

Open
Jflick58 opened this issue May 30, 2023 · 3 comments
Open

Accessing Store globals #157

Jflick58 opened this issue May 30, 2023 · 3 comments

Comments

@Jflick58
Copy link

Jflick58 commented May 30, 2023

Hello, I’ve built a wasm-powered replacement for the exec() function here and wasmtime has been invaluable!

That being said, I had a quick question - once I set a global value, how do I access the globals that I have set? Is it only through function execution?

Sample code:

            # Check if the value is of a supported type
            if isinstance(value, (int, float)):
                # Determine the Wasmtime type based on the Python type
                if isinstance(value, int):
                    value_type = ValType.i32()
                elif isinstance(value, float):
                    value_type = ValType.f64()

                # Create a mutable global instance with the Python value
                global_type = GlobalType(value_type, mutable=True)
                global_var = Global(store, global_type, value)

The data function of the Store class returns None for me. Would appreciate some guidance, thanks!

@alexcrichton
Copy link
Member

Could you expand a bit on what your goal is and what you're using globals for? Globals in a store can't be enumerated so you'd need to store your own list of them somewhere, for example on the host in Python. The data member of a Store is set on creation of the Store (an optional argument) and the data accessor retrieves it, but nothing more. What you can do, however, is place a list of globals onto the object returned from data

@Jflick58
Copy link
Author

Jflick58 commented Jun 3, 2023

Thanks for the response. Basically, I'm trying to use wasmtime and the VmWare labs Wasm Python interpreter to create an isolated version of exec I'm trying to figure out support for globals to replicate the ergonomics of the exec function. It looks like I can set them in an environment, but I was trying to figure out a way to confirm their existence and ability to be accessed for my unit tests.

@alexcrichton
Copy link
Member

Ah ok, in that case I think the "globals" you're referring to are perhaps Python globals? If so they have no relation to a WebAssembly global or the wasmtime.Global object, they're entirely separate. Enumerating Python globals as it's running in wasm would have to be a feature of the interpreter you're using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants