From 32d10bd319c4fac7a5c0b7e97dce5cc7cface0dd Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 17 Nov 2013 16:20:02 +0100 Subject: [PATCH] Use GLib.Marshaller.Free instead of calling g_free directly Using the GLib.Marshaller.Free method means we don't need to have the g_free function definition duplicated all over the place. --- gdk/Keymap.cs | 9 +++------ gdk/Pixbuf.cs | 5 +---- glib/ListBase.cs | 5 +---- glib/PtrArray.cs | 5 +---- gtk/IconSet.cs | 5 +---- gtk/SelectionData.cs | 5 +---- pango/Context.cs | 5 +---- pango/Coverage.cs | 5 +---- pango/FontFamily.cs | 5 +---- pango/FontMap.cs | 5 +---- pango/Layout.cs | 5 +---- pango/LayoutLine.cs | 2 +- pango/TabArray.cs | 7 ++----- 13 files changed, 16 insertions(+), 52 deletions(-) diff --git a/gdk/Keymap.cs b/gdk/Keymap.cs index 75e5daec4..d8b316c65 100644 --- a/gdk/Keymap.cs +++ b/gdk/Keymap.cs @@ -26,9 +26,6 @@ namespace Gdk { public partial class Keymap { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free(IntPtr ptr); - [DllImport ("libgdk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern bool gdk_keymap_get_entries_for_keycode(IntPtr raw, uint hardware_keycode, out IntPtr keys, out IntPtr keyvals, out int n_entries); @@ -46,8 +43,8 @@ namespace Gdk { keyvals [i] = (uint) tmp [i]; keys [i] = KeymapKey.New (ptr); } - g_free (key_ptr); - g_free (keyval_ptr); + GLib.Marshaller.Free (key_ptr); + GLib.Marshaller.Free (keyval_ptr); } else { keys = new KeymapKey [0]; keyvals = new uint [0]; @@ -67,7 +64,7 @@ namespace Gdk { IntPtr ptr = new IntPtr ((long) key_ptr + i * Marshal.SizeOf (typeof (KeymapKey))); result [i] = KeymapKey.New (ptr); } - g_free (key_ptr); + GLib.Marshaller.Free (key_ptr); return result; } else return new KeymapKey [0]; diff --git a/gdk/Pixbuf.cs b/gdk/Pixbuf.cs index 7f5ed32d5..5e9cce1a9 100644 --- a/gdk/Pixbuf.cs +++ b/gdk/Pixbuf.cs @@ -235,9 +235,6 @@ namespace Gdk { return ret; } - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libgdk_pixbuf-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern unsafe bool gdk_pixbuf_save_to_bufferv (IntPtr raw, out IntPtr buffer, out IntPtr buffer_size, IntPtr type, IntPtr[] option_keys, IntPtr[] option_values, out IntPtr error); @@ -282,7 +279,7 @@ namespace Gdk { throw new GLib.GException (error); byte[] result = new byte [(int)buffer_size]; Marshal.Copy (buffer, result, 0, (int) buffer_size); - g_free (buffer); + GLib.Marshaller.Free (buffer); return result; } diff --git a/glib/ListBase.cs b/glib/ListBase.cs index 28b3f2b32..15816a1de 100644 --- a/glib/ListBase.cs +++ b/glib/ListBase.cs @@ -190,9 +190,6 @@ namespace GLib { return fullname + "Adapter"; } - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr item); - [DllImport (Global.GObjectNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern void g_object_unref (IntPtr item); @@ -205,7 +202,7 @@ namespace GLib { } else if (typeof (GLib.IWrapper).IsAssignableFrom (element_type)) { g_object_unref (NthData (i)); } else { - g_free (NthData (i)); + Marshaller.Free (NthData (i)); } } } diff --git a/glib/PtrArray.cs b/glib/PtrArray.cs index 09913380a..d6a433660 100644 --- a/glib/PtrArray.cs +++ b/glib/PtrArray.cs @@ -83,9 +83,6 @@ namespace GLib { [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern void g_object_unref (IntPtr item); - [DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr item); - void Dispose (bool disposing) { if (Handle == IntPtr.Zero) @@ -99,7 +96,7 @@ namespace GLib { else if (typeof (GLib.Opaque).IsAssignableFrom (element_type)) GLib.Opaque.GetOpaque (NthData (i), element_type, true).Dispose (); else - g_free (NthData (i)); + Marshaller.Free (NthData (i)); } if (managed) diff --git a/gtk/IconSet.cs b/gtk/IconSet.cs index 8eda4843a..09a6719ce 100644 --- a/gtk/IconSet.cs +++ b/gtk/IconSet.cs @@ -24,9 +24,6 @@ namespace Gtk { unsafe static extern void gtk_icon_set_get_sizes ( IntPtr raw, out int *pointer_to_enum, out int n_sizes); - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - unsafe static extern void g_free (int *mem); - /// Sizes Property /// To be completed public Gtk.IconSize [] Sizes { @@ -42,7 +39,7 @@ namespace Gtk { for (int i = 0; i < length; i++) retval [i] = (Gtk.IconSize) pointer_to_enum [i]; - g_free (pointer_to_enum); + GLib.Marshaller.Free ((IntPtr)pointer_to_enum); } return retval; diff --git a/gtk/SelectionData.cs b/gtk/SelectionData.cs index f5693deaf..49e8cd4a5 100644 --- a/gtk/SelectionData.cs +++ b/gtk/SelectionData.cs @@ -61,9 +61,6 @@ namespace Gtk { Set(type, format, data, data.Length); } - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr ptr); - [DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern bool gtk_selection_data_get_targets(IntPtr raw, out IntPtr targets, out int n_atoms); @@ -77,7 +74,7 @@ namespace Gtk { IntPtr atom = Marshal.ReadIntPtr (target_ptr, count * IntPtr.Size); result [i] = new Gdk.Atom (atom); } - g_free (target_ptr); + GLib.Marshaller.Free (target_ptr); return result; } else return new Gdk.Atom [0]; diff --git a/pango/Context.cs b/pango/Context.cs index a67778e09..5a978d64f 100644 --- a/pango/Context.cs +++ b/pango/Context.cs @@ -25,9 +25,6 @@ namespace Pango { public partial class Context { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_context_list_families(IntPtr raw, out IntPtr families, out int n_families); @@ -44,7 +41,7 @@ namespace Pango { result [i] = GLib.Object.GetObject (fam_ptr) as FontFamily; } - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); return result; } } diff --git a/pango/Coverage.cs b/pango/Coverage.cs index 3ed728485..e9008e932 100644 --- a/pango/Coverage.cs +++ b/pango/Coverage.cs @@ -25,9 +25,6 @@ namespace Pango { public partial class Coverage { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_coverage_to_bytes (IntPtr raw, out IntPtr bytes, out int n_bytes); @@ -38,7 +35,7 @@ namespace Pango { pango_coverage_to_bytes (Handle, out array_ptr, out count); bytes = new byte [count]; Marshal.Copy (array_ptr, bytes, 0, count); - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); } } } diff --git a/pango/FontFamily.cs b/pango/FontFamily.cs index ebd71f3bb..77fd79ba3 100644 --- a/pango/FontFamily.cs +++ b/pango/FontFamily.cs @@ -25,9 +25,6 @@ namespace Pango { public partial class FontFamily { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_font_family_list_faces(IntPtr raw, out IntPtr faces, out int n_faces); @@ -44,7 +41,7 @@ namespace Pango { result [i] = GLib.Object.GetObject (fam_ptr) as FontFace; } - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); return result; } } diff --git a/pango/FontMap.cs b/pango/FontMap.cs index cee7053f4..311ccfd74 100644 --- a/pango/FontMap.cs +++ b/pango/FontMap.cs @@ -25,9 +25,6 @@ namespace Pango { public partial class FontMap { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_font_map_list_families(IntPtr raw, out IntPtr families, out int n_families); @@ -44,7 +41,7 @@ namespace Pango { result [i] = GLib.Object.GetObject (fam_ptr) as FontFamily; } - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); return result; } } diff --git a/pango/Layout.cs b/pango/Layout.cs index 34c2a682e..abbcc0628 100644 --- a/pango/Layout.cs +++ b/pango/Layout.cs @@ -55,9 +55,6 @@ namespace Pango { accel_char = GLib.Marshaller.GUnicharToChar (ucs4_accel_char); } - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_layout_get_log_attrs (IntPtr raw, out IntPtr attrs, out int n_attrs); @@ -74,7 +71,7 @@ namespace Pango { result [i] = LogAttr.New (fam_ptr); } - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); return result; } } diff --git a/pango/LayoutLine.cs b/pango/LayoutLine.cs index 39e826dc1..89c2e551c 100644 --- a/pango/LayoutLine.cs +++ b/pango/LayoutLine.cs @@ -46,7 +46,7 @@ namespace Pango { } Marshal.Copy (array_ptr, ranges, 0, count); - g_free (array_ptr); + GLib.Marshaller.Free (array_ptr); #endif } } diff --git a/pango/TabArray.cs b/pango/TabArray.cs index 9892edc4f..069f6047d 100644 --- a/pango/TabArray.cs +++ b/pango/TabArray.cs @@ -25,9 +25,6 @@ namespace Pango { public partial class TabArray { - [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_free (IntPtr raw); - [DllImport ("libpango-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void pango_tab_array_get_tabs (IntPtr raw, out IntPtr alignments, out IntPtr locations); @@ -45,8 +42,8 @@ namespace Pango { Marshal.Copy (align_ptr, tmp, 0, sz); for (int i = 0; i < sz; i++) alignments [i] = (TabAlign) tmp [i]; - g_free (align_ptr); - g_free (loc_ptr); + GLib.Marshaller.Free (align_ptr); + GLib.Marshaller.Free (loc_ptr); } } }