diff options
author | Ian Lance Taylor <iant@google.com> | 2000-02-22 19:18:13 +0300 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2000-02-22 19:18:13 +0300 |
commit | 268d66eb67ac962b1b15d434ed6231370894f17f (patch) | |
tree | 3f888fafa9ffec30f738bfd61c379ab719fc570d /include | |
parent | 95d64ccd4e4fd31d850f027fdc1030548e7a2d1e (diff) | |
parent | 929ce68fe67a171b2e3ff506450ca893ed6532b3 (diff) |
This commit was generated by cvs2svn to track changes on a CVS vendor
branch.
Diffstat (limited to 'include')
-rw-r--r-- | include/hashtab.h | 109 | ||||
-rw-r--r-- | include/libiberty.h | 55 | ||||
-rw-r--r-- | include/obstack.h | 18 | ||||
-rw-r--r-- | include/splay-tree.h | 9 | ||||
-rw-r--r-- | include/symcat.h | 4 |
5 files changed, 165 insertions, 30 deletions
diff --git a/include/hashtab.h b/include/hashtab.h new file mode 100644 index 000000000..3990c14cb --- /dev/null +++ b/include/hashtab.h @@ -0,0 +1,109 @@ +/* An expandable hash tables datatype. + Copyright (C) 1999 Free Software Foundation, Inc. + Contributed by Vladimir Makarov (vmakarov@cygnus.com). + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* This package implements basic hash table functionality. It is possible + to search for an entry, create an entry and destroy an entry. + + Elements in the table are generic pointers. + + The size of the table is not fixed; if the occupancy of the table + grows too high the hash table will be expanded. + + The abstract data implementation is based on generalized Algorithm D + from Knuth's book "The art of computer programming". Hash table is + expanded by creation of new hash table and transferring elements from + the old table to the new table. */ + +#ifndef __HASHTAB_H__ +#define __HASHTAB_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include <ansidecl.h> + +/* The hash table element is represented by the following type. */ + +typedef const void *hash_table_entry_t; + +/* Hash tables are of the following type. The structure + (implementation) of this type is not needed for using the hash + tables. All work with hash table should be executed only through + functions mentioned below. */ + +typedef struct hash_table +{ + /* Current size (in entries) of the hash table */ + size_t size; + /* Current number of elements including also deleted elements */ + size_t number_of_elements; + /* Current number of deleted elements in the table */ + size_t number_of_deleted_elements; + /* The following member is used for debugging. Its value is number + of all calls of `find_hash_table_entry' for the hash table. */ + int searches; + /* The following member is used for debugging. Its value is number + of collisions fixed for time of work with the hash table. */ + int collisions; + /* Pointer to function for evaluation of hash value (any unsigned value). + This function has one parameter of type hash_table_entry_t. */ + unsigned (*hash_function) PARAMS ((hash_table_entry_t)); + /* Pointer to function for test on equality of hash table elements (two + parameter of type hash_table_entry_t. */ + int (*eq_function) PARAMS ((hash_table_entry_t, hash_table_entry_t)); + /* Table itself */ + hash_table_entry_t *entries; +} *hash_table_t; + + +/* The prototypes of the package functions. */ + +extern hash_table_t create_hash_table + PARAMS ((size_t, unsigned (*) (hash_table_entry_t), + int (*) (hash_table_entry_t, hash_table_entry_t))); + +extern void delete_hash_table PARAMS ((hash_table_t)); + +extern void empty_hash_table PARAMS ((hash_table_t)); + +extern hash_table_entry_t *find_hash_table_entry + PARAMS ((hash_table_t, hash_table_entry_t, int)); + +extern void remove_element_from_hash_table_entry PARAMS ((hash_table_t, + hash_table_entry_t)); + +extern void clear_hash_table_slot PARAMS ((hash_table_t, hash_table_entry_t *)); + +extern void traverse_hash_table PARAMS ((hash_table_t, + int (*) (hash_table_entry_t, void *), + void *)); + +extern size_t hash_table_size PARAMS ((hash_table_t)); + +extern size_t hash_table_elements_number PARAMS ((hash_table_t)); + +extern int hash_table_collisions PARAMS ((hash_table_t)); + +extern int all_hash_table_collisions PARAMS ((void)); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __HASHTAB_H */ diff --git a/include/libiberty.h b/include/libiberty.h index cf313662e..9a536a4a1 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -19,7 +19,7 @@ extern "C" { /* Build an argument vector from a string. Allocates memory using malloc. Use freeargv to free the vector. */ -extern char **buildargv PARAMS ((char *)); +extern char **buildargv PARAMS ((char *)) ATTRIBUTE_MALLOC; /* Free a vector returned by buildargv. */ @@ -28,7 +28,7 @@ extern void freeargv PARAMS ((char **)); /* Duplicate an argument vector. Allocates memory using malloc. Use freeargv to free the vector. */ -extern char **dupargv PARAMS ((char **)); +extern char **dupargv PARAMS ((char **)) ATTRIBUTE_MALLOC; /* Return the last component of a path name. Note that we can't use a @@ -36,7 +36,7 @@ extern char **dupargv PARAMS ((char **)); across different systems, sometimes as "char *" and sometimes as "const char *" */ -#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) +#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) extern char *basename PARAMS ((const char *)); #else extern char *basename (); @@ -45,19 +45,28 @@ extern char *basename (); /* Concatenate an arbitrary number of strings, up to (char *) NULL. Allocates memory using xmalloc. */ -extern char *concat PARAMS ((const char *, ...)); +extern char *concat PARAMS ((const char *, ...)) ATTRIBUTE_MALLOC; /* Check whether two file descriptors refer to the same file. */ extern int fdmatch PARAMS ((int fd1, int fd2)); +/* Get the working directory. The result is cached, so don't call + chdir() between calls to getpwd(). */ + +extern char * getpwd PARAMS ((void)); + /* Get the amount of time the process has run, in microseconds. */ extern long get_run_time PARAMS ((void)); /* Choose a temporary directory to use for scratch files. */ -extern char *choose_temp_base PARAMS ((void)); +extern char *choose_temp_base PARAMS ((void)) ATTRIBUTE_MALLOC; + +/* Return a temporary file name or NULL if unable to create one. */ + +extern char *make_temp_file PARAMS ((const char *)) ATTRIBUTE_MALLOC; /* Allocate memory filled with spaces. Allocates using malloc. */ @@ -108,11 +117,7 @@ extern int xatexit PARAMS ((void (*fn) (void))); /* Exit, calling all the functions registered with xatexit. */ -#ifndef __GNUC__ -extern void xexit PARAMS ((int status)); -#else -void xexit PARAMS ((int status)) __attribute__ ((noreturn)); -#endif +extern void xexit PARAMS ((int status)) ATTRIBUTE_NORETURN; /* Set the program name used by xmalloc. */ @@ -125,24 +130,29 @@ extern void xmalloc_set_program_name PARAMS ((const char *)); #ifdef ANSI_PROTOTYPES /* Get a definition for size_t. */ #include <stddef.h> +/* Get a definition for va_list. */ +#include <stdarg.h> #endif -extern PTR xmalloc PARAMS ((size_t)); - -/* Reallocate memory without fail. This works like xmalloc. +extern PTR xmalloc PARAMS ((size_t)) ATTRIBUTE_MALLOC; - FIXME: We do not declare the parameter types for the same reason as - xmalloc. */ +/* Reallocate memory without fail. This works like xmalloc. Note, + realloc type functions are not suitable for attribute malloc since + they may return the same address across multiple calls. */ extern PTR xrealloc PARAMS ((PTR, size_t)); /* Allocate memory without fail and set it to zero. This works like xmalloc. */ -extern PTR xcalloc PARAMS ((size_t, size_t)); +extern PTR xcalloc PARAMS ((size_t, size_t)) ATTRIBUTE_MALLOC; /* Copy a string into a memory buffer without fail. */ -extern char *xstrdup PARAMS ((const char *)); +extern char *xstrdup PARAMS ((const char *)) ATTRIBUTE_MALLOC; + +/* Copy an existing memory buffer to a new memory buffer without fail. */ + +extern PTR xmemdup PARAMS ((const PTR, size_t, size_t)) ATTRIBUTE_MALLOC; /* hex character manipulation routines */ @@ -172,6 +182,17 @@ extern int pexecute PARAMS ((const char *, char * const *, const char *, extern int pwait PARAMS ((int, int *, int)); +/* Like sprintf but provides a pointer to malloc'd storage, which must + be freed by the caller. */ + +extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; + +/* Like vsprintf but provides a pointer to malloc'd storage, which + must be freed by the caller. */ + +extern int vasprintf PARAMS ((char **, const char *, va_list)) + ATTRIBUTE_PRINTF(2,0); + #ifdef __cplusplus } #endif diff --git a/include/obstack.h b/include/obstack.h index 38e967776..a20ab5596 100644 --- a/include/obstack.h +++ b/include/obstack.h @@ -143,12 +143,16 @@ extern "C" { #if defined _LIBC || defined HAVE_STRING_H # include <string.h> -# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) +# if defined __STDC__ && __STDC__ +# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) +# else +# define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N)) +# endif #else # ifdef memcpy -# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) +# define _obstack_memcpy(To, From, N) memcpy ((To), (char *)(From), (N)) # else -# define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N)) +# define _obstack_memcpy(To, From, N) bcopy ((char *)(From), (To), (N)) # endif #endif @@ -385,7 +389,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len > __o->chunk_limit) \ _obstack_newchunk (__o, __len); \ - _obstack_memcpy (__o->next_free, (char *) (where), __len); \ + _obstack_memcpy (__o->next_free, (where), __len); \ __o->next_free += __len; \ (void) 0; }) @@ -395,7 +399,7 @@ __extension__ \ int __len = (length); \ if (__o->next_free + __len + 1 > __o->chunk_limit) \ _obstack_newchunk (__o, __len + 1); \ - _obstack_memcpy (__o->next_free, (char *) (where), __len); \ + _obstack_memcpy (__o->next_free, (where), __len); \ __o->next_free += __len; \ *(__o->next_free)++ = 0; \ (void) 0; }) @@ -510,14 +514,14 @@ __extension__ \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ - _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \ + _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ (h)->next_free += (h)->temp) # define obstack_grow0(h,where,length) \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ - _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \ + _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ (h)->next_free += (h)->temp, \ *((h)->next_free)++ = 0) diff --git a/include/splay-tree.h b/include/splay-tree.h index e828fe7e9..6d70c8d90 100644 --- a/include/splay-tree.h +++ b/include/splay-tree.h @@ -44,7 +44,7 @@ typedef unsigned long int splay_tree_key; typedef unsigned long int splay_tree_value; /* Forward declaration for a node in the tree. */ -typedef struct splay_tree_node *splay_tree_node; +typedef struct splay_tree_node_s *splay_tree_node; /* The type of a function which compares two splay-tree keys. The function should return values as for qsort. */ @@ -62,7 +62,7 @@ typedef void (*splay_tree_delete_value_fn) PARAMS((splay_tree_value)); typedef int (*splay_tree_foreach_fn) PARAMS((splay_tree_node, void*)); /* The nodes in the splay tree. */ -struct splay_tree_node +struct splay_tree_node_s { /* The key. */ splay_tree_key key; @@ -76,7 +76,7 @@ struct splay_tree_node }; /* The splay tree itself. */ -typedef struct splay_tree +typedef struct splay_tree_s { /* The root of the tree. */ splay_tree_node root; @@ -95,7 +95,8 @@ extern splay_tree splay_tree_new PARAMS((splay_tree_compare_fn, splay_tree_delete_key_fn, splay_tree_delete_value_fn)); extern void splay_tree_delete PARAMS((splay_tree)); -extern void splay_tree_insert PARAMS((splay_tree, +extern splay_tree_node splay_tree_insert + PARAMS((splay_tree, splay_tree_key, splay_tree_value)); extern splay_tree_node splay_tree_lookup diff --git a/include/symcat.h b/include/symcat.h index 01efada26..3e27162b2 100644 --- a/include/symcat.h +++ b/include/symcat.h @@ -1,6 +1,6 @@ /* Symbol concatenation utilities. - Copyright (C) 1998, Free Software Foundation, Inc. + Copyright (C) 1998, 2000 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ #define CONCAT2(a,b) a/**/b #define CONCAT3(a,b,c) a/**/b/**/c #define CONCAT4(a,b,c,d) a/**/b/**/c/**/d -#define STRINGX(s) "?" +#define STRINGX(s) "s" #endif #define XCONCAT2(a,b) CONCAT2(a,b) |