From be99101f36a6844105cdf84ea03da4ea58963b60 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 29 Oct 2018 15:38:39 +0200 Subject: [PATCH] utils: convert sprint() to format() sprint() recently became more strict, throwing on sprint("%s", 5). Replace with the more modern format(). Mechanically converted with https://github.com/avikivity/unsprint. --- utils/UUID.hh | 2 +- utils/big_decimal.cc | 4 ++-- utils/bloom_calculations.hh | 6 +++--- utils/estimated_histogram.hh | 4 ++-- utils/flush_queue.hh | 2 +- utils/fragmented_temporary_buffer.hh | 2 +- utils/i_filter.cc | 2 +- utils/int_range.hh | 2 +- utils/logalloc.cc | 8 ++++---- utils/uuid.cc | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/utils/UUID.hh b/utils/UUID.hh index f12bc86ecc..e3248cd920 100644 --- a/utils/UUID.hh +++ b/utils/UUID.hh @@ -74,7 +74,7 @@ public: // This matches Java's UUID.toString() actual implementation. Note that // that method's documentation suggest something completely different! sstring to_sstring() const { - return sprint("%08x-%04x-%04x-%04x-%012x", + return format("{:08x}-{:04x}-{:04x}-{:04x}-{:012x}", ((uint64_t)most_sig_bits >> 32), ((uint64_t)most_sig_bits >> 16 & 0xffff), ((uint64_t)most_sig_bits & 0xffff), diff --git a/utils/big_decimal.cc b/utils/big_decimal.cc index fc3350fe98..80b1f97fd0 100644 --- a/utils/big_decimal.cc +++ b/utils/big_decimal.cc @@ -32,14 +32,14 @@ big_decimal::big_decimal(sstring_view text) static const std::regex big_decimal_re("^([\\+\\-]?)([0-9]*)(\\.([0-9]*))?([eE]([\\+\\-]?[0-9]+))?"); std::smatch sm; if (!std::regex_match(str, sm, big_decimal_re)) { - throw marshal_exception(sprint("big_decimal contains invalid characters: '%s'", str)); + throw marshal_exception(format("big_decimal contains invalid characters: '{}'", str)); } bool negative = sm[1] == "-"; auto integer = sm[2].str(); auto fraction = sm[4].str(); auto exponent = sm[6].str(); if (integer.empty() && fraction.empty()) { - throw marshal_exception(sprint("big_decimal - both integer and fraction are empty: '%s'", str)); + throw marshal_exception(format("big_decimal - both integer and fraction are empty: '{}'", str)); } integer.append(fraction); unsigned i; diff --git a/utils/bloom_calculations.hh b/utils/bloom_calculations.hh index 454c5c3132..8b91d2b24b 100644 --- a/utils/bloom_calculations.hh +++ b/utils/bloom_calculations.hh @@ -67,7 +67,7 @@ namespace bloom_calculations { bloom_specification(int k, int buckets_per_element) : K(k), buckets_per_element(buckets_per_element) { } operator sstring() { - return sprint("bloom_specification(K=%d, buckets_per_element=%d)", K, buckets_per_element); + return format("bloom_specification(K={:d}, buckets_per_element={:d})", K, buckets_per_element); } }; @@ -117,7 +117,7 @@ namespace bloom_calculations { } if (max_false_pos_prob < probs[max_buckets_per_element][max_k]) { - throw exceptions::unsupported_operation_exception(sprint("Unable to satisfy %f with %d buckets per element", max_false_pos_prob, max_buckets_per_element)); + throw exceptions::unsupported_operation_exception(format("Unable to satisfy {:f} with {:d} buckets per element", max_false_pos_prob, max_buckets_per_element)); } // First find the minimal required number of buckets: @@ -149,7 +149,7 @@ namespace bloom_calculations { v = v / num_elements; if (v < 1.0) { - throw exceptions::unsupported_operation_exception(sprint("Cannot compute probabilities for %ld elements.", num_elements)); + throw exceptions::unsupported_operation_exception(format("Cannot compute probabilities for {:d} elements.", num_elements)); } return std::min(probs.size() - 1, size_t(v)); } diff --git a/utils/estimated_histogram.hh b/utils/estimated_histogram.hh index 0499b11187..dd6c1c53f7 100644 --- a/utils/estimated_histogram.hh +++ b/utils/estimated_histogram.hh @@ -421,13 +421,13 @@ public: s += "-Inf"; } } else { - s += sprint("%d", bucket_offsets[index - 1] + 1); + s += format("{:d}", bucket_offsets[index - 1] + 1); } s += ".."; if (index == bucket_offsets.size()) { s += "Inf"; } else { - s += sprint("%d", bucket_offsets[index]); + s += format("{:d}", bucket_offsets[index]); } s += "]"; return s; diff --git a/utils/flush_queue.hh b/utils/flush_queue.hh index 0b307ee5c3..81213ea721 100644 --- a/utils/flush_queue.hh +++ b/utils/flush_queue.hh @@ -103,7 +103,7 @@ public: // uphold the guarantee to enforce ordered "post" execution // and signalling of all larger elements. if (!_map.empty() && !_map.count(rp) && rp < _map.rbegin()->first) { - throw std::invalid_argument(sprint("Attempting to insert key out of order: %s", rp)); + throw std::invalid_argument(format("Attempting to insert key out of order: {}", rp)); } _gate.enter(); diff --git a/utils/fragmented_temporary_buffer.hh b/utils/fragmented_temporary_buffer.hh index 814c906c8e..8e4f93a417 100644 --- a/utils/fragmented_temporary_buffer.hh +++ b/utils/fragmented_temporary_buffer.hh @@ -290,7 +290,7 @@ public: struct default_exception_thrower { [[noreturn]] [[gnu::cold]] static void throw_out_of_range(size_t attempted_read, size_t actual_left) { - throw std::out_of_range(sprint("attempted to read %d bytes from a %d byte buffer", attempted_read, actual_left)); + throw std::out_of_range(format("attempted to read {:d} bytes from a {:d} byte buffer", attempted_read, actual_left)); } }; GCC6_CONCEPT(static_assert(fragmented_temporary_buffer_concepts::ExceptionThrower)); diff --git a/utils/i_filter.cc b/utils/i_filter.cc index 81cf335c0e..aa93f8cd50 100644 --- a/utils/i_filter.cc +++ b/utils/i_filter.cc @@ -32,7 +32,7 @@ filter_ptr i_filter::get_filter(int64_t num_elements, double max_false_pos_proba assert(seastar::thread::running_in_thread()); if (max_false_pos_probability > 1.0) { - throw std::invalid_argument(sprint("Invalid probability %f: must be lower than 1.0", max_false_pos_probability)); + throw std::invalid_argument(format("Invalid probability {:f}: must be lower than 1.0", max_false_pos_probability)); } if (max_false_pos_probability == 1.0) { diff --git a/utils/int_range.hh b/utils/int_range.hh index ecc405bf00..a217c54bf4 100644 --- a/utils/int_range.hh +++ b/utils/int_range.hh @@ -49,7 +49,7 @@ stdx::optional intersection(const int_range& a, const int_range& b) { inline int_range make_int_range(int start_inclusive, int end_exclusive) { if (end_exclusive <= start_inclusive) { - throw std::runtime_error(sprint("invalid range: [%d, %d)", start_inclusive, end_exclusive)); + throw std::runtime_error(format("invalid range: [{:d}, {:d})", start_inclusive, end_exclusive)); } return int_range({start_inclusive}, {end_exclusive - 1}); } diff --git a/utils/logalloc.cc b/utils/logalloc.cc index f367850ecf..10470b1c67 100644 --- a/utils/logalloc.cc +++ b/utils/logalloc.cc @@ -1114,13 +1114,13 @@ class region_impl final : public basic_region_impl { friend std::ostream& operator<<(std::ostream& out, const object_descriptor& desc) { if (!desc.is_live()) { - return out << sprint("{free %d}", desc.dead_size()); + return out << format("{{free {:d}}}", desc.dead_size()); } else { auto m = desc.migrator(); auto x = reinterpret_cast(&desc) + sizeof(desc); x = align_up(x, m->align()); auto obj = reinterpret_cast(x); - return out << sprint("{migrator=%p, alignment=%d, size=%d}", + return out << format("{{migrator={:p}, alignment={:d}, size={:d}}}", (void*)m, m->align(), m->size(obj)); } } @@ -1759,7 +1759,7 @@ const eviction_fn& region::evictor() const { } std::ostream& operator<<(std::ostream& out, const occupancy_stats& stats) { - return out << sprint("%.2f%%, %d / %d [B]", + return out << format("{:.2f}%, {:d} / {:d} [B]", stats.used_fraction() * 100, stats.used_space(), stats.total_space()); } @@ -1867,7 +1867,7 @@ struct reclaim_timer { auto bytes_per_second = static_cast(released) / std::chrono::duration_cast>(duration).count(); timing_logger.debug("Reclamation cycle took {} us. Reclamation rate = {} MiB/s", std::chrono::duration_cast>(duration).count(), - sprint("%.3f", bytes_per_second / (1024*1024))); + format("{:.3f}", bytes_per_second / (1024*1024))); } } }; diff --git a/utils/uuid.cc b/utils/uuid.cc index 3cc68b0fdb..4892c68bc9 100644 --- a/utils/uuid.cc +++ b/utils/uuid.cc @@ -55,7 +55,7 @@ UUID::UUID(sstring_view uuid) { boost::erase_all(uuid_string, "-"); auto size = uuid_string.size() / 2; if (size != 16) { - throw marshal_exception(sprint("UUID string size mismatch: '%s'", uuid)); + throw marshal_exception(format("UUID string size mismatch: '{}'", uuid)); } sstring most = sstring(uuid_string.begin(), uuid_string.begin() + size); sstring least = sstring(uuid_string.begin() + size, uuid_string.end());