summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang-c/Index.h2
-rw-r--r--clang/tools/CIndex/CIndexCodeCompletion.cpp14
-rw-r--r--clang/tools/c-index-test/c-index-test.c8
3 files changed, 15 insertions, 9 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1d654c88488..146a1a636ec 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -1478,7 +1478,7 @@ clang_getCompletionChunkKind(CXCompletionString completion_string,
*
* \returns the text associated with the chunk at index \c chunk_number.
*/
-CINDEX_LINKAGE const char *
+CINDEX_LINKAGE CXString
clang_getCompletionChunkText(CXCompletionString completion_string,
unsigned chunk_number);
diff --git a/clang/tools/CIndex/CIndexCodeCompletion.cpp b/clang/tools/CIndex/CIndexCodeCompletion.cpp
index 4e41c5f1c7b..4912fef2e25 100644
--- a/clang/tools/CIndex/CIndexCodeCompletion.cpp
+++ b/clang/tools/CIndex/CIndexCodeCompletion.cpp
@@ -21,6 +21,7 @@
#include "llvm/System/Program.h"
using namespace clang;
+using namespace clang::cxstring;
extern "C" {
@@ -80,11 +81,11 @@ clang_getCompletionChunkKind(CXCompletionString completion_string,
return CXCompletionChunk_Text;
}
-const char *clang_getCompletionChunkText(CXCompletionString completion_string,
- unsigned chunk_number) {
+CXString clang_getCompletionChunkText(CXCompletionString completion_string,
+ unsigned chunk_number) {
CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
if (!CCStr || chunk_number >= CCStr->size())
- return 0;
+ return createCXString(0);
switch ((*CCStr)[chunk_number].Kind) {
case CodeCompletionString::CK_TypedText:
@@ -107,17 +108,18 @@ const char *clang_getCompletionChunkText(CXCompletionString completion_string,
case CodeCompletionString::CK_Equal:
case CodeCompletionString::CK_HorizontalSpace:
case CodeCompletionString::CK_VerticalSpace:
- return (*CCStr)[chunk_number].Text;
+ return createCXString((*CCStr)[chunk_number].Text, false);
case CodeCompletionString::CK_Optional:
// Note: treated as an empty text block.
- return "";
+ return createCXString("");
}
// Should be unreachable, but let's be careful.
- return 0;
+ return createCXString(0);
}
+
CXCompletionString
clang_getCompletionChunkCompletionString(CXCompletionString completion_string,
unsigned chunk_number) {
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 360f75a66e0..640375aaeac 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -755,7 +755,8 @@ void print_completion_string(CXCompletionString completion_string, FILE *file) {
N = clang_getNumCompletionChunks(completion_string);
for (I = 0; I != N; ++I) {
- const char *text = 0;
+ CXString text;
+ const char *cstr;
enum CXCompletionChunkKind Kind
= clang_getCompletionChunkKind(completion_string, I);
@@ -769,10 +770,13 @@ void print_completion_string(CXCompletionString completion_string, FILE *file) {
}
text = clang_getCompletionChunkText(completion_string, I);
+ cstr = clang_getCString(text);
fprintf(file, "{%s %s}",
clang_getCompletionChunkKindSpelling(Kind),
- text? text : "");
+ cstr ? cstr : "");
+ clang_disposeString(text);
}
+
}
void print_completion_result(CXCompletionResult *completion_result,
OpenPOWER on IntegriCloud