[gegl] Don't use a static buffer for node_get_debug_name (bug 723309)



commit 5a71c29c973a9aa6fffcdaf471b30b66074e0a32
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Fri Jan 31 00:32:07 2014 -0800

    Don't use a static buffer for node_get_debug_name (bug 723309)

 gegl/graph/gegl-node.c |   52 +++++++++++++++++++++++++++++++----------------
 1 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/gegl/graph/gegl-node.c b/gegl/graph/gegl-node.c
index e2adf72..937f503 100644
--- a/gegl/graph/gegl-node.c
+++ b/gegl/graph/gegl-node.c
@@ -69,6 +69,7 @@ struct _GeglNodePrivate
   GSList          *children;  /*  used for children */
   GeglNode        *parent;
   gchar           *name;
+  gchar           *debug_name;
   GeglEvalManager *eval_manager;
 };
 
@@ -111,6 +112,8 @@ static void            gegl_node_property_changed         (GObject       *gobjec
                                                            GParamSpec    *arg1,
                                                            gpointer       user_data);
 
+static void            gegl_node_update_debug_name        (GeglNode *node);
+
 
 G_DEFINE_TYPE_WITH_CODE (GeglNode, gegl_node, G_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (GEGL_TYPE_VISITABLE,
@@ -274,6 +277,12 @@ gegl_node_finalize (GObject *gobject)
     {
       g_free (self->priv->name);
     }
+
+  if (self->priv->debug_name)
+    {
+      g_free (self->priv->debug_name);
+    }
+
   g_mutex_clear (&self->mutex);
 
   G_OBJECT_CLASS (gegl_node_parent_class)->finalize (gobject);
@@ -1213,6 +1222,9 @@ gegl_node_set_operation_object (GeglNode      *self,
 
   g_signal_connect (G_OBJECT (operation), "notify", G_CALLBACK (gegl_node_invalidate_have_rect), self);
   g_signal_connect (G_OBJECT (operation), "notify", G_CALLBACK (gegl_node_property_changed), self);
+
+  gegl_node_update_debug_name (self);
+
   gegl_node_property_changed (G_OBJECT (operation), (GParamSpec *) self, self);
 }
 
@@ -1495,31 +1507,32 @@ gegl_node_get_gegl_operation (GeglNode *node)
   return node->operation;
 }
 
-const gchar *
-gegl_node_get_debug_name (GeglNode *node)
+static void
+gegl_node_update_debug_name (GeglNode *node)
 {
-  static gchar  ret_buf[512];
+  const gchar  *name = gegl_node_get_name (node);
+  const gchar  *operation = gegl_node_get_operation (node);
+  gchar        *new_name = NULL;
 
-  const gchar  *name;
-  const gchar  *operation;
-
-  g_return_val_if_fail (GEGL_IS_NODE (node), NULL);
+  g_return_if_fail (GEGL_IS_NODE (node));
 
-  name      = gegl_node_get_name (node);
-  operation = gegl_node_get_operation (node);
+  if (node->priv->debug_name)
+    g_free (node->priv->debug_name);
 
   if (name && *name)
-    {
-      g_snprintf (ret_buf, sizeof (ret_buf),
-                  "%s '%s' %p", operation ? operation : "(none)", name, node);
-    }
+    new_name = g_strdup_printf ("%s '%s' %p", operation ? operation : "(none)", name, node);
   else
-    {
-      g_snprintf (ret_buf, sizeof (ret_buf),
-                  "%s %p", operation ? operation : "(none)", node);
-    }
+    new_name = g_strdup_printf ("%s %p", operation ? operation : "(none)", node);
 
-  return ret_buf;
+  node->priv->debug_name = new_name;
+}
+
+const gchar *
+gegl_node_get_debug_name (GeglNode *node)
+{
+  g_return_val_if_fail (GEGL_IS_NODE (node), NULL);
+
+  return node->priv->debug_name;
 }
 
 GeglNode *
@@ -1821,7 +1834,10 @@ gegl_node_set_name (GeglNode    *self,
 
   if (self->priv->name)
     g_free (self->priv->name);
+
   self->priv->name = g_strdup (name);
+
+  gegl_node_update_debug_name (self);
 }
 
 void


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