THRIFT-5817: [C++] Avoid copy of TUuid
Client: cpp
Patch: Carel Combrink
This closes #3038
diff --git a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
index c0767c3..5777b27 100644
--- a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
@@ -274,9 +274,12 @@
bool is_complex_type(t_type* ttype) {
ttype = get_true_type(ttype);
- return ttype->is_container() || ttype->is_struct() || ttype->is_xception()
+ return ttype->is_container() //
+ || ttype->is_struct() //
+ || ttype->is_xception()
|| (ttype->is_base_type()
- && (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING));
+ && ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING)
+ || (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_UUID)));
}
void set_use_include_prefix(bool use_include_prefix) { use_include_prefix_ = use_include_prefix; }
@@ -4498,7 +4501,7 @@
return bname;
}
- if (((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING) {
+ if ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_STRING) || ((((t_base_type*)ttype)->get_base() == t_base_type::TYPE_UUID))) {
return "const " + bname + "&";
} else {
return "const " + bname;
diff --git a/lib/c_glib/test/testthrifttestclient.cpp b/lib/c_glib/test/testthrifttestclient.cpp
index 513f071..745feb7 100644
--- a/lib/c_glib/test/testthrifttestclient.cpp
+++ b/lib/c_glib/test/testthrifttestclient.cpp
@@ -112,9 +112,9 @@
out = thing;
}
- apache::thrift::TUuid testUuid(const apache::thrift::TUuid thing) override {
+ void testUuid(apache::thrift::TUuid& out, const apache::thrift::TUuid& thing) override {
cout << "[C -> C++] testUuid(\"" << thing << "\")" << '\n';
- return thing;
+ out = thing;
}
void testStruct(Xtruct& out, const Xtruct &thing) override {
diff --git a/lib/c_glib/test/testthrifttestzlibclient.cpp b/lib/c_glib/test/testthrifttestzlibclient.cpp
index dbcd64e..783d065 100644
--- a/lib/c_glib/test/testthrifttestzlibclient.cpp
+++ b/lib/c_glib/test/testthrifttestzlibclient.cpp
@@ -107,9 +107,9 @@
out = thing;
}
- apache::thrift::TUuid testUuid(const apache::thrift::TUuid thing) override {
+ void testUuid(apache::thrift::TUuid& out, const apache::thrift::TUuid& thing) override {
cout << "[C -> C++] testUuid(\"" << thing << "\")" << '\n';
- return thing;
+ out = thing;
}
void testStruct(Xtruct& out, const Xtruct &thing) override {
@@ -297,7 +297,7 @@
}
void testException(const std::string &arg)
- throw(Xception, apache::thrift::TException) override
+ noexcept(false) override
{
cout << "[C -> C++] testException(" << arg << ")" << '\n';
if (arg.compare("Xception") == 0) {
@@ -315,7 +315,7 @@
}
}
- void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) override {
+ void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) noexcept(false) override {
cout << "[C -> C++] testMultiException(" << arg0 << ", " << arg1 << ")" << '\n';
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index 6bda294..64193c6 100644
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -181,7 +181,9 @@
#define UUID_TEST(func, value, expected) \
cout << #func "(" << value << ") = "; \
try { \
- if (!print_eq(expected, testClient.func(value))) \
+ TUuid ret; \
+ testClient.func(ret, value); \
+ if (!print_eq(expected, ret)) \
return_code |= ERR_BASETYPES; \
} catch (TTransportException&) { \
throw; \
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index dc6e69f..858fffa 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -132,9 +132,9 @@
_return = thing;
}
- TUuid testUuid(const TUuid thing) override {
+ void testUuid(apache::thrift::TUuid& _return, const apache::thrift::TUuid& thing) override {
printf("testUuid(\"{%s}\")\n", to_string(thing).c_str());
- return thing;
+ _return = thing;
}
void testStruct(Xtruct& out, const Xtruct& thing) override {
@@ -447,8 +447,9 @@
cob(res);
}
- void testUuid(::std::function<void(TUuid const& _return)> cob, const TUuid thing) override {
- TUuid res = _delegate->testUuid(thing);
+ void testUuid(::std::function<void(apache::thrift::TUuid const& _return)> cob, const apache::thrift::TUuid& thing) override {
+ TUuid res;
+ _delegate->testUuid(res, thing);
cob(res);
}