mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 14:48:46 +02:00
Merge bitcoin/bitcoin#35487: scripted-diff: Rename UNIQUE_NAME to BITCOIN_UNIQUE_NAME
fba713a28cscripted-diff: Rename UNIQUE_NAME to BITCOIN_UNIQUE_NAME (Hennadii Stepanov) Pull request description: https://github.com/bitcoin/bitcoin/pull/34454#issuecomment-3822800049: > ... it is annoying that we keep running into the same bug over and over again (IIRC it happened in the past at least once for Bitcoin Core). Surely this is going to happen again in the future. And here we go again. --- The `nb30.h` Windows header [defines](b536c4fdb0/mingw-w64-headers/include/nb30.h (L78)) `UNIQUE_NAME` as a macro. This introduces a fragile dependency on header inclusion order: if Windows headers happen to be included before `UNIQUE_NAME` is used, the preprocessor expands it into a numeric literal, causing syntax errors. Rename the macro to `BITCOIN_UNIQUE_NAME` to remove this fragility and avoid the collision entirely. --- Noticed while doing a Guix build of the [QML repo](https://github.com/bitcoin-core/gui-qml) for Windows. Recent similar PRs: https://github.com/bitcoin/bitcoin/pull/34454 and https://github.com/bitcoin/bitcoin/pull/34868. ACKs for top commit: maflcko: lgtm ACKfba713a28csedited: ACKfba713a28cw0xlt: ACKfba713a28cTree-SHA512: 7a63b99a754e797eb8fa5d6a598606150f47ae1130d1d26067c509830e6575f0378ce63fe0ca35c69dce9a394451a34ddadd8b3d5f6f9a7e4c529108af546fb6
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user