at master 7.9 kB view raw
1diff --git a/include/my_char_traits.h b/include/my_char_traits.h 2new file mode 100644 3index 00000000000..6336bc039c8 4--- /dev/null 5+++ b/include/my_char_traits.h 6@@ -0,0 +1,65 @@ 7+/* Copyright (c) 2024, Oracle and/or its affiliates. 8+ 9+ This program is free software; you can redistribute it and/or modify 10+ it under the terms of the GNU General Public License, version 2.0, 11+ as published by the Free Software Foundation. 12+ 13+ This program is designed to work with certain software (including 14+ but not limited to OpenSSL) that is licensed under separate terms, 15+ as designated in a particular file or component or in included license 16+ documentation. The authors of MySQL hereby grant you an additional 17+ permission to link the program and your derivative works with the 18+ separately licensed software that they have either included with 19+ the program or referenced in the documentation. 20+ 21+ This program is distributed in the hope that it will be useful, 22+ but WITHOUT ANY WARRANTY; without even the implied warranty of 23+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24+ GNU General Public License, version 2.0, for more details. 25+ 26+ You should have received a copy of the GNU General Public License 27+ along with this program; if not, write to the Free Software 28+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 29+ 30+#ifndef MY_CHAR_TRAITS_INCLUDED 31+#define MY_CHAR_TRAITS_INCLUDED 32+ 33+#include <cstring> 34+ 35+template <class CharT> 36+struct my_char_traits; 37+ 38+/* 39+ This is a standards-compliant, drop-in replacement for 40+ std::char_traits<unsigned char> 41+ We need this because clang libc++ is removing support for it in clang 19. 42+ It is not a complete implementation. Rather we implement just enough to 43+ compile any usage of char_traits<uchar> we have in our codebase. 44+ */ 45+template <> 46+struct my_char_traits<unsigned char> { 47+ using char_type = unsigned char; 48+ using int_type = unsigned int; 49+ 50+ static void assign(char_type &c1, const char_type &c2) { c1 = c2; } 51+ 52+ static char_type *assign(char_type *s, std::size_t n, char_type a) { 53+ return static_cast<char_type *>(memset(s, a, n)); 54+ } 55+ 56+ static int compare(const char_type *s1, const char_type *s2, std::size_t n) { 57+ return memcmp(s1, s2, n); 58+ } 59+ 60+ static char_type *move(char_type *s1, const char_type *s2, std::size_t n) { 61+ if (n == 0) return s1; 62+ return static_cast<char_type *>(memmove(s1, s2, n)); 63+ } 64+ 65+ static char_type *copy(char_type *s1, const char_type *s2, std::size_t n) { 66+ if (n == 0) return s1; 67+ return static_cast<char_type *>(memcpy(s1, s2, n)); 68+ } 69+}; 70+ 71+#endif // MY_CHAR_TRAITS_INCLUDED 72diff --git a/sql/mdl_context_backup.h b/sql/mdl_context_backup.h 73index 89e7e23df34..cf9c307ec2d 100644 74--- a/sql/mdl_context_backup.h 75+++ b/sql/mdl_context_backup.h 76@@ -28,6 +28,7 @@ 77 #include <map> 78 #include <memory> 79 80+#include "my_char_traits.h" 81 #include "sql/malloc_allocator.h" 82 #include "sql/mdl.h" 83 84@@ -47,7 +48,8 @@ class MDL_context_backup_manager { 85 /** 86 Key for uniquely identifying MDL_context in the MDL_context_backup map. 87 */ 88- typedef std::basic_string<uchar> MDL_context_backup_key; 89+ using MDL_context_backup_key = 90+ std::basic_string<uchar, my_char_traits<uchar>>; 91 92 class MDL_context_backup; 93 94diff --git a/sql/range_optimizer/index_range_scan_plan.cc b/sql/range_optimizer/index_range_scan_plan.cc 95index 74fbb100397..8ed1f50da33 100644 96--- a/sql/range_optimizer/index_range_scan_plan.cc 97+++ b/sql/range_optimizer/index_range_scan_plan.cc 98@@ -54,6 +54,8 @@ 99 #include "sql/thr_malloc.h" 100 #include "sql_string.h" 101 102+#include "my_char_traits.h" 103+ 104 using opt_range::null_element; 105 using std::max; 106 using std::min; 107@@ -1025,8 +1027,8 @@ static bool null_part_in_key(KEY_PART *key_part, const uchar *key, 108 109 // TODO(sgunders): This becomes a bit simpler with C++20's string_view 110 // constructors. 111-static inline std::basic_string_view<uchar> make_string_view(const uchar *start, 112- const uchar *end) { 113+static inline std::basic_string_view<uchar, my_char_traits<uchar>> 114+make_string_view(const uchar *start, const uchar *end) { 115 return {start, static_cast<size_t>(end - start)}; 116 } 117 118diff --git a/sql/stream_cipher.h b/sql/stream_cipher.h 119index 606d40645c6..358fbb41959 100644 120--- a/sql/stream_cipher.h 121+++ b/sql/stream_cipher.h 122@@ -28,6 +28,8 @@ 123 #include <memory> 124 #include <string> 125 126+#include "my_char_traits.h" 127+ 128 /** 129 @file stream_cipher.h 130 131@@ -35,7 +37,8 @@ 132 binary log files. 133 */ 134 135-typedef std::basic_string<unsigned char> Key_string; 136+using Key_string = 137+ std::basic_string<unsigned char, my_char_traits<unsigned char>>; 138 139 /** 140 @class Stream_cipher 141diff --git a/unittest/gunit/binlogevents/transaction_compression-t.cc b/unittest/gunit/binlogevents/transaction_compression-t.cc 142index ba13f979aa3..01af0e3a360 100644 143--- a/unittest/gunit/binlogevents/transaction_compression-t.cc 144+++ b/unittest/gunit/binlogevents/transaction_compression-t.cc 145@@ -23,6 +23,7 @@ 146 */ 147 148 #include <array> 149+#include <string> 150 151 #include <gtest/gtest.h> 152 #include "libbinlogevents/include/binary_log.h" 153@@ -51,14 +52,13 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 154 using Managed_buffer_t = Decompressor_t::Managed_buffer_t; 155 using Size_t = Decompressor_t::Size_t; 156 using Char_t = Decompressor_t::Char_t; 157- using String_t = std::basic_string<Char_t>; 158 using Decompress_status_t = 159 binary_log::transaction::compression::Decompress_status; 160 using Compress_status_t = 161 binary_log::transaction::compression::Compress_status; 162 163- static String_t constant_data(Size_t size) { 164- return String_t(size, (Char_t)'a'); 165+ static std::string constant_data(Size_t size) { 166+ return std::string(size, (Char_t)'a'); 167 } 168 169 protected: 170@@ -69,7 +69,7 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 171 void TearDown() override {} 172 173 static void compression_idempotency_test(Compressor_t &c, Decompressor_t &d, 174- String_t data) { 175+ const std::string &data) { 176 auto debug_string = concat( 177 binary_log::transaction::compression::type_to_string(c.get_type_code()), 178 " ", data.size()); 179@@ -104,8 +104,8 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 180 181 // Check decompressed data 182 ASSERT_EQ(managed_buffer.read_part().size(), data.size()) << debug_string; 183- ASSERT_EQ(data, String_t(managed_buffer.read_part().begin(), 184- managed_buffer.read_part().end())) 185+ ASSERT_EQ(data, std::string(managed_buffer.read_part().begin(), 186+ managed_buffer.read_part().end())) 187 << debug_string; 188 189 // Check that we reached EOF 190@@ -118,7 +118,7 @@ TEST_F(TransactionPayloadCompressionTest, CompressDecompressZstdTest) { 191 for (auto size : buffer_sizes) { 192 binary_log::transaction::compression::Zstd_dec d; 193 binary_log::transaction::compression::Zstd_comp c; 194- String_t data{TransactionPayloadCompressionTest::constant_data(size)}; 195+ std::string data{TransactionPayloadCompressionTest::constant_data(size)}; 196 TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 197 c.set_compression_level(22); 198 TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 199@@ -129,7 +129,7 @@ TEST_F(TransactionPayloadCompressionTest, CompressDecompressNoneTest) { 200 for (auto size : buffer_sizes) { 201 binary_log::transaction::compression::None_dec d; 202 binary_log::transaction::compression::None_comp c; 203- String_t data{TransactionPayloadCompressionTest::constant_data(size)}; 204+ std::string data{TransactionPayloadCompressionTest::constant_data(size)}; 205 TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 206 } 207 }