r241789 - Add clang_free to libclang to free memory allocated in libclang.
Yaron Keren
yaron.keren at gmail.com
Thu Jul 9 00:53:24 PDT 2015
Author: yrnkrn
Date: Thu Jul 9 02:53:23 2015
New Revision: 241789
URL: http://llvm.org/viewvc/llvm-project?rev=241789&view=rev
Log:
Add clang_free to libclang to free memory allocated in libclang.
One of the problems libclang tests has running under Windows is memory
allocated in libclang.dll but being freed in the test executable, possibly
by a different memory manager. This patch exposes a new export function,
clang_free(), used to free any allocated memory with the same libclang.dll
memory manager that allocated the memory.
http://reviews.llvm.org/D10949
Reviewed by Reid Kleckner, Douglas Gregor.
Modified:
cfe/trunk/include/clang-c/BuildSystem.h
cfe/trunk/tools/libclang/BuildSystem.cpp
cfe/trunk/tools/libclang/libclang.exports
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=241789&r1=241788&r2=241789&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/BuildSystem.h (original)
+++ cfe/trunk/include/clang-c/BuildSystem.h Thu Jul 9 02:53:23 2015
@@ -73,7 +73,7 @@ clang_VirtualFileOverlay_setCaseSensitiv
*
* \param options is reserved, always pass 0.
* \param out_buffer_ptr pointer to receive the buffer pointer, which should be
- * disposed using \c free().
+ * disposed using \c clang_free().
* \param out_buffer_size pointer to receive the buffer size.
* \returns 0 for success, non-zero to indicate an error.
*/
@@ -83,6 +83,14 @@ clang_VirtualFileOverlay_writeToBuffer(C
unsigned *out_buffer_size);
/**
+ * \brief free memory allocated by libclang, such as the buffer returned by
+ * \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer().
+ *
+ * \param buffer memory pointer to free.
+ */
+CINDEX_LINKAGE void clang_free(void *buffer);
+
+/**
* \brief Dispose a \c CXVirtualFileOverlay object.
*/
CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay);
@@ -122,7 +130,7 @@ clang_ModuleMapDescriptor_setUmbrellaHea
*
* \param options is reserved, always pass 0.
* \param out_buffer_ptr pointer to receive the buffer pointer, which should be
- * disposed using \c free().
+ * disposed using \c clang_free().
* \param out_buffer_size pointer to receive the buffer size.
* \returns 0 for success, non-zero to indicate an error.
*/
Modified: cfe/trunk/tools/libclang/BuildSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/BuildSystem.cpp?rev=241789&r1=241788&r2=241789&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/BuildSystem.cpp (original)
+++ cfe/trunk/tools/libclang/BuildSystem.cpp Thu Jul 9 02:53:23 2015
@@ -84,6 +84,10 @@ clang_VirtualFileOverlay_writeToBuffer(C
return CXError_Success;
}
+void clang_free(void *buffer) {
+ free(buffer);
+}
+
void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay VFO) {
delete unwrap(VFO);
}
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=241789&r1=241788&r2=241789&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Jul 9 02:53:23 2015
@@ -132,6 +132,7 @@ clang_findIncludesInFileWithBlock
clang_findReferencesInFile
clang_findReferencesInFileWithBlock
clang_formatDiagnostic
+clang_free
clang_getArgType
clang_getArrayElementType
clang_getArraySize
Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=241789&r1=241788&r2=241789&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Jul 9 02:53:23 2015
@@ -63,7 +63,7 @@ struct TestVFO {
clang_VirtualFileOverlay_writeToBuffer(VFO, 0, &BufPtr, &BufSize);
std::string BufStr(BufPtr, BufSize);
EXPECT_STREQ(Contents, BufStr.c_str());
- free(BufPtr);
+ clang_free(BufPtr);
}
clang_VirtualFileOverlay_dispose(VFO);
}
@@ -345,7 +345,7 @@ TEST(libclang, ModuleMapDescriptor) {
clang_ModuleMapDescriptor_writeToBuffer(MMD, 0, &BufPtr, &BufSize);
std::string BufStr(BufPtr, BufSize);
EXPECT_STREQ(Contents, BufStr.c_str());
- free(BufPtr);
+ clang_free(BufPtr);
clang_ModuleMapDescriptor_dispose(MMD);
}
More information about the cfe-commits
mailing list