r202675 - [libclang] Change clang_VirtualFileOverlay_writeToBuffer to return a malloc'ed buffer.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Mar 2 22:38:53 PST 2014
Author: akirtzidis
Date: Mon Mar 3 00:38:52 2014
New Revision: 202675
URL: http://llvm.org/viewvc/llvm-project?rev=202675&view=rev
Log:
[libclang] Change clang_VirtualFileOverlay_writeToBuffer to return a malloc'ed buffer.
Returning CXString is not appropriate if we want to switch to a non-string format buffer.
Modified:
cfe/trunk/include/clang-c/BuildSystem.h
cfe/trunk/tools/libclang/BuildSystem.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp
Modified: cfe/trunk/include/clang-c/BuildSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/BuildSystem.h?rev=202675&r1=202674&r2=202675&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/BuildSystem.h (original)
+++ cfe/trunk/include/clang-c/BuildSystem.h Mon Mar 3 00:38:52 2014
@@ -62,13 +62,15 @@ clang_VirtualFileOverlay_addFileMapping(
* \brief Write out the \c CXVirtualFileOverlay object to a char buffer.
*
* \param options is reserved, always pass 0.
- * \param out_buffer pointer to receive the CXString object, which should be
- * disposed using \c clang_disposeString().
+ * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
+ * disposed using \c free().
+ * \param out_buffer_size pointer to receive the buffer size.
* \returns 0 for success, non-zero to indicate an error.
*/
CINDEX_LINKAGE enum CXErrorCode
clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options,
- CXString *out_buffer);
+ char **out_buffer_ptr,
+ unsigned *out_buffer_size);
/**
* \brief Dispose a \c CXVirtualFileOverlay object.
Modified: cfe/trunk/tools/libclang/BuildSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/BuildSystem.cpp?rev=202675&r1=202674&r2=202675&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/BuildSystem.cpp (original)
+++ cfe/trunk/tools/libclang/BuildSystem.cpp Mon Mar 3 00:38:52 2014
@@ -162,9 +162,10 @@ private:
}
enum CXErrorCode
-clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay VFO,
- unsigned, CXString *out_buffer) {
- if (!VFO || !out_buffer)
+clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay VFO, unsigned,
+ char **out_buffer_ptr,
+ unsigned *out_buffer_size) {
+ if (!VFO || !out_buffer_ptr || !out_buffer_size)
return CXError_InvalidArguments;
llvm::SmallVector<EntryTy, 16> Entries;
@@ -186,7 +187,10 @@ clang_VirtualFileOverlay_writeToBuffer(C
JSONVFSPrinter Printer(OS);
Printer.print(Entries);
- *out_buffer = cxstring::createDup(OS.str());
+ StringRef Data = OS.str();
+ *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_size = Data.size();
+ memcpy(*out_buffer_ptr, Data.data(), Data.size());
return CXError_Success;
}
Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=202675&r1=202674&r2=202675&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Mon Mar 3 00:38:52 2014
@@ -51,10 +51,12 @@ struct TestVFO {
~TestVFO() {
if (!Contents)
return;
- CXString Buf;
- clang_VirtualFileOverlay_writeToBuffer(VFO, 0, &Buf);
- EXPECT_STREQ(Contents, clang_getCString(Buf));
- clang_disposeString(Buf);
+ char *BufPtr;
+ unsigned BufSize;
+ clang_VirtualFileOverlay_writeToBuffer(VFO, 0, &BufPtr, &BufSize);
+ std::string BufStr(BufPtr, BufSize);
+ EXPECT_STREQ(Contents, BufStr.c_str());
+ free(BufPtr);
clang_VirtualFileOverlay_dispose(VFO);
}
};
More information about the cfe-commits
mailing list