From 2843487db5a9c9cfe55f6df87699cb9c576a6800 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 24 Feb 2017 20:56:43 +0000 Subject: [PATCH] [Orc][RPC] Accept both const char* and char* arguments for string serialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296168 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/ExecutionEngine/Orc/RawByteChannel.h | 10 +++-- .../ExecutionEngine/Orc/RPCUtilsTest.cpp | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/include/llvm/ExecutionEngine/Orc/RawByteChannel.h b/include/llvm/ExecutionEngine/Orc/RawByteChannel.h index ce01c663afe..39753edaefc 100644 --- a/include/llvm/ExecutionEngine/Orc/RawByteChannel.h +++ b/include/llvm/ExecutionEngine/Orc/RawByteChannel.h @@ -142,10 +142,12 @@ public: } }; -template -class SerializationTraits::value>::type> { +template +class SerializationTraits::value && + (std::is_same::value || + std::is_same::value)>::type> { public: static Error serialize(RawByteChannel &C, const char *S) { return SerializationTraits::serialize(C, diff --git a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp index f1fce9d6f21..355d20b4f78 100644 --- a/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp +++ b/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp @@ -120,6 +120,11 @@ namespace DummyRPCAPI { static const char* getName() { return "IntInt"; } }; + class VoidString : public Function { + public: + static const char* getName() { return "VoidString"; } + }; + class AllTheTypes : public Function( + [](const std::string &S) { + EXPECT_EQ(S, "hello") + << "Server void(std::string) received unexpected result"; + }); + + // Poke the server to handle the negotiate call. + for (int I = 0; I < 4; ++I) { + auto Err = Server.handleOne(); + EXPECT_FALSE(!!Err) << "Server failed to handle call"; + } + }); + + { + // Make an call using a std::string. + auto Err = Client.callB(std::string("hello")); + EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)"; + } + + { + // Make an call using a std::string. + auto Err = Client.callB(StringRef("hello")); + EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)"; + } + + { + // Make an call using a std::string. + auto Err = Client.callB("hello"); + EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(string)"; + } + + ServerThread.join(); +} + TEST(DummyRPC, TestSerialization) { Queue Q1, Q2; DummyRPCEndpoint Client(Q1, Q2); -- 2.50.1