-
Notifications
You must be signed in to change notification settings - Fork 90
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
refactor: api module overhaul #540
Conversation
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.
Even if all of these changes are non-breaking and deprecations, there should be some mention in the changelog
let size = (stable_size() << 16) | ||
.try_into() | ||
.expect("overflow: stable memory too large to read in one go"); | ||
let mut vec = Vec::with_capacity(size); |
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.
Could we use Result rather than panic in the interface here? The .expect(...)
is up to us, and we could use Vec::try_with_capacity().
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.
The content of this src/stable.rs
file was directly copied from src/api/stable/mod.rs
.
I will improve the internal implementation in a later PR.
|
||
let mut vec = self.memory.lock().unwrap(); | ||
let previous_len = vec.len() as u64; | ||
let new_len = vec.len() as u64 + new_bytes; |
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.
let new_len = vec.len() as u64 + new_bytes; | |
let new_len = previous_len + new_bytes; |
/// size that was reserved. | ||
/// | ||
/// *Note*: Pages are 64KiB in WASM. | ||
fn stable_grow(&self, new_pages: u64) -> Result<u64, StableMemoryError>; |
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 want to suggest calling the parameter additional_pages
, which is unambiguous, but the public spec also uses new_pages
.
fn stable_grow(&self, new_pages: u64) -> Result<u64, StableMemoryError>; | |
fn stable_grow(&self, additional_pages: u64) -> Result<u64, StableMemoryError>; |
I will improve the Providing migration guide / changelog / docs will be the last task in #521 before I make the first alpha release. |
Description
Overhaul the
api
module. It now provides a complete binding for the system API. Stable memory API are moved intosrc/stable.rs
.The bindings are named consistently. Please refer to the top documentation comments in
src/api.rs
for additional details.Existing bindings that are inconsistently named according to the new rules are now deprecated.
How Has This Been Tested?
Added
e2e-tests/tests/api.rs
.e2e-tests/bin/api.rs
illustrates how to use the API bindings.Checklist: