changeset 16096:13817d3d0af6

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 <mbooth@redhat.com>.
author Jim Meyering <meyering@redhat.com>
date Fri, 18 Nov 2011 12:09:16 +0100
parents 02a734ccfb9a
children 4179fa4ac758
files ChangeLog NEWS lib/di-set.c lib/hash.c lib/hash.h
diffstat 5 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-11-18  Jim Meyering  <meyering@redhat.com>
+
+	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  <dam@opencsw.org>  (tiny change)
 
 	openat: avoid compilation failure due to lack of <errno.h> inclusion
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@
 
 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.
--- a/lib/di-set.c
+++ b/lib/di-set.c
@@ -233,7 +233,7 @@
     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.
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -1018,7 +1018,9 @@
   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 @@
    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 @@
   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.
--- 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 @@
 /* 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