From c84133987c233c0479859b01a4399269278fcecd Mon Sep 17 00:00:00 2001 From: Evan Shrubsole Date: Fri, 7 Feb 2025 08:54:45 +0000 Subject: [PATCH] Move rtc_base/checks.h and includes to webrtc namespace Bug: webrtc:42232595 Change-Id: I5459af35b9bbab57748dd74cb9151562b9ff2607 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376480 Reviewed-by: Mirko Bonadei Commit-Queue: Evan Shrubsole Cr-Commit-Position: refs/heads/main@{#43856} --- rtc_base/checks.cc | 12 ++--- rtc_base/checks.h | 89 ++++++++++++++++++-------------- rtc_base/numerics/safe_compare.h | 25 ++++++--- rtc_base/type_traits.h | 11 +++- 4 files changed, 84 insertions(+), 53 deletions(-) diff --git a/rtc_base/checks.cc b/rtc_base/checks.cc index 14cfe69049..6fa0514c36 100644 --- a/rtc_base/checks.cc +++ b/rtc_base/checks.cc @@ -59,7 +59,7 @@ void AppendFormat(std::string* s, const char* fmt, ...) { } } // namespace -namespace rtc { +namespace webrtc { namespace webrtc_checks_impl { #if !defined(WEBRTC_CHROMIUM_BUILD) @@ -224,17 +224,17 @@ RTC_NORETURN void UnreachableCodeReached() { #endif // !RTC_DCHECK_IS_ON } // namespace webrtc_checks_impl -} // namespace rtc +} // namespace webrtc // Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros. RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg) { #if RTC_CHECK_MSG_ENABLED - static constexpr rtc::webrtc_checks_impl::CheckArgType t[] = { - rtc::webrtc_checks_impl::CheckArgType::kEnd}; - rtc::webrtc_checks_impl::FatalLog(file, line, msg, t); + static constexpr webrtc::webrtc_checks_impl::CheckArgType t[] = { + webrtc::webrtc_checks_impl::CheckArgType::kEnd}; + webrtc::webrtc_checks_impl::FatalLog(file, line, msg, t); #else - rtc::webrtc_checks_impl::FatalLog(file, line); + webrtc::webrtc_checks_impl::FatalLog(file, line); #endif } diff --git a/rtc_base/checks.h b/rtc_base/checks.h index a562efe74a..438b64d32e 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -11,7 +11,7 @@ #ifndef RTC_BASE_CHECKS_H_ #define RTC_BASE_CHECKS_H_ -// If you for some reson need to know if DCHECKs are on, test the value of +// If you for some reason need to know if DCHECKs are on, test the value of // RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be // defined, to either a true or a false value.) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) @@ -52,7 +52,9 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); #ifdef __cplusplus // C++ version. +#include #include +#include #include "absl/meta/type_traits.h" #include "absl/strings/has_absl_stringify.h" @@ -101,7 +103,10 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); // // - RTC_FATAL() aborts unconditionally. -namespace rtc { +// TODO(bugs.webrtc.org/42232595): Remove this macro once Chrome has migrated. +#define RTC_CHECKS_IN_WEBRTC_NAMESPACE 1 + +namespace webrtc { namespace webrtc_checks_impl { enum class CheckArgType : int8_t { kEnd = 0, @@ -205,7 +210,7 @@ inline Val MakeVal(const void* x) { template inline Val MakeVal( - const rtc::scoped_refptr& p) { + const webrtc::scoped_refptr& p) { return {p.get()}; } @@ -380,17 +385,17 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(); // in a particularly convoluted way with an extra ?: because that appears to be // the simplest construct that keeps Visual Studio from complaining about // condition being unused). -#define RTC_EAT_STREAM_PARAMETERS(ignored) \ - (true ? true : ((void)(ignored), true)) \ - ? static_cast(0) \ - : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_EAT_STREAM_PARAMETERS(ignored) \ + (true ? true : ((void)(ignored), true)) \ + ? static_cast(0) \ + : ::webrtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() // Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if // values of the same types as `a` and `b` can't be compared with the given // operation, and that would evaluate `a` and `b` if evaluated. #define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ - RTC_EAT_STREAM_PARAMETERS(((void)::rtc::Safe##op(a, b))) + RTC_EAT_STREAM_PARAMETERS(((void)::webrtc::Safe##op(a, b))) // RTC_CHECK dies with a fatal error if condition is not true. It is *not* // controlled by NDEBUG or anything else, so the check will be executed @@ -402,34 +407,34 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(); // RTC_CHECK_OP is a helper macro for binary operators. // Don't use this macro directly in your code, use RTC_CHECK_EQ et al below. #if RTC_CHECK_MSG_ENABLED -#define RTC_CHECK(condition) \ - (condition) ? static_cast(0) \ - : ::rtc::webrtc_checks_impl::FatalLogCall( \ - __FILE__, __LINE__, #condition) & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK(condition) \ + (condition) ? static_cast(0) \ + : ::webrtc::webrtc_checks_impl::FatalLogCall( \ + __FILE__, __LINE__, #condition) & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() #define RTC_CHECK_OP(name, op, val1, val2) \ - ::rtc::Safe##name((val1), (val2)) \ + ::webrtc::Safe##name((val1), (val2)) \ ? static_cast(0) \ - : ::rtc::webrtc_checks_impl::FatalLogCall( \ + : ::webrtc::webrtc_checks_impl::FatalLogCall( \ __FILE__, __LINE__, #val1 " " #op " " #val2) & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) + ::webrtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) #else -#define RTC_CHECK(condition) \ - (condition) ? static_cast(0) \ - : true ? ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - "") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() \ - : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK(condition) \ + (condition) ? static_cast(0) \ + : true ? ::webrtc::webrtc_checks_impl::FatalLogCall(__FILE__, \ + __LINE__, "") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() \ + : ::webrtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() -#define RTC_CHECK_OP(name, op, val1, val2) \ - ::rtc::Safe##name((val1), (val2)) ? static_cast(0) \ - : true ? ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - "") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() \ - : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK_OP(name, op, val1, val2) \ + ::webrtc::Safe##name((val1), (val2)) ? static_cast(0) \ + : true ? ::webrtc::webrtc_checks_impl::FatalLogCall(__FILE__, \ + __LINE__, "") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() \ + : ::webrtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() #endif #define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2) @@ -465,16 +470,16 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(); // Kills the process with an error message. Never returns. Use when you wish to // assert that a point in the code is never reached. -#define RTC_CHECK_NOTREACHED() \ - do { \ - ::rtc::webrtc_checks_impl::UnreachableCodeReached( \ - RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \ +#define RTC_CHECK_NOTREACHED() \ + do { \ + ::webrtc::webrtc_checks_impl::UnreachableCodeReached( \ + RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \ } while (0) -#define RTC_FATAL() \ - ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - "FATAL()") & \ - ::rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_FATAL() \ + ::webrtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ + "FATAL()") & \ + ::webrtc::webrtc_checks_impl::LogStreamer<>() // Performs the integer division a/b and returns the result. CHECKs that the // remainder is zero. @@ -484,6 +489,12 @@ inline T CheckedDivExact(T a, T b) { return a / b; } +} // namespace webrtc + +// Re-export symbols from the webrtc namespace for backwards compatibility. +// TODO(bugs.webrtc.org/4222596): Remove once all references are updated. +namespace rtc { +using ::webrtc::CheckedDivExact; } // namespace rtc #else // __cplusplus not defined diff --git a/rtc_base/numerics/safe_compare.h b/rtc_base/numerics/safe_compare.h index d3d918d653..32afcfeeaa 100644 --- a/rtc_base/numerics/safe_compare.h +++ b/rtc_base/numerics/safe_compare.h @@ -10,12 +10,12 @@ // This file defines six constexpr functions: // -// rtc::SafeEq // == -// rtc::SafeNe // != -// rtc::SafeLt // < -// rtc::SafeLe // <= -// rtc::SafeGt // > -// rtc::SafeGe // >= +// webrtc::SafeEq // == +// webrtc::SafeNe // != +// webrtc::SafeLt // < +// webrtc::SafeLe // <= +// webrtc::SafeGt // > +// webrtc::SafeGe // >= // // They each accept two arguments of arbitrary types, and in almost all cases, // they simply call the appropriate comparison operator. However, if both @@ -38,7 +38,7 @@ #include "rtc_base/type_traits.h" -namespace rtc { +namespace webrtc { namespace safe_cmp_impl { @@ -170,6 +170,17 @@ RTC_SAFECMP_MAKE_FUN(Gt) RTC_SAFECMP_MAKE_FUN(Ge) #undef RTC_SAFECMP_MAKE_FUN +} // namespace webrtc + +// Re-export symbols from the webrtc namespace for backwards compatibility. +// TODO(bugs.webrtc.org/4222596): Remove once all references are updated. +namespace rtc { +using ::webrtc::SafeEq; +using ::webrtc::SafeGe; +using ::webrtc::SafeGt; +using ::webrtc::SafeLe; +using ::webrtc::SafeLt; +using ::webrtc::SafeNe; } // namespace rtc #endif // RTC_BASE_NUMERICS_SAFE_COMPARE_H_ diff --git a/rtc_base/type_traits.h b/rtc_base/type_traits.h index 8f90a8840e..7547fb88d5 100644 --- a/rtc_base/type_traits.h +++ b/rtc_base/type_traits.h @@ -15,7 +15,7 @@ #include #include -namespace rtc { +namespace webrtc { // Determines if the given class has zero-argument .data() and .size() methods // whose return values are convertible to T* and size_t, respectively. @@ -136,6 +136,15 @@ static_assert(!IsIntlike::value, ""); } // namespace test_enum_intlike +} // namespace webrtc + +// Re-export symbols from the webrtc namespace for backwards compatibility. +// TODO(bugs.webrtc.org/4222596): Remove once all references are updated. +namespace rtc { +template +using HasDataAndSize = ::webrtc::HasDataAndSize; +template +using IsIntlike = ::webrtc::IsIntlike; } // namespace rtc #endif // RTC_BASE_TYPE_TRAITS_H_