From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, /
Date: Fri, 27 Dec 2019 16:57:06 +0000 (UTC) [thread overview]
Message-ID: <1576419368.deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3.grobian@gentoo> (raw)
commit: deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 15 14:16:08 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 15 14:16:08 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=deefb1d3
libq/set: have del_set return the old value when set
Allow to easily free a set entry that has a value.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/set.c | 22 ++++++++++++++++------
libq/set.h | 2 +-
qmerge.c | 2 +-
3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/libq/set.c b/libq/set.c
index e0ea396..3b56f81 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -195,19 +195,26 @@ get_set(const char *name, set *q)
return NULL;
}
-/* remove elem from a set. matches ->name and frees name,item */
-set *
+/* remove elem from a set. matches ->name and frees name,item, returns
+ * val if removed, NULL otherwise
+ * note that when val isn't set, NULL is returned, so the caller should
+ * use the removed argument to determine if something was removed from
+ * the set. */
+void *
del_set(const char *s, set *q, bool *removed)
{
unsigned int hash;
int pos;
elem *ll;
elem *w;
+ void *ret;
+ bool rmd;
hash = fnv1a32(s);
pos = hash % _SET_HASH_SIZE;
- *removed = false;
+ ret = NULL;
+ rmd = false;
if (q->buckets[pos] != NULL) {
ll = NULL;
for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
@@ -217,17 +224,20 @@ del_set(const char *s, set *q, bool *removed)
} else {
ll->next = w->next;
}
+ ret = w->val;
free(w->name);
free(w);
- *removed = true;
+ rmd = true;
break;
}
}
}
- if (*removed)
+ if (rmd)
q->len--;
- return q;
+ if (removed != NULL)
+ *removed = rmd;
+ return ret;
}
/* return the contents of a set as an array of strings
diff --git a/libq/set.h b/libq/set.h
index 638cc15..8546a90 100644
--- a/libq/set.h
+++ b/libq/set.h
@@ -34,7 +34,7 @@ set *add_set_unique(const char *name, set *q, bool *unique);
void *add_set_value(const char *name, void *ptr, set *q);
bool contains_set(const char *name, set *q);
void *get_set(const char *name, set *q);
-set *del_set(const char *s, set *q, bool *removed);
+void *del_set(const char *s, set *q, bool *removed);
size_t list_set(set *q, char ***l);
size_t values_set(set *q, array_t *ret);
size_t cnt_set(set *q);
diff --git a/qmerge.c b/qmerge.c
index 5b7a298..a2d06ab 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -2341,7 +2341,7 @@ qmerge_add_set_system(void *data, char *buf)
q = add_set(s + 1, q);
else if (s[0] == '-' && s[1] == '*') {
bool ok;
- q = del_set(s + 2, q, &ok);
+ (void)del_set(s + 2, q, &ok);
}
return q;
next reply other threads:[~2019-12-27 16:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-27 16:57 Fabian Groffen [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-06-27 19:19 [gentoo-commits] proj/portage-utils:master commit in: libq/, / Fabian Groffen
2024-03-29 10:57 Fabian Groffen
2024-01-02 7:57 Fabian Groffen
2023-02-07 8:25 Fabian Groffen
2023-02-07 8:10 Fabian Groffen
2021-08-16 13:23 Fabian Groffen
2020-02-21 8:18 Fabian Groffen
2020-01-05 13:28 Fabian Groffen
2020-01-02 11:19 Fabian Groffen
2020-01-01 19:52 Fabian Groffen
2019-12-31 9:05 Fabian Groffen
2019-12-30 17:24 Fabian Groffen
2019-12-29 13:26 Fabian Groffen
2019-07-13 10:04 Fabian Groffen
2019-06-19 10:44 Fabian Groffen
2019-06-05 9:15 Fabian Groffen
2019-05-09 20:19 Fabian Groffen
2019-05-05 18:13 Fabian Groffen
2019-04-28 15:20 Fabian Groffen
2019-03-27 20:18 Fabian Groffen
2019-03-27 10:55 Fabian Groffen
2019-03-22 9:57 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-19 20:32 Fabian Groffen
2019-03-09 18:58 Fabian Groffen
2018-03-23 11:56 Fabian Groffen
2016-12-29 2:25 Mike Frysinger
2016-11-26 23:17 Mike Frysinger
2015-11-28 2:44 Mike Frysinger
2015-02-24 1:26 Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1576419368.deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3.grobian@gentoo \
--to=grobian@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox