[cairo-commit] goocanvas/src goocanvaspath.c, 1.12, 1.13 goocanvaspath.h, 1.8, 1.9

Damon Chaplin commit at pdx.freedesktop.org
Sun May 13 04:43:16 PDT 2007


Committed by: damon

Update of /cvs/cairo/goocanvas/src
In directory kemper:/tmp/cvs-serv13841/src

Modified Files:
	goocanvaspath.c goocanvaspath.h 
Log Message:
2007-05-13  Damon Chaplin  <damon at gnome.org>

	* src/goocanvaspath.c: use a common GooCanvasPathData like the other
	standard items. This fixes a crash where the model's path_commands
	GArray was updated but the view still pointed to the old GArray
	which had been freed.

	* demo/mv-demo-paths.c: 
	* demo/demo-paths.c: added a button to test changing the path data
	dynamically.



Index: goocanvaspath.c
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspath.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- goocanvaspath.c	25 Feb 2007 17:37:57 -0000	1.12
+++ goocanvaspath.c	13 May 2007 11:43:05 -0000	1.13
@@ -99,7 +99,7 @@
 static void
 goo_canvas_path_init (GooCanvasPath *path)
 {
-  path->path_commands = NULL;
+  path->path_data = g_slice_new0 (GooCanvasPathData);
 }
 
 
@@ -163,7 +163,7 @@
   item = g_object_new (GOO_TYPE_CANVAS_PATH, NULL);
   path = (GooCanvasPath*) item;
 
-  path->path_commands = goo_canvas_parse_path_data (path_data);
+  path->path_data->path_commands = goo_canvas_parse_path_data (path_data);
 
   va_start (var_args, path_data);
   first_property = va_arg (var_args, char*);
@@ -191,10 +191,11 @@
      have been reset in dispose() and simple_data will be NULL.) */
   if (simple->simple_data)
     {
-      if (path->path_commands)
-	g_array_free (path->path_commands, TRUE);
+      if (path->path_data->path_commands)
+	g_array_free (path->path_data->path_commands, TRUE);
+      g_slice_free (GooCanvasPathData, path->path_data);
     }
-  path->path_commands = NULL;
+  path->path_data = NULL;
 
   G_OBJECT_CLASS (goo_canvas_path_parent_class)->finalize (object);
 }
@@ -202,7 +203,7 @@
 
 static void
 goo_canvas_path_get_common_property (GObject              *object,
-				     GArray               *path_commands,
+				     GooCanvasPathData    *path_data,
 				     guint                 prop_id,
 				     GValue               *value,
 				     GParamSpec           *pspec)
