]> granicus.if.org Git - llvm/commitdiff
[Orc][RPC] Accept both const char* and char* arguments for string serialization.
authorLang Hames <lhames@gmail.com>
Fri, 24 Feb 2017 20:56:43 +0000 (20:56 +0000)
committerLang Hames <lhames@gmail.com>
Fri, 24 Feb 2017 20:56:43 +0000 (20:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296168 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/RawByteChannel.h
unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp

index ce01c663afecb6651d850b5011298d056ce5d665..39753edaefc5dd45e372b6533aa10f3c9d80c0fe 100644 (file)
@@ -142,10 +142,12 @@ public:
   }
 };
 
-template <typename ChannelT>
-class SerializationTraits<ChannelT, std::string, const char *,
-                          typename std::enable_if<std::is_base_of<
-                              RawByteChannel, ChannelT>::value>::type> {
+template <typename ChannelT, typename T>
+class SerializationTraits<ChannelT, std::string, T,
+                          typename std::enable_if<
+                            std::is_base_of<RawByteChannel, ChannelT>::value &&
+                            (std::is_same<T, const char*>::value ||
+                             std::is_same<T, char*>::value)>::type> {
 public:
   static Error serialize(RawByteChannel &C, const char *S) {
     return SerializationTraits<ChannelT, std::string, StringRef>::serialize(C,
index f1fce9d6f210d564432858df916b36c0e1bb657d..355d20b4f784e85268618dd0649b215f8790a86d 100644 (file)
@@ -120,6 +120,11 @@ namespace DummyRPCAPI {
     static const char* getName() { return "IntInt"; }
   };
 
+  class VoidString : public Function<VoidString, void(std::string)> {
+  public:
+    static const char* getName() { return "VoidString"; }
+  };
+
   class AllTheTypes
     : public Function<AllTheTypes,
                       void(int8_t, uint8_t, int16_t, uint16_t, int32_t,
@@ -340,6 +345,46 @@ TEST(DummyRPC, TestAsyncIntIntHandlerMethod) {
   ServerThread.join();
 }
 
+TEST(DummyRPC, TestCallAsyncVoidString) {
+  Queue Q1, Q2;
+  DummyRPCEndpoint Client(Q1, Q2);
+  DummyRPCEndpoint Server(Q2, Q1);
+
+  std::thread ServerThread([&]() {
+      Server.addHandler<DummyRPCAPI::VoidString>(
+          [](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<DummyRPCAPI::VoidString>(std::string("hello"));
+    EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";
+  }
+
+  {
+    // Make an call using a std::string.
+    auto Err = Client.callB<DummyRPCAPI::VoidString>(StringRef("hello"));
+    EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";
+  }
+
+  {
+    // Make an call using a std::string.
+    auto Err = Client.callB<DummyRPCAPI::VoidString>("hello");
+    EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(string)";
+  }
+
+  ServerThread.join();
+}
+
 TEST(DummyRPC, TestSerialization) {
   Queue Q1, Q2;
   DummyRPCEndpoint Client(Q1, Q2);