[gegl] gegl: Simplify code



commit 66dad2179c1ec9e8b32900ef6ef8f93244d51209
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Oct 27 09:14:52 2017 +0200

    gegl: Simplify code
    
    Leverage modern GLib API like g_clear_* and g_set_object; and the facts
    that g_free and g_(s)list_free* are already NULL-safe, and a GObject's
    finalize virtual method is invoked only once.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789543

 gegl/buffer/gegl-buffer-load.c                  |    3 +-
 gegl/buffer/gegl-buffer-save.c                  |    3 +-
 gegl/buffer/gegl-buffer.c                       |   15 +----
 gegl/buffer/gegl-sampler-cubic.c                |    3 +-
 gegl/buffer/gegl-sampler.c                      |    9 +--
 gegl/buffer/gegl-tile-backend-file-async.c      |   10 +--
 gegl/buffer/gegl-tile-handler-cache.c           |    3 +-
 gegl/buffer/gegl-tile-handler.c                 |   17 +-----
 gegl/gegl-config.c                              |   13 +---
 gegl/gegl-init.c                                |   12 +---
 gegl/gegl-op.h                                  |   69 +++++------------------
 gegl/gegl-serialize.c                           |   11 +---
 gegl/gegl-xml.c                                 |   13 +---
 gegl/graph/gegl-node.c                          |   59 ++++----------------
 gegl/graph/gegl-pad.c                           |   16 +----
 gegl/module/gegldatafiles.c                     |    3 +-
 gegl/module/geglmodule.c                        |   23 +------
 gegl/module/geglmoduledb.c                      |   17 +-----
 gegl/operation/gegl-operation-composer.c        |    6 +-
 gegl/operation/gegl-operation-composer3.c       |    9 +--
 gegl/operation/gegl-operation-meta.c            |    7 +-
 gegl/operation/gegl-operation-point-composer.c  |    6 +-
 gegl/operation/gegl-operation-point-composer3.c |    9 +--
 gegl/operation/gegl-operation.c                 |    6 +-
 gegl/process/gegl-eval-manager.c                |   13 +----
 gegl/process/gegl-graph-traversal.c             |    4 +-
 gegl/process/gegl-processor.c                   |   41 +++-----------
 gegl/property-types/gegl-audio-fragment.c       |    6 +--
 gegl/property-types/gegl-color.c                |    6 +--
 gegl/property-types/gegl-curve.c                |   19 +-----
 30 files changed, 96 insertions(+), 335 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-load.c b/gegl/buffer/gegl-buffer-load.c