@@ -224,14 +225,14 @@
 {
   GooCanvasPath *path = (GooCanvasPath*) object;
 
-  goo_canvas_path_get_common_property (object, path->path_commands, prop_id,
+  goo_canvas_path_get_common_property (object, path->path_data, prop_id,
 				       value, pspec);
 }
 
 
 static void
 goo_canvas_path_set_common_property (GObject              *object,
-				     GArray              **path_commands,
+				     GooCanvasPathData    *path_data,
 				     guint                 prop_id,
 				     const GValue         *value,
 				     GParamSpec           *pspec)
@@ -239,9 +240,9 @@
   switch (prop_id)
     {
     case PROP_DATA:
-      if (*path_commands)
-	g_array_free (*path_commands, TRUE);
-      *path_commands = goo_canvas_parse_path_data (g_value_get_string (value));
+      if (path_data->path_commands)
+	g_array_free (path_data->path_commands, TRUE);
+      path_data->path_commands = goo_canvas_parse_path_data (g_value_get_string (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -265,7 +266,7 @@
       return;
     }
 
-  goo_canvas_path_set_common_property (object, &path->path_commands, prop_id,
+  goo_canvas_path_set_common_property (object, path->path_data, prop_id,
 				       value, pspec);
   goo_canvas_item_simple_changed (simple, TRUE);
 }
@@ -277,7 +278,7 @@
 {
   GooCanvasPath *path = (GooCanvasPath*) simple;
 
-  goo_canvas_create_path (path->path_commands, cr);
+  goo_canvas_create_path (path->path_data->path_commands, cr);
 }
 
 
@@ -292,12 +293,13 @@
   /* If our data was allocated, free it. */
   if (!simple->model)
     {
-      if (path->path_commands)
-	g_array_free (path->path_commands, TRUE);
+      if (path->path_data->path_commands)
+	g_array_free (path->path_data->path_commands, TRUE);
+      g_slice_free (GooCanvasPathData, path->path_data);
     }
 
   /* Now use the new model's data instead. */
-  path->path_commands = emodel->path_commands;
+  path->path_data = &emodel->path_data;
 
   /* Let the parent GooCanvasItemSimple code do the rest. */
   goo_canvas_item_simple_set_model (simple, model);
@@ -374,7 +376,7 @@
 static void
 goo_canvas_path_model_init (GooCanvasPathModel *pmodel)
 {
-  pmodel->path_commands = g_array_new (0, 0, sizeof (GooCanvasPathCommand));
+
 }
 
 
@@ -438,7 +440,7 @@
   model = g_object_new (GOO_TYPE_CANVAS_PATH_MODEL, NULL);
   pmodel = (GooCanvasPathModel*) model;
 
-  pmodel->path_commands = goo_canvas_parse_path_data (path_data);
+  pmodel->path_data.path_commands = goo_canvas_parse_path_data (path_data);
 
   va_start (var_args, path_data);
   first_property = va_arg (var_args, char*);
@@ -461,8 +463,8 @@
 {
   GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
 
-  if (pmodel->path_commands)
-    g_array_free (pmodel->path_commands, TRUE);
+  if (pmodel->path_data.path_commands)
+    g_array_free (pmodel->path_data.path_commands, TRUE);
 
   G_OBJECT_CLASS (goo_canvas_path_model_parent_class)->finalize (object);
 }
@@ -476,7 +478,7 @@
 {
   GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
 
-  goo_canvas_path_get_common_property (object, pmodel->path_commands, prop_id,
+  goo_canvas_path_get_common_property (object, &pmodel->path_data, prop_id,
 				       value, pspec);
 }
 
@@ -489,7 +491,7 @@
 {
   GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
 
-  goo_canvas_path_set_common_property (object, &pmodel->path_commands, prop_id,
+  goo_canvas_path_set_common_property (object, &pmodel->path_data, prop_id,
 				       value, pspec);
   g_signal_emit_by_name (pmodel, "changed", TRUE);
 }

Index: goocanvaspath.h
===================================================================
RCS file: /cvs/cairo/goocanvas/src/goocanvaspath.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- goocanvaspath.h	15 Feb 2007 14:18:50 -0000	1.8
+++ goocanvaspath.h	13 May 2007 11:43:05 -0000	1.9
@@ -13,6 +13,15 @@
 G_BEGIN_DECLS
 
 
+/* This is the data used by both model and view classes. */
+typedef struct _GooCanvasPathData   GooCanvasPathData;
+struct _GooCanvasPathData
+{
+  /* An array of GooCanvasPathCommand. */
+  GArray *path_commands;
+};
+
+
 #define GOO_TYPE_CANVAS_PATH            (goo_canvas_path_get_type ())
 #define GOO_CANVAS_PATH(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_PATH, GooCanvasPath))
 #define GOO_CANVAS_PATH_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_PATH, GooCanvasPathClass))
@@ -33,8 +42,7 @@
 {
   GooCanvasItemSimple parent;
 
-  /* An array of GooCanvasPathCommand. */
-  GArray *path_commands;
+  GooCanvasPathData *path_data;
 };
 
 struct _GooCanvasPathClass
@@ -79,8 +87,7 @@
 {
   GooCanvasItemModelSimple parent_object;
 
-  /* An array of GooCanvasPathCommand. */
-  GArray *path_commands;
+  GooCanvasPathData path_data;
 };
 
 struct _GooCanvasPathModelClass



More information about the cairo-commit mailing list