New constness changes.



Hi all,

while looking at Bug http://bugs.gnome.org/db/82/8267.html, I noticed, that in
fact GSearchFunc should be declared as gint (*func)(gconstpointer a,
gconstpointer b), just like GCompareFunc. So I think, we can just drop
GSearchFunc for GLib 1-4 in favor of GCompareFunc and make the right
parameters in g_tree_remove, g_tree_lookup and g_tree_search const. Appended
is a patch, that does this. This patch also makes the 'value' argument to
g_cache_remove a gconstpointer.

If no-one complains, I'll check that in after Easter.

Bye,
Sebastian
-- 
Sebastian Wilhelmi                   |            här ovanför alla molnen
mailto:wilhelmi@ira.uka.de           |     är himmlen så förunderligt blå
http://goethe.ira.uka.de/~wilhelmi   |
Index: gcache.c
===================================================================
RCS file: /cvs/gnome/glib/gcache.c,v
retrieving revision 1.7
diff -u -b -B -r1.7 gcache.c
--- gcache.c	1999/10/31 23:03:45	1.7
+++ gcache.c	2000/04/19 11:51:57
@@ -144,7 +144,7 @@
 
 void
 g_cache_remove (GCache   *cache,
-		gpointer  value)
+		gconstpointer  value)
 {
   GRealCache *rcache;
   GCacheNode *node;
Index: glib.h
===================================================================
RCS file: /cvs/gnome/glib/glib.h,v
retrieving revision 1.164
diff -u -b -B -r1.164 glib.h
--- glib.h	2000/04/19 09:29:19	1.164
+++ glib.h	2000/04/19 11:51:59
@@ -817,8 +817,6 @@
 						 gpointer	data);
 typedef void		(*GNodeForeachFunc)	(GNode	       *node,
 						 gpointer	data);
-typedef gint		(*GSearchFunc)		(gpointer	key,
-						 gpointer	data);
 typedef void		(*GScannerMsgFunc)	(GScanner      *scanner,
 						 gchar	       *message,
 						 gint		error);
@@ -1118,7 +1116,7 @@
 gpointer g_cache_insert	       (GCache		  *cache,
 				gpointer	   key);
 void	 g_cache_remove	       (GCache		  *cache,
-				gpointer	   value);
+				gconstpointer	   value);
 void	 g_cache_key_foreach   (GCache		  *cache,
 				GHFunc		   func,
 				gpointer	   user_data);
@@ -1135,16 +1133,16 @@
 			  gpointer	 key,
 			  gpointer	 value);
 void	 g_tree_remove	 (GTree		*tree,
-			  gpointer	 key);
+			  gconstpointer	 key);
 gpointer g_tree_lookup	 (GTree		*tree,
-			  gpointer	 key);
+			  gconstpointer	 key);
 void	 g_tree_traverse (GTree		*tree,
 			  GTraverseFunc	 traverse_func,
 			  GTraverseType	 traverse_type,
 			  gpointer	 data);
 gpointer g_tree_search	 (GTree		*tree,
-			  GSearchFunc	 search_func,
-			  gpointer	 data);
+			  GCompareFunc	 search_func,
+			  gconstpointer	 data);
 gint	 g_tree_height	 (GTree		*tree);
 gint	 g_tree_nnodes	 (GTree		*tree);
 
Index: gmem.c
===================================================================
RCS file: /cvs/gnome/glib/gmem.c,v
retrieving revision 1.19
diff -u -b -B -r1.19 gmem.c
--- gmem.c	2000/04/17 13:23:27	1.19
+++ gmem.c	2000/04/19 11:51:59
@@ -126,10 +126,10 @@
 
 static gulong g_mem_chunk_compute_size (gulong    size,
 					gulong    min_size);
-static gint   g_mem_chunk_area_compare (GMemArea *a,
-					GMemArea *b);
-static gint   g_mem_chunk_area_search  (GMemArea *a,
-					gchar    *addr);
+static gint   g_mem_chunk_area_compare (gconstpointer a,
+					gconstpointer b);
+static gint   g_mem_chunk_area_search  (gconstpointer a,
+					gconstpointer addr);
 
 
 /* here we can't use StaticMutexes, as they depend upon a working
@@ -575,8 +575,7 @@
       rmem_chunk->free_atoms = rmem_chunk->free_atoms->next;
       
       /* Determine which area this piece of memory is allocated from */
