This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Conversation
This implements support for `u128`/`i128` as parameters/return value in runtime interfaces. As we can not pass them as identity, as for the other primitives types, we pass them as an pointer to an `[u8; 16]` array.
pepyakin
suggested changes
Jan 21, 2020
| let data = context.read_memory(Pointer::new(arg), 16)?; | ||
| let mut res = [0u8; 16]; | ||
| res.copy_from_slice(&data); | ||
| Ok(unsafe { mem::transmute::<[u8; 16], $type>(res) }) |
Contributor
There was a problem hiding this comment.
- I wonder if this is safe? The alignment of u128 might be 16 and I am not sure sure if we can say anything regarding this about
res. - Does it assume that wasm and host have the same endianness?
I think this can be swapped with u128::from_le_bytes here instead of transmute?
Member
Author
There was a problem hiding this comment.
- What? Why can we not say the same about
res? It is as well 16 bytes. (Looking at the rust source code forfrom_le_bytesit does exactly the same transmute) - Yes it assumes it. Please don't start again this xD As it is no primitive type, I probably also need to call
to_le_byteson the host?
Member
Author
There was a problem hiding this comment.
But good catches! I searched yesterday evening for *_let_bytes, but failed for some reason 🤷♀️
pepyakin
approved these changes
Jan 22, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements support for
u128/i128as parameters/return value inruntime interfaces. As we can not pass them as identity, as for the
other primitives types, we pass them as an pointer to an
[u8; 16]array.