]> Savannah Git Hosting - gnulib.git/commitdiff
hash: deprecate poorly-named hash_insert0: use hash_insert_if_absent
authorJim Meyering <meyering@redhat.com>
Fri, 18 Nov 2011 11:09:16 +0000 (12:09 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 18 Nov 2011 15:00:44 +0000 (16:00 +0100)
* 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>.

ChangeLog
NEWS
lib/di-set.c
lib/hash.c
lib/hash.h

index e8ac873703ac311ed3fd840de0463ff4ae419d85..28b21aa7c94abf61545e04110069f5668b064407 100644 (file)
--- 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
diff --git a/NEWS b/NEWS
index 495c81b8dfeb09f4075c910e366d3be8dd71c00e..0322bd26ebc129c3215de752a4f99c6e809cdb84 100644 (file)
--- 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.
index 4730e750a442ec727716f11265a19185640a2eca..2f7844882f4dad4eafd4e41fc1afc33e68ddee63 100644 (file)
@@ -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.
index 4d76f765e90b4ba549ce097b8eb717a6cb869e2b..0e449136093ab2293bdedf6050a435b59dc89db1 100644 (file)
@@ -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.
index 9f694be5551383af58996bfc3ad43046fe84649e..572032d02ec3c192c6b4f6354a7cd4af4f175f9d 100644 (file)
 #  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