[corlib] Use HGlobalUnmanagedMemoryStream directly from MonoTouch timezoneinfo
authorMarek Safar <marek.safar@gmail.com>
Tue, 24 Feb 2015 19:15:27 +0000 (20:15 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 24 Feb 2015 19:15:56 +0000 (20:15 +0100)
mcs/class/corlib/System.IO/HGlobalUnmanagedMemoryStream.cs [new file with mode: 0644]
mcs/class/corlib/System.Resources/ResourceReader.cs
mcs/class/corlib/System/TimeZoneInfo.MonoTouch.cs
mcs/class/corlib/corlib.dll.sources

diff --git a/mcs/class/corlib/System.IO/HGlobalUnmanagedMemoryStream.cs b/mcs/class/corlib/System.IO/HGlobalUnmanagedMemoryStream.cs
new file mode 100644 (file)
index 0000000..476e187
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// HGlobalUnmanagedMemoryStream.cs
+//
+// Authors:
+//     Marek Safar  <marek.safar@gmail.com>
+//
+// Copyright (C) 2015 Xamarin Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Runtime.InteropServices;
+
+namespace System.IO
+{
+       unsafe class HGlobalUnmanagedMemoryStream : UnmanagedMemoryStream
+       {
+               IntPtr ptr;
+
+               public HGlobalUnmanagedMemoryStream (byte* pointer, long length, IntPtr ptr)
+                       : base (pointer, length, length, FileAccess.ReadWrite)
+               {
+                       this.ptr = ptr;
+               }
+
+               protected override void Dispose (bool disposing)
+               {
+                       if (_isOpen) {
+                               Marshal.FreeHGlobal (ptr);
+                       }
+
+                       base.Dispose (disposing);
+               }
+       }       
+}
\ No newline at end of file
index 3bc3b47e51086571142d644c9860d830c59c4682..87fffa9c6091bddab661f6354b8b32474b9ff170 100644 (file)
@@ -97,26 +97,6 @@ namespace System.Resources
                        }
                }
 
-               unsafe class HGlobalUnmanagedMemoryStream : UnmanagedMemoryStream
-               {
-                       IntPtr ptr;
-
-                       public HGlobalUnmanagedMemoryStream (byte* pointer, long length, IntPtr ptr)
-                               : base (pointer, length, length, FileAccess.ReadWrite)
-                       {
-                               this.ptr = ptr;
-                       }
-
-                       protected override void Dispose (bool disposing)
-                       {
-                               if (_isOpen) {
-                                       Marshal.FreeHGlobal (ptr);
-                               }
-
-                               base.Dispose (disposing);
-                       }
-               }
-               
                BinaryReader reader;
                object readerLock = new object ();
                IFormatter formatter;
index 626136bb45ab36f27c25b5aa0e3eed11a4e92ac0..fa727cce0c6da443dedf1a24efc0693ee3219747 100644 (file)
@@ -75,11 +75,7 @@ namespace System {
                        }
 
                        unsafe {
-                               var s = new UnmanagedMemoryStream ((byte*) data, size);
-                               s.Closed += delegate {
-                                       Marshal.FreeHGlobal (data);
-                               };
-                               return s;
+                               return new HGlobalUnmanagedMemoryStream ((byte*) data, size, data);
                        }
                }
        }
index 96b7ba3bea8546c4042704d33879cdf177611096..6796a1f9ad685d37a8b7502c3d305b8bd6d0e7cc 100644 (file)
@@ -348,6 +348,7 @@ System.IO/FileShare.cs
 System.IO/FileStream.cs
 System.IO/FileStreamAsyncResult.cs
 System.IO/FileSystemInfo.cs
+System.IO/HGlobalUnmanagedMemoryStream.cs
 System.IO/IOException.cs
 System.IO/LogcatTextWriter.cs
 System.IO/MonoIO.cs