2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

switch to ISC_LIST_FOREACH everywhere

the pattern `for (x = ISC_LIST_HEAD(...); x != NULL; ISC_LIST_NEXT(...)`
has been changed to `ISC_LIST_FOREACH` throughout BIND, except in a few
cases where the change would be excessively complex.

in most cases this was a straightforward change. in some places,
however, the list element variable was referenced after the loop
ended, and the code was refactored to avoid this necessity.

also, because `ISC_LIST_FOREACH` uses typeof(list.head) to declare
the list elements, compilation failures can occur if the list object
has a `const` qualifier.  some `const` qualifiers have been removed
from function parameters to avoid this problem, and where that was not
possible, `UNCONST` was used.
This commit is contained in:
Evan Hunt
2025-03-20 22:25:56 -07:00
parent 5cff8f9017
commit 522ca7bb54
66 changed files with 766 additions and 1786 deletions

View File

@@ -280,7 +280,6 @@ ns_hooktable_create(isc_mem_t *mctx, ns_hooktable_t **tablep) {
void
ns_hooktable_free(isc_mem_t *mctx, void **tablep) {
ns_hooktable_t *table = NULL;
ns_hook_t *hook = NULL, *next = NULL;
int i = 0;
REQUIRE(tablep != NULL && *tablep != NULL);
@@ -289,10 +288,7 @@ ns_hooktable_free(isc_mem_t *mctx, void **tablep) {
*tablep = NULL;
for (i = 0; i < NS_HOOKPOINTS_COUNT; i++) {
for (hook = ISC_LIST_HEAD((*table)[i]); hook != NULL;
hook = next)
{
next = ISC_LIST_NEXT(hook, link);
ISC_LIST_FOREACH_SAFE ((*table)[i], hook, link) {
ISC_LIST_UNLINK((*table)[i], hook, link);
if (hook->mctx != NULL) {
isc_mem_putanddetach(&hook->mctx, hook,
@@ -341,15 +337,13 @@ ns_plugins_create(isc_mem_t *mctx, ns_plugins_t **listp) {
void
ns_plugins_free(isc_mem_t *mctx, void **listp) {
ns_plugins_t *list = NULL;
ns_plugin_t *plugin = NULL, *next = NULL;
REQUIRE(listp != NULL && *listp != NULL);
list = *listp;
*listp = NULL;
for (plugin = ISC_LIST_HEAD(*list); plugin != NULL; plugin = next) {
next = ISC_LIST_NEXT(plugin, link);
ISC_LIST_FOREACH_SAFE (*list, plugin, link) {
ISC_LIST_UNLINK(*list, plugin, link);
unload_plugin(&plugin);
}