Revert "[2018-06] [System]: `MonoTlsStream` is now `IDisposable` and cleans up on...
[mono-project.git] / mono / tests / marshal3.cs
blob7f984b60b39603da30e82a6f8c030f1b679a90c8
1 using System;
2 using System.Runtime.InteropServices;
4 public class Test {
7 [StructLayout (LayoutKind.Sequential)]
8 public struct BlittableStruct {
9 public int a;
10 public int b;
13 public unsafe static int Main () {
14 BlittableStruct ss = new BlittableStruct ();
15 int size = Marshal.SizeOf (typeof (BlittableStruct));
17 Console.WriteLine ("BlittableStruct:" + size);
18 if (size != 8)
19 return 1;
21 IntPtr p = Marshal.AllocHGlobal (size);
22 ss.a = 123;
23 ss.b = 124;
25 Marshal.StructureToPtr (ss, p, false);
26 Type t = ss.GetType ();
28 if (Marshal.ReadInt32 (p, 0) != 123)
29 return 1;
30 if (Marshal.ReadInt32 (p, 4) != 124)
31 return 1;
33 BlittableStruct cp = (BlittableStruct)Marshal.PtrToStructure (p, ss.GetType ());
35 if (cp.a != 123)
36 return 2;
38 if (cp.b != 124)
39 return 2;
41 return 0;