Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 1 | // 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 Wang | a007ad3 | 2020-05-07 08:54:24 | [diff] [blame] | 11 | #pragma clang max_tokens_here 244000 |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 12 | #endif |
| 13 | |
Erik Chen | c073e80 | 2020-04-22 21:21:54 | [diff] [blame] | 14 | #include <string.h> |
| 15 | |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 16 | #include <cstdio> |
| 17 | #include <sstream> |
| 18 | |
| 19 | namespace logging { |
| 20 | |
| 21 | char* CheckOpValueStr(int v) { |
| 22 | char buf[50]; |
| 23 | snprintf(buf, sizeof(buf), "%d", v); |
| 24 | return strdup(buf); |
| 25 | } |
| 26 | |
| 27 | char* CheckOpValueStr(unsigned v) { |
| 28 | char buf[50]; |
| 29 | snprintf(buf, sizeof(buf), "%u", v); |
| 30 | return strdup(buf); |
| 31 | } |
| 32 | |
Hans Wennborg | 338a7f40 | 2020-04-20 19:52:32 | [diff] [blame] | 33 | char* CheckOpValueStr(long v) { |
| 34 | char buf[50]; |
| 35 | snprintf(buf, sizeof(buf), "%ld", v); |
| 36 | return strdup(buf); |
| 37 | } |
| 38 | |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 39 | char* CheckOpValueStr(unsigned long v) { |
| 40 | char buf[50]; |
| 41 | snprintf(buf, sizeof(buf), "%lu", v); |
| 42 | return strdup(buf); |
| 43 | } |
| 44 | |
Hans Wennborg | 338a7f40 | 2020-04-20 19:52:32 | [diff] [blame] | 45 | char* CheckOpValueStr(long long v) { |
| 46 | char buf[50]; |
| 47 | snprintf(buf, sizeof(buf), "%lld", v); |
| 48 | return strdup(buf); |
| 49 | } |
| 50 | |
| 51 | char* CheckOpValueStr(unsigned long long v) { |
| 52 | char buf[50]; |
| 53 | snprintf(buf, sizeof(buf), "%llu", v); |
| 54 | return strdup(buf); |
| 55 | } |
| 56 | |
Hans Wennborg | 12aea3e | 2020-04-14 15:29:00 | [diff] [blame] | 57 | char* CheckOpValueStr(const void* v) { |
| 58 | char buf[50]; |
| 59 | snprintf(buf, sizeof(buf), "%p", v); |
| 60 | return strdup(buf); |
| 61 | } |
| 62 | |
| 63 | char* CheckOpValueStr(std::nullptr_t v) { |
| 64 | return strdup("nullptr"); |
| 65 | } |
| 66 | |
| 67 | char* CheckOpValueStr(double v) { |
| 68 | char buf[50]; |
| 69 | snprintf(buf, sizeof(buf), "%.6lf", v); |
| 70 | return strdup(buf); |
| 71 | } |
| 72 | |
| 73 | char* 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 | |
| 80 | CheckOpResult::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 |