]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Polish alignment macros
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 6 Dec 2021 11:39:54 +0000 (11:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 6 Dec 2021 11:39:54 +0000 (11:39 +0000)
config.h.in
src/libcryptobox/cryptobox.c
src/libserver/re_cache.c
src/libutil/mem_pool.h
src/libutil/multipattern.c
src/libutil/str_util.h

index d6a3fc1d08a050c01eb8d88b6908eabc63ad35cb..9487fd76e656893c68d17877babf8cefd7b78ec8 100644 (file)
@@ -322,6 +322,17 @@ typedef off_t goffset;
 #endif
 #endif
 
+#ifndef __cplusplus
+# ifdef G_ALIGNOF
+#  define RSPAMD_ALIGNOF G_ALIGNOF
+# else
+#  define RSPAMD_ALIGNOF(t) _Alignof(t)
+# endif
+#else
+/* glib G_ALIGNOF nor C11 _Alignof are not good enough for C++, nuff said... */
+# define RSPAMD_ALIGNOF(t) alignof(t)
+#endif
+
 /* Address sanitizer */
 #ifdef __clang__
 #  if __has_feature(address_sanitizer)
index fe4d3df2936dafc55e3fadd9121798d4ea2cdcb7..41f13ed73e81f7c7878b10b5780256c09cbbbf9d 100644 (file)
@@ -588,7 +588,7 @@ static gsize
 rspamd_cryptobox_auth_ctx_len (enum rspamd_cryptobox_mode mode)
 {
        if (G_LIKELY (mode == RSPAMD_CRYPTOBOX_MODE_25519)) {
-               return sizeof (crypto_onetimeauth_state) + _Alignof (crypto_onetimeauth_state);
+               return sizeof (crypto_onetimeauth_state) + RSPAMD_ALIGNOF(crypto_onetimeauth_state);
        }
        else {
 #ifndef HAVE_USABLE_OPENSSL
@@ -1440,7 +1440,7 @@ void
 rspamd_cryptobox_hash_init (rspamd_cryptobox_hash_state_t *p, const guchar *key, gsize keylen)
 {
        crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p,
-                       _Alignof(crypto_generichash_blake2b_state));
+                       RSPAMD_ALIGNOF(crypto_generichash_blake2b_state));
        crypto_generichash_blake2b_init (st, key, keylen,
                        crypto_generichash_blake2b_BYTES_MAX);
 }
@@ -1452,7 +1452,7 @@ void
 rspamd_cryptobox_hash_update (rspamd_cryptobox_hash_state_t *p, const guchar *data, gsize len)
 {
        crypto_generichash_blake2b_state *st = cryptobox_align_ptr (p,
-                       _Alignof(crypto_generichash_blake2b_state));
+                       RSPAMD_ALIGNOF(crypto_generichash_blake2b_state));
        crypto_generichash_blake2b_update (st, data, len);
 }
 
index 3016d04c53851303dd320612928473165aee35ea..2c5555154f72704165066c1296d1587302848e01 100644 (file)
@@ -406,7 +406,7 @@ rspamd_re_cache_init (struct rspamd_re_cache *cache, struct rspamd_config *cfg)
                rspamd_regexp_set_cache_id (re, i);
 
                if (re_class->st == NULL) {
-                       (void) !posix_memalign ((void **)&re_class->st, _Alignof (rspamd_cryptobox_hash_state_t),
+                       (void) !posix_memalign ((void **)&re_class->st, RSPAMD_ALIGNOF(rspamd_cryptobox_hash_state_t),
                                        sizeof (*re_class->st));
                        g_assert (re_class->st != NULL);
                        rspamd_cryptobox_hash_init (re_class->st, NULL, 0);
index 2db36e03a4c8b783c36b66575d0565f0a070159d..c369f116aa7da240c2908a9928a8858b2796ecdf 100644 (file)
@@ -68,11 +68,7 @@ struct f_str_s;
 #define MEMPOOL_UID_LEN 20
 /* All pointers are aligned as this variable */
 #define MIN_MEM_ALIGNMENT   G_MEM_ALIGN
-#ifndef __cplusplus
-#define RSPAMD_ALIGNOF G_ALIGNOF
-#else
-#define RSPAMD_ALIGNOF(t) alignof(t)
-#endif
+
 /**
  * Destructor type definition
  */
index 2842b1d599affae57b81c365ca255b82e1401360..8f959f486182a97b48b732dba389373bbc876bd8 100644 (file)
@@ -256,7 +256,7 @@ rspamd_multipattern_create (enum rspamd_multipattern_flags flags)
        struct rspamd_multipattern *mp;
 
        /* Align due to blake2b state */
-       (void) !posix_memalign((void **)&mp, _Alignof (struct rspamd_multipattern),
+       (void) !posix_memalign((void **)&mp, RSPAMD_ALIGNOF(struct rspamd_multipattern),
                        sizeof (*mp));
        g_assert (mp != NULL);
        memset (mp, 0, sizeof (*mp));
@@ -285,7 +285,7 @@ rspamd_multipattern_create_sized (guint npatterns,
        struct rspamd_multipattern *mp;
 
        /* Align due to blake2b state */
-       (void) !posix_memalign((void **)&mp, _Alignof (struct rspamd_multipattern), sizeof (*mp));
+       (void) !posix_memalign((void **)&mp, RSPAMD_ALIGNOF(struct rspamd_multipattern), sizeof (*mp));
        g_assert (mp != NULL);
        memset (mp, 0, sizeof (*mp));
        mp->flags = flags;
index b08dd56ad8dc856c5d29112cfe4cfb84a7251153..47abf062ebf4976a1736ace8b56d0398a8081120 100644 (file)
@@ -473,7 +473,7 @@ gsize rspamd_memspn (const gchar *s, const gchar *e, gsize len);
  * Check if a pointer is aligned; n must be power of two
  */
 #define rspamd_is_aligned(p, n) (((uintptr_t)(p) & ((uintptr_t)(n) - 1)) == 0)
-#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, _Alignof(__typeof((v))))
+#define rspamd_is_aligned_as(p, v) rspamd_is_aligned(p, RSPAMD_ALIGNOF(__typeof((v))))
 gboolean rspamd_str_has_8bit (const guchar *beg, gsize len);
 
 struct UConverter;