Skip to content

Commit 70e99e3

Browse files
committed
Move test
1 parent 4a6c5ba commit 70e99e3

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/tests/Interop/MarshalAPI/FunctionPointer/GenericFunctionPointer.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ static BlittableGeneric<string> UnmanagedExportedFunctionBlittableGenericString(
2929
return new() { X = Convert.ToInt32(arg) };
3030
}
3131

32+
[UnmanagedCallersOnly]
33+
static void UnmanagedExportedFunctionRefInt(ref int val, float arg)
34+
{
35+
val = Convert.ToInt32(arg);
36+
}
37+
3238
class GenericCaller<T>
3339
{
3440
internal static unsafe T GenericCalli<U>(void* fnptr, U arg)
@@ -40,6 +46,11 @@ internal static unsafe BlittableGeneric<T> WrappedGenericCalli<U>(void* fnptr, U
4046
{
4147
return ((delegate* unmanaged<U, BlittableGeneric<T>>)fnptr)(arg);
4248
}
49+
50+
internal static unsafe void NonGenericCalli<T>(void* fnptr, ref int val, float arg)
51+
{
52+
((delegate* unmanaged<float, ref int, void>)fnptr)(ref val, arg);
53+
}
4354
}
4455

4556
struct BlittableGeneric<T>
@@ -81,6 +92,14 @@ public static void RunGenericFunctionPointerTest(float inVal)
8192
outVar = GenericCaller<string>.WrappedGenericCalli((delegate* unmanaged<float, BlittableGeneric<string>>)&UnmanagedExportedFunctionBlittableGenericString, inVal).X;
8293
}
8394
Assert.Equal(expectedValue, outVar);
95+
96+
outVar = 0;
97+
Console.WriteLine("Testing non-GenericCalli with non-blittable argument in a generic caller");
98+
unsafe
99+
{
100+
GenericCaller<string>.NonGenericCalli<string>((delegate* unmanaged<float, ref int, void>)&UnmanagedExportedFunctionRefInt, ref outVar, inVal);
101+
}
102+
Assert.Equal(expectedValue, outVar);
84103
}
85104

86105
[ConditionalFact(nameof(CanRunInvalidGenericFunctionPointerTest))]

src/tests/nativeaot/SmokeTests/PInvoke/PInvoke.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ public static int Main()
346346
TestForwardDelegateWithUnmanagedCallersOnly();
347347
TestDecimal();
348348
TestDifferentModopts();
349-
TestGenericCaller<int>();
350-
TestGenericCaller<string>();
351349
TestFunctionPointers();
352350

353351
return 100;
@@ -1170,17 +1168,6 @@ public static unsafe void TestDifferentModopts()
11701168
refStdcallSuppressTransition(ref storage, 56);
11711169
}
11721170
}
1173-
1174-
public static unsafe void TestGenericCaller<T>()
1175-
{
1176-
byte storage;
1177-
1178-
delegate* unmanaged<byte*, byte, void> unmanagedMethod = &UnmanagedMethod;
1179-
1180-
var outUnmanagedMethod = (delegate* unmanaged<out byte, byte, void>)unmanagedMethod;
1181-
outUnmanagedMethod(out storage, 12);
1182-
ThrowIfNotEquals(storage, 12, "Out unmanaged call failed.");
1183-
}
11841171
}
11851172

11861173
public class SafeMemoryHandle : SafeHandle //SafeHandle subclass

0 commit comments

Comments
 (0)