Support absl::string_view in RTC_CHECK.

Bug: None
Change-Id: I8d4c296f1ac16a96adb88401f78ee9f65911bfc0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126482
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27052}
This commit is contained in:
Mirko Bonadei
2019-03-11 10:31:22 +01:00
committed by Commit Bot
parent 8cc711a7e1
commit d4a37a6ee6
3 changed files with 14 additions and 2 deletions

View File

@ -341,6 +341,7 @@ rtc_source_set("checks") {
deps = [
":safe_compare",
"system:inline",
"//third_party/abseil-cpp/absl/strings",
]
if (is_android) {
libs += [ "log" ]

View File

@ -39,7 +39,7 @@ namespace {
#if defined(__GNUC__)
__attribute__((__format__(__printf__, 2, 3)))
#endif
void AppendFormat(std::string* s, const char* fmt, ...) {
void AppendFormat(std::string* s, const char* fmt, ...) {
va_list args, copy;
va_start(args, fmt);
va_copy(copy, args);
@ -54,7 +54,7 @@ __attribute__((__format__(__printf__, 2, 3)))
}
va_end(args);
}
}
} // namespace
namespace rtc {
namespace webrtc_checks_impl {
@ -96,6 +96,11 @@ bool ParseArg(va_list* args, const CheckArgType** fmt, std::string* s) {
case CheckArgType::kStdString:
s->append(*va_arg(*args, const std::string*));
break;
case CheckArgType::kStringView: {
const absl::string_view sv = *va_arg(*args, const absl::string_view*);
s->append(sv.data(), sv.size());
break;
}
case CheckArgType::kVoidP:
AppendFormat(s, "%p", va_arg(*args, const void*));
break;

View File

@ -42,6 +42,7 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg);
#include <string>
#include "absl/strings/string_view.h"
#include "rtc_base/numerics/safe_compare.h"
#include "rtc_base/system/inline.h"
@ -99,6 +100,7 @@ enum class CheckArgType : int8_t {
kLongDouble,
kCharP,
kStdString,
kStringView,
kVoidP,
// kCheckOp doesn't represent an argument type. Instead, it is sent as the
@ -157,6 +159,10 @@ inline Val<CheckArgType::kStdString, const std::string*> MakeVal(
const std::string& x) {
return {&x};
}
inline Val<CheckArgType::kStringView, const absl::string_view*> MakeVal(
const absl::string_view& x) {
return {&x};
}
inline Val<CheckArgType::kVoidP, const void*> MakeVal(const void* x) {
return {x};