[PATCH] D63961: [clangd][xpc] pass the LSP value using data instead of string
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 15:56:35 PDT 2019
arphaman updated this revision to Diff 207164.
arphaman added a comment.
Added missing `xpc_release` in the test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63961/new/
https://reviews.llvm.org/D63961
Files:
clang-tools-extra/clangd/unittests/xpc/ConversionTests.cpp
clang-tools-extra/clangd/xpc/Conversion.cpp
Index: clang-tools-extra/clangd/xpc/Conversion.cpp
===================================================================
--- clang-tools-extra/clangd/xpc/Conversion.cpp
+++ clang-tools-extra/clangd/xpc/Conversion.cpp
@@ -19,14 +19,21 @@
xpc_object_t jsonToXpc(const json::Value &JSON) {
const char *const Key = "LSP";
- xpc_object_t PayloadObj = xpc_string_create(llvm::to_string(JSON).c_str());
+ std::string Str = llvm::to_string(JSON);
+ xpc_object_t PayloadObj = xpc_data_create(Str.data(), Str.size());
return xpc_dictionary_create(&Key, &PayloadObj, 1);
}
json::Value xpcToJson(const xpc_object_t &XPCObject) {
if (xpc_get_type(XPCObject) == XPC_TYPE_DICTIONARY) {
- const char *const LSP = xpc_dictionary_get_string(XPCObject, "LSP");
- auto Json = json::parse(llvm::StringRef(LSP));
+ size_t Length;
+ const char *LSP =
+ (const char *)xpc_dictionary_get_data(XPCObject, "LSP", &Length);
+ if (!LSP) {
+ elog("ignoring non-LSP XPC message");
+ return json::Value(nullptr);
+ }
+ auto Json = json::parse(llvm::StringRef(LSP, Length));
if (Json)
return *Json;
else
Index: clang-tools-extra/clangd/unittests/xpc/ConversionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/xpc/ConversionTests.cpp
+++ clang-tools-extra/clangd/unittests/xpc/ConversionTests.cpp
@@ -30,6 +30,13 @@
}
}
+TEST(JsonXpcConversionTest, IgnoreNonLSPDictionary) {
+ xpc_object_t EmptyDict = xpc_dictionary_create(nullptr, nullptr, 0);
+ json::Value Val = xpcToJson(EmptyDict);
+ ASSERT_EQ(Val.kind(), json::Value::Null);
+ xpc_release(EmptyDict);
+}
+
} // namespace
} // namespace clangd
} // namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63961.207164.patch
Type: text/x-patch
Size: 1740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190628/c5a01c7e/attachment.bin>
More information about the cfe-commits
mailing list