Fix the build.
authorZoltan Varga <vargaz@gmail.com>
Sun, 24 Mar 2013 08:39:46 +0000 (09:39 +0100)
committerZoltan Varga <vargaz@gmail.com>
Sun, 24 Mar 2013 08:39:46 +0000 (09:39 +0100)
mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
mcs/class/corlib/System/IntPtr.cs
mcs/class/corlib/Test/System.Runtime.InteropServices/MarshalTest.cs

index cdb5ab11737f49db2e261e3bee91fb1bc90eb7e1..240d1139d1c1b3e828cb255d0ef1379345a75d4b 100644 (file)
@@ -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);
                                }
                        }
                }
index 1b36f47d372556da378adc0b7f3946659d67d0d6..e8ca505de18e06bdaa06e9fad7c63672b0a9d95c 100644 (file)
@@ -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
        }
 }
index 8731bde74ea1e026359dfac8806a83cfaf1264a3..1a904931d01b694b2ee672353ac5917034b58b96 100644 (file)
@@ -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);