-
Notifications
You must be signed in to change notification settings - Fork 824
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
fix(c-api) wasm_limits_t
contains Pages
, not Bytes
+ sentinel value
#1690
Merged
Conversation
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
When building a `wasm_memorytype_t` with `wasm_memorytype_new`, we pass a `wasm_limits_t`, where `min` and `max` represent `Pages`. This semantics is set by `wasm_memorytype_new` itself where `min` and `max` from `wasm_limits_t` are used to compute `Pages`, which are then passed to `MemoryType`. Then, in `wasm_memorytype_limits`, we expect to get the same `wasm_limits_t` given to `wasm_memorytype_new`. But it's not! The same `MemoryType` is read, good. The `minimum` and `maximum` fields are `Pages`, good. Then, we compute the `min` and `max` values for the resulting `wasm_limits_t`, which receive `Page.bytes().0`, not good! We don't want the number of bytes, but the number of pages. This patch fixes that.
In the `wasm.h` header file, it is defined by `wasm_limits_max_default`.
Hywan
changed the title
fix(c-api)
fix(c-api) Oct 8, 2020
wasm_limits_t
contains Pages
, not Bytes
.wasm_limits_t
contains Pages
, not Bytes
+ sentinel value
syrusakbary
approved these changes
Oct 8, 2020
bors r+ |
Build succeeded: |
MarkMcCaskey
reviewed
Oct 8, 2020
Comment on lines
+62
to
+66
min: md.minimum.0 as _, | ||
max: md | ||
.maximum | ||
.map(|max| max.0 as _) | ||
.unwrap_or(LIMITS_MAX_SENTINEL), |
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.
Good catch, I didn't see that
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When building a
wasm_memorytype_t
withwasm_memorytype_new
, wepass a
wasm_limits_t
, wheremin
andmax
representPages
. Thissemantics is set by
wasm_memorytype_new
itself wheremin
andmax
from
wasm_limits_t
are used to computePages
, which are then passedto
MemoryType
.Then, in
wasm_memorytype_limits
, we expect to get the samewasm_limits_t
given towasm_memorytype_new
. But it's not!The same
MemoryType
is read, good. Theminimum
andmaximum
fields are
Pages
, good. Then, we compute themin
andmax
valuesfor the resulting
wasm_limits_t
, which receivePage.bytes().0
, notgood! We don't want the number of bytes, but the number of pages.
This patch fixes that.
Edit: This patch also fixes the max limit sentinel value. In
wasm.h
, it is defined bywasm_limits_max_default
(0xffffffff
). In our code, it is correctly used inwasm_memorytype_new
, but not inwasm_memorytype_limits
. A new constant has been introduced:LIMITS_MAX_SENTINEL
. Not super happy with this name though.