From 219a461e6c1b65b12a6b08ba167560c00dd2174d Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Thu, 10 Jun 2010 18:30:24 +0000 Subject: merge from gcc --- include/ChangeLog | 9 +++++++ include/hashtab.h | 5 +++- include/splay-tree.h | 15 +++++++++-- libiberty/ChangeLog | 12 +++++++++ libiberty/functions.texi | 39 +++++++++++++++++++++++++++- libiberty/hashtab.c | 67 +++++++++++++++++++++++++++++++++++------------- libiberty/splay-tree.c | 55 ++++++++++++++++++++++++++++++++++----- 7 files changed, 173 insertions(+), 29 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index bfe4f3c..97e8da5 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,12 @@ +2010-06-08 Laurynas Biveinis + + * splay-tree.h: Update copyright years. + (splay_tree_s): Document fields. + (splay_tree_new_typed_alloc): New. + + * hashtab.h: Update copyright years. + (htab_create_typed_alloc): New. + 2010-06-10 Tristan Gingold * dwarf2.h (enum dwarf_tag): Add DW_TAG_HP_Bliss_field and diff --git a/include/hashtab.h b/include/hashtab.h index 1cd406d..4bb65d6 100644 --- a/include/hashtab.h +++ b/include/hashtab.h @@ -1,5 +1,5 @@ /* An expandable hash tables datatype. - Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2009 + Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2009, 2010 Free Software Foundation, Inc. Contributed by Vladimir Makarov (vmakarov@cygnus.com). @@ -157,6 +157,9 @@ extern htab_t htab_create_alloc_ex (size_t, htab_hash, void *, htab_alloc_with_arg, htab_free_with_arg); +extern htab_t htab_create_typed_alloc (size_t, htab_hash, htab_eq, htab_del, + htab_alloc, htab_alloc, htab_free); + /* Backward-compatibility functions. */ extern htab_t htab_create (size_t, htab_hash, htab_eq, htab_del); extern htab_t htab_try_create (size_t, htab_hash, htab_eq, htab_del); diff --git a/include/splay-tree.h b/include/splay-tree.h index 57a96c4..480b2c43 100644 --- a/include/splay-tree.h +++ b/include/splay-tree.h @@ -1,5 +1,5 @@ /* A splay-tree datatype. - Copyright 1998, 1999, 2000, 2002, 2005, 2007, 2009 + Copyright 1998, 1999, 2000, 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). @@ -119,9 +119,13 @@ struct GTY(()) splay_tree_s { /* 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. */ + /* Node allocate function. Takes allocate_data as a parameter. */ splay_tree_allocate_fn allocate; + + /* 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; }; @@ -136,6 +140,13 @@ extern splay_tree splay_tree_new_with_allocator (splay_tree_compare_fn, splay_tree_allocate_fn, splay_tree_deallocate_fn, void *); +extern splay_tree splay_tree_new_typed_alloc (splay_tree_compare_fn, + splay_tree_delete_key_fn, + splay_tree_delete_value_fn, + splay_tree_allocate_fn, + splay_tree_allocate_fn, + splay_tree_deallocate_fn, + void *); extern void splay_tree_delete (splay_tree); extern splay_tree_node splay_tree_insert (splay_tree, splay_tree_key, diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 4c0cba8..ea95ca5 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -9,6 +9,18 @@ call. * testsuite/demangle-expected: Add a test for this. +2010-06-08 Laurynas Biveinis + + * splay-tree.c: Update copyright years. + (splay_tree_new_typed_alloc): New. + (splay_tree_new_with_allocator): Use it. + + * hashtab.c: Update copyright years. + (htab_create_typed_alloc): New. + (htab_create_alloc): Use it. + + * functions.texi: Regenerate. + 2010-06-03 Joern Rennecke Ralf Wildenhues diff --git a/libiberty/functions.texi b/libiberty/functions.texi index 72ca56c..d9fef8c 100644 --- a/libiberty/functions.texi +++ b/libiberty/functions.texi @@ -3,7 +3,7 @@ @c Edit the *.c files, configure with --enable-maintainer-mode, @c run 'make stamp-functions' and gather-docs will build a new copy. -@c safe-ctype.c:25 +@c splay-tree.c:277 @defvr Extension HOST_CHARSET This macro indicates the basic character set and encoding used by the host: more precisely, the encoding used for character constants in @@ -24,6 +24,25 @@ The host character set is some variant of EBCDIC. (Only one of the nineteen EBCDIC varying characters is tested; exercise caution.) @end ftable @end defvr +@deftypefn Supplemental splay_tree splay_tree_new_with_typed_alloc +(splay_tree_compare_fn @var{compare_fn}, +splay_tree_delete_key_fn @var{delete_key_fn}, +splay_tree_delete_value_fn @var{delete_value_fn}, +splay_tree_allocate_fn @var{tree_allocate_fn}, +splay_tree_allocate_fn @var{node_allocate_fn}, +splay_tree_deallocate_fn @var{deallocate_fn}, +void * @var{allocate_data}) + +This function creates a splay tree that uses two different allocators +@var{tree_allocate_fn} and @var{node_allocate_fn} to use for allocating the +tree itself and its nodes respectively. This is useful when variables of +different types need to be allocated with different allocators. + +The splay tree will use @var{compare_fn} to compare nodes, +@var{delete_key_fn} to deallocate keys, and @var{delete_value_fn} to +deallocate values. + +@end deftypefn @c alloca.c:26 @deftypefn Replacement void* alloca (size_t @var{size}) @@ -477,6 +496,24 @@ systems. @end deftypefn +@c hashtab.c:336 +@deftypefn Supplemental htab_t htab_create_typed_alloc (size_t @var{size}, +htab_hash @var{hash_f}, htab_eq @var{eq_f}, htab_del @var{del_f}, +htab_alloc @var{alloc_tab_f}, htab_alloc @var{alloc_f}, +htab_free @var{free_f}) + +This function creates a hash table that uses two different allocators +@var{alloc_tab_f} and @var{alloc_f} to use for allocating the table itself +and its entries respectively. This is useful when variables of different +types need to be allocated with different allocators. + +The created hash table is slightly larger than @var{size} and it is +initially empty (all the hash table entries are @code{HTAB_EMPTY_ENTRY}). +The function returns the created hash table, or @code{NULL} if memory +allocation fails. + +@end deftypefn + @c index.c:5 @deftypefn Supplemental char* index (char *@var{s}, int @var{c}) diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c index 8c89bfc..359e3ea 100644 --- a/libiberty/hashtab.c +++ b/libiberty/hashtab.c @@ -1,5 +1,5 @@ /* An expandable hash tables datatype. - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 Free Software Foundation, Inc. Contributed by Vladimir Makarov (vmakarov@cygnus.com). @@ -291,20 +291,33 @@ htab_t htab_create_alloc (size_t size, htab_hash hash_f, htab_eq eq_f, htab_del del_f, htab_alloc alloc_f, htab_free free_f) { + return htab_create_typed_alloc (size, hash_f, eq_f, del_f, alloc_f, alloc_f, + free_f); +} + +/* As above, but uses the variants of ALLOC_F and FREE_F which accept + an extra argument. */ + +htab_t +htab_create_alloc_ex (size_t size, htab_hash hash_f, htab_eq eq_f, + htab_del del_f, void *alloc_arg, + htab_alloc_with_arg alloc_f, + htab_free_with_arg free_f) +{ htab_t result; unsigned int size_prime_index; size_prime_index = higher_prime_index (size); size = prime_tab[size_prime_index].prime; - result = (htab_t) (*alloc_f) (1, sizeof (struct htab)); + result = (htab_t) (*alloc_f) (alloc_arg, 1, sizeof (struct htab)); if (result == NULL) return NULL; - result->entries = (PTR *) (*alloc_f) (size, sizeof (PTR)); + result->entries = (PTR *) (*alloc_f) (alloc_arg, size, sizeof (PTR)); if (result->entries == NULL) { if (free_f != NULL) - (*free_f) (result); + (*free_f) (alloc_arg, result); return NULL; } result->size = size; @@ -312,19 +325,37 @@ htab_create_alloc (size_t size, htab_hash hash_f, htab_eq eq_f, result->hash_f = hash_f; result->eq_f = eq_f; result->del_f = del_f; - result->alloc_f = alloc_f; - result->free_f = free_f; + result->alloc_arg = alloc_arg; + result->alloc_with_arg_f = alloc_f; + result->free_with_arg_f = free_f; return result; } -/* As above, but use the variants of alloc_f and free_f which accept - an extra argument. */ +/* + +@deftypefn Supplemental htab_t htab_create_typed_alloc (size_t @var{size}, +htab_hash @var{hash_f}, htab_eq @var{eq_f}, htab_del @var{del_f}, +htab_alloc @var{alloc_tab_f}, htab_alloc @var{alloc_f}, +htab_free @var{free_f}) + +This function creates a hash table that uses two different allocators +@var{alloc_tab_f} and @var{alloc_f} to use for allocating the table itself +and its entries respectively. This is useful when variables of different +types need to be allocated with different allocators. + +The created hash table is slightly larger than @var{size} and it is +initially empty (all the hash table entries are @code{HTAB_EMPTY_ENTRY}). +The function returns the created hash table, or @code{NULL} if memory +allocation fails. + +@end deftypefn + +*/ htab_t -htab_create_alloc_ex (size_t size, htab_hash hash_f, htab_eq eq_f, - htab_del del_f, void *alloc_arg, - htab_alloc_with_arg alloc_f, - htab_free_with_arg free_f) +htab_create_typed_alloc (size_t size, htab_hash hash_f, htab_eq eq_f, + htab_del del_f, htab_alloc alloc_tab_f, + htab_alloc alloc_f, htab_free free_f) { htab_t result; unsigned int size_prime_index; @@ -332,14 +363,14 @@ htab_create_alloc_ex (size_t size, htab_hash hash_f, htab_eq eq_f, size_prime_index = higher_prime_index (size); size = prime_tab[size_prime_index].prime; - result = (htab_t) (*alloc_f) (alloc_arg, 1, sizeof (struct htab)); + result = (htab_t) (*alloc_tab_f) (1, sizeof (struct htab)); if (result == NULL) return NULL; - result->entries = (PTR *) (*alloc_f) (alloc_arg, size, sizeof (PTR)); + result->entries = (PTR *) (*alloc_f) (size, sizeof (PTR)); if (result->entries == NULL) { if (free_f != NULL) - (*free_f) (alloc_arg, result); + (*free_f) (result); return NULL; } result->size = size; @@ -347,12 +378,12 @@ htab_create_alloc_ex (size_t size, htab_hash hash_f, htab_eq eq_f, result->hash_f = hash_f; result->eq_f = eq_f; result->del_f = del_f; - result->alloc_arg = alloc_arg; - result->alloc_with_arg_f = alloc_f; - result->free_with_arg_f = free_f; + result->alloc_f = alloc_f; + result->free_f = free_f; return result; } + /* Update the function pointers and allocation parameter in the htab_t. */ void diff --git a/libiberty/splay-tree.c b/libiberty/splay-tree.c index d7ed868..bf1a0f3 100644 --- a/libiberty/splay-tree.c +++ b/libiberty/splay-tree.c @@ -1,5 +1,6 @@ /* A splay-tree datatype. - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2009, + 2010 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). This file is part of GNU CC. @@ -265,13 +266,53 @@ splay_tree_new_with_allocator (splay_tree_compare_fn compare_fn, splay_tree_deallocate_fn deallocate_fn, void *allocate_data) { - splay_tree sp = (splay_tree) (*allocate_fn) (sizeof (struct splay_tree_s), - allocate_data); + return + splay_tree_new_typed_alloc (compare_fn, delete_key_fn, delete_value_fn, + allocate_fn, allocate_fn, deallocate_fn, + allocate_data); +} + +/* + +@deftypefn Supplemental splay_tree splay_tree_new_with_typed_alloc +(splay_tree_compare_fn @var{compare_fn}, +splay_tree_delete_key_fn @var{delete_key_fn}, +splay_tree_delete_value_fn @var{delete_value_fn}, +splay_tree_allocate_fn @var{tree_allocate_fn}, +splay_tree_allocate_fn @var{node_allocate_fn}, +splay_tree_deallocate_fn @var{deallocate_fn}, +void * @var{allocate_data}) + +This function creates a splay tree that uses two different allocators +@var{tree_allocate_fn} and @var{node_allocate_fn} to use for allocating the +tree itself and its nodes respectively. This is useful when variables of +different types need to be allocated with different allocators. + +The splay tree will use @var{compare_fn} to compare nodes, +@var{delete_key_fn} to deallocate keys, and @var{delete_value_fn} to +deallocate values. + +@end deftypefn + +*/ + +splay_tree +splay_tree_new_typed_alloc (splay_tree_compare_fn compare_fn, + splay_tree_delete_key_fn delete_key_fn, + splay_tree_delete_value_fn delete_value_fn, + splay_tree_allocate_fn tree_allocate_fn, + splay_tree_allocate_fn node_allocate_fn, + splay_tree_deallocate_fn deallocate_fn, + void * 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 = allocate_fn; + sp->allocate = node_allocate_fn; sp->deallocate = deallocate_fn; sp->allocate_data = allocate_data; @@ -313,10 +354,10 @@ splay_tree_insert (splay_tree sp, splay_tree_key key, splay_tree_value value) { /* Create a new node, and insert it at the root. */ splay_tree_node node; - + node = ((splay_tree_node) - (*sp->allocate) (sizeof (struct splay_tree_node_s), - sp->allocate_data)); + (*sp->allocate) (sizeof (struct splay_tree_node_s), + sp->allocate_data)); node->key = key; node->value = value; -- cgit v1.1