[grits] Remove some unused API cruft



commit fca66641b8505a51767d0c249194f25da0823716
Author: Andy Spencer <andy753421 gmail com>
Date:   Wed Dec 26 10:41:15 2012 +0000

    Remove some unused API cruft
    
    This also prevent errors if an object is removed from the viewer twice.
    For example:
    
      - The viewer is destroyed
      - The opengl dispose function removes all objects
      - The application frees plugins
      - The plugins dispose function attempts to remove
        an already removed the object

 src/grits-opengl.c |   14 +++++---------
 src/grits-viewer.c |   22 ++++++++++------------
 src/grits-viewer.h |    8 ++++----
 3 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/src/grits-opengl.c b/src/grits-opengl.c
index 709e6ed..49a9c53 100644
--- a/src/grits-opengl.c
+++ b/src/grits-opengl.c
@@ -593,7 +593,7 @@ static void _objects_free(gpointer value, gpointer _)
 	g_free(level);
 }
 
-static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
+static void grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
 		gint num, gboolean sort)
 {
 	g_assert(GRITS_IS_OPENGL(_opengl));
@@ -617,26 +617,22 @@ static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
 	if (list->next)
 		list->next->prev = link;
 	list->next = link;
+	object->ref = link;
 	g_mutex_unlock(&opengl->objects_lock);
-	return link;
 }
 
-static GritsObject *grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
+void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
 {
 	g_assert(GRITS_IS_OPENGL(_opengl));
 	GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
-	GList *link = object->ref;
 	g_mutex_lock(&opengl->objects_lock);
+	GList *link = object->ref;
 	/* Just unlink and free it, link->prev is assured */
 	link->prev->next = link->next;
 	if (link->next)
 		link->next->prev = link->prev;
-	g_mutex_unlock(&opengl->objects_lock);
-	object->ref    = NULL;
-	object->viewer = NULL;
 	g_free(link);
-	g_object_unref(object);
-	return object;
+	g_mutex_unlock(&opengl->objects_lock);
 }
 
 /****************
diff --git a/src/grits-viewer.c b/src/grits-viewer.c
index 79765e1..52fbaf9 100644
--- a/src/grits-viewer.c
+++ b/src/grits-viewer.c
@@ -548,37 +548,35 @@ void grits_viewer_set_height_func(GritsViewer *viewer, GritsBounds *bounds,
  *
  * The viewer steals the objects reference. Call g_object_ref if you plan on
  * holding a reference as well.
- *
- * Returns: a handle to be pass to grits_viewer_remove()
  */
-gpointer grits_viewer_add(GritsViewer *viewer, GritsObject *object,
+void grits_viewer_add(GritsViewer *viewer, GritsObject *object,
 		gint level, gboolean sort)
 {
 	GritsViewerClass *klass = GRITS_VIEWER_GET_CLASS(viewer);
 	if (!klass->add)
 		g_warning("GritsViewer: add - Unimplemented");
-	object->ref    = klass->add(viewer, object, level, sort);
 	object->viewer = viewer;
-	return object;
+	klass->add(viewer, object, level, sort);
 }
 
 /**
  * grits_viewer_remove:
  * @viewer: the viewer
- * @ref:    the handle obtained from grits_viewer_add()
- *
- * Remove an object from the viewer. The objects reference count is decremented
- * prior to being removed.
+ * @object: the object to remove
  *
- * Returns: the #GritsObject referenced by the handle
+ * Remove an object from the viewer.
+ * The objects reference count is decremented.
  */
-GritsObject *grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
+void grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
 {
 	GritsViewerClass *klass = GRITS_VIEWER_GET_CLASS(viewer);
+	if (!object->viewer)
+		return;
 	if (!klass->remove)
 		g_warning("GritsViewer: remove - Unimplemented");
+	object->viewer = NULL;
 	klass->remove(viewer, object);
-	return object;
+	g_object_unref(object);
 }
 
 /****************
diff --git a/src/grits-viewer.h b/src/grits-viewer.h
index 8991cb5..4b04e3f 100644
--- a/src/grits-viewer.h
+++ b/src/grits-viewer.h
@@ -140,9 +140,9 @@ struct _GritsViewerClass {
 	                          GritsHeightFunc height_func, gpointer user_data,
 	                          gboolean update);
 
-	gpointer (*add)          (GritsViewer *viewer, GritsObject *object,
+	void (*add)              (GritsViewer *viewer, GritsObject *object,
 	                          gint level, gboolean sort);
-	GritsObject *(*remove)   (GritsViewer *viewer, GritsObject *object);
+	void (*remove)           (GritsViewer *viewer, GritsObject *object);
 };
 
 GType grits_viewer_get_type(void);
@@ -183,8 +183,8 @@ void grits_viewer_set_height_func(GritsViewer *viewer, GritsBounds *bounds,
 		GritsHeightFunc height_func, gpointer user_data,
 		gboolean update);
 
-gpointer grits_viewer_add(GritsViewer *viewer, GritsObject *object,
+void grits_viewer_add(GritsViewer *viewer, GritsObject *object,
 		gint level, gboolean sort);
-GritsObject *grits_viewer_remove(GritsViewer *viewer, GritsObject *object);
+void grits_viewer_remove(GritsViewer *viewer, GritsObject *object);
 
 #endif



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