Make WasiCtxBuilder by-ref.

This commit makes `WasiCtxBuilder` take `&mut Self` and return `&mut
Self` for its methods.  This is needed to allow for the same
(unmoved) `WasiCtxBuilder` to be used when building a WASI context.

Also fixes up the C API to remove the unnecessary `Box::from_raw` and
`forget` calls which were previously needed for the moving version of
`WasiCtxBuilder`.
This commit is contained in:
Peter Huene
2020-02-25 13:36:36 -08:00
parent 07066835db
commit fa65a14dba
4 changed files with 113 additions and 109 deletions

View File

@@ -303,22 +303,25 @@ impl ModuleRegistry {
argv: &[String],
vars: &[(String, String)],
) -> Result<ModuleRegistry> {
let mut cx1 = wasi_common::WasiCtxBuilder::new()
.inherit_stdio()
.args(argv)
.envs(vars);
let mut cx1 = wasi_common::WasiCtxBuilder::new();
cx1.inherit_stdio().args(argv).envs(vars);
for (name, file) in preopen_dirs {
cx1 = cx1.preopened_dir(file.try_clone()?, name);
cx1.preopened_dir(file.try_clone()?, name);
}
let cx1 = cx1.build()?;
let mut cx2 = wasi_common::old::snapshot_0::WasiCtxBuilder::new()
.inherit_stdio()
.args(argv)
.envs(vars);
for (name, file) in preopen_dirs {
cx2 = cx2.preopened_dir(file.try_clone()?, name);
}
let cx2 = cx2.build()?;
Ok(ModuleRegistry {