]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
treewide: more C++ compatibility in headers
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 20 May 2025 06:28:32 +0000 (08:28 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 20 May 2025 06:28:32 +0000 (08:28 +0200)
NEWS
lib/defines.h
lib/generic/lru.h
lib/utils.c
lib/utils.h
lib/zonecut.c
lib/zonecut.h

diff --git a/NEWS b/NEWS
index ef42b0c1e235f723fb014aeb7e0ad00fd09b5bcf..0bd683341dfc950b1c0424ca9b60a129ccf86e0d 100644 (file)
--- 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)
 =================================
index 2420589664239c2a0b7f87d8484d949d84e251ae..c4c8d4090cfd307562d4a4d76d8062f820d44c0b 100644 (file)
@@ -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.
index b78888fcb1a2aee9cc55c7324c62aef4f4caf2c3..0e5e8815dc73d23f70fa042944b395aab4ea369b 100644 (file)
@@ -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);
index 016072c5873dcdbb8c91b203e9524b2d8cc2c56c..a2ebceaf1da11f39d7ed76e07d5983416269cb41 100644 (file)
@@ -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;
        }
index bc7cc0164fc670335d9a0c481a670d383698ed1c..5ca0378e228203bf4974545b27b10ef798a8d131 100644 (file)
@@ -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.
index aea38e464b92c40228ed7ff02dd2cb633b4cedd5..8004fd222d808c5963f21835bc879d0bb2b8c5b0 100644 (file)
@@ -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);
index 13b1f8bf51e7af88f07f8dd0a8861afe20d25faf..2bb65849150ecca0bf7def2c1057bd3348222e71 100644 (file)
@@ -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.
  *