-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Store the ValRaw
type in little-endian format
#4035
Merged
alexcrichton
merged 2 commits into
bytecodealliance:main
from
alexcrichton:val-raw-little-endian
Apr 14, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,16 +778,81 @@ impl VMContext { | |
/// This is provided for use with the `Func::new_unchecked` and | ||
/// `Func::call_unchecked` APIs. In general it's unlikely you should be using | ||
/// this from Rust, rather using APIs like `Func::wrap` and `TypedFunc::call`. | ||
/// | ||
/// This is notably an "unsafe" way to work with `Val` and it's recommended to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *ValRaw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment here is actually intended to point to |
||
/// instead use `Val` where possible. An important note about this union is that | ||
/// fields are all stored in little-endian format, regardless of the endianness | ||
/// of the host system. | ||
#[allow(missing_docs)] | ||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub union ValRaw { | ||
/// A WebAssembly `i32` value. | ||
/// | ||
/// Note that the payload here is a Rust `i32` but the WebAssembly `i32` | ||
/// type does not assign an interpretation of the upper bit as either signed | ||
/// or unsigned. The Rust type `i32` is simply chosen for convenience. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub i32: i32, | ||
|
||
/// A WebAssembly `i64` value. | ||
/// | ||
/// Note that the payload here is a Rust `i64` but the WebAssembly `i64` | ||
/// type does not assign an interpretation of the upper bit as either signed | ||
/// or unsigned. The Rust type `i64` is simply chosen for convenience. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub i64: i64, | ||
|
||
/// A WebAssembly `f32` value. | ||
/// | ||
/// Note that the payload here is a Rust `u32`. This is to allow passing any | ||
/// representation of NaN into WebAssembly without risk of changing NaN | ||
/// payload bits as its gets passed around the system. Otherwise though this | ||
/// `u32` value is the return value of `f32::to_bits` in Rust. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub f32: u32, | ||
|
||
/// A WebAssembly `f64` value. | ||
/// | ||
/// Note that the payload here is a Rust `u64`. This is to allow passing any | ||
/// representation of NaN into WebAssembly without risk of changing NaN | ||
/// payload bits as its gets passed around the system. Otherwise though this | ||
/// `u64` value is the return value of `f64::to_bits` in Rust. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub f64: u64, | ||
|
||
/// A WebAssembly `v128` value. | ||
/// | ||
/// The payload here is a Rust `u128` which has the same number of bits but | ||
/// note that `v128` in WebAssembly is often considered a vector type such | ||
/// as `i32x4` or `f64x2`. This means that the actual interpretation of the | ||
/// underlying bits is left up to the instructions which consume this value. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub v128: u128, | ||
|
||
/// A WebAssembly `funcref` value. | ||
/// | ||
/// The payload here is a pointer which is runtime-defined. This is one of | ||
/// the main points of unsafety about the `ValRaw` type as the validity of | ||
/// the pointer here is not easily verified and must be preserved by | ||
/// carefully calling the correct functions throughout the runtime. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub funcref: usize, | ||
|
||
/// A WebAssembly `externref` value. | ||
/// | ||
/// The payload here is a pointer which is runtime-defined. This is one of | ||
/// the main points of unsafety about the `ValRaw` type as the validity of | ||
/// the pointer here is not easily verified and must be preserved by | ||
/// carefully calling the correct functions throughout the runtime. | ||
/// | ||
/// This value is always stored in a little-endian format. | ||
pub externref: usize, | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe store
char[4]
,char[8]
, ... instead? Otherwise people will likely forget to do the endianness transform. Especially as all common architectures are little endian too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to leave this in to avoid the need for funky casts and such in C. This is not intended to be super heavily used either and other language bindings will have to deal with this anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need funky casts either way to support big endian systems.