glib: Use Marshaller methods in Argv for g_malloc and g_free

This commit is contained in:
Bertrand Lorentz 2013-11-17 16:27:39 +01:00
parent ced6f5e677
commit 2d48906523

View File

@ -30,18 +30,10 @@ namespace GLib {
IntPtr handle; IntPtr handle;
bool add_progname = false; bool add_progname = false;
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_malloc(IntPtr size);
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_free (IntPtr mem);
~Argv () ~Argv ()
{ {
foreach (IntPtr arg in arg_ptrs) Marshaller.Free (arg_ptrs);
g_free (arg); Marshaller.Free (handle);
g_free (handle);
} }
public Argv (string[] args) : this (args, false) {} public Argv (string[] args) : this (args, false) {}
@ -61,7 +53,7 @@ namespace GLib {
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
arg_ptrs [i] = Marshaller.StringToPtrGStrdup (args[i]); arg_ptrs [i] = Marshaller.StringToPtrGStrdup (args[i]);
handle = g_malloc (new IntPtr (IntPtr.Size * args.Length)); handle = Marshaller.Malloc ((ulong)(IntPtr.Size * args.Length));
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]); Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]);