From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 94B3F138335 for ; Fri, 27 Dec 2019 16:57:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8B156E08F5; Fri, 27 Dec 2019 16:57:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5A5DEE089D for ; Fri, 27 Dec 2019 16:57:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1A6AD34DB6A for ; Fri, 27 Dec 2019 16:57:08 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8370A36 for ; Fri, 27 Dec 2019 16:57:06 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1576419368.deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/, / X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/set.c libq/set.h qmerge.c X-VCS-Directories: libq/ / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3 X-VCS-Branch: master Date: Fri, 27 Dec 2019 16:57:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 16d65e7e-0e86-4471-b141-1cf6505e848c X-Archives-Hash: 7135980da28156cc9162166292e2ca1d commit: deefb1d324ea8e7fc125c0b8b8271da3e3f3f0b3 Author: Fabian Groffen gentoo org> AuthorDate: Sun Dec 15 14:16:08 2019 +0000 Commit: Fabian Groffen gentoo 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 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;