]> git.sesse.net Git - vlc/commitdiff
Safe handle class for LibVLC heap allocation
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 21 Feb 2009 14:42:09 +0000 (16:42 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Sat, 21 Feb 2009 16:15:09 +0000 (18:15 +0200)
bindings/cil/src/libvlc.cs
bindings/cil/src/ustring.cs

index 6087453be30f470e9cfb01c76c82984d77f754e6..1728cc95bee44004b8558fa02327499edff651c7 100644 (file)
@@ -98,7 +98,7 @@ namespace VideoLAN.LibVLC
 
         [DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_mrl")]
         public static extern
-        void MediaGetMRL (MediaHandle media);
+        MemoryHandle MediaGetMRL (MediaHandle media, NativeException ex);
 
         [DllImport ("libvlc.dll", EntryPoint="libvlc_media_duplicate")]
         public static extern
index a605b8fb7a7ec0a226919e002582ff8765b56561..d6ad65a208b18ce4c881463a55c2bdd7cb117c2c 100644 (file)
@@ -33,7 +33,7 @@ namespace VideoLAN.LibVLC
      * arrays (as used by the native LibVLC) and managed strings.
      */
     [StructLayout (LayoutKind.Sequential)]
-    public struct U8String
+    internal struct U8String
     {
         public byte[] mb_str; /**< nul-terminated UTF-8 bytes array */
 
@@ -91,4 +91,34 @@ namespace VideoLAN.LibVLC
             return new U8String (ptr).ToString ();
         }
     };
+
+    /**
+     * @brief MemoryHandle: heap allocation by the C run-time
+     * @ingroup Internals
+     */
+    internal sealed class MemoryHandle : NonNullHandle
+    {
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_free")]
+        private static extern void Free (IntPtr ptr);
+
+        /**
+         * NonNullHandle.Destroy
+         */
+        protected override void Destroy ()
+        {
+            Free (handle);
+        }
+
+        public override string ToString ()
+        {
+            return U8String.FromNative (handle);
+        }
+
+        public string Transform ()
+        {
+            string value = ToString ();
+            Close ();
+            return value;
+        }
+    };
 };