Skip to content

Commit 10ac9c8

Browse files
author
Tor Didriksen
committed
Bug#38434120 Add support for recent versions of protobuf
Homebrew on macOS currently has protoc 6.32.1. It will generate functions returning std::string_view, or absl::string_view, rather than std::string. see https://protobuf.dev/editions/features/#string_type We have application code which assume std::string. The fix is to convert string_view to string where necessary. Our .proto files should probably be upgraded at some point, but for now, fix the application code instead. Note that our "bundled" protobuf will likely be upgraded to something similar to what Homebrew has now. Change-Id: Ib2a39c69afd0e37c1e38dd20a8a9b1ece6d73903 (cherry picked from commit 61cbee439476c65a7fb9f7b79871e638f64b39e9)
1 parent b11bfbf commit 10ac9c8

File tree

13 files changed

+49
-46
lines changed

13 files changed

+49
-46
lines changed

plugin/x/client/xprotocol_impl.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ std::unique_ptr<XProtocol::Message> Protocol_impl::deserialize_message(
782782
DBUG_LOG("debug", "Deserialize message: " << ret_val->GetTypeName());
783783
if (!ret_val->ParseFromCodedStream(input_stream)) {
784784
std::string error_message(ERR_MSG_MESSAGE_NOT_INITIALIZED);
785-
error_message += "Name:" + ret_val->GetTypeName() + ", ";
785+
error_message += "Name:" + std::string(ret_val->GetTypeName()) + ", ";
786786
error_message += ret_val->InitializationErrorString();
787787
*out_error = XError(CR_MALFORMED_PACKET, error_message);
788788

@@ -816,7 +816,7 @@ std::unique_ptr<XProtocol::Message> Protocol_impl::deserialize_received_message(
816816

817817
if (!ret_val->IsInitialized()) {
818818
std::string err(ERR_MSG_MESSAGE_NOT_INITIALIZED);
819-
err += "Name:" + ret_val->GetTypeName() + ", ";
819+
err += "Name:" + std::string(ret_val->GetTypeName()) + ", ";
820820
err += ret_val->InitializationErrorString();
821821
*out_error = XError(CR_MALFORMED_PACKET, err);
822822

@@ -1122,7 +1122,7 @@ XProtocol::Message *Protocol_impl::recv_message_with_header(
11221122

11231123
if (!m_compressed.ParseFromCodedStream(&cis)) {
11241124
std::string error_message(ERR_MSG_MESSAGE_NOT_INITIALIZED);
1125-
error_message += "Name:" + m_compressed.GetTypeName() + ", ";
1125+
error_message += "Name:" + std::string(m_compressed.GetTypeName()) + ", ";
11261126
error_message += m_compressed.InitializationErrorString();
11271127
*out_error = XError(CR_MALFORMED_PACKET, error_message);
11281128
return nullptr;

plugin/x/protocol/plugin/encoder_file_output.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Encoder_file_output : public File_output {
7979
return;
8080

8181
write_to_context(context, "");
82-
write_to_context(context, "struct ", message->name(), " {");
82+
write_to_context(context, "struct ", std::string(message->name()), " {");
8383

8484
if (message->options().HasExtension(Mysqlx::server_message_id)) {
8585
const auto server_id_numeric = static_cast<int>(
@@ -97,7 +97,8 @@ class Encoder_file_output : public File_output {
9797
bool is_reserved = false;
9898
const auto field = message->field(i);
9999
const auto field_tag = std::to_string(field->number());
100-
const auto field_name = get_cpp_field_name(field->name(), &is_reserved);
100+
const auto field_name =
101+
get_cpp_field_name(std::string(field->name()), &is_reserved);
101102

102103
if (is_reserved) {
103104
write_to_context(context,
@@ -129,7 +130,7 @@ class Encoder_file_output : public File_output {
129130

130131
// Check if we there is a message containing Server message ID
131132
if (0 == m_used_message_ids.count(enum_value->number())) {
132-
std::string value = " " + enum_value->name() + " = " +
133+
std::string value = " " + std::string(enum_value->name()) + " = " +
133134
std::to_string(enum_value->number());
134135

135136
values.push_back(value);

plugin/x/protocol/plugin/message_field_chain.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool Message_field_chain::begin_validate_field(const FieldDescriptor *field,
5858

5959
// Check against cycles in Message dependencies graph
6060
const bool was_node_visited =
61-
message && 0 != m_types_done.count(message->full_name());
61+
message && 0 != m_types_done.count(std::string(message->full_name()));
6262

6363
if (nullptr == message || was_node_visited || 0 == message->field_count()) {
6464
m_output_file->append_chain(m_context, chain);
@@ -74,7 +74,7 @@ bool Message_field_chain::begin_validate_field(const FieldDescriptor *field,
7474

7575
void Message_field_chain::end_validate_field(const FieldDescriptor *field,
7676
const Descriptor *message) {
77-
m_types_done.erase(message->full_name());
77+
m_types_done.erase(std::string(message->full_name()));
7878
const auto position = m_chain.find_last_of(".");
7979

8080
if (std::string::npos != position) m_chain.resize(position);

plugin/x/protocol/plugin/messages_used_by_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ bool Messages_used_by_server::begin_validate_field(const FieldDescriptor *field,
4949
const auto &message_options = message->options();
5050

5151
if (!message_options.HasExtension(Mysqlx::server_message_id)) {
52-
if (0 == m_forced_packages.count(message->file()->package()))
52+
if (0 == m_forced_packages.count(std::string(message->file()->package())))
5353
return false;
5454
}
5555
}
5656

5757
// Check against cycles in Message dependencies graph
5858
const bool was_node_visited =
59-
message && 0 != m_types_done.count(message->full_name());
59+
message && 0 != m_types_done.count(std::string(message->full_name()));
6060

6161
if (nullptr == message || was_node_visited) {
6262
return false;

plugin/x/protocol/stream/decompression_input_stream.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ class Decompression_input_stream
9393
return Skip(count - left);
9494
}
9595

96-
google::protobuf::int64 ByteCount() const override {
97-
return m_all + m_output_buffer_offset;
98-
}
96+
int64_t ByteCount() const override { return m_all + m_output_buffer_offset; }
9997

10098
private:
10199
bool ReadCompressed() {

plugin/x/src/io/vio_input_stream.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ bool Vio_input_stream::Skip(int count) {
141141
return true;
142142
}
143143

144-
Vio_input_stream::gint64 Vio_input_stream::ByteCount() const {
145-
return m_bytes_count;
146-
}
144+
int64_t Vio_input_stream::ByteCount() const { return m_bytes_count; }
147145

148146
bool Vio_input_stream::peek_data(const void **data, int *size) {
149147
if (m_buffer_data_pos < m_buffer_data_count) {

plugin/x/src/io/vio_input_stream.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828

2929
#include <google/protobuf/io/zero_copy_stream.h>
3030
#include <my_inttypes.h>
31+
#include <cstdint>
3132
#include <memory>
3233

3334
#include "plugin/x/src/interface/vio.h"
3435

3536
namespace xpl {
3637

3738
class Vio_input_stream : public google::protobuf::io::ZeroCopyInputStream {
38-
public:
39-
using gint64 = google::protobuf::int64;
40-
4139
public:
4240
explicit Vio_input_stream(const std::shared_ptr<iface::Vio> &connection);
4341
~Vio_input_stream() override;
@@ -58,7 +56,7 @@ class Vio_input_stream : public google::protobuf::io::ZeroCopyInputStream {
5856
bool Next(const void **data, int *size) override;
5957
void BackUp(int count) override;
6058
bool Skip(int count) override;
61-
gint64 ByteCount() const override;
59+
int64_t ByteCount() const override;
6260

6361
private:
6462
bool read_more_data();

plugin/x/src/ngs/protocol_encoder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void Protocol_encoder::log_protobuf(const unsigned id,
257257
}
258258
#else
259259
log_debug("%u: %s, Type: %s", id, direction_name,
260-
message->GetTypeName().c_str());
260+
std::string(message->GetTypeName()).c_str());
261261
#endif
262262
}
263263

plugin/x/src/prepare_param_handler.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ ngs::Error_code Prepare_param_handler::prepare_parameters(
147147
"' and of type '%s' is not supported for binding"
148148
" to prepared statement",
149149
ph.m_id,
150-
arg.has_scalar() ? arg.scalar().GetTypeName().c_str()
151-
: arg.GetTypeName().c_str());
150+
arg.has_scalar()
151+
? std::string(arg.scalar().GetTypeName()).c_str()
152+
: std::string(arg.GetTypeName()).c_str());
152153
}
153154
}
154155
return ngs::Success();

plugin/x/tests/driver/connector/session_holder.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,24 @@ xcl::Handler_result Session_holder::count_received_messages(
357357
const auto server_message_name =
358358
Mysqlx::ServerMessages::descriptor()->full_name();
359359
const bool is_empty_message = (protobuf_message_name == server_message_name);
360-
const std::string &msg_name = !is_empty_message
361-
? msg.GetDescriptor()->full_name()
362-
: server_msgs_by_id[msg_id].second;
360+
const std::string &msg_name =
361+
!is_empty_message ? std::string(msg.GetDescriptor()->full_name())
362+
: server_msgs_by_id[msg_id].second;
363363

364364
++m_received_msg_counters[msg_name];
365365

366366
if (msg_name != Mysqlx::Notice::Frame::descriptor()->full_name())
367367
return xcl::Handler_result::Continue;
368368

369369
static const std::array<std::string, 5> k_notice_type_id = {
370-
Mysqlx::Notice::Warning::descriptor()->full_name(),
371-
Mysqlx::Notice::SessionVariableChanged::descriptor()->full_name(),
372-
Mysqlx::Notice::SessionStateChanged::descriptor()->full_name(),
373-
Mysqlx::Notice::GroupReplicationStateChanged::descriptor()->full_name(),
374-
Mysqlx::Notice::ServerHello::descriptor()->full_name(),
370+
std::string(Mysqlx::Notice::Warning::descriptor()->full_name()),
371+
std::string(
372+
Mysqlx::Notice::SessionVariableChanged::descriptor()->full_name()),
373+
std::string(
374+
Mysqlx::Notice::SessionStateChanged::descriptor()->full_name()),
375+
std::string(Mysqlx::Notice::GroupReplicationStateChanged::descriptor()
376+
->full_name()),
377+
std::string(Mysqlx::Notice::ServerHello::descriptor()->full_name()),
375378
};
376379

377380
const auto notice_type =

0 commit comments

Comments
 (0)