]> granicus.if.org Git - clang/commitdiff
Add clang_free to libclang to free memory allocated in libclang.
authorYaron Keren <yaron.keren@gmail.com>
Thu, 9 Jul 2015 07:53:23 +0000 (07:53 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Thu, 9 Jul 2015 07:53:23 +0000 (07:53 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241789 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/BuildSystem.h
tools/libclang/BuildSystem.cpp
tools/libclang/libclang.exports
unittests/libclang/LibclangTest.cpp

index 7aa01914cf244580ee2068248c4d95f09e99eda7..8d323a4e6cae3f0f6dc45367e3427482ddbe7b05 100644 (file)
@@ -73,7 +73,7 @@ clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay,
  *
  * \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.
  */
@@ -82,6 +82,14 @@ clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options,
                                        char **out_buffer_ptr,
                                        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.
  */
@@ -122,7 +130,7 @@ clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor,
  *
  * \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.
  */
index e9423c3286988fb7a8de1ff538f495d4d24b5a6b..fe3db755eba83dd8cc490a12d55afd5c4794980b 100644 (file)
@@ -84,6 +84,10 @@ clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay VFO, unsigned,
   return CXError_Success;
 }
 
+void clang_free(void *buffer) {
+  free(buffer);
+}
+
 void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay VFO) {
   delete unwrap(VFO);
 }
index f78f9981a98bd9ec47b25123ff47124d021684a3..f6a7175579aa3715a279a5ba403882ffd8d43612 100644 (file)
@@ -132,6 +132,7 @@ clang_findIncludesInFileWithBlock
 clang_findReferencesInFile
 clang_findReferencesInFileWithBlock
 clang_formatDiagnostic
+clang_free
 clang_getArgType
 clang_getArrayElementType
 clang_getArraySize
index e827ebc0da86bc9dd24f4f99feb95a8274bb989c..becebf076d61c78536f7afc96cf890b0aa142cc4 100644 (file)
@@ -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);
 }