-      temp_area = g_tree_search (rmem_chunk->mem_tree,
-				 (GSearchFunc) g_mem_chunk_area_search,
+      temp_area = g_tree_search (rmem_chunk->mem_tree, g_mem_chunk_area_search,
 				 mem);
       
       /* If the area has been marked, then it is being destroyed.
@@ -735,8 +734,7 @@
       free_atom->next = rmem_chunk->free_atoms;
       rmem_chunk->free_atoms = free_atom;
       
-      temp_area = g_tree_search (rmem_chunk->mem_tree,
-				 (GSearchFunc) g_mem_chunk_area_search,
+      temp_area = g_tree_search (rmem_chunk->mem_tree, g_mem_chunk_area_search,
 				 mem);
       
       temp_area->allocated -= 1;
@@ -775,7 +773,7 @@
 	  mem = (gpointer) temp_free_atom;
 	  
 	  mem_area = g_tree_search (rmem_chunk->mem_tree,
-				    (GSearchFunc) g_mem_chunk_area_search,
+				    g_mem_chunk_area_search,
 				    mem);
 	  
           /* If this mem area is marked for destruction then delete the
@@ -938,9 +936,12 @@
 }
 
 static gint
-g_mem_chunk_area_compare (GMemArea *a,
-			  GMemArea *b)
+g_mem_chunk_area_compare (gconstpointer a_in,
+			  gconstpointer b_in)
 {
+  const GMemArea *a = a_in;
+  const GMemArea *b = b_in;
+  
   if (a->mem > b->mem)
     return 1;
   else if (a->mem < b->mem)
@@ -949,9 +950,11 @@
 }
 
 static gint
-g_mem_chunk_area_search (GMemArea *a,
-			 gchar    *addr)
+g_mem_chunk_area_search (gconstpointer a_in,
+			 gconstpointer addr_in)
 {
+  const GMemArea *a = a_in;
+  const gchar *addr = addr_in;
   if (a->mem <= addr)
     {
       if (addr < &a->mem[a->index])
Index: gtree.c
===================================================================
RCS file: /cvs/gnome/glib/gtree.c,v
retrieving revision 1.11
diff -u -b -B -r1.11 gtree.c
--- gtree.c	2000/04/17 13:23:27	1.11
+++ gtree.c	2000/04/19 11:52:00
@@ -60,7 +60,7 @@
 						     gint           *inserted);
 static GTreeNode* g_tree_node_remove                (GTreeNode      *node,
 						     GCompareFunc    compare,
-						     gpointer        key);
+						     gconstpointer   key);
 static GTreeNode* g_tree_node_balance               (GTreeNode      *node);
 static GTreeNode* g_tree_node_remove_leftmost       (GTreeNode      *node,
 						     GTreeNode     **leftmost);
@@ -70,7 +70,7 @@
 						     gint            old_balance);
 static gpointer   g_tree_node_lookup                (GTreeNode      *node,
 						     GCompareFunc    compare,
-						     gpointer        key);
+						     gconstpointer   key);
 static gint       g_tree_node_count                 (GTreeNode      *node);
 static gint       g_tree_node_pre_order             (GTreeNode      *node,
 						     GTraverseFunc   traverse_func,
@@ -82,8 +82,8 @@
 						     GTraverseFunc   traverse_func,
 						     gpointer        data);
 static gpointer   g_tree_node_search                (GTreeNode      *node,
-						     GSearchFunc     search_func,
-						     gpointer        data);
+						     GCompareFunc    search_func,
+						     gconstpointer   data);
 static gint       g_tree_node_height                (GTreeNode      *node);
 static GTreeNode* g_tree_node_rotate_left           (GTreeNode      *node);
 static GTreeNode* g_tree_node_rotate_right          (GTreeNode      *node);
@@ -196,7 +196,7 @@
 
 void
 g_tree_remove (GTree    *tree,
-	       gpointer  key)
+	       gconstpointer  key)
 {
   GRealTree *rtree;
 
@@ -209,7 +209,7 @@
 
 gpointer
 g_tree_lookup (GTree    *tree,
-	       gpointer  key)
+	       gconstpointer  key)
 {
   GRealTree *rtree;
 
@@ -257,8 +257,8 @@
 
 gpointer
 g_tree_search (GTree       *tree,
-	       GSearchFunc  search_func,
-	       gpointer     data)
+	       GCompareFunc      search_func,
+	       gconstpointer     data)
 {
   GRealTree *rtree;
 
@@ -373,7 +373,7 @@
 static GTreeNode*
 g_tree_node_remove (GTreeNode    *node,
 		    GCompareFunc  compare,
-		    gpointer      key)
+		    gconstpointer  key)
 {
   GTreeNode *new_root;
   gint old_balance;
@@ -505,7 +505,7 @@
 static gpointer
 g_tree_node_lookup (GTreeNode    *node,
 		    GCompareFunc  compare,
-		    gpointer      key)
+		    gconstpointer  key)
 {
   gint cmp;
 
@@ -609,8 +609,8 @@
 
 static gpointer
 g_tree_node_search (GTreeNode   *node,
-		    GSearchFunc  search_func,
-		    gpointer     data)
+		    GCompareFunc   search_func,
+		    gconstpointer  data)
 {
   gint dir;
 


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