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 <mbonadei@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43856}
This commit is contained in:
Evan Shrubsole 2025-02-07 08:54:45 +00:00 committed by WebRTC LUCI CQ
parent 150943c078
commit c84133987c
4 changed files with 84 additions and 53 deletions

View File

@ -59,7 +59,7 @@ void AppendFormat(std::string* s, const char* fmt, ...) {
} }
} // namespace } // namespace
namespace rtc { namespace webrtc {
namespace webrtc_checks_impl { namespace webrtc_checks_impl {
#if !defined(WEBRTC_CHROMIUM_BUILD) #if !defined(WEBRTC_CHROMIUM_BUILD)
@ -224,17 +224,17 @@ RTC_NORETURN void UnreachableCodeReached() {
#endif // !RTC_DCHECK_IS_ON #endif // !RTC_DCHECK_IS_ON
} // namespace webrtc_checks_impl } // namespace webrtc_checks_impl
} // namespace rtc } // namespace webrtc
// Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros. // Function to call from the C version of the RTC_CHECK and RTC_DCHECK macros.
RTC_NORETURN void rtc_FatalMessage(const char* file, RTC_NORETURN void rtc_FatalMessage(const char* file,
int line, int line,
const char* msg) { const char* msg) {
#if RTC_CHECK_MSG_ENABLED #if RTC_CHECK_MSG_ENABLED
static constexpr rtc::webrtc_checks_impl::CheckArgType t[] = { static constexpr webrtc::webrtc_checks_impl::CheckArgType t[] = {
rtc::webrtc_checks_impl::CheckArgType::kEnd}; webrtc::webrtc_checks_impl::CheckArgType::kEnd};
rtc::webrtc_checks_impl::FatalLog(file, line, msg, t); webrtc::webrtc_checks_impl::FatalLog(file, line, msg, t);
#else #else
rtc::webrtc_checks_impl::FatalLog(file, line); webrtc::webrtc_checks_impl::FatalLog(file, line);
#endif #endif
} }

View File

@ -11,7 +11,7 @@
#ifndef RTC_BASE_CHECKS_H_ #ifndef RTC_BASE_CHECKS_H_
#define 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 // 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.) // defined, to either a true or a false value.)
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #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 #ifdef __cplusplus
// C++ version. // C++ version.
#include <cstdint>
#include <string> #include <string>
#include <type_traits>
#include "absl/meta/type_traits.h" #include "absl/meta/type_traits.h"
#include "absl/strings/has_absl_stringify.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. // - 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 { namespace webrtc_checks_impl {
enum class CheckArgType : int8_t { enum class CheckArgType : int8_t {
kEnd = 0, kEnd = 0,
@ -205,7 +210,7 @@ inline Val<CheckArgType::kVoidP, const void*> MakeVal(const void* x) {
template <typename T> template <typename T>
inline Val<CheckArgType::kVoidP, const void*> MakeVal( inline Val<CheckArgType::kVoidP, const void*> MakeVal(
const rtc::scoped_refptr<T>& p) { const webrtc::scoped_refptr<T>& p) {
return {p.get()}; return {p.get()};
} }
@ -383,14 +388,14 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached();
#define RTC_EAT_STREAM_PARAMETERS(ignored) \ #define RTC_EAT_STREAM_PARAMETERS(ignored) \
(true ? true : ((void)(ignored), true)) \ (true ? true : ((void)(ignored), true)) \
? static_cast<void>(0) \ ? static_cast<void>(0) \
: ::rtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \ : ::webrtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \
::rtc::webrtc_checks_impl::LogStreamer<>() ::webrtc::webrtc_checks_impl::LogStreamer<>()
// Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if // 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 // 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. // operation, and that would evaluate `a` and `b` if evaluated.
#define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ #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* // 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 // controlled by NDEBUG or anything else, so the check will be executed
@ -404,32 +409,32 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached();
#if RTC_CHECK_MSG_ENABLED #if RTC_CHECK_MSG_ENABLED
#define RTC_CHECK(condition) \ #define RTC_CHECK(condition) \
(condition) ? static_cast<void>(0) \ (condition) ? static_cast<void>(0) \
: ::rtc::webrtc_checks_impl::FatalLogCall<false>( \ : ::webrtc::webrtc_checks_impl::FatalLogCall<false>( \
__FILE__, __LINE__, #condition) & \ __FILE__, __LINE__, #condition) & \
::rtc::webrtc_checks_impl::LogStreamer<>() ::webrtc::webrtc_checks_impl::LogStreamer<>()
#define RTC_CHECK_OP(name, op, val1, val2) \ #define RTC_CHECK_OP(name, op, val1, val2) \
::rtc::Safe##name((val1), (val2)) \ ::webrtc::Safe##name((val1), (val2)) \
? static_cast<void>(0) \ ? static_cast<void>(0) \
: ::rtc::webrtc_checks_impl::FatalLogCall<true>( \ : ::webrtc::webrtc_checks_impl::FatalLogCall<true>( \
__FILE__, __LINE__, #val1 " " #op " " #val2) & \ __FILE__, __LINE__, #val1 " " #op " " #val2) & \
::rtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) ::webrtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2)
#else #else
#define RTC_CHECK(condition) \ #define RTC_CHECK(condition) \
(condition) ? static_cast<void>(0) \ (condition) ? static_cast<void>(0) \
: true ? ::rtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \ : true ? ::webrtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, \
"") & \ __LINE__, "") & \
::rtc::webrtc_checks_impl::LogStreamer<>() \ ::webrtc::webrtc_checks_impl::LogStreamer<>() \
: ::rtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \ : ::webrtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \
::rtc::webrtc_checks_impl::LogStreamer<>() ::webrtc::webrtc_checks_impl::LogStreamer<>()
#define RTC_CHECK_OP(name, op, val1, val2) \ #define RTC_CHECK_OP(name, op, val1, val2) \
::rtc::Safe##name((val1), (val2)) ? static_cast<void>(0) \ ::webrtc::Safe##name((val1), (val2)) ? static_cast<void>(0) \
: true ? ::rtc::webrtc_checks_impl::FatalLogCall<true>(__FILE__, __LINE__, \ : true ? ::webrtc::webrtc_checks_impl::FatalLogCall<true>(__FILE__, \
"") & \ __LINE__, "") & \
::rtc::webrtc_checks_impl::LogStreamer<>() \ ::webrtc::webrtc_checks_impl::LogStreamer<>() \
: ::rtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \ : ::webrtc::webrtc_checks_impl::FatalLogCall<false>("", 0, "") & \
::rtc::webrtc_checks_impl::LogStreamer<>() ::webrtc::webrtc_checks_impl::LogStreamer<>()
#endif #endif
#define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2) #define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2)
@ -467,14 +472,14 @@ RTC_NORETURN RTC_EXPORT void UnreachableCodeReached();
// assert that a point in the code is never reached. // assert that a point in the code is never reached.
#define RTC_CHECK_NOTREACHED() \ #define RTC_CHECK_NOTREACHED() \
do { \ do { \
::rtc::webrtc_checks_impl::UnreachableCodeReached( \ ::webrtc::webrtc_checks_impl::UnreachableCodeReached( \
RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \ RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \
} while (0) } while (0)
#define RTC_FATAL() \ #define RTC_FATAL() \
::rtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \ ::webrtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \
"FATAL()") & \ "FATAL()") & \
::rtc::webrtc_checks_impl::LogStreamer<>() ::webrtc::webrtc_checks_impl::LogStreamer<>()
// Performs the integer division a/b and returns the result. CHECKs that the // Performs the integer division a/b and returns the result. CHECKs that the
// remainder is zero. // remainder is zero.
@ -484,6 +489,12 @@ inline T CheckedDivExact(T a, T b) {
return a / 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 } // namespace rtc
#else // __cplusplus not defined #else // __cplusplus not defined

View File

@ -10,12 +10,12 @@
// This file defines six constexpr functions: // This file defines six constexpr functions:
// //
// rtc::SafeEq // == // webrtc::SafeEq // ==
// rtc::SafeNe // != // webrtc::SafeNe // !=
// rtc::SafeLt // < // webrtc::SafeLt // <
// rtc::SafeLe // <= // webrtc::SafeLe // <=
// rtc::SafeGt // > // webrtc::SafeGt // >
// rtc::SafeGe // >= // webrtc::SafeGe // >=
// //
// They each accept two arguments of arbitrary types, and in almost all cases, // They each accept two arguments of arbitrary types, and in almost all cases,
// they simply call the appropriate comparison operator. However, if both // they simply call the appropriate comparison operator. However, if both
@ -38,7 +38,7 @@
#include "rtc_base/type_traits.h" #include "rtc_base/type_traits.h"
namespace rtc { namespace webrtc {
namespace safe_cmp_impl { namespace safe_cmp_impl {
@ -170,6 +170,17 @@ RTC_SAFECMP_MAKE_FUN(Gt)
RTC_SAFECMP_MAKE_FUN(Ge) RTC_SAFECMP_MAKE_FUN(Ge)
#undef RTC_SAFECMP_MAKE_FUN #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 } // namespace rtc
#endif // RTC_BASE_NUMERICS_SAFE_COMPARE_H_ #endif // RTC_BASE_NUMERICS_SAFE_COMPARE_H_

View File

@ -15,7 +15,7 @@
#include <string> #include <string>
#include <type_traits> #include <type_traits>
namespace rtc { namespace webrtc {
// Determines if the given class has zero-argument .data() and .size() methods // Determines if the given class has zero-argument .data() and .size() methods
// whose return values are convertible to T* and size_t, respectively. // whose return values are convertible to T* and size_t, respectively.
@ -136,6 +136,15 @@ static_assert(!IsIntlike<S>::value, "");
} // namespace test_enum_intlike } // 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 <typename DS, typename T>
using HasDataAndSize = ::webrtc::HasDataAndSize<DS, T>;
template <typename T>
using IsIntlike = ::webrtc::IsIntlike<T>;
} // namespace rtc } // namespace rtc
#endif // RTC_BASE_TYPE_TRAITS_H_ #endif // RTC_BASE_TYPE_TRAITS_H_