[gc-improv] (libiberty) Finish splay-tree conversion

View: New views
1 Messages — Rating Filter:   Alert me  

[gc-improv] (libiberty) Finish splay-tree conversion

by Laurynas Biveinis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quite embarrassingly, in May I started conversion of splay trees to
typed allocators, did not finish it, but for some reason committed
half-finished code (only interface done) to gc-improv. I received a
reminder by a bootstrap failure on sparc64-unknown-linux-gnu.

The conversion itself is the same as with hash tables - if the
implementation of data structure allocates more than one type of
objects (in this case splay tree itself and its nodes), then
allocators for each of those types need to be provided.

With this patch, bootstrap on sparc proceeds beyond the point of
failure, so I am committing it now to gc-improv. Further failures, if
any, will be treated with separate patches.

include:

2009-11-03  Laurynas Biveinis  <laurynas.biveinis@...>

        * splay-tree.h (splay_tree_s): Rename allocate to allocate_node.

libiberty:

2009-11-03  Laurynas Biveinis  <laurynas.biveinis@...>

        * splay-tree.c (splay_tree_new_with_allocator): Call
        splay_tree_with_separate_allocators.
        (splay_tree_new_with_separate_allocators): Move former
        splay_tree_new_with_allocator implementation here.



--
Laurynas

[fix-splay-tree.patch]

Index: include/splay-tree.h
===================================================================
--- include/splay-tree.h (revision 153781)
+++ include/splay-tree.h (working copy)
@@ -119,9 +119,13 @@
   /* The deallocate-value function.  NULL if no cleanup is necessary.  */
   splay_tree_delete_value_fn delete_value;
 
-  /* Allocate/free functions, and a data pointer to pass to them.  */
-  splay_tree_allocate_fn allocate;
+  /* Node allocate function.  Takes allocate_data as a parameter. */
+  splay_tree_allocate_fn allocate_node;
+
+  /* Free function for nodes and trees.  Takes allocate_data as a parameter.  */
   splay_tree_deallocate_fn deallocate;
+
+  /* Parameter for allocate/free functions.  */
   void * GTY((skip)) allocate_data;
 };
 
Index: libiberty/splay-tree.c
===================================================================
--- libiberty/splay-tree.c (revision 153781)
+++ libiberty/splay-tree.c (working copy)
@@ -265,15 +265,11 @@
                                splay_tree_deallocate_fn deallocate_fn,
                                void *allocate_data)
 {
-  splay_tree sp = (splay_tree) (*allocate_fn) (sizeof (struct splay_tree_s),
+  splay_tree sp
+    = splay_tree_new_with_separate_allocators (compare_fn, delete_key_fn,
+                                               delete_value_fn, allocate_fn,
+                                               allocate_fn, deallocate_fn,
                                                allocate_data);
-  sp->root = 0;
-  sp->comp = compare_fn;
-  sp->delete_key = delete_key_fn;
-  sp->delete_value = delete_value_fn;
-  sp->allocate = allocate_fn;
-  sp->deallocate = deallocate_fn;
-  sp->allocate_data = allocate_data;
 
   return sp;
 }
@@ -287,10 +283,18 @@
  splay_tree_deallocate_fn deallocate_fn,
  void * allocate_data)
 {
-  splay_tree sp = splay_tree_new_with_allocator (compare_fn, delete_key_fn,
- delete_value_fn,
- tree_allocate_fn,
- deallocate_fn, allocate_data);
+  splay_tree sp = (splay_tree) (*tree_allocate_fn)
+    (sizeof (struct splay_tree_s), allocate_data);
+
+  sp->root = 0;
+  sp->comp = compare_fn;
+  sp->delete_key = delete_key_fn;
+  sp->delete_value = delete_value_fn;
+  sp->allocate_node = node_allocate_fn;
+  sp->deallocate = deallocate_fn;
+  sp->allocate_data = allocate_data;
+
+  return sp;
 }
 
 /* Deallocate SP.  */
@@ -330,8 +334,8 @@
       splay_tree_node node;
       
       node = ((splay_tree_node)
-              (*sp->allocate) (sizeof (struct splay_tree_node_s),
-                               sp->allocate_data));
+              (*sp->allocate_node) (sizeof (struct splay_tree_node_s),
+                                    sp->allocate_data));
       node->key = key;
       node->value = value;