blob: 4f887fc578757afc9ee1804eb6835296489345a4 [file] [log] [blame]
Hans Wennborg12aea3e2020-04-14 15:29:001// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/check_op.h"
6
7// check_op.h is a widely included header and its size has significant impact on
8// build time. Try not to raise this limit unless absolutely necessary. See
9// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
10#ifndef NACL_TC_REV
Tiancong Wanga007ad32020-05-07 08:54:2411#pragma clang max_tokens_here 244000
Hans Wennborg12aea3e2020-04-14 15:29:0012#endif
13
Erik Chenc073e802020-04-22 21:21:5414#include <string.h>
15
Hans Wennborg12aea3e2020-04-14 15:29:0016#include <cstdio>
17#include <sstream>
18
19namespace logging {
20
21char* CheckOpValueStr(int v) {
22 char buf[50];
23 snprintf(buf, sizeof(buf), "%d", v);
24 return strdup(buf);
25}
26
27char* CheckOpValueStr(unsigned v) {
28 char buf[50];
29 snprintf(buf, sizeof(buf), "%u", v);
30 return strdup(buf);
31}
32
Hans Wennborg338a7f402020-04-20 19:52:3233char* CheckOpValueStr(long v) {
34 char buf[50];
35 snprintf(buf, sizeof(buf), "%ld", v);
36 return strdup(buf);
37}
38
Hans Wennborg12aea3e2020-04-14 15:29:0039char* CheckOpValueStr(unsigned long v) {
40 char buf[50];
41 snprintf(buf, sizeof(buf), "%lu", v);
42 return strdup(buf);
43}
44
Hans Wennborg338a7f402020-04-20 19:52:3245char* CheckOpValueStr(long long v) {
46 char buf[50];
47 snprintf(buf, sizeof(buf), "%lld", v);
48 return strdup(buf);
49}
50
51char* CheckOpValueStr(unsigned long long v) {
52 char buf[50];
53 snprintf(buf, sizeof(buf), "%llu", v);
54 return strdup(buf);
55}
56
Hans Wennborg12aea3e2020-04-14 15:29:0057char* CheckOpValueStr(const void* v) {
58 char buf[50];
59 snprintf(buf, sizeof(buf), "%p", v);
60 return strdup(buf);
61}
62
63char* CheckOpValueStr(std::nullptr_t v) {
64 return strdup("nullptr");
65}
66
67char* CheckOpValueStr(double v) {
68 char buf[50];
69 snprintf(buf, sizeof(buf), "%.6lf", v);
70 return strdup(buf);
71}
72
73char* StreamValToStr(const void* v,
74 void (*stream_func)(std::ostream&, const void*)) {
75 std::stringstream ss;
76 stream_func(ss, v);
77 return strdup(ss.str().c_str());
78}
79
80CheckOpResult::CheckOpResult(const char* expr_str, char* v1_str, char* v2_str) {
81 std::ostringstream ss;
82 ss << expr_str << " (" << v1_str << " vs. " << v2_str << ")";
83 message_ = strdup(ss.str().c_str());
84 free(v1_str);
85 free(v2_str);
86}
87
88} // namespace logging