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

feat(extension) Implement wasm_get_memory_buffer #37

Merged
merged 9 commits into from
Mar 27, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Mar 27, 2019

Sequel of #35.
Depends on wasmerio/wasmer#296.

Implement wasm_get_memory_buffer:

function wasm_get_memory_buffer(resource $wasm_instance): ?WasmArrayBuffer;

Usage example:

$bytes = wasm_fetch_bytes('my_program.wasm');
$instance = wasm_new_instance($bytes);
$pointer = wasm_invoke_function($instance, 'function_returning_a_pointer_to_a_string', []);

// Get a memory buffer.
$memory = wasm_get_memory_buffer($instance);

// Get a view over the memory buffer.
$view = new WasmUint8Array($memory, $pointer);

// Read the memory to, for instance, read a NUL-terminated ASCII string.
$nth = 0;

while (0 !== $view[$nth]) {
    echo chr($view[$nth]);
    ++$nth;
}

echo "\n";

Hywan added 2 commits March 27, 2019 12:14
Huge diff because the object declarations have moved before the
function declarations.
@Hywan Hywan added 🎉 enhancement New feature or request 🧪 tests I love tests 📦 component-extension About the PHP extension written in C/C++ 📚 documentation Do you like to read? labels Mar 27, 2019
@Hywan Hywan self-assigned this Mar 27, 2019
@Hywan Hywan marked this pull request as ready for review March 27, 2019 13:31
@Hywan Hywan merged commit e65ff4f into master Mar 27, 2019
@Hywan Hywan deleted the feat-extension-get-memory branch April 3, 2019 09:13
@Hywan Hywan mentioned this pull request Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-extension About the PHP extension written in C/C++ 📚 documentation Do you like to read? 🎉 enhancement New feature or request 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant