[llvm] r296168 - [Orc][RPC] Accept both const char* and char* arguments for string serialization.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 09:00:39 PST 2017


Maybe std::is_convertible would be a more general fix than several is_same
checks? (could handle any string-like thing indirectly by "is_convertible"
to StringRef, for example? (that'd handle char*, const char*, (even const
volatile char*), std::string, etc) - not sure if you want to support
std::string here, I don't have quite enough context)

On Fri, Feb 24, 2017 at 1:08 PM Lang Hames via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: lhames
> Date: Fri Feb 24 14:56:43 2017
> New Revision: 296168
>
> URL: http://llvm.org/viewvc/llvm-project?rev=296168&view=rev
> Log:
> [Orc][RPC] Accept both const char* and char* arguments for string
> serialization.
>
>
> Modified:
>     llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h
>     llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
>
> Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h?rev=296168&r1=296167&r2=296168&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h (original)
> +++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h Fri Feb
> 24 14:56:43 2017
> @@ -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,
>
> Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=296168&r1=296167&r2=296168&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp (original)
> +++ llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp Fri Feb 24
> 14:56:43 2017
> @@ -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,
> @@ -338,6 +343,46 @@ TEST(DummyRPC, TestAsyncIntIntHandlerMet
>    }
>
>    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) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170227/e786584b/attachment-0001.html>


More information about the llvm-commits mailing list