Favor using non-braced using statement.

This commit is contained in:
Peter Huene
2020-02-24 18:44:37 -08:00
parent a6ec8f85a6
commit 4e1d2a2fc1
10 changed files with 328 additions and 343 deletions

View File

@@ -165,10 +165,8 @@ Alternatively, the `run` function could be invoked without using the runtime bin
```c#
...
using (var instance = module.Instantiate(new Host()))
{
instance.Externs.Functions[0].Invoke();
}
using var instance = module.Instantiate(new Host());
instance.Externs.Functions[0].Invoke();
...
```

View File

@@ -52,8 +52,7 @@ namespace Wasmtime.Bindings
{
var parameters = Interop.ToValueTypeVec(Import.Parameters);
var results = Interop.ToValueTypeVec(Import.Results);
using (var funcType = Interop.wasm_functype_new(ref parameters, ref results))
{
using var funcType = Interop.wasm_functype_new(ref parameters, ref results);
var callback = CreateCallback(store, host);
var func = Interop.wasm_func_new(store.Handle, funcType, callback);
// Store the callback with the safe handle to keep the delegate GC reachable
@@ -61,7 +60,6 @@ namespace Wasmtime.Bindings
return func;
}
}
}
private void Validate()
{

View File

@@ -59,16 +59,16 @@ namespace Wasmtime.Bindings
var valueTypeHandle = valueType.DangerousGetHandle();
valueType.SetHandleAsInvalid();
using (var globalType = Interop.wasm_globaltype_new(
using var globalType = Interop.wasm_globaltype_new(
valueTypeHandle,
Import.IsMutable ? Interop.wasm_mutability_t.WASM_VAR : Interop.wasm_mutability_t.WASM_CONST))
{
Import.IsMutable ? Interop.wasm_mutability_t.WASM_VAR : Interop.wasm_mutability_t.WASM_CONST
);
var handle = Interop.wasm_global_new(store.Handle, globalType, &v);
global.Handle = handle;
return handle;
}
}
}
private void Validate()
{

View File

@@ -68,14 +68,13 @@ namespace Wasmtime.Bindings
Interop.wasm_limits_t limits = new Interop.wasm_limits_t();
limits.min = min;
limits.max = max;
using (var memoryType = Interop.wasm_memorytype_new(&limits))
{
using var memoryType = Interop.wasm_memorytype_new(&limits);
var handle = Interop.wasm_memory_new(store.Handle, memoryType);
memory.Handle = handle;
return handle;
}
}
}
private void Validate()
{

View File

@@ -36,8 +36,8 @@ namespace Wasmtime.Tests
public void ItBindsImportMethodsAndCallsThemCorrectly()
{
var host = new MyHost();
using (var instance = Fixture.Module.Instantiate(host))
{
using var instance = Fixture.Module.Instantiate(host);
var add_func = instance.Externs.Functions.Where(f => f.Name == "add_wrapper").Single();
int invoke_add(int x, int y) => (int)add_func.Invoke(new object[] { x, y });
@@ -50,14 +50,13 @@ namespace Wasmtime.Tests
invoke_add(1970, 50).Should().Be(2020);
}
}
[Fact]
public void ItPropagatesExceptionsToCallersViaTraps()
{
var host = new MyHost();
using (var instance = Fixture.Module.Instantiate(host))
{
using var instance = Fixture.Module.Instantiate(host);
var throw_func = instance.Externs.Functions.Where(f => f.Name == "do_throw_wrapper").Single();
Action action = () => throw_func.Invoke();
@@ -67,5 +66,4 @@ namespace Wasmtime.Tests
.WithMessage(THROW_MESSAGE);
}
}
}
}

View File

@@ -46,8 +46,8 @@ namespace Wasmtime.Tests
[Fact]
public void ItCreatesExternsForTheGlobals()
{
using (var instance = Fixture.Module.Instantiate(new Host()))
{
using var instance = Fixture.Module.Instantiate(new Host());
dynamic dyn = instance;
var globals = instance.Externs.Globals;
globals.Count.Should().Be(8);
@@ -164,7 +164,6 @@ namespace Wasmtime.Tests
.Throw<InvalidOperationException>()
.WithMessage("The value of global 'global_f64' cannot be modified.");
}
}
public static IEnumerable<object[]> GetGlobalExports()
{

View File

@@ -118,7 +118,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithMissingImport()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NoImportsHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new NoImportsHost()); };
action
.Should()
@@ -129,7 +129,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithStaticField()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new GlobalIsStaticHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new GlobalIsStaticHost()); };
action
.Should()
@@ -140,7 +140,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithNonReadOnlyField()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new GlobalIsNotReadOnlyHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new GlobalIsNotReadOnlyHost()); };
action
.Should()
@@ -151,7 +151,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithInvalidType()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAGlobalHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAGlobalHost()); };
action
.Should()
@@ -162,7 +162,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithInvalidGlobalType()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAValidGlobalTypeHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAValidGlobalTypeHost()); };
action
.Should()
@@ -173,7 +173,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithGlobalTypeMismatch()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new TypeMismatchHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new TypeMismatchHost()); };
action
.Should()
@@ -184,7 +184,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWhenGlobalIsNotMut()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotMutHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotMutHost()); };
action
.Should()
@@ -195,7 +195,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWhenGlobalIsMut()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MutHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new MutHost()); };
action
.Should()
@@ -207,8 +207,8 @@ namespace Wasmtime.Tests
public void ItBindsTheGlobalsCorrectly()
{
var host = new ValidHost();
using (dynamic instance = Fixture.Module.Instantiate(host))
{
using dynamic instance = Fixture.Module.Instantiate(host);
host.Int32Mut.Value.Should().Be(0);
((int)instance.get_global_i32_mut()).Should().Be(0);
host.Int32.Value.Should().Be(1);
@@ -255,5 +255,4 @@ namespace Wasmtime.Tests
((double)instance.get_global_f64_mut()).Should().Be(17);
}
}
}
}

