>From 8878aa565e6ed547719db6a5a10a14b613184118 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 11 Oct 2020 23:42:02 +0200 Subject: [PATCH 3/3] hash: Rename hash_delete to hash_remove. * lib/hash.h (hash_remove): Renamed from hash_delete. (hash_delete): New declaration. * lib/hash.c (hash_remove): Renamed from hash_delete. (hash_delete): New function. * tests/test-hash.c (main): Update. * lib/fts-cycle.c (leave_dir): Likewise. * NEWS: Mention the change. --- ChangeLog | 11 +++++++++++ NEWS | 4 ++++ lib/fts-cycle.c | 2 +- lib/hash.c | 8 +++++++- lib/hash.h | 7 ++++++- tests/test-hash.c | 10 +++++----- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 299074f..c05604b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2020-10-11 Bruno Haible + hash: Rename hash_delete to hash_remove. + * lib/hash.h (hash_remove): Renamed from hash_delete. + (hash_delete): New declaration. + * lib/hash.c (hash_remove): Renamed from hash_delete. + (hash_delete): New function. + * tests/test-hash.c (main): Update. + * lib/fts-cycle.c (leave_dir): Likewise. + * NEWS: Mention the change. + +2020-10-11 Bruno Haible + hash, xhash: Make usable from C++. * lib/hash.h: Add extern "C". diff --git a/NEWS b/NEWS index 18465b2..9c9d587 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,10 @@ User visible incompatible changes Date Modules Changes +2020-10-11 hash This module deprecates the 'hash_delete' function + using gcc's "deprecated" attribute. Use the better- + named 'hash_remove' equivalent. + 2020-08-24 diffseq If you do not define NOTE_ORDERED to true, the NOTE_DELETE and NOTE_INSERT actions might not be done in order, to help cut down worst-case diff --git a/lib/fts-cycle.c b/lib/fts-cycle.c index 46b5f61..a2d59be 100644 --- a/lib/fts-cycle.c +++ b/lib/fts-cycle.c @@ -131,7 +131,7 @@ leave_dir (FTS *fts, FTSENT *ent) void *found; obj.dev = st->st_dev; obj.ino = st->st_ino; - found = hash_delete (fts->fts_cycle.ht, &obj); + found = hash_remove (fts->fts_cycle.ht, &obj); if (!found) abort (); free (found); diff --git a/lib/hash.c b/lib/hash.c index 6b7b76a..2d64c82 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -1012,7 +1012,7 @@ hash_insert (Hash_table *table, void const *entry) } void * -hash_delete (Hash_table *table, const void *entry) +hash_remove (Hash_table *table, const void *entry) { void *data; struct hash_entry *bucket; @@ -1071,6 +1071,12 @@ hash_delete (Hash_table *table, const void *entry) return data; } +void * +hash_delete (Hash_table *table, const void *entry) +{ + return hash_remove (table, entry); +} + /* Testing. */ #if TESTING diff --git a/lib/hash.h b/lib/hash.h index a9d78c0..e280adb 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -247,7 +247,12 @@ extern int hash_insert_if_absent (Hash_table *table, const void *entry, /* If ENTRY is already in the table, remove it and return the just-deleted data (the user may want to deallocate its storage). If ENTRY is not in the table, don't modify the table and return NULL. */ -extern void *hash_delete (Hash_table *table, const void *entry); +extern void *hash_remove (Hash_table *table, const void *entry); + +/* Same as hash_remove. This interface is deprecated. + FIXME: Remove in 2022. */ +extern void *hash_delete (Hash_table *table, const void *entry) + _GL_ATTRIBUTE_DEPRECATED; # ifdef __cplusplus } diff --git a/tests/test-hash.c b/tests/test-hash.c index 67d9519..6f1391c 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -132,10 +132,10 @@ main (int argc, char **argv) ASSERT (hash_get_entries (ht, buf, 5) == 3); ASSERT (STREQ (buf[0], "a") || STREQ (buf[0], "b") || STREQ (buf[0], "c")); } - ASSERT (hash_delete (ht, "a")); - ASSERT (hash_delete (ht, "a") == NULL); - ASSERT (hash_delete (ht, "b")); - ASSERT (hash_delete (ht, "c")); + ASSERT (hash_remove (ht, "a")); + ASSERT (hash_remove (ht, "a") == NULL); + ASSERT (hash_remove (ht, "b")); + ASSERT (hash_remove (ht, "c")); ASSERT (hash_rehash (ht, 47)); ASSERT (hash_rehash (ht, 467)); @@ -246,7 +246,7 @@ main (int argc, char **argv) /* empty */ } ASSERT (p); - v = hash_delete (ht, p); + v = hash_remove (ht, p); ASSERT (v); free (v); } -- 2.7.4