index 5a6523f..a35393f 100644
--- a/gegl/buffer/gegl-buffer-load.c
+++ b/gegl/buffer/gegl-buffer-load.c
@@ -63,8 +63,7 @@ load_info_destroy (LoadInfo *info)
 {
   if (!info)
     return;
-  if (info->path)
-    g_free (info->path);
+  g_free (info->path);
   if (info->i != -1)
     close (info->i);
   if (info->tiles != NULL)
diff --git a/gegl/buffer/gegl-buffer-save.c b/gegl/buffer/gegl-buffer-save.c
index ce0cbdd..feb673e 100644
--- a/gegl/buffer/gegl-buffer-save.c
+++ b/gegl/buffer/gegl-buffer-save.c
@@ -106,8 +106,7 @@ save_info_destroy (SaveInfo *info)
 {
   if (!info)
     return;
-  if (info->path)
-    g_free (info->path);
+  g_free (info->path);
   if (info->o != -1)
     close (info->o);
   if (info->tiles != NULL)
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index aca8adb..a73726c 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -211,8 +211,7 @@ gegl_buffer_set_property (GObject      *gobject,
         break;
 
       case PROP_PATH:
-        if (buffer->path)
-          g_free (buffer->path);
+        g_free (buffer->path);
         buffer->path = g_value_dup_string (value);
         break;
 
@@ -264,8 +263,7 @@ gegl_buffer_set_property (GObject      *gobject,
         break;
 
       case PROP_BACKEND:
-        if (buffer->backend)
-          g_object_unref (buffer->backend);
+        g_clear_object (&buffer->backend);
         buffer->backend = g_value_dup_object (value);
         break;
 
@@ -388,11 +386,7 @@ gegl_buffer_dispose (GObject *object)
 
   _gegl_buffer_drop_hot_tile (buffer);
 
-  if (buffer->backend)
-    {
-      g_object_unref (buffer->backend);
-      buffer->backend = NULL;
-    }
+  g_clear_object (&buffer->backend);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -508,8 +502,7 @@ gegl_buffer_constructor (GType                  type,
           buffer->tile_width = gegl_tile_backend_get_tile_width (backend);
           buffer->tile_height = gegl_tile_backend_get_tile_height (backend);
 
-          if (buffer->path)
-            g_free (buffer->path);
+          g_free (buffer->path);
 
           if (GEGL_IS_TILE_BACKEND_FILE (backend))
             g_object_get (backend, "path", &buffer->path, NULL);
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index e7848a7..4fd7231 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -311,8 +311,7 @@ set_property (GObject      *object,
         break;
 
       case PROP_TYPE:
-        if (self->type)
-          g_free (self->type);
+        g_free (self->type);
         self->type = g_value_dup_string (value);
         break;
 
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 7f1deff..972b1fe 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -562,8 +562,7 @@ gegl_buffer_sample_at_level (GeglBuffer       *buffer,
 
       if (buffer->sampler)
       {
-        g_object_unref (buffer->sampler);
-        buffer->sampler = NULL;
+        g_clear_object (&buffer->sampler);
         buffer->sampler_type = 0;
       }
 
@@ -612,11 +611,7 @@ gegl_buffer_sample_cleanup (GeglBuffer *buffer)
   if (threaded)
     g_mutex_lock (&gegl_buffer_sampler_mutex);
 
-  if (buffer->sampler)
-    {
-      g_object_unref (buffer->sampler);
-      buffer->sampler = NULL;
-    }
+  g_clear_object (&buffer->sampler);
 
   if (threaded)
     g_mutex_unlock (&gegl_buffer_sampler_mutex);
diff --git a/gegl/buffer/gegl-tile-backend-file-async.c b/gegl/buffer/gegl-tile-backend-file-async.c
index 1885a04..c78bf83 100644
--- a/gegl/buffer/gegl-tile-backend-file-async.c
+++ b/gegl/buffer/gegl-tile-backend-file-async.c
@@ -879,8 +879,7 @@ gegl_tile_backend_file_set_property (GObject      *object,
   switch (property_id)
     {
       case PROP_PATH:
-        if (self->path)
-          g_free (self->path);
+        g_free (self->path);
         self->path = g_value_dup_string (value);
         break;
 
@@ -971,11 +970,8 @@ gegl_tile_backend_file_finalize (GObject *object)
       g_free (self->path);
     }
 
-  if (self->monitor)
-    g_object_unref (self->monitor);
-
-  if (self->file)
-    g_object_unref (self->file);
+  g_clear_object (&self->monitor);
+  g_clear_object (&self->file);
 
   g_cond_clear (&self->cond);
 
diff --git a/gegl/buffer/gegl-tile-handler-cache.c b/gegl/buffer/gegl-tile-handler-cache.c
index 40bfd80..f74f355 100644
--- a/gegl/buffer/gegl-tile-handler-cache.c
+++ b/gegl/buffer/gegl-tile-handler-cache.c
@@ -321,8 +321,7 @@ gegl_tile_handler_cache_wash (GeglTileHandlerCache *cache)
     {
       gegl_tile_store (last_dirty);
       gegl_tile_unref (last_dirty);
-      if (last_dirty->tile_storage)
-        g_object_unref (last_dirty->tile_storage);
+      g_clear_object (&last_dirty->tile_storage);
       return TRUE;
     }
   return FALSE;
diff --git a/gegl/buffer/gegl-tile-handler.c b/gegl/buffer/gegl-tile-handler.c
index 72f610e..74cf511 100644
--- a/gegl/buffer/gegl-tile-handler.c
+++ b/gegl/buffer/gegl-tile-handler.c
@@ -49,11 +49,7 @@ gegl_tile_handler_dispose (GObject *object)
 {
   GeglTileHandler *handler = GEGL_TILE_HANDLER (object);
 
-  if (handler->source)
-    {
-      g_object_unref (handler->source);
-      handler->source = NULL;
-    }
+  g_clear_object (&handler->source);
 
   G_OBJECT_CLASS (gegl_tile_handler_parent_class)->dispose (object);
 }
@@ -145,16 +141,7 @@ void
 gegl_tile_handler_set_source (GeglTileHandler *handler,
                               GeglTileSource  *source)
 {
-  if (source != handler->source)
-    {
-      if (handler->source)
-        g_object_unref (handler->source);
-
-      handler->source = source;
-
-      if (handler->source)
-        g_object_ref (handler->source);
-    }
+  g_set_object (&handler->source, source);
 }
 
 void
diff --git a/gegl/gegl-config.c b/gegl/gegl-config.c
index 5a0a3f4..5f3ee2a 100644
--- a/gegl/gegl-config.c
+++ b/gegl/gegl-config.c
@@ -132,8 +132,7 @@ gegl_config_set_property (GObject      *gobject,
         config->quality = g_value_get_double (value);
         return;
       case PROP_SWAP:
-        if (config->swap)
-          g_free (config->swap);
+        g_free (config->swap);
         config->swap = g_value_dup_string (value);
         break;
       case PROP_THREADS:
@@ -146,8 +145,7 @@ gegl_config_set_property (GObject      *gobject,
         config->queue_size = g_value_get_int (value);
         break;
       case PROP_APPLICATION_LICENSE:
-        if (config->application_license)
-          g_free (config->application_license);
+        g_free (config->application_license);
         config->application_license = g_value_dup_string (value);
         break;
       default:
@@ -161,11 +159,8 @@ gegl_config_finalize (GObject *gobject)
 {
   GeglConfig *config = GEGL_CONFIG (gobject);
 
-  if (config->swap)
-    g_free (config->swap);
-
-  if (config->application_license)
-    g_free (config->application_license);
+  g_free (config->swap);
+  g_free (config->application_license);
 
   G_OBJECT_CLASS (gegl_config_parent_class)->finalize (gobject);
 }
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index b6cb445..3df8ac6 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -146,8 +146,7 @@ gegl_init_swap_dir (void)
       ! g_file_test (swapdir, G_FILE_TEST_IS_DIR) &&
       g_mkdir_with_parents (swapdir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
     {
-      g_free (swapdir);
-      swapdir = NULL;
+      g_clear_pointer (&swapdir, g_free);
     }
 
   g_object_set (config, "swap", swapdir, NULL);
@@ -475,11 +474,7 @@ gegl_exit (void)
 
   gegl_temp_buffer_free ();
 
-  if (module_db != NULL)
-    {
-      g_object_unref (module_db);
-      module_db = NULL;
-    }
+  g_clear_object (&module_db);
 
   babl_exit ();
 
@@ -543,8 +538,7 @@ gegl_exit (void)
 
       g_pattern_spec_free (pattern);
     }
-  g_object_unref (config);
-  config = NULL;
+  g_clear_object (&config);
   global_time = 0;
 }
 
diff --git a/gegl/gegl-op.h b/gegl/gegl-op.h
index eb5fac2..d155bc5 100644
--- a/gegl/gegl-op.h
+++ b/gegl/gegl-op.h
@@ -489,8 +489,7 @@ set_property (GObject      *gobject,
       break;
 #define property_string(name, label, def_val)                         \
     case PROP_##name:                                                 \
-      if (properties->name)                                           \
-        g_free (properties->name);                                    \
+      g_free (properties->name);                                      \
       properties->name = g_value_dup_string (value);                  \
       break;
 #define property_boolean(name, label, def_val)                        \
@@ -499,38 +498,32 @@ set_property (GObject      *gobject,
       break;
 #define property_file_path(name, label, def_val)                      \
     case PROP_##name:                                                 \
-      if (properties->name)                                           \
-        g_free (properties->name);                                    \
+      g_free (properties->name);                                      \
       properties->name = g_value_dup_string (value);                  \
       break;
 #define property_uri(name, label, def_val)                            \
     case PROP_##name:                                                 \
-      if (properties->name)                                           \
-        g_free (properties->name);                                    \
+      g_free (properties->name);                                      \
       properties->name = g_value_dup_string (value);                  \
       break;
 #define property_object(name, label, def_val)                         \
     case PROP_##name:                                                 \
-      if (properties->name != NULL)                                   \
-         g_object_unref (properties->name);                           \
+      g_clear_object (&properties->name);                             \
       properties->name = g_value_dup_object (value);                  \
       break;
 #define property_curve(name, label, def_val)                          \
     case PROP_##name:                                                 \
-      if (properties->name != NULL)                                   \
-         g_object_unref (properties->name);                           \
+      g_clear_object (&properties->name);                             \
       properties->name = g_value_dup_object (value);                  \
       break;
 #define property_color(name, label, def_val)                          \
     case PROP_##name:                                                 \
-      if (properties->name != NULL)                                   \
-         g_object_unref (properties->name);                           \
+      g_clear_object (&properties->name);                             \
       properties->name = g_value_dup_object (value);                  \
       break;
 #define property_audio_fragment(name, label, def_val)                 \
     case PROP_##name:                                                 \
-      if (properties->name != NULL)                                   \
-         g_object_unref (properties->name);                           \
+      g_clear_object (&properties->name);                             \
       properties->name = g_value_dup_object (value);                  \
       break;
 #define property_path(name, label, def_val)                           \
@@ -605,54 +598,22 @@ static void gegl_op_destroy_notify (gpointer data)
 #define property_double(name, label, def_val)
 #define property_int(name, label, def_val) 
 #define property_string(name, label, ...)      \
-  if (properties->name)                             \
-    {                                               \
-      g_free (properties->name);                    \
-      properties->name = NULL;                      \
-    }
+  g_clear_pointer (&properties->name, g_free);
 #define property_boolean(name, label, def_val)
 #define property_file_path(name, label, def_val)    \
-  if (properties->name)                             \
-    {                                               \
-      g_free (properties->name);                    \
-      properties->name = NULL;                      \
-    }
+  g_clear_pointer (&properties->name, g_free);
 #define property_uri(name, label, def_val)          \
-  if (properties->name)                             \
-    {                                               \
-      g_free (properties->name);                    \
-      properties->name = NULL;                      \
-    }
+  g_clear_pointer (&properties->name, g_free);
 #define property_object(name, label, def_val)       \
-  if (properties->name)                             \
-    {                                               \
-      g_object_unref (properties->name);            \
-      properties->name = NULL;                      \
-    }
+  g_clear_object (&properties->name);
 #define property_curve(name, label, def_val)       \
-  if (properties->name)                             \
-    {                                               \
-      g_object_unref (properties->name);            \
-      properties->name = NULL;                      \
-    }
+  g_clear_object (&properties->name);
 #define property_color(name, label, def_val)       \
-  if (properties->name)                             \
-    {                                               \
-      g_object_unref (properties->name);            \
-      properties->name = NULL;                      \
-    }
+  g_clear_object (&properties->name);
 #define property_audio_fragment(name, label, def_val) \
-  if (properties->name)                             \
-    {                                               \
-      g_object_unref (properties->name);            \
-      properties->name = NULL;                      \
-    }
+  g_clear_object (&properties->name);
 #define property_path(name, label, def_val)         \
-  if (properties->name)                             \
-    {                                               \
-      g_object_unref (properties->name);            \
-      properties->name = NULL;                      \
-    }
+  g_clear_object (&properties->name);
 #define property_pointer(name, label, ...)
 #define property_format(name, label, ...)
 #define property_enum(name, label, ...)
diff --git a/gegl/gegl-serialize.c b/gegl/gegl-serialize.c
index fa25b04..d112387 100644
--- a/gegl/gegl-serialize.c
+++ b/gegl/gegl-serialize.c
@@ -300,8 +300,7 @@ gegl_create_chain_argv (char      **ops,
                           {
                             string = g_string_new ("");
                             in_strkeyframes = 1;
-                            if (prop)
-                              g_free (prop);
+                            g_free (prop);
                             prop = g_strdup (key);
                           }
                         else
@@ -312,8 +311,7 @@ gegl_create_chain_argv (char      **ops,
                             anim_quark = g_quark_from_string (tmpbuf);
                             path = gegl_path_new ();
                             in_keyframes = 1;
-                            if (prop)
-                              g_free (prop);
+                            g_free (prop);
                             prop = g_strdup (key);
 
                             g_object_set_qdata_full (G_OBJECT (
@@ -671,10 +669,7 @@ gegl_create_chain_argv (char      **ops,
                             level_pad[level]);
     }
 
-  if (prop)
-    {
-      g_free (prop);
-    }
+  g_free (prop);
   g_hash_table_unref (ht);
   gegl_node_link_many (iter[level], proxy, NULL);
 }
diff --git a/gegl/gegl-xml.c b/gegl/gegl-xml.c
index aa0614b..c0962ec 100644
--- a/gegl/gegl-xml.c
+++ b/gegl/gegl-xml.c
@@ -231,9 +231,7 @@ set_clone_prop_as_well:
           if (pd->curve)
             {
               gegl_node_set (new, param_name, pd->curve, NULL);
-
-              g_object_unref (pd->curve);
-              pd->curve = NULL;
+              g_clear_object (&pd->curve);
             }
         }
       else if (paramspec->value_type == GEGL_TYPE_PATH)
@@ -492,8 +490,7 @@ static void end_element (GMarkupParseContext *context,
     }
   else if (!strcmp (element_name, "param"))
     {
-      g_free (pd->param);
-      pd->param = NULL;
+      g_clear_pointer (&pd->param, g_free);
     }
   else if (!strcmp (element_name, "curve"))
     {
@@ -587,11 +584,7 @@ GeglNode *gegl_node_new_from_xml (const gchar *xmldata,
     }
   else
     {
-      if (pd.gegl)
-        {
-          g_object_unref (pd.gegl);
-          pd.gegl = NULL;
-        }
+      g_clear_object (&pd.gegl);
     }
 
   g_list_free (pd.refs);
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index 4d88065..3de6d83 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -252,17 +252,8 @@ gegl_node_dispose (GObject *gobject)
     }
 
   gegl_node_remove_children (self);
-  if (self->cache)
-    {
-      g_object_unref (self->cache);
-      self->cache = NULL;
-    }
-
-  if (self->priv->eval_manager)
-    {
-      g_object_unref (self->priv->eval_manager);
-      self->priv->eval_manager = NULL;
-    }
+  g_clear_object (&self->cache);
+  g_clear_object (&self->priv->eval_manager);
 
   G_OBJECT_CLASS (gegl_node_parent_class)->dispose (gobject);
 }
@@ -275,31 +266,13 @@ gegl_node_finalize (GObject *gobject)
   gegl_node_disconnect_sources (self);
   gegl_node_disconnect_sinks (self);
 
-  if (self->pads)
-    {
-      g_slist_foreach (self->pads, (GFunc) g_object_unref, NULL);
-      g_slist_free (self->pads);
-      self->pads = NULL;
-    }
-
+  g_slist_free_full (self->pads, g_object_unref);
   g_slist_free (self->input_pads);
   g_slist_free (self->output_pads);
 
-  if (self->operation)
-    {
-      g_object_unref (self->operation);
-      self->operation = NULL;
-    }
-
-  if (self->priv->name)
-    {
-      g_free (self->priv->name);
-    }
-
-  if (self->priv->debug_name)
-    {
-      g_free (self->priv->debug_name);
-    }
+  g_clear_object (&self->operation);
+  g_free (self->priv->name);
+  g_free (self->priv->debug_name);
 
   g_mutex_clear (&self->mutex);
 
@@ -1035,8 +1008,7 @@ gegl_node_blit (GeglNode            *self,
       if (buffer && destination_buf)
         gegl_buffer_get (buffer, roi, scale, format, destination_buf, rowstride, GEGL_ABYSS_NONE);
 
-      if (buffer)
-        g_object_unref (buffer);
+      g_clear_object (&buffer);
     }
   else if (flags & GEGL_BLIT_CACHE)
     {
@@ -1257,10 +1229,7 @@ gegl_node_set_operation_object (GeglNode      *self,
   gegl_node_disconnect_sources (self);
   gegl_node_disconnect_sinks (self);
 
-  if (self->operation)
-    g_object_unref (self->operation);
-
-  self->operation = g_object_ref (operation);
+  g_set_object (&self->operation, operation);
 
   /* Delete all the pads from the previous operation */
   while (self->pads)
@@ -1600,8 +1569,7 @@ gegl_node_update_debug_name (GeglNode *node)
 
   g_return_if_fail (GEGL_IS_NODE (node));
 
-  if (node->priv->debug_name)
-    g_free (node->priv->debug_name);
+  g_free (node->priv->debug_name);
 
   if (name && *name)
     new_name = g_strdup_printf ("%s '%s' %p", operation ? operation : "(none)", name, node);
@@ -1872,10 +1840,7 @@ gegl_node_get_cache (GeglNode *node)
     }
 
   if (node->cache && gegl_buffer_get_format ((GeglBuffer *)(node->cache)) != format)
-    {
-      g_object_unref (node->cache);
-      node->cache = NULL;
-    }
+    g_clear_object (&node->cache);
 
   if (node->cache)
     return node->cache;
@@ -1919,9 +1884,7 @@ gegl_node_set_name (GeglNode    *self,
 {
   g_return_if_fail (GEGL_IS_NODE (self));
 
-  if (self->priv->name)
-    g_free (self->priv->name);
-
+  g_free (self->priv->name);
   self->priv->name = g_strdup (name);
 
   gegl_node_update_debug_name (self);
diff --git a/gegl/graph/gegl-pad.c b/gegl/graph/gegl-pad.c
index 5fd4edf..0ef9fe3 100644
--- a/gegl/graph/gegl-pad.c
+++ b/gegl/graph/gegl-pad.c
@@ -80,17 +80,8 @@ finalize (GObject *gobject)
 
   g_assert (self->connections == NULL);
 
-  if (self->param_spec)
-    {
-      g_param_spec_unref (self->param_spec);
-      self->param_spec = NULL;
-    }
-
-  if (self->name)
-    {
-      g_free (self->name);
-      self->name = NULL;
-    }
+  g_clear_pointer (&self->param_spec, (GDestroyNotify) g_param_spec_unref);
+  g_free (self->name);
 
   G_OBJECT_CLASS (gegl_pad_parent_class)->finalize (gobject);
 }
@@ -215,8 +206,7 @@ gegl_pad_get_name (GeglPad *self)
 void gegl_pad_set_name (GeglPad     *self,
                         const gchar *name)
 {
-  if (self->name)
-    g_free (self->name);
+  g_free (self->name);
   self->name = g_strdup (name);
 }
 
diff --git a/gegl/module/gegldatafiles.c b/gegl/module/gegldatafiles.c
index bc2f062..5b239b4 100644
--- a/gegl/module/gegldatafiles.c
+++ b/gegl/module/gegldatafiles.c
@@ -151,8 +151,7 @@ gegl_path_parse (const gchar  *path,
 static void
 gegl_path_free (GList *path)
 {
-  g_list_foreach (path, (GFunc) g_free, NULL);
-  g_list_free (path);
+  g_list_free_full (path, g_free);
 }
 
 void
diff --git a/gegl/module/geglmodule.c b/gegl/module/geglmodule.c
index 81e9e86..4b25236 100644
--- a/gegl/module/geglmodule.c
+++ b/gegl/module/geglmodule.c
@@ -98,23 +98,10 @@ gegl_module_finalize (GObject *object)
 {
   GeglModule *module = GEGL_MODULE (object);
 
-  if (module->info)
-    {
-      gegl_module_info_free (module->info);
-      module->info = NULL;
-    }
+  g_clear_pointer (&module->info, (GDestroyNotify) gegl_module_info_free);
 
-  if (module->last_module_error)
-    {
-      g_free (module->last_module_error);
-      module->last_module_error = NULL;
-    }
-
-  if (module->filename)
-    {
-      g_free (module->filename);
-      module->filename = NULL;
-    }
+  g_free (module->last_module_error);
+  g_free (module->filename);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -396,9 +383,7 @@ static void
 gegl_module_error_message (GeglModule  *module,
                            const gchar *error_str)
 {
-  if (module->last_module_error)
-    g_free (module->last_module_error);
-
+  g_free (module->last_module_error);
   module->last_module_error = g_strdup (error_str);
 
   g_message (_("Module '%s' load error: %s"),
diff --git a/gegl/module/geglmoduledb.c b/gegl/module/geglmoduledb.c
index c44ff37..a844c70 100644
--- a/gegl/module/geglmoduledb.c
+++ b/gegl/module/geglmoduledb.c
@@ -118,17 +118,8 @@ gegl_module_db_finalize (GObject *object)
 {
   GeglModuleDB *db = GEGL_MODULE_DB (object);
 
-  if (db->modules)
-    {
-      g_list_free (db->modules);
-      db->modules = NULL;
-    }
-
-  if (db->load_inhibit)
-    {
-      g_free (db->load_inhibit);
-      db->load_inhibit = NULL;
-    }
+  g_list_free (db->modules);
+  g_free (db->load_inhibit);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -207,9 +198,7 @@ gegl_module_db_set_load_inhibit (GeglModuleDB *db,
 
   g_return_if_fail (GEGL_IS_MODULE_DB (db));
 
-  if (db->load_inhibit)
-    g_free (db->load_inhibit);
-
+  g_free (db->load_inhibit);
   db->load_inhibit = g_strdup (load_inhibit);
 
   for (list = db->modules; list; list = g_list_next (list))
diff --git a/gegl/operation/gegl-operation-composer.c b/gegl/operation/gegl-operation-composer.c
index 1ea6a19..82554b6 100644
--- a/gegl/operation/gegl-operation-composer.c
+++ b/gegl/operation/gegl-operation-composer.c
@@ -218,10 +218,8 @@ gegl_operation_composer_process (GeglOperation        *operation,
         success = klass->process (operation, input, aux, output, result, level);
       }
 
-      if (input)
-        g_object_unref (input);
-      if (aux)
-        g_object_unref (aux);
+      g_clear_object (&input);
+      g_clear_object (&aux);
     }
   else
     {
diff --git a/gegl/operation/gegl-operation-composer3.c b/gegl/operation/gegl-operation-composer3.c
index 92fe61e..a612fea 100644
--- a/gegl/operation/gegl-operation-composer3.c
+++ b/gegl/operation/gegl-operation-composer3.c
@@ -241,12 +241,9 @@ gegl_operation_composer3_process (GeglOperation        *operation,
         success = klass->process (operation, input, aux, aux2, output, result, level);
       }
 
-      if (input)
-        g_object_unref (input);
-      if (aux)
-        g_object_unref (aux);
-      if (aux2)
-        g_object_unref (aux2);
+      g_clear_object (&input);
+      g_clear_object (&aux);
+      g_clear_object (&aux2);
     }
   else
     {
diff --git a/gegl/operation/gegl-operation-meta.c b/gegl/operation/gegl-operation-meta.c
index 0106467..e419d2c 100644
--- a/gegl/operation/gegl-operation-meta.c
+++ b/gegl/operation/gegl-operation-meta.c
@@ -119,10 +119,9 @@ redirect_destroy (Redirect *self)
 {
   if (!self)
     return;
-  if (self->name)
-    g_free (self->name);
-  if (self->internal_name)
-    g_free (self->internal_name);
+
+  g_free (self->name);
+  g_free (self->internal_name);
   g_slice_free (Redirect, self);
 }
 
diff --git a/gegl/operation/gegl-operation-point-composer.c b/gegl/operation/gegl-operation-point-composer.c
index 37268bf..5b76044 100644
--- a/gegl/operation/gegl-operation-point-composer.c
+++ b/gegl/operation/gegl-operation-point-composer.c
@@ -153,10 +153,8 @@ gegl_operation_composer_process (GeglOperation        *operation,
     {
       success = klass->process (operation, input, aux, output, result, level);
 
-      if (input)
-        g_object_unref (input);
-      if (aux)
-        g_object_unref (aux);
+      g_clear_object (&input);
+      g_clear_object (&aux);
     }
   else
     {
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index 3f352de..e7bf2e5 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -151,12 +151,9 @@ gegl_operation_composer3_process (GeglOperation        *operation,
     {
       success = klass->process (operation, input, aux, aux2, output, result, level);
 
-      if (input)
-        g_object_unref (input);
-      if (aux)
-        g_object_unref (aux);
-      if (aux2)
-        g_object_unref (aux2);
+      g_clear_object (&input);
+      g_clear_object (&aux);
+      g_clear_object (&aux2);
     }
   else
     {
diff --git a/gegl/operation/gegl-operation.c b/gegl/operation/gegl-operation.c
index 5356420..05b4c82 100644
--- a/gegl/operation/gegl-operation.c
+++ b/gegl/operation/gegl-operation.c
@@ -634,10 +634,8 @@ gegl_operation_cl_set_kernel_args (GeglOperation *operation,
         }
     }
 
-  if (self)
-    g_free (self);
-  if (parent)
-    g_free (parent);
+  g_free (self);
+  g_free (parent);
 
   return TRUE;
 }
diff --git a/gegl/process/gegl-eval-manager.c b/gegl/process/gegl-eval-manager.c
index f97ade5..ec71e59 100644
--- a/gegl/process/gegl-eval-manager.c
+++ b/gegl/process/gegl-eval-manager.c
@@ -58,17 +58,8 @@ gegl_eval_manager_finalize (GObject *self_object)
 {
   GeglEvalManager *self = GEGL_EVAL_MANAGER (self_object);
 
-  if (self->pad_name)
-    {
-      g_free (self->pad_name);
-      self->pad_name = NULL;
-    }
-
-  if (self->traversal)
-    {
-      gegl_graph_free (self->traversal);
-      self->traversal = NULL;
-    }
+  g_free (self->pad_name);
+  g_clear_pointer (&self->traversal, (GDestroyNotify) gegl_graph_free);
 
   g_signal_handlers_disconnect_by_data (self->node, self);
 
diff --git a/gegl/process/gegl-graph-traversal.c b/gegl/process/gegl-graph-traversal.c
index 2114434..2d4c2ab 100644
--- a/gegl/process/gegl-graph-traversal.c
+++ b/gegl/process/gegl-graph-traversal.c
@@ -126,9 +126,7 @@ gegl_graph_free (GeglGraphTraversal *path)
   g_list_free (path->dfs_path);
   g_list_free (path->bfs_path);
   g_hash_table_unref (path->contexts);
-  if (path->shared_empty)
-    g_object_unref (path->shared_empty);
-
+  g_clear_object (&path->shared_empty);
   g_free (path);
 }
 
diff --git a/gegl/process/gegl-processor.c b/gegl/process/gegl-processor.c
index 2d82223..a86a8fb 100644
--- a/gegl/process/gegl-processor.c
+++ b/gegl/process/gegl-processor.c
@@ -160,35 +160,14 @@ gegl_processor_finalize (GObject *self_object)
 {
   GeglProcessor *processor = GEGL_PROCESSOR (self_object);
 
-  if (processor->context)
-    {
-      gegl_operation_context_destroy (processor->context);
-    }
-
-  if (processor->node)
-    {
-      g_object_unref (processor->node);
-    }
-
-  if (processor->real_node)
-    {
-      g_object_unref (processor->real_node);
-    }
+  g_clear_pointer (&processor->context, (GDestroyNotify) gegl_operation_context_destroy);
 
-  if (processor->input)
-    {
-      g_object_unref (processor->input);
-    }
-
-  if (processor->queued_region)
-    {
-      gegl_region_destroy (processor->queued_region);
-    }
+  g_clear_object (&processor->node);
+  g_clear_object (&processor->real_node);
+  g_clear_object (&processor->input);
 
-  if (processor->valid_region)
-    {
-      gegl_region_destroy (processor->valid_region);
-    }
+  g_clear_pointer (&processor->queued_region, (GDestroyNotify) gegl_region_destroy);
+  g_clear_pointer (&processor->valid_region, (GDestroyNotify) gegl_region_destroy);
 
   G_OBJECT_CLASS (gegl_processor_parent_class)->finalize (self_object);
 }
@@ -259,12 +238,8 @@ gegl_processor_set_node (GeglProcessor *processor,
   g_return_if_fail (GEGL_IS_NODE (node));
   g_return_if_fail (node->is_graph || GEGL_IS_OPERATION (node->operation));
 
-  if (processor->node)
-    g_object_unref (processor->node);
-  if (processor->real_node)
-    g_object_unref (processor->real_node);
-
-  processor->node = g_object_ref (node);
+  g_set_object (&processor->node, node);
+  g_clear_object (&processor->real_node);
 
   /* nodes with meta operations are also graphs and can be sinks, so
    * we don't use their output proxy */
diff --git a/gegl/property-types/gegl-audio-fragment.c b/gegl/property-types/gegl-audio-fragment.c
index a857041..9b0776e 100644
--- a/gegl/property-types/gegl-audio-fragment.c
+++ b/gegl/property-types/gegl-audio-fragment.c
@@ -55,11 +55,7 @@ static void deallocate_data (GeglAudioFragment *audio)
   int i;
   for (i = 0; i < GEGL_MAX_AUDIO_CHANNELS; i++)
   {
-    if (audio->data[i])
-    {
-      g_free (audio->data[i]);
-      audio->data[i] = NULL;
-    }
+    g_clear_pointer (&audio->data[i], g_free);
   }
 }
 
diff --git a/gegl/property-types/gegl-color.c b/gegl/property-types/gegl-color.c
index 0b65822..125cece 100644
--- a/gegl/property-types/gegl-color.c
+++ b/gegl/property-types/gegl-color.c
@@ -504,11 +504,7 @@ gegl_param_color_finalize (GParamSpec *self)
   GeglParamColor  *param_color  = GEGL_PARAM_COLOR (self);
   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GEGL_TYPE_PARAM_COLOR));
 
-  if (param_color->default_color)
-    {
-      g_object_unref (param_color->default_color);
-      param_color->default_color = NULL;
-    }
+  g_clear_object (&param_color->default_color);
 
   parent_class->finalize (self);
 }
diff --git a/gegl/property-types/gegl-curve.c b/gegl/property-types/gegl-curve.c
index 2e42155..0a58f07 100644
--- a/gegl/property-types/gegl-curve.c
+++ b/gegl/property-types/gegl-curve.c
@@ -100,13 +100,7 @@ finalize (GObject *gobject)
   GeglCurvePrivate *priv = GEGL_CURVE_GET_PRIVATE (self);
 
   g_array_free (priv->points, TRUE);
-  priv->points = NULL;
-
-  if (priv->indir != NULL)
-    {
-      g_free (priv->indir);
-      priv->indir = NULL;
-    }
+  g_free (priv->indir);
 
   G_OBJECT_CLASS (gegl_curve_parent_class)->finalize (gobject);
 }
@@ -297,10 +291,7 @@ recalculate (GeglCurvePrivate *priv)
   if (len < 2)
     return;
 
-  if (priv->indir != NULL)
-    {
-      g_free (priv->indir);
-    }
+  g_free (priv->indir);
   priv->indir = (GeglCurvePoint**) g_malloc (sizeof (GeglCurvePoint*) * len);
 
   for (i = 0; i < len; ++i)
@@ -472,11 +463,7 @@ gegl_param_curve_finalize (GParamSpec *self)
   GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (
                                                        GEGL_TYPE_PARAM_CURVE));
 
-  if (param_curve->default_curve)
-    {
-      g_object_unref (param_curve->default_curve);
-      param_curve->default_curve = NULL;
-    }
+  g_clear_object (&param_curve->default_curve);
 
   parent_class->finalize (self);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]