View File

@@ -45,8 +45,8 @@ namespace Wasmtime.Tests
public void ItCreatesExternsForTheMemories()
{
var host = new Host();
using (var instance = Fixture.Module.Instantiate(host))
{
using var instance = Fixture.Module.Instantiate(host);
instance.Externs.Memories.Count.Should().Be(1);
var memory = instance.Externs.Memories[0];
@@ -82,7 +82,6 @@ namespace Wasmtime.Tests
memory.WriteIntPtr(48, (IntPtr)17);
memory.ReadIntPtr(48).Should().Be((IntPtr)17);
}
}
public static IEnumerable<object[]> GetMemoryExports()
{

View File

@@ -74,7 +74,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithMissingImport()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MissingImportsHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new MissingImportsHost()); };
action
.Should()
@@ -85,7 +85,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithStaticField()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MemoryIsStaticHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new MemoryIsStaticHost()); };
action
.Should()
@@ -96,7 +96,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithNonReadOnlyField()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new MemoryIsNotReadOnlyHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new MemoryIsNotReadOnlyHost()); };
action
.Should()
@@ -107,7 +107,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWithInvalidType()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new NotAMemoryHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new NotAMemoryHost()); };
action
.Should()
@@ -118,7 +118,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWhenMemoryHasInvalidMinimum()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new InvalidMinimumHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new InvalidMinimumHost()); };
action
.Should()
@@ -129,7 +129,7 @@ namespace Wasmtime.Tests
[Fact]
public void ItFailsToInstantiateWhenMemoryHasInvalidMaximum()
{
Action action = () => { using (var instance = Fixture.Module.Instantiate(new InvalidMaximumHost())) { } };
Action action = () => { using var instance = Fixture.Module.Instantiate(new InvalidMaximumHost()); };
action
.Should()
@@ -141,8 +141,8 @@ namespace Wasmtime.Tests
public void ItBindsTheGlobalsCorrectly()
{
var host = new ValidHost();
using (dynamic instance = Fixture.Module.Instantiate(host))
{
using dynamic instance = Fixture.Module.Instantiate(host);
host.Mem.ReadString(0, 11).Should().Be("Hello World");
int written = host.Mem.WriteString(0, "WebAssembly Rocks!");
host.Mem.ReadString(0, written).Should().Be("WebAssembly Rocks!");
@@ -183,5 +183,4 @@ namespace Wasmtime.Tests
((IntPtr)instance.ReadIntPtr()).Should().Be((IntPtr)17);
}
}
}
}

View File

@@ -145,8 +145,7 @@ namespace Wasmtime.Tests
{
const string MESSAGE = "WASM IS VERY COOL";
using (var file = new TempFile())
{
using var file = new TempFile();
File.WriteAllText(file.Path, MESSAGE);
var wasi = new WasiBuilder()
@@ -164,7 +163,6 @@ namespace Wasmtime.Tests
Assert.Equal(MESSAGE.Length, memory.ReadInt32(32));
Assert.Equal(MESSAGE, memory.ReadString(8, MESSAGE.Length));
}
}
[Theory]
[InlineData(1)]
@@ -173,8 +171,8 @@ namespace Wasmtime.Tests
{
const string MESSAGE = "WASM IS VERY COOL";
using (var file = new TempFile())
{
using var file = new TempFile();
var builder = new WasiBuilder();
if (fd == 1)
{
@@ -200,15 +198,14 @@ namespace Wasmtime.Tests
Assert.Equal(0, inst.call_fd_close(fd));
Assert.Equal(MESSAGE, File.ReadAllText(file.Path));
}
}
[Fact]
public void ItSetsPreopenDirectories()
{
const string MESSAGE = "WASM IS VERY COOL";
using (var file = new TempFile())
{
using var file = new TempFile();
var wasi = new WasiBuilder()
.WithPreopenedDirectory(Path.GetDirectoryName(file.Path), "/foo")
.Build(Fixture.Module.Store);
@@ -246,5 +243,4 @@ namespace Wasmtime.Tests
Assert.Equal(MESSAGE, File.ReadAllText(file.Path));
}
}
}
}