From: Vladimír Čunát Date: Tue, 20 May 2025 06:28:32 +0000 (+0200) Subject: treewide: more C++ compatibility in headers X-Git-Tag: v6.0.13~6^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c2eb4747df263ca51be62af51ea54158df0e52c6;p=thirdparty%2Fknot-resolver.git treewide: more C++ compatibility in headers --- diff --git a/NEWS b/NEWS index ef42b0c1e..0bd683341 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ Bugfixes - fix undefined disable_defer (!1685) - daemon: fix a memory leak present since v6.0.9 (#927) +Improvements +------------ +- C++ compatibility of lib/ headers (!1689) + Knot Resolver 6.0.12 (2025-04-24) ================================= diff --git a/lib/defines.h b/lib/defines.h index 242058966..c4c8d4090 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -41,7 +41,9 @@ static inline int KR_COLD kr_error(int x) { /* We require C11 but want to avoid including the standard assertion header * so we alias it ourselves. */ +#ifndef __cplusplus #define static_assert _Static_assert +#endif /* * Connection limits. diff --git a/lib/generic/lru.h b/lib/generic/lru.h index b78888fcb..0e5e8815d 100644 --- a/lib/generic/lru.h +++ b/lib/generic/lru.h @@ -172,7 +172,7 @@ enum lru_apply_do { enum lru_apply_do (*(name))(const char *key, uint len, val_type *val, void *baton) typedef lru_apply_fun_g(lru_apply_fun, void); -#define CACHE_ALIGNED _Alignas(64) +#define CACHE_ALIGNED alignas(64) struct lru; void lru_free_items_impl(struct lru *lru); diff --git a/lib/utils.c b/lib/utils.c index 016072c58..a2ebceaf1 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -744,14 +744,14 @@ void kr_bitmask(unsigned char *a, size_t a_len, int bits) a[i] = 0; } -int kr_rrkey(char *key, uint16_t class, const knot_dname_t *owner, +int kr_rrkey(char *key, uint16_t rrclass, const knot_dname_t *owner, uint16_t type, uint16_t additional) { if (!key || !owner) { return kr_error(EINVAL); } uint8_t *key_buf = (uint8_t *)key; - int ret = u16tostr(key_buf, class); + int ret = u16tostr(key_buf, rrclass); if (ret <= 0) { return ret; } diff --git a/lib/utils.h b/lib/utils.h index bc7cc0164..5ca0378e2 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -372,7 +372,11 @@ int kr_straddr_subnet(void *dst, const char *addr); * \note Only internet addresses are supported, i.e. no AF_UNIX sockets. */ KR_EXPORT -int kr_straddr_split(const char *instr, char ipaddr[static restrict (INET6_ADDRSTRLEN + 1)], +int kr_straddr_split(const char *instr, char ipaddr[ + #ifndef __cplusplus + static restrict (INET6_ADDRSTRLEN + 1) + #endif + ], uint16_t *port); /** Formats ip address and port in "addr#port" format. @@ -422,7 +426,7 @@ static inline bool kr_sockaddr_link_local(const struct sockaddr *addr) * @return key length if successful or an error * */ KR_EXPORT -int kr_rrkey(char *key, uint16_t class, const knot_dname_t *owner, +int kr_rrkey(char *key, uint16_t rrclass, const knot_dname_t *owner, uint16_t type, uint16_t additional); /** Add RRSet copy to a ranked RR array. diff --git a/lib/zonecut.c b/lib/zonecut.c index aea38e464..8004fd222 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -532,7 +532,7 @@ static int fetch_secure_rrset(knot_rrset_t **rr, struct kr_cache *cache, int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const knot_dname_t *name, const struct kr_query *qry, - bool * restrict secured) + bool *secured) { if (!ctx || !cut || !name) return kr_error(EINVAL); diff --git a/lib/zonecut.h b/lib/zonecut.h index 13b1f8bf5..2bb658491 100644 --- a/lib/zonecut.h +++ b/lib/zonecut.h @@ -153,7 +153,7 @@ int kr_zonecut_set_sbelt(struct kr_context *ctx, struct kr_zonecut *cut); KR_EXPORT int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const knot_dname_t *name, const struct kr_query *qry, - bool * restrict secured); + bool *secured); /** * Check if any address is present in the zone cut. *