diff options
Diffstat (limited to 'absl/log/internal')
-rw-r--r-- | absl/log/internal/BUILD.bazel | 2 | ||||
-rw-r--r-- | absl/log/internal/nullguard.cc | 35 | ||||
-rw-r--r-- | absl/log/internal/nullguard.h | 15 |
3 files changed, 45 insertions, 7 deletions
diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel index 08276887..a1f1a67c 100644 --- a/absl/log/internal/BUILD.bazel +++ b/absl/log/internal/BUILD.bazel @@ -226,11 +226,13 @@ cc_library( cc_library( name = "nullguard", + srcs = ["nullguard.cc"], hdrs = ["nullguard.h"], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", + "//absl/base:core_headers", ], ) diff --git a/absl/log/internal/nullguard.cc b/absl/log/internal/nullguard.cc new file mode 100644 index 00000000..7b785c55 --- /dev/null +++ b/absl/log/internal/nullguard.cc @@ -0,0 +1,35 @@ +// Copyright 2023 The Abseil Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/log/internal/nullguard.h" + +#include <array> + +#include "absl/base/attributes.h" +#include "absl/base/config.h" + +namespace absl { +ABSL_NAMESPACE_BEGIN +namespace log_internal { + +ABSL_CONST_INIT const std::array<char, 7> kCharNull{ + {'(', 'n', 'u', 'l', 'l', ')', '\0'}}; +ABSL_CONST_INIT const std::array<signed char, 7> kSignedCharNull{ + {'(', 'n', 'u', 'l', 'l', ')', '\0'}}; +ABSL_CONST_INIT const std::array<unsigned char, 7> kUnsignedCharNull{ + {'(', 'n', 'u', 'l', 'l', ')', '\0'}}; + +} // namespace log_internal +ABSL_NAMESPACE_END +} // namespace absl diff --git a/absl/log/internal/nullguard.h b/absl/log/internal/nullguard.h index 8ea38356..a0ed4ad7 100644 --- a/absl/log/internal/nullguard.h +++ b/absl/log/internal/nullguard.h @@ -27,26 +27,29 @@ #include <array> #include <cstddef> +#include "absl/base/attributes.h" #include "absl/base/config.h" namespace absl { ABSL_NAMESPACE_BEGIN namespace log_internal { +ABSL_CONST_INIT extern const std::array<char, 7> kCharNull; +ABSL_CONST_INIT extern const std::array<signed char, 7> kSignedCharNull; +ABSL_CONST_INIT extern const std::array<unsigned char, 7> kUnsignedCharNull; + template <typename T> struct NullGuard final { static const T& Guard(const T& v) { return v; } }; template <> struct NullGuard<char*> final { - static const char* Guard(const char* v) { return v ? v : "(null)"; } + static const char* Guard(const char* v) { return v ? v : kCharNull.data(); } }; template <> struct NullGuard<const char*> final { - static const char* Guard(const char* v) { return v ? v : "(null)"; } + static const char* Guard(const char* v) { return v ? v : kCharNull.data(); } }; -constexpr std::array<signed char, 7> kSignedCharNull{ - {'(', 'n', 'u', 'l', 'l', ')', '\0'}}; template <> struct NullGuard<signed char*> final { static const signed char* Guard(const signed char* v) { @@ -59,8 +62,6 @@ struct NullGuard<const signed char*> final { return v ? v : kSignedCharNull.data(); } }; -constexpr std::array<unsigned char, 7> kUnsignedCharNull{ - {'(', 'n', 'u', 'l', 'l', ')', '\0'}}; template <> struct NullGuard<unsigned char*> final { static const unsigned char* Guard(const unsigned char* v) { @@ -75,7 +76,7 @@ struct NullGuard<const unsigned char*> final { }; template <> struct NullGuard<std::nullptr_t> final { - static const char* Guard(const std::nullptr_t&) { return "(null)"; } + static const char* Guard(const std::nullptr_t&) { return kCharNull.data(); } }; } // namespace log_internal |