Skip to content

Commit

Permalink
Merge branch 'master' into fix-windows_memory_grow
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb authored Sep 3, 2021
2 parents b0c7bd0 + 4ab4e91 commit 5777991
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 116 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ languages**, so you can use WebAssembly _anywhere_.
| | [**Swift**][Swift integration] | *no published package* | |
| ![Zig logo] | [**Zig**][Zig integration] | *no published package* | |
| ![Dart logo] | [**Dart**][Dart integration] | [`wasm` pub package] | |
| | [**Lisp**][Lisp integration] | *under heavy development - no published package* | |

[👋  Missing a language?](https://github.com/wasmerio/wasmer/issues/new?assignees=&labels=%F0%9F%8E%89+enhancement&template=---feature-request.md&title=)

Expand Down Expand Up @@ -209,6 +210,8 @@ languages**, so you can use WebAssembly _anywhere_.
[dart integration]: https://github.com/dart-lang/wasm
[`wasm` pub package]: https://pub.dev/packages/wasm

[lisp integration]: https://github.com/helmutkian/cl-wasm-runtime

## Contribute

We appreciate your help! 💜
Expand Down
23 changes: 16 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@ fn main() -> anyhow::Result<()> {
buffer: String::new(),
path: vec![],
};
let wasi_versions = ["unstable", "snapshot1"];

with_test_module(&mut wasitests, "wasitests", |wasitests| {
for wasi_version in &wasi_versions {
for wasi_version in &["unstable", "snapshot1"] {
with_test_module(wasitests, wasi_version, |wasitests| {
let _wasi_tests = test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
wasi_processor,
)?;
for (wasi_filesystem_test_name, wasi_filesystem_kind) in &[
("host_fs", "WasiFileSystemKind::Host"),
("mem_fs", "WasiFileSystemKind::InMemory"),
] {
with_test_module(wasitests, wasi_filesystem_test_name, |wasitests| {
test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
|out, path| wasi_processor(out, path, wasi_filesystem_kind),
)
})?;
}

Ok(())
})?;
}

Ok(())
})?;

Expand Down
32 changes: 25 additions & 7 deletions lib/vfs/src/mem_fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl VirtualFile for FileHandle {
};

match fs.storage.get(self.inode) {
Some(Node::File { file, .. }) => file.buffer.len().try_into().unwrap_or(0),
Some(Node::File { file, .. }) => file.len().try_into().unwrap_or(0),
_ => 0,
}
}
Expand All @@ -107,9 +107,11 @@ impl VirtualFile for FileHandle {
.map_err(|_| FsError::Lock)?;

match fs.storage.get_mut(self.inode) {
Some(Node::File { file, .. }) => file
.buffer
.resize(new_size.try_into().map_err(|_| FsError::UnknownError)?, 0),
Some(Node::File { file, metadata, .. }) => {
file.buffer
.resize(new_size.try_into().map_err(|_| FsError::UnknownError)?, 0);
metadata.len = new_size;
}
_ => return Err(FsError::NotAFile),
}

Expand Down Expand Up @@ -561,8 +563,8 @@ impl Write for FileHandle {
io::Error::new(io::ErrorKind::Other, "failed to acquire a write lock")
})?;

let file = match fs.storage.get_mut(self.inode) {
Some(Node::File { file, .. }) => file,
let (file, metadata) = match fs.storage.get_mut(self.inode) {
Some(Node::File { file, metadata, .. }) => (file, metadata),
_ => {
return Err(io::Error::new(
io::ErrorKind::NotFound,
Expand All @@ -571,7 +573,11 @@ impl Write for FileHandle {
}
};

file.write(buf)
let bytes_written = file.write(buf)?;

metadata.len = file.len().try_into().unwrap();

Ok(bytes_written)
}

fn flush(&mut self) -> io::Result<()> {
Expand Down Expand Up @@ -687,6 +693,10 @@ mod test_read_write_seek {
.open(path!("/foo.txt"))
.expect("failed to create a new file");

assert!(
matches!(fs.metadata(path!("/foo.txt")), Ok(Metadata { len: 0, .. })),
"checking the `metadata.len` is 0",
);
assert!(
matches!(file.write(b"foobarbazqux"), Ok(12)),
"writing `foobarbazqux`",
Expand Down Expand Up @@ -715,6 +725,10 @@ mod test_read_write_seek {
"reading more bytes than available",
);
assert_eq!(buffer[..12], b"foobarbazqux"[..], "checking the 12 bytes");
assert!(
matches!(fs.metadata(path!("/foo.txt")), Ok(Metadata { len: 12, .. })),
"checking the `metadata.len` is 0",
);
}

#[test]
Expand Down Expand Up @@ -847,6 +861,10 @@ impl File {
self.buffer.clear();
self.cursor = 0;
}

pub(super) fn len(&self) -> usize {
self.buffer.len()
}
}

impl Read for File {
Expand Down
1 change: 1 addition & 0 deletions lib/vfs/src/mem_fs/file_opener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl crate::FileOpener for FileOpener {
// Truncate if needed.
if truncate {
file.truncate();
metadata.len = 0;
}

// Move the cursor to the end if needed.
Expand Down
Loading

0 comments on commit 5777991

Please sign in to comment.