From c5075a9a616d4f4c3959c22b48df0d575ebf26b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 28 Feb 2025 21:04:21 +0100 Subject: [PATCH] Remove convenience list macros from isc/util.h The short convenience list macros were used very sparingly and inconsistenly in the code base. As the consistency is prefered over the convenience, all shortened list macro were removed in favor of their ISC_LIST API targets. --- lib/dns/dyndb.c | 16 ++++++------ lib/dns/qpzone.c | 49 ++++++++++++++++++++----------------- lib/isc/include/isc/util.h | 18 -------------- lib/isc/lex.c | 24 +++++++++--------- lib/isc/netmgr/http.c | 2 +- lib/isc/netmgr/netmgr-int.h | 10 ++++---- lib/isc/ratelimiter.c | 4 +-- lib/ns/hooks.c | 2 +- 8 files changed, 55 insertions(+), 70 deletions(-) diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index b4ead8dcfa..fd327bef9f 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -43,7 +43,7 @@ struct dyndb_implementation { dns_dyndb_destroy_t *destroy_func; char *name; void *inst; - LINK(dyndb_implementation_t) link; + ISC_LINK(dyndb_implementation_t) link; }; /* @@ -52,7 +52,7 @@ struct dyndb_implementation { * These are stored here so they can be cleaned up on shutdown. * (The order in which they are stored is not important.) */ -static LIST(dyndb_implementation_t) dyndb_implementations; +static ISC_LIST(dyndb_implementation_t) dyndb_implementations; /* Locks dyndb_implementations. */ static isc_mutex_t dyndb_lock; @@ -60,7 +60,7 @@ static isc_mutex_t dyndb_lock; void dns__dyndb_initialize(void) { isc_mutex_init(&dyndb_lock); - INIT_LIST(dyndb_implementations); + ISC_LIST_INIT(dyndb_implementations); } void @@ -135,7 +135,7 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, isc_mem_attach(mctx, &imp->mctx); - INIT_LINK(imp, link); + ISC_LINK_INIT(imp, link); r = uv_dlopen(filename, &imp->handle); if (r != 0) { @@ -225,7 +225,7 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters, CHECK(implementation->register_func(mctx, name, parameters, file, line, dctx, &implementation->inst)); - APPEND(dyndb_implementations, implementation, link); + ISC_LIST_APPEND(dyndb_implementations, implementation, link); result = ISC_R_SUCCESS; cleanup: @@ -245,10 +245,10 @@ dns_dyndb_cleanup(void) { dyndb_implementation_t *prev; LOCK(&dyndb_lock); - elem = TAIL(dyndb_implementations); + elem = ISC_LIST_TAIL(dyndb_implementations); while (elem != NULL) { - prev = PREV(elem, link); - UNLINK(dyndb_implementations, elem, link); + prev = ISC_LIST_PREV(elem, link); + ISC_LIST_UNLINK(dyndb_implementations, elem, link); isc_log_write(DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB, ISC_LOG_INFO, "unloading DynDB instance '%s'", elem->name); diff --git a/lib/dns/qpzone.c b/lib/dns/qpzone.c index 766d25fe8a..72050bf96b 100644 --- a/lib/dns/qpzone.c +++ b/lib/dns/qpzone.c @@ -544,7 +544,7 @@ qpzone_destroy(qpzonedb_t *qpdb) { isc_refcount_decrementz(&qpdb->current_version->references); isc_refcount_destroy(&qpdb->current_version->references); - UNLINK(qpdb->open_versions, qpdb->current_version, link); + ISC_LIST_UNLINK(qpdb->open_versions, qpdb->current_version, link); cds_wfs_destroy(&qpdb->current_version->glue_stack); isc_rwlock_destroy(&qpdb->current_version->rwlock); isc_mem_put(qpdb->common.mctx, qpdb->current_version, @@ -723,7 +723,7 @@ dns__qpzone_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, * Keep the current version in the open list so that list operation * won't happen in normal lookup operations. */ - PREPEND(qpdb->open_versions, qpdb->current_version, link); + ISC_LIST_PREPEND(qpdb->open_versions, qpdb->current_version, link); qpdb->common.magic = DNS_DB_MAGIC; qpdb->common.impmagic = QPZONE_DB_MAGIC; @@ -1125,13 +1125,13 @@ cleanup_nondirty(qpz_version_t *version, qpz_changedlist_t *cleanup_list) { * * The caller must be holding the database lock. */ - for (changed = HEAD(version->changed_list); changed != NULL; + for (changed = ISC_LIST_HEAD(version->changed_list); changed != NULL; changed = next_changed) { - next_changed = NEXT(changed, link); + next_changed = ISC_LIST_NEXT(changed, link); if (!changed->dirty) { - UNLINK(version->changed_list, changed, link); - APPEND(*cleanup_list, changed, link); + ISC_LIST_UNLINK(version->changed_list, changed, link); + ISC_LIST_APPEND(*cleanup_list, changed, link); } } } @@ -1378,12 +1378,13 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, (void)isc_refcount_current( &cur_version->references); if (cur_version->serial == qpdb->least_serial) { - INSIST(EMPTY( + INSIST(ISC_LIST_EMPTY( cur_version->changed_list)); } - UNLINK(qpdb->open_versions, cur_version, link); + ISC_LIST_UNLINK(qpdb->open_versions, + cur_version, link); } - if (EMPTY(qpdb->open_versions)) { + if (ISC_LIST_EMPTY(qpdb->open_versions)) { /* * We're going to become the least open * version. @@ -1413,8 +1414,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, */ if (cur_ref == 1) { cleanup_version = cur_version; - APPENDLIST(version->changed_list, - cleanup_version->changed_list, link); + ISC_LIST_APPENDLIST( + version->changed_list, + cleanup_version->changed_list, link); } /* * Become the current version. @@ -1433,8 +1435,8 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, */ INSIST(isc_refcount_increment0(&version->references) == 0); - PREPEND(qpdb->open_versions, qpdb->current_version, - link); + ISC_LIST_PREPEND(qpdb->open_versions, + qpdb->current_version, link); resigned_list = version->resigned_list; ISC_LIST_INIT(version->resigned_list); } else { @@ -1461,7 +1463,7 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, * Find the version with the least serial * number greater than ours. */ - least_greater = PREV(version, link); + least_greater = ISC_LIST_PREV(version, link); if (least_greater == NULL) { least_greater = qpdb->current_version; } @@ -1482,20 +1484,21 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, * Add any unexecuted cleanups to * those of the least greater version. */ - APPENDLIST(least_greater->changed_list, - version->changed_list, link); + ISC_LIST_APPENDLIST(least_greater->changed_list, + version->changed_list, + link); } } else if (version->serial == qpdb->least_serial) { - INSIST(EMPTY(version->changed_list)); + INSIST(ISC_LIST_EMPTY(version->changed_list)); } - UNLINK(qpdb->open_versions, version, link); + ISC_LIST_UNLINK(qpdb->open_versions, version, link); } least_serial = qpdb->least_serial; RWUNLOCK(&qpdb->lock, isc_rwlocktype_write); if (cleanup_version != NULL) { isc_refcount_destroy(&cleanup_version->references); - INSIST(EMPTY(cleanup_version->changed_list)); + INSIST(ISC_LIST_EMPTY(cleanup_version->changed_list)); cleanup_gluelists(&cleanup_version->glue_stack); cds_wfs_destroy(&cleanup_version->glue_stack); isc_rwlock_destroy(&cleanup_version->rwlock); @@ -1506,8 +1509,8 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, /* * Commit/rollback re-signed headers. */ - for (header = HEAD(resigned_list); header != NULL; - header = HEAD(resigned_list)) + for (header = ISC_LIST_HEAD(resigned_list); header != NULL; + header = ISC_LIST_HEAD(resigned_list)) { isc_rwlock_t *nlock = NULL; isc_rwlocktype_t nlocktype = isc_rwlocktype_none; @@ -1527,13 +1530,13 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, dns_qp_t *tree = NULL, *nsec = NULL, *nsec3 = NULL; bool need_tree = false, need_nsec = false, need_nsec3 = false; - for (changed = HEAD(cleanup_list); changed != NULL; + for (changed = ISC_LIST_HEAD(cleanup_list); changed != NULL; changed = next_changed) { isc_rwlock_t *nlock = NULL; isc_rwlocktype_t nlocktype = isc_rwlocktype_none; - next_changed = NEXT(changed, link); + next_changed = ISC_LIST_NEXT(changed, link); node = changed->node; nlock = &qpdb->buckets[node->locknum].lock; diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 6d0b537c0e..bcfe3ad2ae 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -223,24 +223,6 @@ */ #include /* Contractual promise. */ -#define LIST(type) ISC_LIST(type) -#define INIT_LIST(type) ISC_LIST_INIT(type) -#define LINK(type) ISC_LINK(type) -#define INIT_LINK(elt, link) ISC_LINK_INIT(elt, link) -#define HEAD(list) ISC_LIST_HEAD(list) -#define TAIL(list) ISC_LIST_TAIL(list) -#define EMPTY(list) ISC_LIST_EMPTY(list) -#define PREV(elt, link) ISC_LIST_PREV(elt, link) -#define NEXT(elt, link) ISC_LIST_NEXT(elt, link) -#define APPEND(list, elt, link) ISC_LIST_APPEND(list, elt, link) -#define PREPEND(list, elt, link) ISC_LIST_PREPEND(list, elt, link) -#define UNLINK(list, elt, link) ISC_LIST_UNLINK(list, elt, link) -#define ENQUEUE(list, elt, link) ISC_LIST_APPEND(list, elt, link) -#define DEQUEUE(list, elt, link) ISC_LIST_UNLINK(list, elt, link) -#define INSERTBEFORE(li, b, e, ln) ISC_LIST_INSERTBEFORE(li, b, e, ln) -#define INSERTAFTER(li, a, e, ln) ISC_LIST_INSERTAFTER(li, a, e, ln) -#define APPENDLIST(list1, list2, link) ISC_LIST_APPENDLIST(list1, list2, link) - /*% * Performance */ diff --git a/lib/isc/lex.c b/lib/isc/lex.c index b1ac9b2cbd..e38947cbdd 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -61,7 +61,7 @@ struct isc_lex { unsigned int paren_count; unsigned int saved_paren_count; isc_lexspecials_t specials; - LIST(struct inputsource) sources; + ISC_LIST(struct inputsource) sources; }; static void @@ -104,7 +104,7 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) { lex->paren_count = 0; lex->saved_paren_count = 0; memset(lex->specials, 0, 256); - INIT_LIST(lex->sources); + ISC_LIST_INIT(lex->sources); lex->magic = LEX_MAGIC; *lexp = lex; @@ -123,7 +123,7 @@ isc_lex_destroy(isc_lex_t **lexp) { *lexp = NULL; REQUIRE(VALID_LEX(lex)); - while (!EMPTY(lex->sources)) { + while (!ISC_LIST_EMPTY(lex->sources)) { RUNTIME_CHECK(isc_lex_close(lex) == ISC_R_SUCCESS); } if (lex->data != NULL) { @@ -259,7 +259,7 @@ isc_lex_close(isc_lex_t *lex) { REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOMORE; } @@ -352,7 +352,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { */ REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(tokenp != NULL); if (source == NULL) { @@ -999,7 +999,7 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) { */ REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); REQUIRE(isc_buffer_consumedlength(source->pushback) != 0 || @@ -1018,7 +1018,7 @@ isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); REQUIRE(source != NULL); REQUIRE(tokenp != NULL); REQUIRE(isc_buffer_consumedlength(source->pushback) != 0 || @@ -1038,7 +1038,7 @@ isc_lex_getsourcename(isc_lex_t *lex) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return NULL; @@ -1052,7 +1052,7 @@ isc_lex_getsourceline(isc_lex_t *lex) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return 0; @@ -1067,7 +1067,7 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) { char *newname; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOTFOUND; @@ -1083,7 +1083,7 @@ isc_lex_setsourceline(isc_lex_t *lex, unsigned long line) { inputsource *source; REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return ISC_R_NOTFOUND; @@ -1099,7 +1099,7 @@ isc_lex_isfile(isc_lex_t *lex) { REQUIRE(VALID_LEX(lex)); - source = HEAD(lex->sources); + source = ISC_LIST_HEAD(lex->sources); if (source == NULL) { return false; diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index 39beec0487..cb8a77197f 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -150,7 +150,7 @@ typedef struct http_cstream { isc_nm_http_response_status_t response_status; isc_nmsocket_t *httpsock; - LINK(struct http_cstream) link; + ISC_LINK(struct http_cstream) link; } http_cstream_t; #define HTTP2_SESSION_MAGIC ISC_MAGIC('H', '2', 'S', 'S') diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index c42348fcce..fb49de7879 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -270,8 +270,8 @@ struct isc_nmhandle { void *backtrace[TRACE_SIZE]; int backtrace_size; #endif - LINK(isc_nmhandle_t) active_link; - LINK(isc_nmhandle_t) inactive_link; + ISC_LINK(isc_nmhandle_t) active_link; + ISC_LINK(isc_nmhandle_t) inactive_link; void *opaque; @@ -422,7 +422,7 @@ typedef struct isc_nm_httphandler { char *path; isc_nm_recv_cb_t cb; void *cbarg; - LINK(struct isc_nm_httphandler) link; + ISC_LINK(struct isc_nm_httphandler) link; } isc_nm_httphandler_t; struct isc_nm_http_endpoints { @@ -466,7 +466,7 @@ typedef struct isc_nmsocket_h2 { isc_nm_recv_cb_t cb; void *cbarg; - LINK(struct isc_nmsocket_h2) link; + ISC_LINK(struct isc_nmsocket_h2) link; isc_nm_http_endpoints_t **listener_endpoints; size_t n_listener_endpoints; @@ -712,7 +712,7 @@ struct isc_nmsocket { void *backtrace[TRACE_SIZE]; int backtrace_size; #endif - LINK(isc_nmsocket_t) active_link; + ISC_LINK(isc_nmsocket_t) active_link; isc_job_t job; }; diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 5cb83f273c..c66cebc4f7 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -231,7 +231,7 @@ isc__ratelimiter_tick(void *arg) { REQUIRE(rl->timer != NULL); if (rl->state == isc_ratelimiter_shuttingdown) { - INSIST(EMPTY(rl->pending)); + INSIST(ISC_LIST_EMPTY(rl->pending)); goto unlock; } @@ -277,7 +277,7 @@ isc__ratelimiter_doshutdown(void *arg) { LOCK(&rl->lock); INSIST(rl->state == isc_ratelimiter_shuttingdown); - INSIST(EMPTY(rl->pending)); + INSIST(ISC_LIST_EMPTY(rl->pending)); isc_timer_stop(rl->timer); isc_timer_destroy(&rl->timer); diff --git a/lib/ns/hooks.c b/lib/ns/hooks.c index 915f476c3b..33be5cd206 100644 --- a/lib/ns/hooks.c +++ b/lib/ns/hooks.c @@ -48,7 +48,7 @@ struct ns_plugin { ns_plugin_check_t *check_func; ns_plugin_register_t *register_func; ns_plugin_destroy_t *destroy_func; - LINK(ns_plugin_t) link; + ISC_LINK(ns_plugin_t) link; }; static ns_hooklist_t default_hooktable[NS_HOOKPOINTS_COUNT];