From 15d2e25404b45713c3cef66d2d291c08b009352a Mon Sep 17 00:00:00 2001 From: Jehan Date: Tue, 6 May 2025 15:23:33 +0200 Subject: [PATCH] libgimp: further cleanup in GimpGradientChooser code. - No need of local_grad_data_new(). Just set default variables in init() as it should be. - Also move gimp_gradient_chooser_draw_interior() to the init() function, so that the new() function is only a wrapper of g_object_new() which is the proper way to implement new classes. - Get rid of wrong comment. --- libgimp/gimpgradientchooser.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libgimp/gimpgradientchooser.c b/libgimp/gimpgradientchooser.c index 1d7836f377..6f4262b770 100644 --- a/libgimp/gimpgradientchooser.c +++ b/libgimp/gimpgradientchooser.c @@ -76,7 +76,6 @@ static gboolean gimp_gradient_select_model_change_handler (GimpGradientChooser GimpResource *resource, gboolean is_closing); -static void local_grad_data_new (GimpGradientChooser *self); static void local_grad_data_free (GimpGradientChooser *self); static gboolean local_grad_data_exists (GimpGradientChooser *self); static gboolean local_grad_data_refresh (GimpGradientChooser *self, @@ -115,6 +114,10 @@ gimp_gradient_chooser_init (GimpGradientChooser *self) button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (self), button); + self->local_grad_data.data = NULL; + self->local_grad_data.n_samples = 0; + self->local_grad_data.allocation_width = 0; + self->preview = gtk_drawing_area_new (); gtk_widget_set_size_request (self->preview, CELL_WIDTH, CELL_HEIGHT); gtk_container_add (GTK_CONTAINER (button), self->preview); @@ -133,6 +136,8 @@ gimp_gradient_chooser_init (GimpGradientChooser *self) self->preview, &drag_target); _gimp_resource_chooser_set_clickable (GIMP_RESOURCE_CHOOSER (self), button); + + gimp_gradient_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (self)); } /* Called when dialog is closed and owning ResourceSelect button is disposed. */ @@ -193,10 +198,6 @@ gimp_gradient_chooser_new (const gchar *title, "resource", gradient, NULL); - local_grad_data_new (GIMP_GRADIENT_CHOOSER (self)); - - gimp_gradient_chooser_draw_interior (GIMP_RESOURCE_CHOOSER (self)); - return self; } @@ -390,23 +391,10 @@ local_grad_data_exists (GimpGradientChooser *self) return self->local_grad_data.data != NULL; } -static void -local_grad_data_new (GimpGradientChooser *self) -{ - self->local_grad_data.data = NULL; - self->local_grad_data.n_samples = 0; - self->local_grad_data.allocation_width = 0; -} - static void local_grad_data_free (GimpGradientChooser *self) { - /* More robust when set to NULL. - * g_free(NULL) is safe but g_free twice is not. - */ - g_free (self->local_grad_data.data); - self->local_grad_data.data = NULL; - + g_clear_pointer (&self->local_grad_data.data, g_free); self->local_grad_data.n_samples = 0; }