Skip to content

Commit

Permalink
Fix CallTargetNativeTest so that it compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Jun 17, 2024
1 parent 1930d1d commit 9e2ea7a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
<ProjectReference Include="..\..\..\..\src\Datadog.Trace\Datadog.Trace.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static CallTargetState OnMethodBegin<TTarget>(TTarget instance, ref strin
ref var readOnlySpanValue = ref arg02.DangerousGetReadOnlySpan<char>(out success);
if (success)
{
readOnlySpanValue = "World";
readOnlySpanValue = "World".AsSpan();
}

ref var spanValue = ref arg03.DangerousGetSpan<char>(out success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static CallTargetState OnMethodBegin<TTarget, TArg1>(TTarget instance, re
ref var readOnlySpanValue = ref callTargetRefStruct.DangerousGetReadOnlySpan<char>(out success);
if (success)
{
readOnlySpanValue = "Hello World";
readOnlySpanValue = "Hello World".AsSpan();
return returnValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static CallTargetState OnMethodBegin<TTarget, TArg1, TArg2>(TTarget insta
ref var readOnlySpanValue = ref callTargetRefStruct.DangerousGetReadOnlySpan<char>(out success);
if (success)
{
readOnlySpanValue = "Hello";
readOnlySpanValue = "Hello".AsSpan();
goto secondArgument;
}

Expand All @@ -41,7 +41,7 @@ public static CallTargetState OnMethodBegin<TTarget, TArg1, TArg2>(TTarget insta
ref var readOnlySpanValue = ref callTargetRefStruct2.DangerousGetReadOnlySpan<char>(out success);
if (success)
{
readOnlySpanValue = "World";
readOnlySpanValue = "World".AsSpan();
goto returnValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ private static void WithRefStructArguments()
var wRefStructArg = new WithRefStructArguments();

Console.WriteLine($"{typeof(WithRefArguments).FullName} | ReadOnlySpan<char> methods");
RunMethod(() => wRefStructArg.VoidReadOnlySpanMethod("BadParam"));
RunMethod(() => wRefStructArg.VoidReadOnlySpanMethod("BadParam".AsSpan()));
RunMethod(() =>
{
var arg1 = "BadParam".AsSpan();
wRefStructArg.VoidReadOnlySpanMethod(ref arg1);
if (arg1 != "Hello World") throw new Exception("Error modifying arg1 value.");
if (!arg1.SequenceEqual("Hello World".AsSpan())) throw new Exception("Error modifying arg1 value.");
});
RunMethod(() =>
{
Expand All @@ -27,15 +27,18 @@ private static void WithRefStructArguments()
var arg1 = "BadParam".AsSpan();
var arg2 = "BadParam".AsSpan();
wRefStructArg.Void2ReadOnlySpanMethod(ref arg1, ref arg2);
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg1.SequenceEqual("Hello".AsSpan())) throw new Exception("Error modifying arg1 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
});
RunMethod(() =>
{
var arg1 = "BadParam".AsSpan();
var arg2 = "BadParam".AsSpan();
wRefStructArg.Void2ReadOnlySpanMethod(arg1, ref arg2);
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan()))
{
throw new Exception("Error modifying arg2 value.");
}
});

Console.WriteLine($"{typeof(WithRefArguments).FullName} | Span<char> methods");
Expand Down Expand Up @@ -118,7 +121,7 @@ private static void WithRefStructArguments()
var arg4 = new ReadOnlyRefStruct("BadParam");
wRefStructArg.VoidMixedMethod(ref arg1, ref arg2, ref arg3, ref arg4);
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
if (arg3.ToString() != "Hello") throw new Exception("Error modifying arg3 value.");
if (arg4.Value != "World") throw new Exception("Error modifying arg4 value.");
});
Expand All @@ -129,7 +132,7 @@ private static void WithRefStructArguments()
var arg3 = new Span<char>(['B', 'a', 'd', 'P', 'a', 'r', 'a', 'm']);
var arg4 = new ReadOnlyRefStruct("BadParam");
wRefStructArg.VoidMixedMethod(arg1, ref arg2, arg3, ref arg4);
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
if (arg4.Value != "World") throw new Exception("Error modifying arg4 value.");
});
}
Expand All @@ -141,30 +144,30 @@ internal class WithRefStructArguments

public void VoidReadOnlySpanMethod(ReadOnlySpan<char> arg1)
{
if (arg1 != "Hello World") throw new Exception("Error modifying arg1 value.");
if (!arg1.SequenceEqual("Hello World".AsSpan())) throw new Exception("Error modifying arg1 value.");
}

public void VoidReadOnlySpanMethod(ref ReadOnlySpan<char> arg1)
{
if (arg1 != "Hello World") throw new Exception("Error modifying arg1 value.");
if (!arg1.SequenceEqual("Hello World".AsSpan())) throw new Exception("Error modifying arg1 value.");
}

public void Void2ReadOnlySpanMethod(ReadOnlySpan<char> arg1, ReadOnlySpan<char> arg2)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg1.SequenceEqual("Hello".AsSpan())) throw new Exception("Error modifying arg1 value.");
if (arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
}

public void Void2ReadOnlySpanMethod(ref ReadOnlySpan<char> arg1, ref ReadOnlySpan<char> arg2)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg1.SequenceEqual("Hello".AsSpan())) throw new Exception("Error modifying arg1 value.");
if (arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
}

public void Void2ReadOnlySpanMethod(ReadOnlySpan<char> arg1, ref ReadOnlySpan<char> arg2)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg1.SequenceEqual("Hello".AsSpan())) throw new Exception("Error modifying arg1 value.");
if (arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
}

// *** Span<char> arguments ***
Expand Down Expand Up @@ -232,23 +235,23 @@ public void Void2ReadOnlyRefStructMethod(ReadOnlyRefStruct arg1, ref ReadOnlyRef
public void VoidMixedMethod(string arg1, ReadOnlySpan<char> arg2, Span<char> arg3, ReadOnlyRefStruct arg4)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
if (arg3.ToString() != "Hello") throw new Exception("Error modifying arg3 value.");
if (arg4.Value != "World") throw new Exception("Error modifying arg4 value.");
}

public void VoidMixedMethod(ref string arg1, ref ReadOnlySpan<char> arg2, ref Span<char> arg3, ref ReadOnlyRefStruct arg4)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
if (arg3.ToString() != "Hello") throw new Exception("Error modifying arg3 value.");
if (arg4.Value != "World") throw new Exception("Error modifying arg4 value.");
}

public void VoidMixedMethod(string arg1, ref ReadOnlySpan<char> arg2, Span<char> arg3, ref ReadOnlyRefStruct arg4)
{
if (arg1 != "Hello") throw new Exception("Error modifying arg1 value.");
if (arg2 != "World") throw new Exception("Error modifying arg2 value.");
if (!arg2.SequenceEqual("World".AsSpan())) throw new Exception("Error modifying arg2 value.");
if (arg3.ToString() != "Hello") throw new Exception("Error modifying arg3 value.");
if (arg4.Value != "World") throw new Exception("Error modifying arg4 value.");
}
Expand Down

0 comments on commit 9e2ea7a

Please sign in to comment.