scripted-diff: Rename UNIQUE_NAME to BITCOIN_UNIQUE_NAME
What changed, and why it matters
This commit is a simple rename of an internal helper macro from UNIQUE_NAME to BITCOIN_UNIQUE_NAME. The change prevents a potential future build failure on Windows because a Windows system header also defines UNIQUE_NAME. It does not change program behavior, fix a vulnerability, or affect live network code.
No security action needed. Treat as normal build/maintenance cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch is a scripted global rename of the UNIQUE_NAME(name) macro to BITCOIN_UNIQUE_NAME(name). The macro concatenates a base identifier with COUNTER to create unique variable names inside other macros (LOG_TIME_*, LOCK, REVERSE_LOCK, STDLOCK, ASSERT_DEBUG_LOG). The rename avoids a name collision with the Windows nb30.h header, which also defines UNIQUE_NAME as a macro. The change is purely defensive/build-hygiene and has no runtime effect.
Changed components
src/util/macros.hsrc/logging/timer.hsrc/sync.hsrc/test/util/logging.hsrc/util/stdmutex.hInspect captured patch +9 / −9
diff --git a/src/logging/timer.h b/src/logging/timer.h
index 2b183822..1706c9e7 100644
--- a/src/logging/timer.h
+++ b/src/logging/timer.h
@@ -99,13 +99,13 @@ private:
#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
- BCLog::Timer<std::chrono::microseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
+ BCLog::Timer<std::chrono::microseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
- BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
+ BCLog::Timer<std::chrono::milliseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category) \
- BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false)
+ BCLog::Timer<std::chrono::milliseconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category, /* msg_on_completion=*/false)
#define LOG_TIME_SECONDS(end_msg) \
- BCLog::Timer<std::chrono::seconds> UNIQUE_NAME(logging_timer)(__func__, end_msg)
+ BCLog::Timer<std::chrono::seconds> BITCOIN_UNIQUE_NAME(logging_timer)(__func__, end_msg)
#endif // BITCOIN_LOGGING_TIMER_H
diff --git a/src/sync.h b/src/sync.h
index 123184d4..28bc78e9 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -251,7 +251,7 @@ public:
// it is not possible to use the lock's copy of the mutex for that purpose.
// Instead, the original mutex needs to be passed back to the reverse_lock for
// the sake of thread-safety analysis, but it is not actually used otherwise.
-#define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__)
+#define REVERSE_LOCK(g, cs) typename std::decay<decltype(g)>::type::reverse_lock BITCOIN_UNIQUE_NAME(revlock)(g, cs, #cs, __FILE__, __LINE__)
// When locking a Mutex, require negative capability to ensure the lock
// is not already held
@@ -265,7 +265,7 @@ inline MutexType& MaybeCheckNotHeld(MutexType& m) LOCKS_EXCLUDED(m) LOCK_RETURNE
template <typename MutexType>
inline MutexType* MaybeCheckNotHeld(MutexType* m) LOCKS_EXCLUDED(m) LOCK_RETURNED(m) { return m; }
-#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
+#define LOCK(cs) UniqueLock BITCOIN_UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
#define LOCK2(cs1, cs2) \
UniqueLock criticalblock1(MaybeCheckNotHeld(cs1), #cs1, __FILE__, __LINE__); \
UniqueLock criticalblock2(MaybeCheckNotHeld(cs2), #cs2, __FILE__, __LINE__)
diff --git a/src/test/util/logging.h b/src/test/util/logging.h
index ed3ee19e..6df208d8 100644
--- a/src/test/util/logging.h
+++ b/src/test/util/logging.h
@@ -39,6 +39,6 @@ private:
MatchFn m_match;
};
-#define ASSERT_DEBUG_LOG(message) DebugLogHelper UNIQUE_NAME(debugloghelper)(message)
+#define ASSERT_DEBUG_LOG(message) DebugLogHelper BITCOIN_UNIQUE_NAME(debugloghelper)(message)
#endif // BITCOIN_TEST_UTIL_LOGGING_H
diff --git a/src/util/macros.h b/src/util/macros.h
index 9ad2fa6e..eedd23c6 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -8,7 +8,7 @@
#define PASTE(x, y) x ## y
#define PASTE2(x, y) PASTE(x, y)
-#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
+#define BITCOIN_UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
/**
* Converts the parameter X to a string after macro replacement on X has been performed.
diff --git a/src/util/stdmutex.h b/src/util/stdmutex.h
index ab89a987..d2ac1ba1 100644
--- a/src/util/stdmutex.h
+++ b/src/util/stdmutex.h
@@ -38,6 +38,6 @@ public:
};
// Provide STDLOCK(..) wrapper around StdMutex::Guard that checks the lock is not already held
-#define STDLOCK(cs) StdMutex::Guard UNIQUE_NAME(criticalblock){StdMutex::CheckNotHeld(cs)}
+#define STDLOCK(cs) StdMutex::Guard BITCOIN_UNIQUE_NAME(criticalblock){StdMutex::CheckNotHeld(cs)}
#endif // BITCOIN_UTIL_STDMUTEX_H
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.