[tor-commits] [tor/master] log: Define count, boundary, and all macros for domains and flags

asn at torproject.org asn at torproject.org
Thu Oct 3 16:14:07 UTC 2019


commit 25c5322dfe228178391b37fffd3333abdf57baa5
Author: teor <teor at torproject.org>
Date:   Thu Sep 26 13:33:17 2019 +1000

    log: Define count, boundary, and all macros for domains and flags
    
    And do static checks on those macro definitions.
    
    Part of 31854.
---
 src/lib/log/log.c |  4 +++-
 src/lib/log/log.h | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/lib/log/log.c b/src/lib/log/log.c
index 994fdbdd9..db4f15441 100644
--- a/src/lib/log/log.c
+++ b/src/lib/log/log.c
@@ -1337,7 +1337,9 @@ static const char *domain_list[] = {
 
 CTASSERT(ARRAY_LENGTH(domain_list) == N_LOGGING_DOMAINS + 1);
 
-CTASSERT((UINT64_C(1)<<(N_LOGGING_DOMAINS-1)) < LOWEST_RESERVED_LD_FLAG_);
+CTASSERT(HIGHEST_RESERVED_LD_DOMAIN_ < LD_ALL_DOMAINS);
+CTASSERT(LD_ALL_DOMAINS < LOWEST_RESERVED_LD_FLAG_);
+CTASSERT(LOWEST_RESERVED_LD_FLAG_ < LD_ALL_FLAGS);
 
 /** Return a bitmask for the log domain for which <b>domain</b> is the name,
  * or 0 if there is no such name. */
diff --git a/src/lib/log/log.h b/src/lib/log/log.h
index da4bcbe60..b957fd156 100644
--- a/src/lib/log/log.h
+++ b/src/lib/log/log.h
@@ -117,10 +117,21 @@
 #define LD_BTRACK    (UINT64_C(1)<<28)
 /** Message-passing backend. */
 #define LD_MESG      (UINT64_C(1)<<29)
+
+/** The number of log domains. */
 #define N_LOGGING_DOMAINS 30
+/** The highest log domain */
+#define HIGHEST_RESERVED_LD_DOMAIN_ (UINT64_C(1)<<(N_LOGGING_DOMAINS - 1))
+/** All log domains. */
+#define LD_ALL_DOMAINS ((~(UINT64_C(0)))>>(64 - N_LOGGING_DOMAINS))
 
+/** The number of log flags. */
+#define N_LOGGING_FLAGS 3
 /** First bit that is reserved in log_domain_mask_t for non-domain flags. */
-#define LOWEST_RESERVED_LD_FLAG_ (UINT64_C(1)<<61)
+#define LOWEST_RESERVED_LD_FLAG_ (UINT64_C(1)<<(64 - N_LOGGING_FLAGS))
+/** All log flags. */
+#define LD_ALL_FLAGS ((~(UINT64_C(0)))<<(64 - N_LOGGING_FLAGS))
+
 #ifdef TOR_UNIT_TESTS
 /** This log message should not be intercepted by mock_saving_logv */
 #define LD_NO_MOCK (UINT64_C(1)<<61)





More information about the tor-commits mailing list