Commit 0cb3e75f authored by Michael Natterer's avatar Michael Natterer 😴

app: use a lot of g_clear_object() and g_clear_pointer()

More than 2000 lines of code less in app/, instead of

if (instance->member)
  {
    g_object_unref/g_free/g_whatever (instance->member);
    instance->member = NULL;
  }

we now simply use

g_clear_object/pointer (&instance->member);
parent f3561549
......@@ -270,8 +270,7 @@ actions_exit (Gimp *gimp)
g_return_if_fail (global_action_factory != NULL);
g_return_if_fail (global_action_factory->gimp == gimp);
g_object_unref (global_action_factory);
global_action_factory = NULL;
g_clear_object (&global_action_factory);
}
Gimp *
......
......@@ -726,14 +726,9 @@ gimp_core_config_finalize (GObject *object)
g_free (core_config->plug_in_rc_path);
g_free (core_config->import_raw_plug_in);
if (core_config->default_image)
g_object_unref (core_config->default_image);
if (core_config->default_grid)
g_object_unref (core_config->default_grid);
if (core_config->color_management)
g_object_unref (core_config->color_management);
g_clear_object (&core_config->default_image);
g_clear_object (&core_config->default_grid);
g_clear_object (&core_config->color_management);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......
......@@ -558,35 +558,12 @@ gimp_dialog_config_finalize (GObject *object)
{
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (object);
if (config->layer_new_name)
{
g_free (config->layer_new_name);
config->layer_new_name = NULL;
}
g_clear_pointer (&config->layer_new_name, g_free);
g_clear_pointer (&config->channel_new_name, g_free);
g_clear_pointer (&config->vectors_new_name, g_free);
if (config->channel_new_name)
{
g_free (config->channel_new_name);
config->channel_new_name = NULL;
}
if (config->vectors_new_name)
{
g_free (config->vectors_new_name);
config->vectors_new_name = NULL;
}
if (config->fill_options)
{
g_object_unref (config->fill_options);
config->fill_options = NULL;
}
if (config->stroke_options)
{
g_object_unref (config->stroke_options);
config->stroke_options = NULL;
}
g_clear_object (&config->fill_options);
g_clear_object (&config->stroke_options);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......
......@@ -367,11 +367,8 @@ gimp_display_config_finalize (GObject *object)
g_free (display_config->image_title_format);
g_free (display_config->image_status_format);
if (display_config->default_view)
g_object_unref (display_config->default_view);
if (display_config->default_fullscreen_view)
g_object_unref (display_config->default_fullscreen_view);
g_clear_object (&display_config->default_view);
g_clear_object (&display_config->default_fullscreen_view);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......
......@@ -130,17 +130,8 @@ gimp_rc_finalize (GObject *object)
{
GimpRc *rc = GIMP_RC (object);
if (rc->system_gimprc)
{
g_object_unref (rc->system_gimprc);
rc->system_gimprc = NULL;
}
if (rc->user_gimprc)
{
g_object_unref (rc->user_gimprc);
rc->user_gimprc = NULL;
}
g_clear_object (&rc->system_gimprc);
g_clear_object (&rc->user_gimprc);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......
......@@ -250,53 +250,14 @@ gimp_data_factories_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->brush_factory)
{
g_object_unref (gimp->brush_factory);
gimp->brush_factory = NULL;
}
if (gimp->dynamics_factory)
{
g_object_unref (gimp->dynamics_factory);
gimp->dynamics_factory = NULL;
}
if (gimp->mybrush_factory)
{
g_object_unref (gimp->mybrush_factory);
gimp->mybrush_factory = NULL;
}
if (gimp->pattern_factory)
{
g_object_unref (gimp->pattern_factory);
gimp->pattern_factory = NULL;
}
if (gimp->gradient_factory)
{
g_object_unref (gimp->gradient_factory);
gimp->gradient_factory = NULL;
}
if (gimp->palette_factory)
{
g_object_unref (gimp->palette_factory);
gimp->palette_factory = NULL;
}
if (gimp->tool_preset_factory)
{
g_object_unref (gimp->tool_preset_factory);
gimp->tool_preset_factory = NULL;
}
if (gimp->tag_cache)
{
g_object_unref (gimp->tag_cache);
gimp->tag_cache = NULL;
}
g_clear_object (&gimp->brush_factory);
g_clear_object (&gimp->dynamics_factory);
g_clear_object (&gimp->mybrush_factory);
g_clear_object (&gimp->pattern_factory);
g_clear_object (&gimp->gradient_factory);
g_clear_object (&gimp->palette_factory);
g_clear_object (&gimp->tool_preset_factory);
g_clear_object (&gimp->tag_cache);
}
gint64
......
......@@ -53,11 +53,7 @@ gimp_modules_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (gimp->module_db)
{
g_object_unref (gimp->module_db);
gimp->module_db = NULL;
}
g_clear_object (&gimp->module_db);
}
void
......
......@@ -343,25 +343,12 @@ gimp_dispose (GObject *object)
gimp_filter_history_clear (gimp);
if (gimp->edit_config)
{
g_object_unref (gimp->edit_config);
gimp->edit_config = NULL;
}
if (gimp->config)
{
g_object_unref (gimp->config);
gimp->config = NULL;
}
g_clear_object (&gimp->edit_config);
g_clear_object (&gimp->config);
gimp_contexts_exit (gimp);
if (gimp->image_new_last_template)
{
g_object_unref (gimp->image_new_last_template);
gimp->image_new_last_template = NULL;
}
g_clear_object (&gimp->image_new_last_template);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
......@@ -388,17 +375,8 @@ gimp_finalize (GObject *object)
standards = g_list_prepend (standards,
gimp_palette_get_standard (gimp->user_context));
if (gimp->templates)
{
g_object_unref (gimp->templates);
gimp->templates = NULL;
}
if (gimp->documents)
{
g_object_unref (gimp->documents);
gimp->documents = NULL;
}
g_clear_object (&gimp->templates);
g_clear_object (&gimp->documents);
gimp_tool_info_set_standard (gimp, NULL);
......@@ -406,92 +384,35 @@ gimp_finalize (GObject *object)
{
gimp_container_foreach (gimp->tool_info_list,
(GFunc) g_object_run_dispose, NULL);
g_object_unref (gimp->tool_info_list);
gimp->tool_info_list = NULL;
g_clear_object (&gimp->tool_info_list);
}
xcf_exit (gimp);
if (gimp->pdb)
{
g_object_unref (gimp->pdb);
gimp->pdb = NULL;
}
g_clear_object (&gimp->pdb);
gimp_data_factories_exit (gimp);
gimp_fonts_exit (gimp);
if (gimp->named_buffers)
{
g_object_unref (gimp->named_buffers);
gimp->named_buffers = NULL;
}
if (gimp->clipboard_buffer)
{
g_object_unref (gimp->clipboard_buffer);
gimp->clipboard_buffer = NULL;
}
if (gimp->clipboard_image)
{
g_object_unref (gimp->clipboard_image);
gimp->clipboard_image = NULL;
}
if (gimp->displays)
{
g_object_unref (gimp->displays);
gimp->displays = NULL;
}
if (gimp->item_table)
{
g_object_unref (gimp->item_table);
gimp->item_table = NULL;
}
if (gimp->image_table)
{
g_object_unref (gimp->image_table);
gimp->image_table = NULL;
}
if (gimp->images)
{
g_object_unref (gimp->images);
gimp->images = NULL;
}
if (gimp->plug_in_manager)
{
g_object_unref (gimp->plug_in_manager);
gimp->plug_in_manager = NULL;
}
g_clear_object (&gimp->named_buffers);
g_clear_object (&gimp->clipboard_buffer);
g_clear_object (&gimp->clipboard_image);
g_clear_object (&gimp->displays);
g_clear_object (&gimp->item_table);
g_clear_object (&gimp->image_table);
g_clear_object (&gimp->images);
g_clear_object (&gimp->plug_in_manager);
if (gimp->module_db)
gimp_modules_exit (gimp);
gimp_paint_exit (gimp);
if (gimp->parasites)
{
g_object_unref (gimp->parasites);
gimp->parasites = NULL;
}
if (gimp->default_folder)
{
g_object_unref (gimp->default_folder);
gimp->default_folder = NULL;
}
g_clear_object (&gimp->parasites);
g_clear_object (&gimp->default_folder);
if (gimp->session_name)
{
g_free (gimp->session_name);
gimp->session_name = NULL;
}
g_clear_pointer (&gimp->session_name, g_free);
if (gimp->context_list)
{
......@@ -1005,14 +926,8 @@ gimp_set_clipboard_image (Gimp *gimp,
if (image)
g_object_ref (image);
if (gimp->clipboard_buffer)
{
g_object_unref (gimp->clipboard_buffer);
gimp->clipboard_buffer = NULL;
}
if (gimp->clipboard_image)
g_object_unref (gimp->clipboard_image);
g_clear_object (&gimp->clipboard_buffer);
g_clear_object (&gimp->clipboard_image);
gimp->clipboard_image = image;
......@@ -1038,14 +953,8 @@ gimp_set_clipboard_buffer (Gimp *gimp,
if (buffer)
g_object_ref (buffer);
if (gimp->clipboard_image)
{
g_object_unref (gimp->clipboard_image);
gimp->clipboard_image = NULL;
}
if (gimp->clipboard_buffer)
g_object_unref (gimp->clipboard_buffer);
g_clear_object (&gimp->clipboard_image);
g_clear_object (&gimp->clipboard_buffer);
gimp->clipboard_buffer = buffer;
......
......@@ -182,46 +182,14 @@ gimp_brush_finalize (GObject *object)
{
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->priv->mask)
{
gimp_temp_buf_unref (brush->priv->mask);
brush->priv->mask = NULL;
}
if (brush->priv->pixmap)
{
gimp_temp_buf_unref (brush->priv->pixmap);
brush->priv->pixmap = NULL;
}
if (brush->priv->blured_mask)
{
gimp_temp_buf_unref (brush->priv->blured_mask);
brush->priv->blured_mask = NULL;
}
g_clear_pointer (&brush->priv->mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->pixmap, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->blured_mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->blured_pixmap, gimp_temp_buf_unref);
if (brush->priv->blured_pixmap)
{
gimp_temp_buf_unref (brush->priv->blured_pixmap);
brush->priv->blured_pixmap = NULL;
}
if (brush->priv->mask_cache)
{
g_object_unref (brush->priv->mask_cache);
brush->priv->mask_cache = NULL;
}
if (brush->priv->pixmap_cache)
{
g_object_unref (brush->priv->pixmap_cache);
brush->priv->pixmap_cache = NULL;
}
if (brush->priv->boundary_cache)
{
g_object_unref (brush->priv->boundary_cache);
brush->priv->boundary_cache = NULL;
}
g_clear_object (&brush->priv->mask_cache);
g_clear_object (&brush->priv->pixmap_cache);
g_clear_object (&brush->priv->boundary_cache);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -429,17 +397,8 @@ gimp_brush_dirty (GimpData *data)
if (brush->priv->boundary_cache)
gimp_brush_cache_clear (brush->priv->boundary_cache);
if (brush->priv->blured_mask)
{
gimp_temp_buf_unref (brush->priv->blured_mask);
brush->priv->blured_mask = NULL;
}
if (brush->priv->blured_pixmap)
{
gimp_temp_buf_unref (brush->priv->blured_pixmap);
brush->priv->blured_pixmap = NULL;
}
g_clear_pointer (&brush->priv->blured_mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->blured_pixmap, gimp_temp_buf_unref);
GIMP_DATA_CLASS (parent_class)->dirty (data);
}
......@@ -466,26 +425,12 @@ gimp_brush_real_begin_use (GimpBrush *brush)
static void
gimp_brush_real_end_use (GimpBrush *brush)
{
g_object_unref (brush->priv->mask_cache);
brush->priv->mask_cache = NULL;
g_object_unref (brush->priv->pixmap_cache);
brush->priv->pixmap_cache = NULL;
g_object_unref (brush->priv->boundary_cache);
brush->priv->boundary_cache = NULL;
if (brush->priv->blured_mask)
{
gimp_temp_buf_unref (brush->priv->blured_mask);
brush->priv->blured_mask = NULL;
}
g_clear_object (&brush->priv->mask_cache);
g_clear_object (&brush->priv->pixmap_cache);
g_clear_object (&brush->priv->boundary_cache);
if (brush->priv->blured_pixmap)
{
gimp_temp_buf_unref (brush->priv->blured_pixmap);
brush->priv->blured_pixmap = NULL;
}
g_clear_pointer (&brush->priv->blured_mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->blured_pixmap, gimp_temp_buf_unref);
}
static GimpBrush *
......@@ -911,17 +856,8 @@ void
gimp_brush_flush_blur_caches (GimpBrush *brush)
{
#if 0
if (brush->priv->blured_mask)
{
gimp_temp_buf_unref (brush->priv->blured_mask);
brush->priv->blured_mask = NULL;
}
if (brush->priv->blured_pixmap)
{
gimp_temp_buf_unref (brush->priv->blured_pixmap);
brush->priv->blured_pixmap = NULL;
}
g_clear_pointer (&brush->priv->blured_mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->blured_pixmap, gimp_temp_buf_unref);
if (brush->priv->mask_cache)
gimp_brush_cache_clear (brush->priv->mask_cache);
......@@ -946,14 +882,13 @@ gint
gimp_brush_get_width (GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), 0);
if (brush->priv->blured_mask)
{
return gimp_temp_buf_get_width (brush->priv->blured_mask);
}
return gimp_temp_buf_get_width (brush->priv->blured_mask);
if (brush->priv->blured_pixmap)
{
return gimp_temp_buf_get_width (brush->priv->blured_pixmap);
}
return gimp_temp_buf_get_width (brush->priv->blured_pixmap);
return gimp_temp_buf_get_width (brush->priv->mask);
}
......@@ -963,14 +898,11 @@ gimp_brush_get_height (GimpBrush *brush)
g_return_val_if_fail (GIMP_IS_BRUSH (brush), 0);
if (brush->priv->blured_mask)
{
return gimp_temp_buf_get_height (brush->priv->blured_mask);
}
if (brush->priv->blured_pixmap)
{
return gimp_temp_buf_get_height (brush->priv->blured_pixmap);
}
return gimp_temp_buf_get_height (brush->priv->mask);
}
......
......@@ -210,17 +210,8 @@ gimp_brush_clipboard_changed (Gimp *gimp,
gint width;
gint height;
if (brush->priv->mask)
{
gimp_temp_buf_unref (brush->priv->mask);
brush->priv->mask = NULL;
}
if (brush->priv->pixmap)
{
gimp_temp_buf_unref (brush->priv->pixmap);
brush->priv->pixmap = NULL;
}
g_clear_pointer (&brush->priv->mask, gimp_temp_buf_unref);
g_clear_pointer (&brush->priv->pixmap, gimp_temp_buf_unref);
paste = gimp_get_clipboard_object (gimp);
......
......@@ -254,8 +254,7 @@ gimp_brush_generated_dirty (GimpData *data)
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
GimpBrush *gbrush = GIMP_BRUSH (brush);
if (gbrush->priv->mask)
gimp_temp_buf_unref (gbrush->priv->mask);
g_clear_pointer (&gbrush->priv->mask, gimp_temp_buf_unref);
gbrush->priv->mask = gimp_brush_generated_calc (brush,
brush->shape,
......
......@@ -123,11 +123,7 @@ gimp_buffer_finalize (GObject *object)
{
GimpBuffer *buffer = GIMP_BUFFER (object);
if (buffer->buffer)
{
g_object_unref (buffer->buffer);
buffer->buffer = NULL;
}
g_clear_object (&buffer->buffer);
gimp_buffer_set_color_profile (buffer, NULL);
......@@ -528,16 +524,10 @@ gimp_buffer_set_color_profile (GimpBuffer *buffer,
if (profile != buffer->color_profile)
{
if (buffer->color_profile)
{
g_object_unref (buffer->color_profile);
buffer->color_profile = NULL;
}
g_clear_object (&buffer->color_profile);
if (profile)
{
buffer->color_profile = g_object_ref (profile);
}
buffer->color_profile = g_object_ref (profile);
}
}
......
......@@ -968,83 +968,19 @@ gimp_context_dispose (GObject *object)
context->gimp = NULL;
}
if (context->tool_info)
{
g_object_unref (context->tool_info);
context->tool_info = NULL;
}
if (context->paint_info)
{
g_object_unref (context->paint_info);
context->paint_info = NULL;
}
if (context->brush)
{
g_object_unref (context->brush);
context->brush = NULL;
}
if (context->dynamics)
{
g_object_unref (context->dynamics);
context->dynamics = NULL;
}
if (context->mybrush)
{
g_object_unref (context->mybrush);
context->mybrush = NULL;
}
if (context->pattern)
{
g_object_unref (context->pattern);
context->pattern = NULL;
}
if (context->gradient)
{
g_object_unref (context->gradient);
context->gradient = NULL;
}
if (context->palette)
{
g_object_unref (context->palette);
context->palette = NULL;
}
if (context->tool_preset)
{
g_object_unref (context->tool_preset);
context->tool_preset = NULL;
}
if (context->font)
{
g_object_unref (context->font);
context->font = NULL;
}
if (context->buffer)
{
g_object_unref (context->buffer);
context->buffer = NULL;
}
if (context->imagefile)
{
g_object_unref (context->imagefile);