-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.0] [Mono] Fix offset calculation for nested struct, when p…
…invoke is enabled (#91417) * Fix offset calculation for nested struct * Add a test for nested struct with pinvoke * Move and update test with real c++ implementation * Exclude newly added test from wasm * Disable interop tests on android and apple devices --------- Co-authored-by: Fan Yang <yangfan@microsoft.com>
- Loading branch information
1 parent
399f37c
commit cd8b2cb
Showing
7 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/tests/Interop/StructMarshalling/PInvoke/GameControllerButtonBind.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
public unsafe partial struct GameControllerButtonBind | ||
{ | ||
public GameControllerButtonBind | ||
( | ||
GameControllerBindType? bindType = null, | ||
GameControllerButtonBindValue? value = null | ||
) : this() | ||
{ | ||
if (bindType is not null) | ||
{ | ||
BindType = bindType.Value; | ||
} | ||
|
||
if (value is not null) | ||
{ | ||
Value = value.Value; | ||
} | ||
} | ||
|
||
public GameControllerBindType BindType; | ||
|
||
public GameControllerButtonBindValue Value; | ||
} | ||
|
||
public enum GameControllerBindType : int | ||
{ | ||
ControllerBindtypeNone = 0x0, | ||
ControllerBindtypeButton = 0x1, | ||
ControllerBindtypeAxis = 0x2, | ||
ControllerBindtypeHat = 0x3, | ||
None = 0x0, | ||
Button = 0x1, | ||
Axis = 0x2, | ||
Hat = 0x3, | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public unsafe partial struct GameControllerButtonBindValue | ||
{ | ||
[FieldOffset(0)] | ||
public int Button; | ||
|
||
[FieldOffset(0)] | ||
public int Axis; | ||
|
||
[FieldOffset(0)] | ||
public GameControllerButtonBindValueHat Hat; | ||
} | ||
|
||
public unsafe partial struct GameControllerButtonBindValueHat | ||
{ | ||
public int Hat; | ||
|
||
public int HatMask; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/tests/Interop/StructMarshalling/PInvoke/NestedStruct.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
|
||
public class Managed | ||
{ | ||
[DllImport("MarshalStructAsParam")] | ||
static extern GameControllerBindType getBindType (GameControllerButtonBind button); | ||
|
||
public static int Main() | ||
{ | ||
GameControllerButtonBind button = new GameControllerButtonBind(GameControllerBindType.ControllerBindtypeAxis, null); | ||
if (getBindType(button) == GameControllerBindType.ControllerBindtypeAxis) | ||
{ | ||
Console.WriteLine("\nTEST PASSED!"); | ||
return 100; | ||
} | ||
else | ||
{ | ||
Console.WriteLine("\nTEST FAILED!"); | ||
return 1; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/tests/Interop/StructMarshalling/PInvoke/NestedStruct.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="NestedStruct.cs" /> | ||
<Compile Include="GameControllerButtonBind.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
<CMakeProjectReference Include="CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters