From 0681cc0f8310d7a1486ef4eb7012af247ef81ad8 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sun, 24 Mar 2013 09:39:46 +0100 Subject: [PATCH] Fix the build. --- .../System.Runtime.InteropServices/Marshal.cs | 40 +++++++++---------- mcs/class/corlib/System/IntPtr.cs | 6 +++ .../MarshalTest.cs | 4 ++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs b/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs index cdb5ab11737..240d1139d1c 100644 --- a/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs +++ b/mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs @@ -712,7 +712,7 @@ namespace System.Runtime.InteropServices public static byte ReadByte (IntPtr ptr, int ofs) { unsafe { - return *(byte*)(ptr + ofs); + return *((byte*)ptr + ofs); } } @@ -741,14 +741,14 @@ namespace System.Runtime.InteropServices } public static short ReadInt16 (IntPtr ptr, int ofs) { - if ((ptr + ofs).ToInt32 () % 2 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 2 == 0) { unsafe { - return *(short*)(ptr + ofs); + return *(short*)(IntPtr.Add (ptr, ofs)); } } else { unsafe { short s; - String.memcpy ((byte*)&s, (byte*)(ptr + ofs), 2); + String.memcpy ((byte*)&s, (byte*)(IntPtr.Add (ptr, ofs)), 2); return s; } } @@ -779,14 +779,14 @@ namespace System.Runtime.InteropServices [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)] public static int ReadInt32 (IntPtr ptr, int ofs) { - if ((ptr + ofs).ToInt32 () % 4 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 4 == 0) { unsafe { - return *(int*)(ptr + ofs); + return *(int*)(IntPtr.Add (ptr, ofs)); } } else { unsafe { int s; - String.memcpy ((byte*)&s, (byte*)(ptr + ofs), 4); + String.memcpy ((byte*)&s, (byte*)(IntPtr.Add (ptr, ofs)), 4); return s; } } @@ -819,14 +819,14 @@ namespace System.Runtime.InteropServices } public static long ReadInt64 (IntPtr ptr, int ofs) { - if ((ptr + ofs).ToInt32 () % 8 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 8 == 0) { unsafe { - return *(long*)(ptr + ofs); + return *(long*)(IntPtr.Add (ptr, ofs)); } } else { unsafe { long s; - String.memcpy ((byte*)&s, (byte*)(ptr + ofs), 8); + String.memcpy ((byte*)&s, (byte*)(IntPtr.Add (ptr, ofs)), 8); return s; } } @@ -1092,7 +1092,7 @@ namespace System.Runtime.InteropServices public static void WriteByte (IntPtr ptr, int ofs, byte val) { unsafe { - *(byte*)(ptr + ofs) = val; + *(byte*)(IntPtr.Add (ptr, ofs)) = val; } } @@ -1117,13 +1117,13 @@ namespace System.Runtime.InteropServices } public static void WriteInt16 (IntPtr ptr, int ofs, short val) { - if ((ptr + ofs).ToInt32 () % 2 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 2 == 0) { unsafe { - *(short*)(ptr + ofs) = val; + *(short*)(IntPtr.Add (ptr, ofs)) = val; } } else { unsafe { - String.memcpy ((byte*)(ptr + ofs), (byte*)&val, 2); + String.memcpy ((byte*)(IntPtr.Add (ptr, ofs)), (byte*)&val, 2); } } } @@ -1164,13 +1164,13 @@ namespace System.Runtime.InteropServices } public static void WriteInt32 (IntPtr ptr, int ofs, int val) { - if ((ptr + ofs).ToInt32 () % 4 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 4 == 0) { unsafe { - *(int*)(ptr + ofs) = val; + *(int*)(IntPtr.Add (ptr, ofs)) = val; } } else { unsafe { - String.memcpy ((byte*)(ptr + ofs), (byte*)&val, 4); + String.memcpy ((byte*)(IntPtr.Add (ptr, ofs)), (byte*)&val, 4); } } } @@ -1197,13 +1197,13 @@ namespace System.Runtime.InteropServices } public static void WriteInt64 (IntPtr ptr, int ofs, long val) { - if ((ptr + ofs).ToInt32 () % 8 == 0) { + if ((IntPtr.Add (ptr, ofs)).ToInt32 () % 8 == 0) { unsafe { - *(long*)(ptr + ofs) = val; + *(long*)(IntPtr.Add (ptr, ofs)) = val; } } else { unsafe { - String.memcpy ((byte*)(ptr + ofs), (byte*)&val, 8); + String.memcpy ((byte*)(IntPtr.Add (ptr, ofs)), (byte*)&val, 8); } } } diff --git a/mcs/class/corlib/System/IntPtr.cs b/mcs/class/corlib/System/IntPtr.cs index 1b36f47d372..e8ca505de18 100644 --- a/mcs/class/corlib/System/IntPtr.cs +++ b/mcs/class/corlib/System/IntPtr.cs @@ -224,6 +224,12 @@ namespace System { return (IntPtr) (unchecked (((byte *) pointer) - offset)); } +#else + /* Needed by Marshal.cs */ + internal static IntPtr Add (IntPtr pointer, int offset) + { + return (IntPtr) (unchecked (((byte *) pointer) + offset)); + } #endif } } diff --git a/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs b/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs index 8731bde74ea..1a904931d01 100644 --- a/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs +++ b/mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs @@ -284,7 +284,9 @@ namespace MonoTests.System.Runtime.InteropServices Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr)); Assert.AreEqual (0x1234, Marshal.ReadInt16 (ptr, 0)); Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 2)); +#if NET_4_5 Assert.AreEqual (0x4567, Marshal.ReadInt16 ((ptr + 5))); +#endif Assert.AreEqual (0x4567, Marshal.ReadInt16 (ptr, 5)); } finally { Marshal.FreeHGlobal (ptr); @@ -302,7 +304,9 @@ namespace MonoTests.System.Runtime.InteropServices Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr)); Assert.AreEqual (0x12345678, Marshal.ReadInt32 (ptr, 0)); Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 4)); +#if NET_4_5 Assert.AreEqual (0x77654321, Marshal.ReadInt32 ((ptr + 10))); +#endif Assert.AreEqual (0x77654321, Marshal.ReadInt32 (ptr, 10)); } finally { Marshal.FreeHGlobal (ptr); -- 2.25.1