From fdc642643d25a4d67e5a04ae8ad4b0528a8c3835 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 23 Feb 2024 00:46:16 +0000 Subject: [PATCH] Reduce namespace pollution. Use the CALLSTACK_ prefix uniformly, and undefine all the macros at the end of the file. Change-Id: Ie5f92bb8cb8b3753082b1c1145696a1e0409e04d --- libutils/include/utils/CallStack.h | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/libutils/include/utils/CallStack.h b/libutils/include/utils/CallStack.h index 54d559b80..0239b682e 100644 --- a/libutils/include/utils/CallStack.h +++ b/libutils/include/utils/CallStack.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef ANDROID_CALLSTACK_H -#define ANDROID_CALLSTACK_H +#pragma once #include @@ -27,14 +26,14 @@ #include #if !defined(__APPLE__) && !defined(_WIN32) -# define WEAKS_AVAILABLE 1 +# define CALLSTACK_WEAKS_AVAILABLE 1 #endif #ifndef CALLSTACK_WEAK -# ifdef WEAKS_AVAILABLE +# ifdef CALLSTACK_WEAKS_AVAILABLE # define CALLSTACK_WEAK __attribute__((weak)) -# else // !WEAKS_AVAILABLE +# else // !CALLSTACK_WEAKS_AVAILABLE # define CALLSTACK_WEAK -# endif // !WEAKS_AVAILABLE +# endif // !CALLSTACK_WEAKS_AVAILABLE #endif // CALLSTACK_WEAK predefined #ifndef CALLSTACK_ALWAYS_INLINE @@ -91,7 +90,7 @@ public: // // DO NOT USE THESE. They will disappear. struct StackDeleter { -#ifdef WEAKS_AVAILABLE +#ifdef CALLSTACK_WEAKS_AVAILABLE void operator()(CallStack* stack) { deleteStack(stack); } @@ -103,7 +102,7 @@ public: typedef std::unique_ptr CallStackUPtr; // Return current call stack if possible, nullptr otherwise. -#ifdef WEAKS_AVAILABLE +#ifdef CALLSTACK_WEAKS_AVAILABLE static CallStackUPtr CALLSTACK_ALWAYS_INLINE getCurrent(int32_t ignoreDepth = 1) { if (reinterpret_cast(getCurrentInternal) == 0) { ALOGW("CallStack::getCurrentInternal not linked, returning null"); @@ -112,13 +111,13 @@ public: return getCurrentInternal(ignoreDepth); } } -#else // !WEAKS_AVAILABLE +#else // !CALLSTACK_WEAKS_AVAILABLE static CallStackUPtr CALLSTACK_ALWAYS_INLINE getCurrent(int32_t = 1) { return CallStackUPtr(nullptr); } -#endif // !WEAKS_AVAILABLE +#endif // !CALLSTACK_WEAKS_AVAILABLE -#ifdef WEAKS_AVAILABLE +#ifdef CALLSTACK_WEAKS_AVAILABLE static void CALLSTACK_ALWAYS_INLINE logStack(const char* logtag, CallStack* stack = getCurrent().get(), android_LogPriority priority = ANDROID_LOG_DEBUG) { @@ -135,9 +134,9 @@ public: android_LogPriority = ANDROID_LOG_DEBUG) { ALOG(LOG_WARN, logtag, "CallStack::logStackInternal not linked"); } -#endif // !WEAKS_AVAILABLE +#endif // !CALLSTACK_WEAKS_AVAILABLE -#ifdef WEAKS_AVAILABLE +#ifdef CALLSTACK_WEAKS_AVAILABLE static String8 CALLSTACK_ALWAYS_INLINE stackToString(const char* prefix = nullptr, const CallStack* stack = getCurrent().get()) { if (reinterpret_cast(stackToStringInternal) != 0 && stack != nullptr) { @@ -146,15 +145,15 @@ public: return String8::format("%s", (prefix ? prefix : "")); } } -#else // !WEAKS_AVAILABLE +#else // !CALLSTACK_WEAKS_AVAILABLE static String8 CALLSTACK_ALWAYS_INLINE stackToString(const char* prefix = nullptr, const CallStack* = getCurrent().get()) { return String8::format("%s", (prefix ? prefix : "")); } -#endif // !WEAKS_AVAILABLE +#endif // !CALLSTACK_WEAKS_AVAILABLE private: -#ifdef WEAKS_AVAILABLE +#ifdef CALLSTACK_WEAKS_AVAILABLE static CallStackUPtr CALLSTACK_WEAK getCurrentInternal(int32_t ignoreDepth); static void CALLSTACK_WEAK logStackInternal(const char* logtag, const CallStack* stack, android_LogPriority priority); @@ -162,13 +161,13 @@ public: // The deleter is only invoked on non-null pointers. Hence it will never be // invoked if CallStack is not linked. static void CALLSTACK_WEAK deleteStack(CallStack* stack); -#endif // WEAKS_AVAILABLE +#endif // CALLSTACK_WEAKS_AVAILABLE Vector mFrameLines; }; } // namespace android +#undef CALLSTACK_WEAKS_AVAILABLE +#undef CALLSTACK_WEAK #undef CALLSTACK_ALWAYS_INLINE - -#endif // ANDROID_CALLSTACK_H