GNOME Bugzilla – Bug 383557
Use g_slice for gtk_border_copy/free
Last modified: 2006-12-24 09:55:24 UTC
/** * gtk_border_copy: * @border_: a #GtkBorder. * @returns: a copy of @border_. * * Copies a #GtkBorder structure. **/ GtkBorder * gtk_border_copy (const GtkBorder *border) { return (GtkBorder *)g_memdup (border, sizeof (GtkBorder)); } /** * gtk_border_free: * @border_: a #GtkBorder. * * Frees a #GtkBorder structure. **/ void gtk_border_free (GtkBorder *border) { g_free (border); } Looks like can use g_slice.
Sounds fine. Do you have a patch.
Created attachment 78850 [details] [review] the patch The patch makes a tiny semantic difference here: that the free function warns if passed NULL. This is the traditional way that copy/free pairs are done in pango and gtk+. However, in Pango I've started moving to not warning when NULL is passed to copy/free pairs (on an on-demand basis). That sometimes makes life a lot easier. For example, pango_context_get_matrix() may return NULL if no matrix is set. It makes life a lot easier if you could just pass whatever pango_context_get_matrix() returns to pango_matrix_copy(), and later on pass whatever that returns (that can be NULL) to pango_matrix_free()...
Why do you want to change gtk_border_free() to warn on NULL ? I don't think we should change that now, gtk_border_free() is supported API. Other than that, the patch looks fine.
(In reply to comment #3) > Why do you want to change gtk_border_free() to warn on NULL ? > I don't think we should change that now, gtk_border_free() is supported > API. Just because other copy/free pairs did that. > Other than that, the patch looks fine. Will commit without that part.
2006-12-24 Behdad Esfahbod <behdad@gnome.org> * gtk/gtkstyle.c (gtk_border_copy), (gtk_border_free): Use gslice for GtkBorder (#383557).
2006-12-24 Behdad Esfahbod <behdad@gnome.org> * gtk/gtkentry.c (_gtk_entry_effective_inner_border): Use gtk_border_free when freeing border. 2006-12-24 Matthias Clasen <mclasen@redhat.com> * gtk/gtkbutton.c (gtk_button_get_props): Use gtk_border_free when freeing borders.