<div dir="ltr">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)</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 24, 2017 at 1:08 PM Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br class="gmail_msg">
Date: Fri Feb 24 14:56:43 2017<br class="gmail_msg">
New Revision: 296168<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=296168&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=296168&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
[Orc][RPC] Accept both const char* and char* arguments for string serialization.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h<br class="gmail_msg">
llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h?rev=296168&r1=296167&r2=296168&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h?rev=296168&r1=296167&r2=296168&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/RawByteChannel.h Fri Feb 24 14:56:43 2017<br class="gmail_msg">
@@ -142,10 +142,12 @@ public:<br class="gmail_msg">
}<br class="gmail_msg">
};<br class="gmail_msg">
<br class="gmail_msg">
-template <typename ChannelT><br class="gmail_msg">
-class SerializationTraits<ChannelT, std::string, const char *,<br class="gmail_msg">
- typename std::enable_if<std::is_base_of<<br class="gmail_msg">
- RawByteChannel, ChannelT>::value>::type> {<br class="gmail_msg">
+template <typename ChannelT, typename T><br class="gmail_msg">
+class SerializationTraits<ChannelT, std::string, T,<br class="gmail_msg">
+ typename std::enable_if<<br class="gmail_msg">
+ std::is_base_of<RawByteChannel, ChannelT>::value &&<br class="gmail_msg">
+ (std::is_same<T, const char*>::value ||<br class="gmail_msg">
+ std::is_same<T, char*>::value)>::type> {<br class="gmail_msg">
public:<br class="gmail_msg">
static Error serialize(RawByteChannel &C, const char *S) {<br class="gmail_msg">
return SerializationTraits<ChannelT, std::string, StringRef>::serialize(C,<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=296168&r1=296167&r2=296168&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp?rev=296168&r1=296167&r2=296168&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp (original)<br class="gmail_msg">
+++ llvm/trunk/unittests/ExecutionEngine/Orc/RPCUtilsTest.cpp Fri Feb 24 14:56:43 2017<br class="gmail_msg">
@@ -120,6 +120,11 @@ namespace DummyRPCAPI {<br class="gmail_msg">
static const char* getName() { return "IntInt"; }<br class="gmail_msg">
};<br class="gmail_msg">
<br class="gmail_msg">
+ class VoidString : public Function<VoidString, void(std::string)> {<br class="gmail_msg">
+ public:<br class="gmail_msg">
+ static const char* getName() { return "VoidString"; }<br class="gmail_msg">
+ };<br class="gmail_msg">
+<br class="gmail_msg">
class AllTheTypes<br class="gmail_msg">
: public Function<AllTheTypes,<br class="gmail_msg">
void(int8_t, uint8_t, int16_t, uint16_t, int32_t,<br class="gmail_msg">
@@ -338,6 +343,46 @@ TEST(DummyRPC, TestAsyncIntIntHandlerMet<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
ServerThread.join();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(DummyRPC, TestCallAsyncVoidString) {<br class="gmail_msg">
+ Queue Q1, Q2;<br class="gmail_msg">
+ DummyRPCEndpoint Client(Q1, Q2);<br class="gmail_msg">
+ DummyRPCEndpoint Server(Q2, Q1);<br class="gmail_msg">
+<br class="gmail_msg">
+ std::thread ServerThread([&]() {<br class="gmail_msg">
+ Server.addHandler<DummyRPCAPI::VoidString>(<br class="gmail_msg">
+ [](const std::string &S) {<br class="gmail_msg">
+ EXPECT_EQ(S, "hello")<br class="gmail_msg">
+ << "Server void(std::string) received unexpected result";<br class="gmail_msg">
+ });<br class="gmail_msg">
+<br class="gmail_msg">
+ // Poke the server to handle the negotiate call.<br class="gmail_msg">
+ for (int I = 0; I < 4; ++I) {<br class="gmail_msg">
+ auto Err = Server.handleOne();<br class="gmail_msg">
+ EXPECT_FALSE(!!Err) << "Server failed to handle call";<br class="gmail_msg">
+ }<br class="gmail_msg">
+ });<br class="gmail_msg">
+<br class="gmail_msg">
+ {<br class="gmail_msg">
+ // Make an call using a std::string.<br class="gmail_msg">
+ auto Err = Client.callB<DummyRPCAPI::VoidString>(std::string("hello"));<br class="gmail_msg">
+ EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ {<br class="gmail_msg">
+ // Make an call using a std::string.<br class="gmail_msg">
+ auto Err = Client.callB<DummyRPCAPI::VoidString>(StringRef("hello"));<br class="gmail_msg">
+ EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(std::string)";<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ {<br class="gmail_msg">
+ // Make an call using a std::string.<br class="gmail_msg">
+ auto Err = Client.callB<DummyRPCAPI::VoidString>("hello");<br class="gmail_msg">
+ EXPECT_FALSE(!!Err) << "Client.callAsync failed for void(string)";<br class="gmail_msg">
+ }<br class="gmail_msg">
+<br class="gmail_msg">
+ ServerThread.join();<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
TEST(DummyRPC, TestSerialization) {<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>