From 2895f9dcb663cc11cd70395c98442574bc5df5fd Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 18 Nov 2011 12:09:16 +0100 Subject: [PATCH] hash: deprecate poorly-named hash_insert0: use hash_insert_if_absent * lib/hash.c (hash_insert_if_absent): Rename from hash_insert0. Add a sentence to the comment. (hash_insert0): New function that simply calls hash_insert_if_absent. * lib/hash.h (hash_insert_if_absent): Declare it. (hash_insert0): Add deprecation attribute. (_GL_ATTRIBUTE_DEPRECATED): Define. * lib/di-set.c (di_set_insert): Use hash_insert_if_absent, not hash_insert0. * NEWS: Mention it, even though it's not really an incompatible change Prompted by a question from Matthew Booth . --- ChangeLog | 13 +++++++++++++ NEWS | 4 ++++ lib/di-set.c | 2 +- lib/hash.c | 15 +++++++++++++-- lib/hash.h | 19 +++++++++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8ac87370..28b21aa7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-11-18 Jim Meyering + + hash: deprecate poorly-named hash_insert0: use hash_insert_if_absent + * lib/hash.c (hash_insert_if_absent): Rename from hash_insert0. + Add a sentence to the comment. + (hash_insert0): New function that simply calls hash_insert_if_absent. + * lib/hash.h (hash_insert_if_absent): Declare it. + (hash_insert0): Add deprecation attribute. + (_GL_ATTRIBUTE_DEPRECATED): Define. + * lib/di-set.c (di_set_insert): Use hash_insert_if_absent, + not hash_insert0. + * NEWS: Mention it, even though it's not really an incompatible change. + 2011-11-18 Dagobert Michelsen (tiny change) openat: avoid compilation failure due to lack of inclusion diff --git a/NEWS b/NEWS index 495c81b8d..0322bd26e 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ User visible incompatible changes Date Modules Changes +2011-11-18 hash This module deprecates the hash_insert0 function + using gcc's "deprecated" attribute. Use the better- + named hash_insert_if_absent equivalent. + 2011-11-04 openat This module no longer provides the mkdirat() function. If you need this function, you now need to request the 'mkdirat' module. diff --git a/lib/di-set.c b/lib/di-set.c index 4730e750a..2f7844882 100644 --- a/lib/di-set.c +++ b/lib/di-set.c @@ -233,7 +233,7 @@ di_set_insert (struct di_set *dis, dev_t dev, ino_t ino) return -1; /* Put I into the inode set. */ - return hash_insert0 (ino_set, (void const *) i, NULL); + return hash_insert_if_absent (ino_set, (void const *) i, NULL); } /* Look up the DEV,INO pair in the set DIS. diff --git a/lib/hash.c b/lib/hash.c index 4d76f765e..0e4491360 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -1018,7 +1018,9 @@ hash_rehash (Hash_table *table, size_t candidate) return false; } -/* Return -1 upon memory allocation failure. +/* Insert ENTRY into hash TABLE if there is not already a matching entry. + + Return -1 upon memory allocation failure. Return 1 if insertion succeeded. Return 0 if there is already a matching entry in the table, and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT @@ -1033,7 +1035,8 @@ hash_rehash (Hash_table *table, size_t candidate) when the ENTRY value is a simple scalar, you must use hash_insert0. ENTRY must not be NULL. */ int -hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent) +hash_insert_if_absent (Hash_table *table, void const *entry, + void const **matched_ent) { void *data; struct hash_entry *bucket; @@ -1113,6 +1116,14 @@ hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent) return 1; } +/* hash_insert0 is the deprecated name for hash_insert_if_absent. + . */ +int +hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent) +{ + return hash_insert_if_absent (table, entry, matched_ent); +} + /* If ENTRY matches an entry already in the hash table, return the pointer to the entry from the table. Otherwise, insert ENTRY and return ENTRY. Return NULL if the storage required for insertion cannot be allocated. diff --git a/lib/hash.h b/lib/hash.h index 9f694be55..572032d02 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -35,6 +35,16 @@ # define _GL_ATTRIBUTE_WUR /* empty */ # endif +# ifndef _GL_ATTRIBUTE_DEPRECATED +/* The __attribute__((__deprecated__)) feature + is available in gcc versions 3.1 and newer. */ +# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1) +# define _GL_ATTRIBUTE_DEPRECATED /* empty */ +# else +# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__)) +# endif +# endif + typedef size_t (*Hash_hasher) (const void *, size_t); typedef bool (*Hash_comparator) (const void *, const void *); typedef void (*Hash_data_freer) (void *); @@ -85,8 +95,13 @@ void hash_free (Hash_table *); /* Insertion and deletion. */ bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR; void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR; -int hash_insert0 (Hash_table *table, const void *entry, - const void **matched_ent); + +/* Deprecate this interface. It has been renamed to hash_insert_if_absent. */ +int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */ + const void *entry, + const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED; +int hash_insert_if_absent (Hash_table *table, const void *entry, + const void **matched_ent); void *hash_delete (Hash_table *, const void *); #endif -- 2.11.0